Skip to content

Commit

Permalink
add seqPLoop, ref #31
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu committed Sep 7, 2024
1 parent 5bf1805 commit 832a9eb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,36 @@ export function arrange(...sections) {
return s_cat(...sections).slow(total);
}

/**
* Similarly to `arrange`, allows you to arrange multiple patterns together over multiple cycles.
* Unlike `arrange`, you specify a start and stop time for each pattern rather than duration, which
* means that patterns can overlap.
* @return {Pattern}
* @example
seqPLoop([0, 2, "bd(3,8)"],
[1, 3, "cp(3,8)"]
)
.sound()
*/
export function seqPLoop(...parts) {
let total = Fraction(0);
const pats = [];
for (let part of parts) {
if (part.length == 2) {
part.unshift(total);
}
total = part[1];
}

return stack(
...parts.map(([start, stop, pat]) =>
pure(reify(pat)).compress(Fraction(start).div(total), Fraction(stop).div(total)),
),
)
.slow(total)
.innerJoin(); // or resetJoin or restartJoin ??
}

export function fastcat(...pats) {
let result = slowcat(...pats);
if (pats.length > 1) {
Expand Down
20 changes: 20 additions & 0 deletions test/__snapshots__/examples.test.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6850,6 +6850,26 @@ exports[`runs examples > example "seq" example index 0 2`] = `
]
`;

exports[`runs examples > example "seqPLoop" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:bd ]",
"[ 3/8 → 1/2 | s:bd ]",
"[ 3/4 → 7/8 | s:bd ]",
"[ 1/1 → 9/8 | s:bd ]",
"[ 1/1 → 9/8 | s:cp ]",
"[ 11/8 → 3/2 | s:bd ]",
"[ 11/8 → 3/2 | s:cp ]",
"[ 7/4 → 15/8 | s:bd ]",
"[ 7/4 → 15/8 | s:cp ]",
"[ 2/1 → 17/8 | s:cp ]",
"[ 19/8 → 5/2 | s:cp ]",
"[ 11/4 → 23/8 | s:cp ]",
"[ 3/1 → 25/8 | s:bd ]",
"[ 27/8 → 7/2 | s:bd ]",
"[ 15/4 → 31/8 | s:bd ]",
]
`;

exports[`runs examples > example "shape" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:hh shape:0 ]",
Expand Down

0 comments on commit 832a9eb

Please sign in to comment.