mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-05 06:57:35 -04:00
fix ops to work with lists
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user