-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpod.cpp
323 lines (310 loc) · 6.93 KB
/
pod.cpp
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#include "pod.h"
#include "led_colours.h"
#include "EventQueue.h"
DaisyPod hw;
extern Parameter knob1, knob2;
uint32_t last_ui_update = 0;
bool long_press = false;
bool setup_page = false;
int8_t next_dir;
void UpdateEncoder(int8_t cur_page)
{
if (hw.encoder.Pressed()) {
if (!long_press) {
if (hw.encoder.TimeHeldMs() > LONG_PRESS) {
long_press = true;
setup_page = !setup_page;
}
}
}
if(hw.encoder.FallingEdge()) {
if (long_press) {
long_press = false;
} else {
if (setup_page) {
// button presses handled below
} else {
eq.push_event(eq.INCR_WAV, 0);
}
}
}
int32_t incr = hw.encoder.Increment();
if (incr == 0) { return; }
if (setup_page) {
// nothing here button presses handled below
} else {
(incr > 0) ? \
eq.push_event(eq.PAGE_UP, 0) : \
eq.push_event(eq.PAGE_DN, 0);
}
}
void UpdateUI(int8_t cur_page)
{
// limit update rate
uint32_t now = hw.seed.system.GetNow();
if (last_ui_update - now >= 1) {
last_ui_update = now;
if (setup_page) {
hw.led1.Set(CYAN);
} else {
switch(cur_page)
{
case 0:
hw.led1.Set(RED);
/*
* k1 = Grain Pitch
* k2 = Scan Rate (disabled in live mode)
* b1 = cycle env type
* b2 = Reset Grain Pitch and Scan Rate
*/
break;
case 1:
hw.led1.Set(ORANGE);
/*
* k1 = Grain Duration
* k2 = Grain Density
* b1 = Grain Reverse
* b2 = Scan Reverse (disabled in live mode)
*/
break;
case 2:
hw.led1.Set(YELLOW);
/*
* k1 = Scatter Distance
* b1 = Toggle Scatter
* b2 = Toggle Freeze
*/
break;
case 3:
hw.led1.Set(GREEN);
/*
* k1 = Pitch Distance
* b1 = Toggle Random Pitch
* b2 = Toggle Random Density
*/
break;
case 4:
hw.led1.Set(BLUE);
/*
* NOTE: led flashes blue during start up to indicate file reading
* k1 = Sample Start (disabled in live mode)
* k2 = Sample End (disabled in live mode)
* b1 = Live Mode
* b2 = Sample Mode
*/
break;
case 5:
hw.led1.Set(PURPLE);
/*
* k1 = Bit Crush
* k2 = Downsample
*/
break;
case 6:
hw.led1.Set(VIOLET);
/*
* k1 = pan
* k2 = pan dist
* b1 = Toggle random pan
*/
break;
case 7:
hw.led1.Set(ROSE);
/*
* k1 = delay mix
* k2 = delay time
* b1 = Toggle Gate (disabled in live mode)
* b2 = Toggle Retrig (disabled in live mode)
*/
break;
case 8:
hw.led1.Set(LGREEN);
/*
* k1 = delay fbk
* k2 = delay xst
* b1 = Toggle MIDI note mode
* b2 = Toggle Wave Loop (disabled in live mode)
*/
break;
default:
hw.led1.Set(WHITE);
break;
}
}
hw.UpdateLeds();
}
}
void UpdateButtons(int8_t cur_page)
{
if (setup_page) {
if(hw.button1.RisingEdge()) {
eq.push_event(eq.INCR_MIDI, 0);
}
if(hw.button2.RisingEdge()) {
next_dir = cur_dir;
next_dir++;
if (next_dir >= dir_count) next_dir = 0;
eq.push_event(eq.NEXT_DIR, next_dir);
}
return;
}
switch(cur_page)
{
case 0:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.INCR_GRAIN_ENV, 0);
}
if(hw.button2.RisingEdge()) {
eq.push_event(eq.RST_PITCH_SCAN, 0);
}
break;
case 1:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.TOG_GRAIN_REV, 0);
}
if(hw.button2.RisingEdge()) {
eq.push_event(eq.TOG_SCAN_REV, 0);
}
break;
case 2:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.TOG_SCAT, 0);
}
if(hw.button2.RisingEdge()) {
eq.push_event(eq.TOG_FREEZE, 0);
}
break;
case 3:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.TOG_RND_PITCH, 0);
}
if(hw.button2.RisingEdge()) {
eq.push_event(eq.TOG_RND_DENS, 0);
}
break;
case 4:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.LIVE_REC, 0);
}
if(hw.button2.RisingEdge()) {
eq.push_event(eq.LIVE_PLAY, 0);
}
break;
case 5:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.TOG_LOOP, 0);
}
break;
case 6:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.TOG_RND_PAN, 0);
}
break;
case 7:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.TOG_GATE, 0);
}
if(hw.button2.RisingEdge()) {
eq.push_event(eq.TOG_RETRIG, 0);
}
break;
case 8:
if(hw.button1.RisingEdge()) {
eq.push_event(eq.TOG_NOTE, 0);
}
break;
default:
break;
}
}
float hw_init() {
hw.Init();
return hw.AudioSampleRate();
}
void hw_start(AudioHandle::AudioCallback cb) {
knob1.Init(hw.knob1, 0.0f, 1.0f, knob1.LINEAR);
knob2.Init(hw.knob2, 0.0f, 1.0f, knob2.LINEAR);
hw.StartAdc();
hw.StartAudio(cb);
hw.midi.StartReceive();
}
void Status(status_t status)
{
switch(status)
{
case STARTUP:
hw.led1.Set(RED);
#ifdef DEBUG_POD
hw.seed.PrintLine("GRNLTR %s", VER);
hw.seed.PrintLine("SD CFG");
#endif
break;
case FSI_INIT:
hw.led1.Set(ORANGE);
#ifdef DEBUG_POD
hw.seed.PrintLine(" OK");
hw.seed.PrintLine("FSI Init");
#endif
break;
case SD_MOUNT:
hw.led1.Set(YELLOW);
#ifdef DEBUG_POD
hw.seed.PrintLine(" OK");
hw.seed.PrintLine("SD Mount");
#endif
break;
case MOUNT_ERROR:
hw.led2.Set(CYAN);
#ifdef DEBUG_POD
hw.seed.PrintLine(" FAILED!");
#endif
break;
case LIST_DIRS:
hw.led1.Set(GREEN);
#ifdef DEBUG_POD
hw.seed.PrintLine(" OK");
hw.seed.PrintLine("Searching %s", GRNLTR_PATH);
#endif
break;
case NO_GRNLTR_DIR:
hw.led2.Set(LGREEN);
#ifdef DEBUG_POD
hw.seed.PrintLine("%s not found or empty!", GRNLTR_PATH);
#endif
break;
case DIR_ERROR:
hw.led2.Set(WHITE);
#ifdef DEBUG_POD
hw.seed.PrintLine(" DIR read error");
#endif
break;
case NO_WAVS:
hw.led2.Set(ROSE);
#ifdef DEBUG_POD
hw.seed.PrintLine(" No WAVs found");
#endif
break;
case READING_WAV:
hw.led1.Set(BLUE);
break;
case MISSING_WAV:
hw.led2.Set(LBLUE);
break;
case OK:
hw.led1.Set(OFF);
hw.led2.Set(OFF);
#ifdef DEBUG_POD
hw.seed.PrintLine(" OK");
#endif
break;
case GRNLTR_INIT:
hw.led1.Set(PURPLE);
#ifdef DEBUG_POD
hw.seed.PrintLine("Initializing GRNLTR");
#endif
break;
default:
break;
}
hw.UpdateLeds();
}