Merge pull request #780 from tidalcycles/xfade

add xfade
This commit is contained in:
Felix Roos 2023-11-05 12:21:28 +01:00 committed by GitHub
commit ec611aac45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 0 deletions

View File

@ -2392,3 +2392,29 @@ export const ref = (accessor) =>
pure(1)
.withValue(() => reify(accessor()))
.innerJoin();
let fadeGain = (p) => (p < 0.5 ? 1 : 1 - (p - 0.5) / 0.5);
/**
* Cross-fades between left and right from 0 to 1:
* - 0 = (full left, no right)
* - .5 = (both equal)
* - 1 = (no left, full right)
*
* @name xfade
* @example
* xfade(s("bd*2"), "<0 .25 .5 .75 1>", s("hh*8"))
*/
export let xfade = (a, pos, b) => {
pos = reify(pos);
a = reify(a);
b = reify(b);
let gaina = pos.fmap((v) => ({ gain: fadeGain(v) }));
let gainb = pos.fmap((v) => ({ gain: fadeGain(1 - v) }));
return stack(a.mul(gaina), b.mul(gainb));
};
// the prototype version is actually flipped so left/right makes sense
Pattern.prototype.xfade = function (pos, b) {
return xfade(this, pos, b);
};

View File

@ -5235,6 +5235,51 @@ exports[`runs examples > example "withValue" example index 0 1`] = `
]
`;
exports[`runs examples > example "xfade" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:hh gain:0 ]",
"[ 0/1 → 1/2 | s:bd gain:1 ]",
"[ 1/8 → 1/4 | s:hh gain:0 ]",
"[ 1/4 → 3/8 | s:hh gain:0 ]",
"[ 3/8 → 1/2 | s:hh gain:0 ]",
"[ 1/2 → 5/8 | s:hh gain:0 ]",
"[ 1/2 → 1/1 | s:bd gain:1 ]",
"[ 5/8 → 3/4 | s:hh gain:0 ]",
"[ 3/4 → 7/8 | s:hh gain:0 ]",
"[ 7/8 → 1/1 | s:hh gain:0 ]",
"[ 1/1 → 9/8 | s:hh gain:0.5 ]",
"[ 1/1 → 3/2 | s:bd gain:1 ]",
"[ 9/8 → 5/4 | s:hh gain:0.5 ]",
"[ 5/4 → 11/8 | s:hh gain:0.5 ]",
"[ 11/8 → 3/2 | s:hh gain:0.5 ]",
"[ 3/2 → 13/8 | s:hh gain:0.5 ]",
"[ 3/2 → 2/1 | s:bd gain:1 ]",
"[ 13/8 → 7/4 | s:hh gain:0.5 ]",
"[ 7/4 → 15/8 | s:hh gain:0.5 ]",
"[ 15/8 → 2/1 | s:hh gain:0.5 ]",
"[ 2/1 → 17/8 | s:hh gain:1 ]",
"[ 2/1 → 5/2 | s:bd gain:1 ]",
"[ 17/8 → 9/4 | s:hh gain:1 ]",
"[ 9/4 → 19/8 | s:hh gain:1 ]",
"[ 19/8 → 5/2 | s:hh gain:1 ]",
"[ 5/2 → 21/8 | s:hh gain:1 ]",
"[ 5/2 → 3/1 | s:bd gain:1 ]",
"[ 21/8 → 11/4 | s:hh gain:1 ]",
"[ 11/4 → 23/8 | s:hh gain:1 ]",
"[ 23/8 → 3/1 | s:hh gain:1 ]",
"[ 3/1 → 25/8 | s:hh gain:1 ]",
"[ 3/1 → 7/2 | s:bd gain:0.5 ]",
"[ 25/8 → 13/4 | s:hh gain:1 ]",
"[ 13/4 → 27/8 | s:hh gain:1 ]",
"[ 27/8 → 7/2 | s:hh gain:1 ]",
"[ 7/2 → 29/8 | s:hh gain:1 ]",
"[ 7/2 → 4/1 | s:bd gain:0.5 ]",
"[ 29/8 → 15/4 | s:hh gain:1 ]",
"[ 15/4 → 31/8 | s:hh gain:1 ]",
"[ 31/8 → 4/1 | s:hh gain:1 ]",
]
`;
exports[`runs examples > example "zoom" example index 0 1`] = `
[
"[ 0/1 → 1/6 | s:hh ]",

View File

@ -156,6 +156,10 @@ There is one filter envelope for each filter type and thus one set of envelope f
<JsDoc client:idle name="postgain" h={0} />
## xfade
<JsDoc client:idle name="xfade" h={0} />
# Panning
## jux