Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 90506f9

Browse files
authored
Merge pull request #1321 from daslyfe/jade/slit
feat: Create scrub function for scrubbing an audio file
2 parents 8f4dcb6 + 695ac6a commit 90506f9

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

packages/core/controls.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,3 +1780,32 @@ export const as = register('as', (mapping, pat) => {
17801780
return v;
17811781
});
17821782
});
1783+
1784+
/**
1785+
* Allows you to scrub an audio file like a tape loop by passing values that represents the position in the audio file
1786+
* in the optional array syntax ex: "0.5:2", the second value controls the speed of playback
1787+
* @name scrub
1788+
* @memberof Pattern
1789+
* @returns Pattern
1790+
* @example
1791+
* samples('github:switchangel/pad')
1792+
* s("swpad:0").scrub("{0.1!2 .25@3 0.7!2 <0.8:1.5>}%8")
1793+
* @example
1794+
* samples('github:yaxu/clean-breaks/main');
1795+
* s("amen/4").fit().scrub("{0@3 0@2 4@3}%8".div(16))
1796+
*/
1797+
1798+
export const scrub = register(
1799+
'scrub',
1800+
(beginPat, pat) => {
1801+
return beginPat.outerBind((v) => {
1802+
if (!Array.isArray(v)) {
1803+
v = [v];
1804+
}
1805+
const [beginVal, speedMultiplier = 1] = v;
1806+
1807+
return pat.begin(beginVal).mul(speed(speedMultiplier)).clip(1);
1808+
});
1809+
},
1810+
false,
1811+
);

test/__snapshots__/examples.test.mjs.snap

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7871,6 +7871,52 @@ but parts might be played more than once, or not at all, per cycle." example ind
78717871
]
78727872
`;
78737873

7874+
exports[`runs examples > example "scrub" example index 0 1`] = `
7875+
[
7876+
"[ 0/1 → 1/8 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7877+
"[ 1/8 → 1/4 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7878+
"[ 1/4 → 5/8 | s:swpad n:0 begin:0.25 speed:1 clip:1 ]",
7879+
"[ 5/8 → 3/4 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7880+
"[ 3/4 → 7/8 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7881+
"[ 7/8 → 1/1 | s:swpad n:0 begin:0.8 speed:1.5 clip:1 ]",
7882+
"[ 1/1 → 9/8 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7883+
"[ 9/8 → 5/4 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7884+
"[ 5/4 → 13/8 | s:swpad n:0 begin:0.25 speed:1 clip:1 ]",
7885+
"[ 13/8 → 7/4 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7886+
"[ 7/4 → 15/8 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7887+
"[ 15/8 → 2/1 | s:swpad n:0 begin:0.8 speed:1.5 clip:1 ]",
7888+
"[ 2/1 → 17/8 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7889+
"[ 17/8 → 9/4 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7890+
"[ 9/4 → 21/8 | s:swpad n:0 begin:0.25 speed:1 clip:1 ]",
7891+
"[ 21/8 → 11/4 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7892+
"[ 11/4 → 23/8 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7893+
"[ 23/8 → 3/1 | s:swpad n:0 begin:0.8 speed:1.5 clip:1 ]",
7894+
"[ 3/1 → 25/8 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7895+
"[ 25/8 → 13/4 | s:swpad n:0 begin:0.1 speed:1 clip:1 ]",
7896+
"[ 13/4 → 29/8 | s:swpad n:0 begin:0.25 speed:1 clip:1 ]",
7897+
"[ 29/8 → 15/4 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7898+
"[ 15/4 → 31/8 | s:swpad n:0 begin:0.7 speed:1 clip:1 ]",
7899+
"[ 31/8 → 4/1 | s:swpad n:0 begin:0.8 speed:1.5 clip:1 ]",
7900+
]
7901+
`;
7902+
7903+
exports[`runs examples > example "scrub" example index 1 1`] = `
7904+
[
7905+
"[ 0/1 → 3/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7906+
"[ 3/8 → 5/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7907+
"[ 5/8 → 1/1 | s:amen speed:0.25 unit:c begin:0.25 clip:1 ]",
7908+
"[ 1/1 → 11/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7909+
"[ 11/8 → 13/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7910+
"[ 13/8 → 2/1 | s:amen speed:0.25 unit:c begin:0.25 clip:1 ]",
7911+
"[ 2/1 → 19/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7912+
"[ 19/8 → 21/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7913+
"[ 21/8 → 3/1 | s:amen speed:0.25 unit:c begin:0.25 clip:1 ]",
7914+
"[ 3/1 → 27/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7915+
"[ 27/8 → 29/8 | s:amen speed:0.25 unit:c begin:0 clip:1 ]",
7916+
"[ 29/8 → 4/1 | s:amen speed:0.25 unit:c begin:0.25 clip:1 ]",
7917+
]
7918+
`;
7919+
78747920
exports[`runs examples > example "segment" example index 0 1`] = `
78757921
[
78767922
"[ 0/1 → 1/24 | note:40 ]",

0 commit comments

Comments
 (0)