mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-21 04:49:59 -04:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2c3c35e1e | |||
| a37db0c5f2 | |||
| d0b5f90de2 | |||
| 5a878b7099 | |||
| 7a3e0fd3fe | |||
| 4061dd4cf8 | |||
| b523205590 | |||
| 956598da18 | |||
| e011f3b982 | |||
| cb591815ed | |||
| 6a4fd27f5b | |||
| d30df8d4cf | |||
| a6008e2700 | |||
| f4b1baac87 |
@@ -1456,14 +1456,39 @@ export function cat(...pats) {
|
||||
* @return {Pattern}
|
||||
* @example
|
||||
* arrange(
|
||||
* [4, "<c a f e>(3,8)"],
|
||||
* [2, "<g a>(5,8)"]
|
||||
* 4, "<c a f e>(3,8)",
|
||||
* 2, "<g a>(5,8)"
|
||||
* ).note()
|
||||
*/
|
||||
export function arrange(...sections) {
|
||||
const total = sections.reduce((sum, [cycles]) => sum + cycles, 0);
|
||||
sections = sections.map(([cycles, section]) => [cycles, section.fast(cycles)]);
|
||||
return stepcat(...sections).slow(total);
|
||||
export function arrange(...input) {
|
||||
if (Array.isArray(input[0])) {
|
||||
return arrange_deprecated(...input);
|
||||
}
|
||||
|
||||
if (input.length % 2 !== 0) {
|
||||
throw new Error('Arrange needs a length paramter for each pattern (length, pattern, length, pattern)');
|
||||
}
|
||||
let sects = [];
|
||||
let total = 0;
|
||||
for (let i = 0; i < input.length; i += 2) {
|
||||
let cycles = input.at(i);
|
||||
total += cycles;
|
||||
|
||||
let pattern = input.at(i + 1);
|
||||
sects.push([cycles, pattern.fast(cycles)]);
|
||||
}
|
||||
return stepcat(...sects).slow(total);
|
||||
}
|
||||
// handle old array syntax ex:
|
||||
// arrange(
|
||||
// [4, "<c a f e>(3,8)"],
|
||||
// [2, "<g a>(5,8)"]
|
||||
// ).note()
|
||||
//
|
||||
function arrange_deprecated(...sects) {
|
||||
const total = sects.reduce((sum, [cycles]) => sum + cycles, 0);
|
||||
sects = sects.map(([cycles, pattern]) => [cycles, pattern.fast(cycles)]);
|
||||
return stepcat(...sects).slow(total);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2234,7 +2259,7 @@ export const brak = register('brak', function (pat) {
|
||||
});
|
||||
|
||||
/**
|
||||
* Reverse all haps in a pattern
|
||||
* Reverse all cycles in a pattern. See also `revv` for reversing a whole pattern.
|
||||
*
|
||||
* @name rev
|
||||
* @memberof Pattern
|
||||
@@ -2266,6 +2291,23 @@ export const rev = register(
|
||||
true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Reverse a whole pattern. See also `rev` for reversing each cycle.
|
||||
*
|
||||
* @name revv
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @example
|
||||
* // This is the same as `<[g e] [d c]>`. If `rev()` is used, you get
|
||||
* // the same as `<[d c] [g e]>`, where each cycle reverses, but the order of
|
||||
* // cycles stays the same.
|
||||
* note("<[c d] [e g]>").revv()
|
||||
*/
|
||||
export const revv = register('revv', function (pat) {
|
||||
const negateSpan = (span) => new TimeSpan(Fraction(0).sub(span.end), Fraction(0).sub(span.begin));
|
||||
return pat.withQuerySpan(negateSpan).withHapSpan(negateSpan);
|
||||
});
|
||||
|
||||
/** Like press, but allows you to specify the amount by which each
|
||||
* event is shifted. pressBy(0.5) is the same as press, while
|
||||
* pressBy(1/3) shifts each event by a third of its timespan.
|
||||
|
||||
@@ -586,6 +586,18 @@ describe('Pattern', () => {
|
||||
.map((a) => a.value),
|
||||
).toStrictEqual(['c', 'b', 'a']);
|
||||
});
|
||||
it('Does not reverse the order of cycles', () => {
|
||||
expect(fastcat('a', 'b', 'c', 'd').slow(2).rev().fast(2).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
fastcat('b', 'a', 'd', 'c').firstCycle(),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('revv()', () => {
|
||||
it('Does reverse the order of cycles', () => {
|
||||
expect(fastcat('a', 'b', 'c', 'd').slow(2).revv().fast(2).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
fastcat('d', 'c', 'b', 'a').firstCycle(),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('sequence()', () => {
|
||||
it('Can work like fastcat', () => {
|
||||
|
||||
@@ -274,7 +274,7 @@ export async function initAudioOnFirstClick(options) {
|
||||
}
|
||||
|
||||
let controller;
|
||||
function getSuperdoughAudioController() {
|
||||
export function getSuperdoughAudioController() {
|
||||
if (controller == null) {
|
||||
controller = new SuperdoughAudioController(getAudioContext());
|
||||
}
|
||||
|
||||
@@ -9256,6 +9256,19 @@ exports[`runs examples > example "rev" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "revv" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | note:g ]",
|
||||
"[ 1/2 → 1/1 | note:e ]",
|
||||
"[ 1/1 → 3/2 | note:d ]",
|
||||
"[ 3/2 → 2/1 | note:c ]",
|
||||
"[ 2/1 → 5/2 | note:g ]",
|
||||
"[ 5/2 → 3/1 | note:e ]",
|
||||
"[ 3/1 → 7/2 | note:d ]",
|
||||
"[ 7/2 → 4/1 | note:c ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "ribbon" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/1 | note:d ]",
|
||||
|
||||
Reference in New Issue
Block a user