change behaviour of polymeter, and remove polymeterSteps (#1302)

* change behaviour of polymeter, and remove polymeterSteps

* format
This commit is contained in:
Alex McLean 2025-03-04 18:17:37 +00:00 committed by GitHub
parent 86333ab6f6
commit b15843f3a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 105 deletions

View File

@ -1328,7 +1328,7 @@ export function stackBy(by, ...pats) {
left: stackLeft,
right: stackRight,
expand: stack,
repeat: (...args) => polymeterSteps(steps, ...args),
repeat: (...args) => polymeter(...args).steps(steps),
};
return by
.inhabit(lookup)
@ -2648,34 +2648,10 @@ export function _polymeterListSteps(steps, ...args) {
/**
* *Experimental*
*
* Aligns the steps of the patterns, to match the given number of steps per cycle, creating polymeters.
*
* @name polymeterSteps
* @param {number} steps how many items are placed in one cycle
* @param {any[]} patterns one or more patterns
* @example
* // the same as "{c d, e f g}%4"
* polymeterSteps(4, "c d", "e f g").note()
*/
export function polymeterSteps(steps, ...args) {
if (args.length == 0) {
return silence;
}
if (Array.isArray(args[0])) {
// Support old behaviour
return _polymeterListSteps(steps, ...args);
}
return polymeter(...args).pace(steps);
}
/**
* *Experimental*
*
* Aligns the steps of the patterns, to match the steps per cycle of the first pattern, creating polymeters. See `polymeterSteps` to set the target steps explicitly.
* Aligns the steps of the patterns, creating polymeters. The patterns are repeated until they all fit the cycle. For example, in the below the first pattern is repeated twice, and the second is repeated three times, to fit the lowest common multiple of six steps.
* @synonyms pm
* @example
* // The same as note("{c eb g, c2 g2}")
* // The same as note("{c eb g, c2 g2}%6")
* polymeter("c eb g", "c2 g2").note()
*
*/
@ -2691,13 +2667,12 @@ export function polymeter(...args) {
if (args.length == 0) {
return silence;
}
const steps = args[0]._steps;
const steps = lcm(...args.map((x) => x._steps));
if (steps.eq(Fraction(0))) {
return nothing;
}
const [head, ...tail] = args;
const result = stack(head, ...tail.map((pat) => pat._slow(pat._steps.div(steps))));
const result = stack(...args.map((x) => x.pace(steps)));
result._steps = steps;
return result;
}
@ -3065,8 +3040,6 @@ export const timeCat = stepcat;
// Deprecated stepwise aliases
export const s_cat = stepcat;
export const s_alt = stepalt;
export const s_polymeterSteps = polymeterSteps;
Pattern.prototype.s_polymeterSteps = Pattern.prototype.polymeterSteps;
export const s_polymeter = polymeter;
Pattern.prototype.s_polymeter = Pattern.prototype.polymeter;
export const s_taper = shrink;

View File

@ -22,7 +22,6 @@ import {
sequence,
palindrome,
polymeter,
polymeterSteps,
polyrhythm,
silence,
fast,
@ -611,17 +610,10 @@ describe('Pattern', () => {
});
describe('polymeter()', () => {
it('Can layer up cycles, stepwise, with lists', () => {
expect(polymeterSteps(3, ['d', 'e']).firstCycle()).toStrictEqual(
fastcat(pure('d'), pure('e'), pure('d')).firstCycle(),
);
expect(polymeter(['a', 'b', 'c'], ['d', 'e']).fast(2).firstCycle()).toStrictEqual(
stack(sequence('a', 'b', 'c', 'a', 'b', 'c'), sequence('d', 'e', 'd', 'e', 'd', 'e')).firstCycle(),
);
});
it('Can layer up cycles, stepwise, with weighted patterns', () => {
sameFirst(polymeterSteps(3, sequence('a', 'b')).fast(2), sequence('a', 'b', 'a', 'b', 'a', 'b'));
});
});
describe('firstOf()', () => {

View File

@ -6178,67 +6178,54 @@ exports[`runs examples > example "ply" example index 0 1`] = `
exports[`runs examples > example "polymeter" example index 0 1`] = `
[
"[ 0/1 → 1/3 | note:c ]",
"[ 0/1 → 1/3 | note:c2 ]",
"[ 1/3 → 2/3 | note:eb ]",
"[ 1/3 → 2/3 | note:g2 ]",
"[ 2/3 → 1/1 | note:g ]",
"[ 2/3 → 1/1 | note:c2 ]",
"[ 1/1 → 4/3 | note:c ]",
"[ 1/1 → 4/3 | note:g2 ]",
"[ 4/3 → 5/3 | note:eb ]",
"[ 4/3 → 5/3 | note:c2 ]",
"[ 5/3 → 2/1 | note:g ]",
"[ 5/3 → 2/1 | note:g2 ]",
"[ 2/1 → 7/3 | note:c ]",
"[ 2/1 → 7/3 | note:c2 ]",
"[ 7/3 → 8/3 | note:eb ]",
"[ 7/3 → 8/3 | note:g2 ]",
"[ 8/3 → 3/1 | note:g ]",
"[ 8/3 → 3/1 | note:c2 ]",
"[ 3/1 → 10/3 | note:c ]",
"[ 3/1 → 10/3 | note:g2 ]",
"[ 10/3 → 11/3 | note:eb ]",
"[ 10/3 → 11/3 | note:c2 ]",
"[ 11/3 → 4/1 | note:g ]",
"[ 11/3 → 4/1 | note:g2 ]",
]
`;
exports[`runs examples > example "polymeterSteps" example index 0 1`] = `
[
"[ 0/1 → 1/4 | note:c ]",
"[ 0/1 → 1/4 | note:e ]",
"[ 1/4 → 1/2 | note:d ]",
"[ 1/4 → 1/2 | note:f ]",
"[ 1/2 → 3/4 | note:c ]",
"[ 1/2 → 3/4 | note:g ]",
"[ 3/4 → 1/1 | note:d ]",
"[ 3/4 → 1/1 | note:e ]",
"[ 1/1 → 5/4 | note:c ]",
"[ 1/1 → 5/4 | note:f ]",
"[ 5/4 → 3/2 | note:d ]",
"[ 5/4 → 3/2 | note:g ]",
"[ 3/2 → 7/4 | note:c ]",
"[ 3/2 → 7/4 | note:e ]",
"[ 7/4 → 2/1 | note:d ]",
"[ 7/4 → 2/1 | note:f ]",
"[ 2/1 → 9/4 | note:c ]",
"[ 2/1 → 9/4 | note:g ]",
"[ 9/4 → 5/2 | note:d ]",
"[ 9/4 → 5/2 | note:e ]",
"[ 5/2 → 11/4 | note:c ]",
"[ 5/2 → 11/4 | note:f ]",
"[ 11/4 → 3/1 | note:d ]",
"[ 11/4 → 3/1 | note:g ]",
"[ 3/1 → 13/4 | note:c ]",
"[ 3/1 → 13/4 | note:e ]",
"[ 13/4 → 7/2 | note:d ]",
"[ 13/4 → 7/2 | note:f ]",
"[ 7/2 → 15/4 | note:c ]",
"[ 7/2 → 15/4 | note:g ]",
"[ 15/4 → 4/1 | note:d ]",
"[ 15/4 → 4/1 | note:e ]",
"[ 0/1 → 1/6 | note:c ]",
"[ 0/1 → 1/6 | note:c2 ]",
"[ 1/6 → 1/3 | note:eb ]",
"[ 1/6 → 1/3 | note:g2 ]",
"[ 1/3 → 1/2 | note:g ]",
"[ 1/3 → 1/2 | note:c2 ]",
"[ 1/2 → 2/3 | note:c ]",
"[ 1/2 → 2/3 | note:g2 ]",
"[ 2/3 → 5/6 | note:eb ]",
"[ 2/3 → 5/6 | note:c2 ]",
"[ 5/6 → 1/1 | note:g ]",
"[ 5/6 → 1/1 | note:g2 ]",
"[ 1/1 → 7/6 | note:c ]",
"[ 1/1 → 7/6 | note:c2 ]",
"[ 7/6 → 4/3 | note:eb ]",
"[ 7/6 → 4/3 | note:g2 ]",
"[ 4/3 → 3/2 | note:g ]",
"[ 4/3 → 3/2 | note:c2 ]",
"[ 3/2 → 5/3 | note:c ]",
"[ 3/2 → 5/3 | note:g2 ]",
"[ 5/3 → 11/6 | note:eb ]",
"[ 5/3 → 11/6 | note:c2 ]",
"[ 11/6 → 2/1 | note:g ]",
"[ 11/6 → 2/1 | note:g2 ]",
"[ 2/1 → 13/6 | note:c ]",
"[ 2/1 → 13/6 | note:c2 ]",
"[ 13/6 → 7/3 | note:eb ]",
"[ 13/6 → 7/3 | note:g2 ]",
"[ 7/3 → 5/2 | note:g ]",
"[ 7/3 → 5/2 | note:c2 ]",
"[ 5/2 → 8/3 | note:c ]",
"[ 5/2 → 8/3 | note:g2 ]",
"[ 8/3 → 17/6 | note:eb ]",
"[ 8/3 → 17/6 | note:c2 ]",
"[ 17/6 → 3/1 | note:g ]",
"[ 17/6 → 3/1 | note:g2 ]",
"[ 3/1 → 19/6 | note:c ]",
"[ 3/1 → 19/6 | note:c2 ]",
"[ 19/6 → 10/3 | note:eb ]",
"[ 19/6 → 10/3 | note:g2 ]",
"[ 10/3 → 7/2 | note:g ]",
"[ 10/3 → 7/2 | note:c2 ]",
"[ 7/2 → 11/3 | note:c ]",
"[ 7/2 → 11/3 | note:g2 ]",
"[ 11/3 → 23/6 | note:eb ]",
"[ 11/3 → 23/6 | note:c2 ]",
"[ 23/6 → 4/1 | note:g ]",
"[ 23/6 → 4/1 | note:g2 ]",
]
`;

View File

@ -116,10 +116,6 @@ Earlier versions of many of these functions had `s_` prefixes, and the `pace` fu
<JsDoc client:idle name="polymeter" h={0} />
### polymeterSteps
<JsDoc client:idle name="polymeterSteps" h={0} />
### shrink
<JsDoc client:idle name="shrink" h={0} />