-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequencer.ck
620 lines (557 loc) · 20.3 KB
/
sequencer.ck
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
// Step Sequencer for Samples
// - Drum patterns can be configured on the fly using LPD8 Sequencer input
// - Supports loading patterns and drum samples
// - Output to LPD8 highights the pads that are playing
// - One MIDI device can be clocked
// - Recording funtionality is provided by an external Chuck Script rec.ck
// Set BPM and calculate a duration of one step
140.0 => float bpm;
4 => int resolution;
minute / bpm / resolution => dur step;
// Root path to samples
"/Users/alec/Recording/Tools/Chuck/Samples/" => string rootPath;
// Path to recording script
"/Users/alec/Recording/Tools/Chuck/rec.ck" => string recScriptPath;
// Drum machine buffer - maximum number of Samples played in parallel
SndBuf samples[6];
// Common gain control and echo effect
Echo e2 => Pan2 p => JCRev jre => blackhole;
Gain g => Echo e1 => dac;
Gain gl => dac.left;
Gain gr => dac.right;
// Dynamic parameter initialization
0.0 => g.gain;
0.0 => gl.gain;
0.0 => gr.gain;
0::ms => e1.delay;
//0::ms => e2.delay;
// Midi Outputs for LPD8 and a clocked device
MidiOut lpd8out;
MidiOut clockout;
// Load available MIDI In and MIDI Out devices
loadMIDI();
loadMIDIOut();
// Sequencer dynamic settings
16 => int patternLength; // Starting pattern length: 16 or 32
// What is currently playing
0 => int currPattern;
6 => int currPreset;
0 => int currSample;
// Temp Variables that are used to control the output (output only if something changes)
-1 => int prevPattern;
-1 => int prevPreset;
-1 => int prevChangeTrack;
// What is currently being changed
-1 => int changeTrack; // Drum track
-1 => int changeStep; // Step (currSample)
-1 => int changeTo; // Change to Off (0) or On (1)
-1 => int lightOnPad; // Pad to highlight
-1 => int eraseMe; // Signal to erase current pattern
// Recording - external Script rec.ck is required
0 => int rec; // Signal to start recording
// Preset includes:
// - Path to Sample Folder
// - Array with max 5 Drum Types, Drum Type Names correspond to the names of Sample Files
// - up to 8 Drum Patterns
// Relative path to the samples folder per Preset
["Drums/Industrial/Set1/",
"Drums/Industrial/Set2/",
"Drums/Breakbeat/Set1/",
"Drums/Breakbeat/Set2/",
"Drums/IDM/Set1/",
"Drums/Vinyl/Set1/",
"Drums/Vinyl/Set2/",
"Drums/Standard/Set1/"
] @=> string availableSets[];
// Available Samples (available .wav Files) per Preset
// Kick-Snare-Closed Hat-Open Hat-Percussion-Tom
[
["Kick", "Snare", "ClosedHat", "OpenHat", "Tom", "Tom2"]
, ["Kick", "Snare", "ClosedHat", "OpenHat", "Tom", "Tom2"]
, ["Kick", "Snare", "ClosedHat", "OpenHat", "Tamb", ""]
, ["Kick01", "Snare01", "ClHat01", "OpHat01", "", ""]
, ["Kick", "Snare", "ClHat", "OpHat", "Bass", "Tom"]
, ["Kick", "Snare", "ClosedHat", "OpenHat", "Shaker", "Tom"]
, ["Kick", "Snare", "ClosedHat", "OpenHat", "Shaker", "Tom"]
, ["Kick", "Snare", "ClosedHat", "OpenHat", "", ""]
] @=> string availableSamples[][];
// Pannings of the samples
["C", "C", "L", "L", "R", "C"] @=> string panSamples[];
// Gains of the Samples
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0] @=> float gainSamples[];
// Load samples and assign to the chain before echo
loadSamples();
// Configure Drum Patterns per Preset
[
//--1---2---3---4---5---6---7---8---9--10--11--12--13--14--15--16
[ // #1 Blank
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
]
] @=> int drumPatterns[][][];
// 1 - hard motorik 100+ bpm
// 2 - hiphop 90-110 bpm
// 3 - triphop 70-90 bpm
// 4 - motorik base industrial any bpm
// 5 - slow industrial 80-110 bpm
// 6 - the funky drummer
// 7 - cold sweat
if(drumPatterns[0][0].cap() == 0 || samples.cap() == 0) {
<<< "[dac] no patterns or samples loaded" >>>;
me.exit();
}
// <<<"Sequencer is waiting for Input">>>;
// Output Message for LPD8 to manage the lights on the pads
MidiMsg msgout;
// Temp variables
int onOff;
int recordingId;
int startRec;
string strPattern;
-1 => recordingId;
0 => int clockIsTicking;
sendMIDIClockTick();
sendMIDIClockTick();
sendMIDIClockTick();
sendMIDIClockTick();
sendMIDIClockTick();
sendMIDIClockTick();
// Endless cycle that goes when current pattern is set to a non-negative value
while(true) {
// i = column (step), j = row (sample)
for( 0 => int i; i < patternLength; i++) {
-1 => lightOnPad;
// Recording starts from the beginning of the pattern
if( i == 0 && rec == 1 ) {
2 => rec; // Set the flag that the recording is running
// Recording is performed by an external Chuck Script
Machine.add(recScriptPath) => recordingId;
}
for( 0 => int j; j < samples.cap(); j++) {
// For each 1 in the pattern get the name of the current sample basing on the row number in the pattern (j)
if(currPattern >= 0 && drumPatterns[currPattern][j][i] == 1) {
j => currSample;
if(samples[currSample] != NULL) {
0 => samples[currSample].pos;
gainSamples[currSample] => samples[currSample].gain;
1.0 => samples[currSample].rate;
}
}
strPattern + " " + drumPatterns[currPattern][j][i] => strPattern;
}
// If current track is the one that is currently being changed then save the number of the current step
if(currPattern >= 0 && changeTrack != -1) {
i => lightOnPad;
drumPatterns[currPattern][changeTrack][i] => onOff;
} else {
-1 => lightOnPad;
0 => onOff;
}
// Turn any light on the track off
lightPad(lightOnPad, 0);
//MidiClock - endless cycle that sends MIDI Clock Out basing on the current step duration
if (clockIsTicking == 0) {
sendMIDIClockStart();
1 => clockIsTicking;
} else {
sendMIDIClockTick();
}
// For each step advance time let the samples sound and let the MIDI Clock tick!
sendMIDIClockTick();
sendMIDIClockTick();
sendMIDIClockTick();
sendMIDIClockTick();
sendMIDIClockTick();
if(rec == 2) { // For running recording
<<< "[rec]: Recording ", strPattern >>>; // Output pattern
if(i == patternLength-1) { // Stop recording if this is the last step of the sequence
0 => rec;
if(recordingId != -1) {
Machine.remove(recordingId);
}
}
}
// Turn the "light on" if the track has a sample on a current position and "light off" if not
lightPad(lightOnPad, onOff);
-1 => lightOnPad;
"" => strPattern;
}
// Output actual information on the setup after a sequence has played
if(currPattern >= 0 && prevPattern != currPattern) {
<<< "[dac] Pattern",currPattern, patternLength, "steps", bpm, "bpm" >>>;
currPattern => prevPattern;
if(changeTrack >= 0 && changeTrack != prevChangeTrack) {
changeTrack => prevChangeTrack;
<<< "[seq] Editing Track ", changeTrack >>>;
}
}
}
// Loads Samples for Drum Patterns
fun void loadSamples(){
0 => int j;
// Loading samples
for(0 => int i; i < availableSamples[currPreset].cap(); i++) {
if(availableSamples[currPreset][i] != "" && availableSets[currPreset] != ""){
rootPath + availableSets[currPreset] + availableSamples[currPreset][i] + ".wav" => samples[j].read;
// Assign samples to different chains for panning
if (panSamples[i] != "") {
if(panSamples[i] == "L") {
samples[j] => gr;
} else if (panSamples[i] == "R") {
samples[j] => gl;
} else {
samples[j] => g;
}
} else {
samples[j] => g;
}
j++;
}
}
// In case no samples have been loaded
if(j == 0) {
-1 => currPattern;
<<< "[seq] No samples found, current pattern set to -1 ">>>;
} else {
<<< "[seq]", j, "Samples loaded for preset", currPreset >>>;
}
}
// Load Midi Out devices
// LPD8 is the Out that receives info which pads to highlight
// Clockout device is the one that is being clocked
fun void loadMIDIOut(){
// devices to open
MidiOut mout[4];
// number of devices
int outdevices;
// connect Midi Out devices
for( 0 => int i; i < mout.cap(); i++ ) {
mout[i].printerr( 0 ); // no error
// Open the device and check its name; LPD8 is assigned to the lpd8out, any other device is assigned the clockout
if( mout[i].open(i) ) {
//<<< "[midiout] device ", i, ": ", mout[i].name(), " opened" >>>;
if(mout[i].name() == "LPD8" ) {
lpd8out.open(i);
<<< "[midiout] Sequencer", i, ":", lpd8out.name(), "opened" >>>;
outdevices++;
} else if(mout[i].name() == "Steinberg UR22 Port1" ) {
clockout.open(i);
<<< "[midiout] Clocked device", i, ":", clockout.name(), "opened" >>>;
outdevices++;
}
//outdevices++;
}
else break;
}
if( outdevices == 0 ) {
<<< "[midi] No MIDI Out devices" >>>;
me.exit();
}
}
// Loads MIDI In Devices
fun void loadMIDI(){
// devices to open (chuck --probe)
MidiIn min[3];
// number of devices
int devices;
// connect midi devices and open a shread for each event parser
for( 0 => int i; i < min.cap(); i++ ) {
min[i].printerr( 0 ); // no error
// open the device
if( min[i].open( i ) ) {
if(min[i].name() == "LPD8" ) {
<<< "[midiin] Sequencer", i, ":", min[i].name(), "opened" >>>;
spork ~ waitMIDI( min[i], i);
}
devices++;
}
else break;
}
if( devices == 0 ) {
<<< "[midiin] No MIDI devices" >>>;
me.exit();
}
}
// Processing of MIDI events to control the unit generators
fun void processMIDI (int deviceid, int msgdata1, int msgdata2, int msgdata3)
{
// Dummy variables for storing the attribute values
float varf;
dur vard;
int vari;
int z;
// Debugging of the midi-in // <<< "[tmp]", msgdata1, " / ", msgdata2 >>>;
// ------------- Program Change Mode ------------- //
// Preset 1, any pad: Load samples
if (msgdata2 >= 36 && msgdata2 <= 43 ){
msgdata2-36 => vari;
if (vari+1 > availableSets.cap()) {
<<< "[seq] Samples set", vari, "not found" >>>;
} else {
vari => currPreset;
loadSamples();
<<< "[seq] Samples set", currPreset >>>;
}
}
// Preset 2, any pad: Change drum pattern to a precofigured one
else if (msgdata2 >= 28 && msgdata2 <= 35){
msgdata2-28 => vari;
if(vari+1 > drumPatterns.cap()) {
<<< "[seq] Drum pattern", vari, "not found" >>>;
} else {
vari => currPattern;
<<< "[seq] Drum pattern", currPattern >>>;
}
}
// Preset 3, pad 1: Change the pattern length 16 <> 32
else if (msgdata2 == 20) {
if(patternLength == 16) {
32 => patternLength;
} else {
16 => patternLength;
}
<<< "[seq] Pattern length", patternLength >>>;
}
// Preset 3, pad 2: Start/end the recording
else if (msgdata2 == 21) {
if(rec == 0) {
1 => rec;
} else {
0 => rec;
}
<<< "[seq] Recording mode", rec >>>;
}
// Preset 3, pad 3, double tap: Erase current pattern
else if (msgdata2 == 22) {
if(eraseMe == -1) {
1 => eraseMe;
<<< "[seq] Confirm to erase" >>>;
} else if(eraseMe == 1) {
2 => eraseMe;
erasePattern();
<<< "[seq] Pattern erased" >>>;
-1 => eraseMe;
}
}
// ------------- Control Change Mode ------------- //
// Preset 1/2/3/4, any pad, on pad pressed: Select a Drum Track to change
else if (msgdata2 >= 44 && msgdata2 <= 51 && msgdata1 == 176) {
msgdata2-44 => vari;
if(vari+1 > availableSamples[currPreset].cap()) {
<<< "[seq] Track", vari, "not found" >>>;
} else {
vari => changeTrack;
<<< "[seq] Editing track", changeTrack >>>;
}
}
// ------------- Pad Mode ------------- //
// Preset 1/2/3/4, any pad, on pad pressed: Set/unset the step of the sequence
else if (msgdata2 >= 52 && msgdata2 <= 83 && msgdata1 == 144){
msgdata2-52 => vari;
vari => changeStep;
changePattern();
<<< "[seq] Editing step", changeStep, "/", changeTrack >>>;
}
// ------------- Knobs ------------- //
// Preset 1/2/3, knob 1: Master gain
else if(msgdata2 == 1) {
1.0 / 127.0 * msgdata3 => varf;
varf => g.gain;
varf => gl.gain;
varf => gr.gain;
<<< "[par] Gain", varf >>>;
}
// Preset 1/2/3, knob 2: Master BPM
else if(msgdata2 == 2) {
60.0 + msgdata3 => bpm;
<<< "[par] BPM", bpm >>>;
minute / bpm / resolution => step;
}
// Preset 1/2/3, knob 3-8: Gain of the respective drum track
else if(msgdata2 >= 3 && msgdata2 <= 8) {
1.0 / 127.0 * msgdata3 => varf;
<<< "[par] Sample Gain", varf >>>;
varf => gainSamples[msgdata2-3];
}
// Preset 4, knob 1: Echo 1
else if(msgdata2 == 120) {
step * msgdata3 / 127 => vard;
vard => e1.delay;
<<< "[par] Delay 1", vard >>>;
}
// Preset 4, knob 2: Echo 1
else if(msgdata2 == 121) {
1.0 / 127.0 * msgdata3 => varf;
varf => jre.mix;
<<< "[par] Reverb", varf >>>;
} else {
// do nothing
}
}
// Erase playing pattern
fun void erasePattern()
{
if(currPattern != -1 && eraseMe == 2) {
for( 0 => int z; z < patternLength; z++) {
for( 0 => int x; x < samples.cap(); x++) {
0 => drumPatterns[currPattern][x][z];
}
}
-1 => eraseMe;
}
}
// Logic for editing the Steps of the Patters
fun void changePattern ()
{
// Check whether change signal was sent
if(changeTrack != -1 && changeStep != -1) {
if(drumPatterns[currPattern][changeTrack][changeStep] == 1) {
0 => changeTo;
} else if(drumPatterns[currPattern][changeTrack][changeStep] == 0) {
1 => changeTo;
}
changeTo => drumPatterns[currPattern][changeTrack][changeStep];
<<< "[seq] Step", changeStep , "to", changeTo >>>;
-1 => eraseMe;
}
}
// Sends MIDI Out to turn the lights on the Pads on (onOff=1) and off (onOff=0)
fun void lightPad ( int padNumber, int onOff ){
if (padNumber != -1) {
if (onOff == 1) {
144 => msgout.data1; // 144 light On for channel 1
} else {
128 => msgout.data1; // 128 light Off for channel 1
}
// Set the MIDI Note (Pad number)
52 + padNumber => msgout.data2;
127 => msgout.data3;
// Send MIDI out
lpd8out.send(msgout);
}
}
// Handler for a MIDI In event
fun void waitMIDI ( MidiIn min, int deviceid )
{
MidiMsg msg;
while( true )
{
min => now;
while( min.recv( msg ) )
{
// <<< "[midi] ", deviceid, ":", msg.data1, msg.data2, msg.data3 >>>;
processMIDI(deviceid, msg.data1, msg.data2, msg.data3 );
}
}
}
// Send MIDI Clock
// the clocking interval is based on the current step duration
// changing the step duration (i.e. changing BPM) outside of the function will result in changing the clock tick
fun void sendMIDIClockTick() {
// while (true) {
MidiMsg midiMsg;
0xf8 => midiMsg.data1; // MIDI clock
0 => midiMsg.data2;
0 => midiMsg.data3;
clockout.send(midiMsg); // Send a message to the clocked device
step/6 => now; // maybe after send?
// }
}
// Send MIDI Clock
// the clocking interval is based on the current step duration
// changing the step duration (i.e. changing BPM) outside of the function will result in changing the clock tick
fun void sendMIDIClockStart() {
// while (true) {
MidiMsg midiMsg;
0xfa => midiMsg.data1; // MIDI clock
0 => midiMsg.data2;
0 => midiMsg.data3;
clockout.send(midiMsg); // Send a message to the clocked device
// step/6 => now; // maybe after send?
// }
}