diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 9ba55e7e..217cafa3 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1277,9 +1277,9 @@ export function register(name, func) { args = args.map(reify); // For methods that take a single argument (plus 'this'), allow // multiple arguments but sequence them - if (arity == 2 && args.length != 1) { + if (arity === 2 && args.length !== 1) { args = [sequence(...args)]; - } else if (arity != args.length + 1) { + } else if (arity !== args.length + 1) { throw new Error(`.${name}() expects ${arity - 1} inputs but got ${args.length}.`); } return pfunc(...args, this); diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index d92d51fe..50e2f69e 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th */ import { Hap } from './hap.mjs'; -import { Pattern, fastcat, reify, silence, stack, isPattern } from './pattern.mjs'; +import { Pattern, fastcat, reify, silence, stack, register } from './pattern.mjs'; import Fraction from './fraction.mjs'; import { id } from './util.mjs'; @@ -276,9 +276,9 @@ Pattern.prototype._degradeByWith = function (withPat, x) { * @example * s("[hh?0.2]*8") */ -Pattern.prototype._degradeBy = function (x) { - return this._degradeByWith(rand, x); -}; +export const degradeBy = register('degradeBy', function (x, pat) { + return pat._degradeByWith(rand, x); +}); /** * @@ -292,9 +292,7 @@ Pattern.prototype._degradeBy = function (x) { * @example * s("[hh?]*8") */ -Pattern.prototype.degrade = function () { - return this._degradeBy(0.5); -}; +export const degrade = register('degrade', (pat) => pat._degradeBy(0.5)); /** * Inverse of {@link Pattern#degradeBy}: Randomly removes events from the pattern by a given amount. @@ -309,16 +307,14 @@ Pattern.prototype.degrade = function () { * @example * s("hh*8").undegradeBy(0.2) */ -Pattern.prototype._undegradeBy = function (x) { - return this._degradeByWith( +export const undegradeBy = register('undegradeBy', function (x, pat) { + return pat._degradeByWith( rand.fmap((r) => 1 - r), x, ); -}; +}); -Pattern.prototype.undegrade = function () { - return this._undegradeBy(0.5); -}; +export const undegrade = register('degrade', (pat) => pat._undegradeBy(0.5)); Pattern.prototype._sometimesBy = function (x, func) { return stack(this._degradeBy(x), func(this._undegradeBy(1 - x))); @@ -505,5 +501,3 @@ Pattern.prototype.never = function (func) { Pattern.prototype.always = function (func) { return func(this); }; - -Pattern.prototype.patternified.push('degradeBy', 'undegradeBy'); diff --git a/packages/mini/mini.mjs b/packages/mini/mini.mjs index dc9e53a3..dde3331a 100644 --- a/packages/mini/mini.mjs +++ b/packages/mini/mini.mjs @@ -178,11 +178,6 @@ export const h = (string) => { return patternifyAST(ast); }; -// shorthand for mini -Pattern.prototype.define('mini', mini, { composable: true }); -Pattern.prototype.define('m', mini, { composable: true }); -Pattern.prototype.define('h', h, { composable: true }); - export function minify(thing) { if (typeof thing === 'string') { return mini(thing);