Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
numeralArgs,
parseNumeral,
pairs,
listifyOp,
} from './util.mjs';
import drawLine from './drawLine.mjs';
import { logger } from './logger.mjs';
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading