mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
add ratio function
This commit is contained in:
parent
e4a35fdd72
commit
09b14a5702
@ -1582,6 +1582,24 @@ export const range2 = register('range2', function (min, max, pat) {
|
||||
return pat.fromBipolar()._range(min, max);
|
||||
});
|
||||
|
||||
/**
|
||||
* Allows dividing numbers via list notation using ":".
|
||||
* Returns a new pattern with just numbers.
|
||||
* @name ratio
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @example
|
||||
* ratio("1, 5:4, 3:2").mul(110).freq().s("piano").slow(2)
|
||||
*/
|
||||
export const ratio = register('ratio', (pat) =>
|
||||
pat.fmap((v) => {
|
||||
if (!Array.isArray(v)) {
|
||||
return v;
|
||||
}
|
||||
return v.slice(1).reduce((acc, n) => acc / n, v[0]);
|
||||
}),
|
||||
);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Structural and temporal transformations
|
||||
|
||||
|
||||
@ -3193,6 +3193,23 @@ exports[`runs examples > example "rarely" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "ratio" example index 0 1`] = `
|
||||
[
|
||||
"[ (0/1 → 1/1) ⇝ 2/1 | freq:110 s:piano ]",
|
||||
"[ (0/1 → 1/1) ⇝ 2/1 | freq:137.5 s:piano ]",
|
||||
"[ (0/1 → 1/1) ⇝ 2/1 | freq:165 s:piano ]",
|
||||
"[ 0/1 ⇜ (1/1 → 2/1) | freq:110 s:piano ]",
|
||||
"[ 0/1 ⇜ (1/1 → 2/1) | freq:137.5 s:piano ]",
|
||||
"[ 0/1 ⇜ (1/1 → 2/1) | freq:165 s:piano ]",
|
||||
"[ (2/1 → 3/1) ⇝ 4/1 | freq:110 s:piano ]",
|
||||
"[ (2/1 → 3/1) ⇝ 4/1 | freq:137.5 s:piano ]",
|
||||
"[ (2/1 → 3/1) ⇝ 4/1 | freq:165 s:piano ]",
|
||||
"[ 2/1 ⇜ (3/1 → 4/1) | freq:110 s:piano ]",
|
||||
"[ 2/1 ⇜ (3/1 → 4/1) | freq:137.5 s:piano ]",
|
||||
"[ 2/1 ⇜ (3/1 → 4/1) | freq:165 s:piano ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "release" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | note:c3 release:0 ]",
|
||||
|
||||
@ -139,6 +139,10 @@ This group of functions allows to modify the value of events.
|
||||
|
||||
<JsDoc client:idle name="Pattern.range2" h={0} />
|
||||
|
||||
## ratio
|
||||
|
||||
<JsDoc client:idle name="Pattern.ratio" h={0} />
|
||||
|
||||
# Custom Parameters
|
||||
|
||||
You can also create your own parameters:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user