-
Notifications
You must be signed in to change notification settings - Fork 0
/
multimodal-daw-mod.pde
680 lines (645 loc) · 20.7 KB
/
multimodal-daw-mod.pde
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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
import websockets.*; // Import Websockets library
import themidibus.*; // Import the MidiBus library
import processing.video.*; // Import Video library
WebsocketServer socket; // The WebsocketServer
MidiBus myBus; // the midibus
Capture video; // video input
color firstTrackColor; // first color to track
color secondTrackColor; // second color to track
float threshold = 20; // threshold for color recognition
int yellowX = 320; // sets color position to center as default
int yellowY = 180;
int redX = 320;
int redY = 180;
int activeMode = 0;
int activeTrack = 1; // sets track 1 as default active channel
int activeComp = 0; // sets track 1 as default active channel for compression, so values are updated according to the values in Logic Pro X
int[][] compList = { {0,0,0,0}, // drums compression default settings
{0,0,0,0}, // kick compression default settings
{0,0,0,0}, // snare compression default settings
{0,0,0,0}, // tom compression default settings
{0,0,0,0}, // overheads compression default settings
{0,0,0,0}, // bass compression default settings
{0,0,0,0}, // guitar compression default settings
{0,0,0,0}, // acoustic guitar compression default settings
{0,0,0,0}, // dobro compression default settings
{0,0,0,0}, // electric guitar compression default settings
{0,0,0,0}, // fiddle compression default settings
{0,0,0,0}, // piano compression default settings
{0,0,0,0}, }; // vocals compression default settings
void setup() {
socket = new WebsocketServer(this, 1337, "/p5websocket"); // connection to Google Chrome
MidiBus.list(); // list all available midi-devices on STDOUT. This will show each device's index and name.
myBus = new MidiBus(this, "Processing to DAW (bus 1)", "Processing to DAW (bus 1)"); // create a new MidiBus using the device names to select the Midi input and output devices respectively.
size(640, 360); // video input size
String[] cameras = Capture.list();
printArray(cameras);
video = new Capture(this, cameras[3]);
video.start();
firstTrackColor = color(240, 240, 36); // first color set to yellow
secondTrackColor = color(240, 43, 36); // first color set to red
}
void captureEvent(Capture video) { // capture video input
video.read();
}
void draw() {
video.loadPixels();
image(video, 0, 0);
findColors();
if (activeMode == 1) { // check if mode is activated and run desired function
volumePanControl();
} else if (activeMode == 2) {
EQControl();
} else if (activeMode == 3) {
comp();
} else if (activeMode == 4) {
reverb();
}
}
// WEBSOCKET EVENT INPUT & CONFIGURATION
void webSocketServerEvent(String msg){
msg = trim(msg); // removes spaces infront and after string
msg = msg.toLowerCase(); // lowercase only
println(msg);
modeSelection(msg); // sends msg to check for mode selection & implementation
trackSelection(msg); // sends msg to check for track selection & implementation
markerSelection(msg); // sends msg to check for marker selection & implementation
soloMute(msg); // sends msg to check for solo/mute prompt and implementation
playPause(msg); // sends msg to check for play/pause prompt and implementation
loop(msg); // sends msg to check for looped section & implementation
barNavigation(msg); // sends msg to check for bar navigation & implementation
startNavigation(msg); // sends msg to check for start/beginning navigation & implementation
}
// FIND POSITION OF COLORS AND UPDATE VARIABLES
void findColors() {
threshold = 80; // sets color threshold
float avgX = 0; // XY coordinate of closest color
float avgY = 0;
float avgX2 = 0;
float avgY2 = 0;
int count = 0;
int count2 = 0;
for (int x = 0; x < video.width; x++ ) { // begin loop to walk through every pixel
for (int y = 0; y < video.height; y++ ) {
int loc = x + y * video.width;
color firstColor = video.pixels[loc]; // what is first color
float r1 = red(firstColor);
float g1 = green(firstColor);
float b1 = blue(firstColor);
float r2 = red(firstTrackColor);
float g2 = green(firstTrackColor);
float b2 = blue(firstTrackColor);
color secondColor = video.pixels[loc]; // what is second color
float r3 = red(secondColor);
float g3 = green(secondColor);
float b3 = blue(secondColor);
float r4 = red(secondTrackColor);
float g4 = green(secondTrackColor);
float b4 = blue(secondTrackColor);
float d = distSq(r1, g1, b1, r2, g2, b2);
float d2 = distSq(r3, g3, b3, r4, g4, b4);
if (d < threshold*threshold) {
stroke(255);
strokeWeight(1);
point(x, y);
avgX += x;
avgY += y;
count++;
}
if (d2 < threshold*threshold) {
stroke(255);
strokeWeight(1);
point(x, y);
avgX2 += x;
avgY2 += y;
count2++;
}
}
}
if (count > 0) {
avgX = avgX / count;
avgY = avgY / count;
fill(255); // draw a circle at the tracked pixel
strokeWeight(4.0);
stroke(0);
ellipse(avgX, avgY, 24, 24);
yellowX = int(avgX); // store position in variables
yellowY = int(avgY);
} else {
yellowX = 320; // resets x-position to center if no input is detected
yellowY = 180; // resets y-position to center if no input is detected
}
if (count2 > 0) {
avgX2 = avgX2 / count2;
avgY2 = avgY2 / count2;
fill(255); // draw a circle at the tracked pixel
strokeWeight(4.0);
stroke(0);
ellipse(avgX2, avgY2, 24, 24);
redX = int(avgX2); // stores position in variable
redY = int(avgY2);
} else {
redX = 320; // resets x-position to center if no input is detected
redY = 180; // resets y-position to center if no input is detected
}
}
float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
return d;
}
float distSq2(float x1, float y1, float z1, float x2, float y2, float z2) {
float d2 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
return d2;
}
// KEY PRESSED OR RELEASED TO ENABLE/DISABLE WEBSOCKET INPUT
void keyPressed() {
if (key == 'r') {
socket.sendMessage("active"); // sends data to browser
}
}
void keyReleased() {
if (key == 'r') {
socket.sendMessage("inactive"); // sends data to browser
}
}
// CHECKS FOR MODE SELECTION
void modeSelection(String message) {
switch(message) {
case "exit mode": // exit mode
case "exit":
case "exceed":
case "escape mode":
case "luk equalizer":
case "luk kompressor":
case "luftkompressor":
case "luk reverb":
case "luk rumklang":
activeMode = 0;
break;
case "balance": // balance mode
case "volume":
case "panorering":
activeMode = 1;
break;
case "equalizer": // equalizer mode
activeMode = 2;
break;
case "compressor": // compressor mode
case "kompressor":
activeMode = 3;
break;
case "rumklang": // reverb mode
case "reverb":
case "rum tang":
case "rumfang":
activeMode = 4;
break;
}
}
// CHECKS FOR TRACK SELECTION
void trackSelection(String message) {
switch(message) {
case "drums": // drum group
case "trommer":
trackSelect(1);
activeComp = 0; // sets compression settings for active track
break;
case "kick": // kick drum
case "kik":
case "store tromme":
case "tjek":
case "kick drum":
trackSelect(2);
activeComp = 1;
break;
case "snare": // snare drum
case "snare drum":
case "snerrer":
case "lilletromme":
case "snerle":
trackSelect(3);
activeComp = 2;
break;
case "tom": // tom
case "tam":
trackSelect(4);
activeComp = 3;
break;
case "overheads": // overheads
case "overhead":
case "oversæt":
trackSelect(5);
activeComp = 4;
break;
case "bass": // bass
case "base":
case "bas":
case "beige":
trackSelect(6);
activeComp = 5;
break;
case "guitars": // guitar group
case "alle guitar":
case "guitar":
case "guitarer":
trackSelect(7);
activeComp = 6;
break;
case "acoustic guitar": // acoustic guitar
case "akustisk guitar":
case "western guitar":
trackSelect(8);
activeComp = 7;
break;
case "dobro": // dobro
case "dobro guitar":
case "borup":
case "doro":
case "gopro":
trackSelect(9);
activeComp = 8;
break;
case "electric guitar": // electric guitar
case "elektrisk guitar":
case "elguitar":
case "el guitar":
trackSelect(10);
activeComp = 9;
break;
case "fiddle": // fiddle
case "violin":
case "fidel":
case "vettel":
trackSelect(11);
activeComp = 10;
break;
case "piano": // piano
case "klaver":
trackSelect(12);
activeComp = 11;
break;
case "lead vocal": // vocal
case "vocal":
case "forsanger":
case "vokal":
case "pokal":
trackSelect(13);
activeComp = 12;
break;
}
}
// TRACK SELECTION & IMPLEMENTATION
void trackSelect(int selectedTrack) {
if (selectedTrack > activeTrack) {
for(int i = selectedTrack; i > activeTrack; activeTrack++) {
int channel = 1;
int number = 1;
int value = 1; // select next track
myBus.sendControllerChange(channel, number, value); // send a controllerChange
}
} else if (selectedTrack < activeTrack) {
for(int i = selectedTrack; i < activeTrack; activeTrack--) {
int channel = 1;
int number = 1;
int value = 2; // select previous track
myBus.sendControllerChange(channel, number, value);
}
}
activeTrack = selectedTrack;
}
// MARKER SELECTION & IMPLEMENTATION
void markerSelection(String message) {
switch(message) {
case "intro":
int channel = 1;
int number = 1;
int value = 3;
myBus.sendControllerChange(channel, number, value);
break;
case "vers 1":
case "hvad er ssid":
channel = 1;
number = 1;
value = 4;
myBus.sendControllerChange(channel, number, value);
break;
case "vers 2":
channel = 1;
number = 1;
value = 5;
myBus.sendControllerChange(channel, number, value);
break;
case "guitar solo":
channel = 1;
number = 1;
value = 6;
myBus.sendControllerChange(channel, number, value);
break;
case "vers 3":
case "spærtræ":
channel = 1;
number = 1;
value = 7;
myBus.sendControllerChange(channel, number, value);
break;
case "fiddle solo":
channel = 1;
number = 1;
value = 8;
myBus.sendControllerChange(channel, number, value);
break;
case "vers 4":
case "per ps4":
channel = 1;
number = 1;
value = 9;
myBus.sendControllerChange(channel, number, value);
break;
}
}
// SOLO OR MUTE TRACK
void soloMute(String message) {
switch(message) {
case "solo":
case "unsolo":
case "hon solo":
case "non solo":
case "han solo":
case "on solo":
case "om solo":
int channel = 1;
int number = 1;
int value = 10;
myBus.sendControllerChange(channel, number, value);
break;
case "mute":
case "unmute":
channel = 1;
number = 2;
value = 1; // select previous track
myBus.sendControllerChange(channel, number, value);
break;
}
}
// PLAY OR PAUSE PROJECT
void playPause(String message) {
switch(message) {
case "play":
case "start":
case "afspil":
int channel = 1;
int number = 2;
int value = 2;
myBus.sendControllerChange(channel, number, value);
break;
case "stop":
case "pause":
channel = 1;
number = 2;
value = 3;
myBus.sendControllerChange(channel, number, value);
break;
}
}
// LOOP MARKED SECTION OR EXIT LOOP
void loop(String message) {
switch(message) {
case "loop":
int channel = 1;
int number = 2;
int value = 4;
myBus.sendControllerChange(channel, number, value);
break;
case "cancel loop":
case "afbryd loop":
case "slet loop":
case "fjern loop":
case "delete loop":
case "stop loop":
case "unloop":
case "on youtube":
channel = 1;
number = 2;
value = 5;
myBus.sendControllerChange(channel, number, value);
break;
}
}
// BAR NAVIGATION
void barNavigation(String message) {
String arr[] = message.split(" ", 2); // splits string to an array
String direction = arr[0]; // stores the first word in var
String barAmount = message.substring(message.lastIndexOf(" ")+1); // takes last word of string
int amount = int(barAmount); // converts string into integer
switch(direction) {
case "forward": // go forth number of bars
case "frem":
int channel = 1;
int number = 2;
int value = 6;
for (int i = 0; i < amount; i++) { // runs number of bars
myBus.sendControllerChange(channel, number, value);
}
break;
case "rewind": // go back number of bars
case "tilbage":
channel = 1;
number = 2;
value = 7;
for (int i = 0; i < amount; i++) { // runs number of bars
myBus.sendControllerChange(channel, number, value);
}
break;
}
}
// GO TO BEGINNING AND PLAY FROM BEGINNING
void startNavigation(String message) {
switch(message) {
case "back to start": // go back to start
case "til toppen":
case "til start":
int channel = 1;
int number = 2;
int value = 8;
myBus.sendControllerChange(channel, number, value);
break;
case "afspil fra begyndelsen": // go back to start and play
case "afspil fra toppen":
case "afspil fra starten":
case "play from beginning":
channel = 1;
number = 2;
value = 9;
myBus.sendControllerChange(channel, number, value);
break;
}
}
// CONTROL PAN & VOLUME OF SELECTED TRACK
void volumePanControl() {
if (yellowY <= 100 || redY <= 100) {
int channel = 1;
int number = 3;
int value = 1;
myBus.sendControllerChange(channel, number, value);
} else if (yellowY >= 300 || redY >= 300) {
int channel = 1;
int number = 2;
int value = 10;
myBus.sendControllerChange(channel, number, value);
} else if (yellowX <= 150 || redX <= 150) {
int channel = 1;
int number = 3;
int value = 2;
myBus.sendControllerChange(channel, number, value);
} else if (yellowX >= 490 || redX >= 490) {
int channel = 1;
int number = 3;
int value = 3;
myBus.sendControllerChange(channel, number, value);
}
}
// EQUALIZER CONTROLS
void EQControl() {
if (redX > 320 && yellowY <= 100) { // turn EQ parameter upwards
if (redY > 300) { // low shelf
int channel = 1;
int number = 3;
int value = 5;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 240 && redY <= 300) { // peak 1
int channel = 1;
int number = 3;
int value = 7;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 180 && redY <= 240) { // peak 2
int channel = 1;
int number = 3;
int value = 9;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 120 && redY < 180) { // peak 3 - take away = with 180, to make a safe zone, when redY is reset to 180, when color is not present
int channel = 1;
int number = 4;
int value = 1;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 60 && redY <= 120) { // peak 4
int channel = 1;
int number = 4;
int value = 3;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 0 && redY <= 60) { // high shelf
int channel = 1;
int number = 4;
int value = 5;
myBus.sendControllerChange(channel, number, value);
}
} else if (redX > 320 && yellowY >= 300) { // turn EQ parameter downwards
if (redY > 300) { // low shelf
int channel = 1;
int number = 3;
int value = 6;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 240 && redY <= 300) { // peak 1
int channel = 1;
int number = 3;
int value = 8;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 180 && redY <= 240) { // peak 2
int channel = 1;
int number = 3;
int value = 10;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 120 && redY < 180) { // peak 3 - take away = with 180, to make a safe zone, when redY is reset to 180, when color is not present
int channel = 1;
int number = 4;
int value = 2;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 60 && redY <= 120) { // peak 4
int channel = 1;
int number = 4;
int value = 4;
myBus.sendControllerChange(channel, number, value);
} else if (redY > 0 && redY <= 60) { // high shelf
int channel = 1;
int number = 4;
int value = 6;
myBus.sendControllerChange(channel, number, value);
}
}
}
// COMPRESSOR CONTROLS
void comp() {
if (yellowX < 320) { // check for yellow color
float myx = map(yellowX, 319, 0, 0, 100); // map to compressor value (threshold)
int yellowXMapped = (int(myx)); // float to integer
for (int i = yellowXMapped; i > compList[activeComp][0]; compList[activeComp][0]++) { // use compression settings from active track
int channel = 1;
int number = 4;
int value = 8;
myBus.sendControllerChange(channel, number, value);
}
for (int i = yellowXMapped; i < compList[activeComp][0]; compList[activeComp][0]--) {
int channel = 1;
int number = 4;
int value = 7;
myBus.sendControllerChange(channel, number, value);
}
float myy = map(yellowY, 360, 0, 0, 100); // map to compressor value (attack)
int yellowYMapped = (int(myy));
for (int i = yellowYMapped; i > compList[activeComp][1]; compList[activeComp][1]++) {
int channel = 1;
int number = 4;
int value = 9;
myBus.sendControllerChange(channel, number, value);
}
for (int i = yellowYMapped; i < compList[activeComp][1]; compList[activeComp][1]--) {
int channel = 1;
int number = 4;
int value = 10;
myBus.sendControllerChange(channel, number, value);
}
}
if (redX > 320) { // check for red color
float mrx = map(redX, 321, 640, 0, 85); // map to compressor value (ratio)
int redXMapped = (int(mrx));
for (int i = redXMapped; i > compList[activeComp][2]; compList[activeComp][2]++) {
int channel = 1;
int number = 5;
int value = 1;
myBus.sendControllerChange(channel, number, value);
}
for (int i = redXMapped; i < compList[activeComp][2]; compList[activeComp][2]--) {
int channel = 1;
int number = 5;
int value = 2;
myBus.sendControllerChange(channel, number, value);
}
float mry = map(redY, 360, 0, 0, 118); // map to compressor value (release)
int redYMapped = (int(mry));
for (int i = redYMapped; i > compList[activeComp][3]; compList[activeComp][3]++) {
int channel = 1;
int number = 5;
int value = 3;
myBus.sendControllerChange(channel, number, value);
}
for (int i = redYMapped; i < compList[activeComp][3]; compList[activeComp][3]--) {
int channel = 1;
int number = 5;
int value = 4;
myBus.sendControllerChange(channel, number, value);
}
}
}
// REVERB CONTROLS
void reverb() {
if (yellowY <= 100 || redY <= 100) {
int channel = 1;
int number = 5;
int value = 5;
myBus.sendControllerChange(channel, number, value);
} else if (yellowY >= 300 || redY >= 300) {
int channel = 1;
int number = 5;
int value = 6;
myBus.sendControllerChange(channel, number, value);
}
}