-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathVibrato.jsfx
192 lines (160 loc) · 4.78 KB
/
Vibrato.jsfx
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
desc:Vibrato (by Geraint Luff)
in_pin:Left
in_pin:Right
out_pin:Left
out_pin:Right
slider1:depth_cents=30<0, 100>-depth (cents)
slider2:rate_hz=5.1<3, 10>-rate (Hz)
slider3:attack_ms=500<0,2000>-attack (ms)
slider4:release_ms=1000<0,10000>-release (ms)
slider5:attack_curve_mode=0<0,1,1{immediate,delayed}>-attack type
slider6:lookahead_ms=0<0,300,1>-lookahead (ms)
import ui-lib.jsfx-inc
import delay-utils.jsfx-inc
filename:0,themes/bitmap-simple/theme-dark-blue.png
// Photo by Tom Barrett on Unsplash: https://unsplash.com/photos/-bSucp2nUdQ
filename:1,themes/backgrounds/tom-barrett-512968-unsplash-small-denoised.png
@init
MAX_DELAY = 0.5;
MAX_DELAY_SAMPLES = ceil(MAX_DELAY*srate);
gfx_ext_retina = 1;
freemem = 0;
freemem = ui_setup(freemem);
freemem = delay0.delay_setup(freemem, MAX_DELAY_SAMPLES);
freemem = delay1.delay_setup(freemem, MAX_DELAY_SAMPLES);
currently_active = 0;
current_depth_samples = 0;
current_phase = 1;
note_count = 0;
samples_since_attack = 0;
samples_since_release = 0;
@block
lookahead_samples = floor(srate*lookahead_ms*0.001);
pdc_delay = lookahead_samples;
pdc_bot_ch = 0;
pdc_top_ch = 2;
attack_samples = attack_ms*0.001*srate;
release_samples = release_ms*0.001*srate;
phase_rate = rate_hz/srate;
while (midirecv(offset, msg1, note, vel)) (
type = (msg1&240);
channel = (msg1&15) + 1;
type == $x90 && vel != 0 ? (
currently_active = 1;
note_count += 1;
samples_since_attack = -offset - lookahead_samples;
) : type == $x80 || (type == $x90 && vel == 0) ? (
note_count -= 1;
!note_count ? (
samples_since_release = -offset - lookahead_samples;
);
) : (
type == $xB0 ? ( // Controller
note == 123 || note == 120 ? (
note_count = 0;
);
);
);
midisend(offset, msg1, note, vel);
);
note_count = max(0, note_count);
@sample
delay0.delay_input(spl0);
delay1.delay_input(spl1);
currently_active ? (
samples_since_attack += 1;
samples_since_release += 1;
current_depth_samples ? (
phase_value = (0.5 - 0.5*cos(current_phase*2*$pi));
delay_samples = min(MAX_DELAY_SAMPLES, lookahead_samples + current_depth_samples*phase_value);
spl0 = delay0.delay_output_linear1(delay_samples);
spl1 = delay1.delay_output_linear1(delay_samples);
) : lookahead_samples ? (
spl0 = delay0.delay_output_samples(lookahead_samples);
spl1 = delay1.delay_output_samples(lookahead_samples);
);
current_phase += phase_rate;
current_phase >= 1 ? (
samples_since_attack < attack_samples ? (
envelope = max(0, samples_since_attack)/attack_samples;
attack_curve_mode ? (
envelope *= envelope;
);
) : (
envelope = 1;
);
note_count <= 0 ? (
samples_since_release < release_samples ? (
envelope *= 1 - max(0, samples_since_release)/release_samples;
) : (
envelope = 0;
currently_active = 0;
);
);
current_phase = 0;
current_depth_samples = envelope*srate*(depth_cents*0.01/12/(2*$pi)/rate_hz);
);
) : lookahead_samples ? (
spl0 = delay0.delay_output_samples(lookahead_samples);
spl1 = delay1.delay_output_samples(lookahead_samples);
);
@gfx 350 320
function labels(label, value, number_format) local(h) (
h = max((ui_height() - 60)/2, ui_height()*0.2);
ui_split_top(h);
ui_align(0.5, 1);
ui_text(label);
ui_pop();
ui_split_bottom(h);
ui_align(0.5, 0);
number_format >= 0 ? (
ui_textnumber(value, number_format);
);
ui_pop();
);
control_start("main", "bitmap-simple", 0);
gfx_a = 0.8;
g_scale = max(gfx_w/600, gfx_h/401);
gfx_x = (gfx_w - 600*g_scale)*0.5;
gfx_y = (gfx_h - 401*g_scale)*0.5;
gfx_mode = 2;
gfx_blit(1, g_scale, 0);
gfx_mode = 0;
ui_screen() == "main" ? (
control_navbar("Vibrato");
ui_push_width(350);
ui_split_topratio(0.5);
ui_split_leftratio(2/3);
control_group("LFO");
ui_split_leftratio(1/2);
labels("Depth", depth_cents, "%i cents");
ui_automate(depth_cents, control_dial(depth_cents, 0, 100, 2, 30));
ui_split_next();
labels("Rate", rate_hz + 0.05, "%.1f Hz");
ui_automate(rate_hz, control_dial(rate_hz, 3, 10, 1, 5.1));
ui_pop();
ui_pop();
control_group("Latency");
labels("Lookahead", lookahead_ms, "%i ms");
lookahead_ms = control_dial(lookahead_ms, 0, ceil(1000/rate_hz), 0, 0);
lookahead_ms = floor(lookahead_ms + 0.5);
ui_pop();
control_group("Note Envelope");
ui_split_leftratio(1/3);
labels("Attack", attack_ms, "%i ms");
ui_automate(attack_ms, control_dial(attack_ms, 0, 2000, 2.2, 500));
ui_split_next();
labels("Release", release_ms, "%i ms");
ui_automate(release_ms, control_dial(release_ms, 0, 10000, 4.4, 1000));
ui_split_next();
labels("Attack curve", 0, attack_curve_mode ? "delayed" : "immediate");
ui_automate(attack_curve_mode, control_switch(attack_curve_mode));
ui_pop();
ui_pop();
) : control_system();
@serialize
preset_version = 2;
file_var(0, preset_version);
preset_version < 2 ? (
lookahead_ms = 0;
);