diff --git a/packages/core/controls.mjs b/packages/core/controls.mjs index 65b7b3748..ea928d41a 100644 --- a/packages/core/controls.mjs +++ b/packages/core/controls.mjs @@ -828,12 +828,14 @@ generic_params.forEach(([type, name, description]) => { }; return result; }; + Pattern.__registered.push(name); Pattern.prototype[name] = _setter(controls[name], name); }); // create custom param controls.createParam = (name) => { const func = (...pats) => _name(name, ...pats); + Pattern.__registered.push(name); Pattern.prototype[name] = _setter(func, name); return (...pats) => _name(name, ...pats); }; diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 65b24fe44..1bbdf1e02 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1356,6 +1356,11 @@ export function register(name, func, f_params = null) { return right.reduce(app, start).innerJoin(); }; + if (!Pattern.__registered) { + Pattern.__registered = []; + } + Pattern.__registered.push(name); + Pattern.prototype[name] = function (...args) { args = args.map(reify); // For methods that take a single argument (plus 'this'), allow diff --git a/packages/core/util.mjs b/packages/core/util.mjs index b56b23be0..132498a06 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -4,6 +4,8 @@ Copyright (C) 2022 Strudel contributors - see . */ +import { Pattern } from './pattern.mjs'; + // returns true if the given string is a note export const isNoteWithOctave = (name) => /^[a-gA-G][#bs]*[0-9]$/.test(name); export const isNote = (name) => /^[a-gA-G][#bs]*[0-9]?$/.test(name); @@ -147,17 +149,27 @@ export function curry(func, overload, arity = func.length) { return func.apply(this, args); } else { const partial = function (...args2) { - const result = curried.apply(this, args.concat(args2)); - if (args.length == arity - 1) { - // The penultimate arg.. so add some composition magic - // TODO - To make this useful, we also need to add stub functions for every pattern method to - // do the actual composing - result.__compose = function (pat) { - return result(pat); + return curried.apply(this, args.concat(args2)); + }; + + if (args.length == arity - 1) { + // The penultimate arg.. so add some composition magic + // TODO - To make this useful, we also need to add stub functions for every pattern method to + // do the actual composing + for (const r of Pattern.__registered) { + partial[r] = function (...args) { + const result = new Pattern(() => []); + result.__compose = function (pat) { + return partial(pat)[r](...args); + }; + return result; }; } - return result; - }; + partial.__compose = function (pat) { + return partial(pat); + }; + } + if (overload) { overload(partial, args); }