-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdynamic_crossfade.genexpr
43 lines (43 loc) · 1.07 KB
/
dynamic_crossfade.genexpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
ramp(signal, movement) {
//Buffer input("input");
History length(44 * 4999);
History toggle(0);
History go(0);
lo = 999;
hi = 44 * 4999;
if(movement) {
length = hi;
go = elapsed;
toggle = movement > 0;
}
amp = slide(abs(signal), 0, lo);
length = clip(amp * hi, lo, length);
x = elapsed - go;
fade = min(x / length, 1); //0 to 1
fade = abs(toggle - fade); //invert?
//poke(input, fade, x);
signal *= fade;
return signal, fade;
}
dynamic_crossfade(control, s1, s2) {
Buffer o1("o1");
Buffer o2("o2");
History direction(-1);
History go(0);
History debug(0);
mix1, fader1 = ramp(s1, direction);
mix2, fader2 = ramp(s2, direction * -1);
finished = !(fader1 % 1) && !(fader2 % 1);
direction = 0;
if(finished) {
direction = change(control);
if(direction) {
go = elapsed;
debug += 1;
}
}
//x = elapsed - go;
//poke(o1, mix1, x);
//poke(o2, mix2, x);
return mix1, mix2, mix1 + mix2, !finished;
}