Compare commits

...

1 Commits

Author SHA1 Message Date
alex 3568f0e437 fix ops to work with lists 2025-04-06 20:04:54 +01:00
2 changed files with 13 additions and 1 deletions
+3 -1
View File
@@ -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) {
+10
View File
@@ -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) {