diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 6e294129e..464e5f233 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -21,6 +21,7 @@ import { numeralArgs, parseNumeral, pairs, + listifyOp, } from './util.mjs'; import drawLine from './drawLine.mjs'; import { logger } from './logger.mjs'; @@ -1049,7 +1050,8 @@ function _composeOp(a, b, func) { const hows = ['In', 'Out', 'Mix', 'Squeeze', 'SqueezeOut', 'Reset', 'Restart', 'Poly']; // generate methods to do what and how - for (const [what, [op, preprocess]] of Object.entries(composers)) { + for (const [what, [_op, preprocess]] of Object.entries(composers)) { + const op = listifyOp(_op); // make plain version, e.g. pat._add(value) adds that plain value // to all the values in pat Pattern.prototype['_' + what] = function (value) { diff --git a/packages/core/util.mjs b/packages/core/util.mjs index b7b1e8413..515f3792d 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -466,6 +466,16 @@ export function getCurrentKeyboardState() { return { ...keyState }; // Return a shallow copy of the key state object } +export function listifyOp(op) { + return function (a, b) { + if (!Array.isArray(a)) { + return op(a, Array.isArray(b) ? b[0] : b); + } + b = Array.isArray(b) ? b : [b]; + return a.map((x, i) => (i < b.length ? op(x, b[i]) : x)); + }; +} + // Floating point versions, see Fraction for rational versions // // greatest common divisor // export const gcd = function (x, y, ...z) {