-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteraction.pde
1018 lines (829 loc) · 24.5 KB
/
interaction.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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import com.martinleopold.pui.*;
BottomButton[] bottomButtons = new BottomButton[6];
Storage store;
XML tuneXml;
int defaultBgColor = color(2,46,92);
int highlightColor = color(244,144,24);
int xOffset;
int titleOffset;
float s;
int o;
PUI pui;
void setupGui() {
pui = PUI.init(this).size(300, 300).hide();
createBottomButtons();
}
com.martinleopold.pui.Slider speed1Slider, offset1Slider, speed2Slider, offset2Slider, speed3Slider, offset3Slider, speed4Slider, offset4Slider, midiGateSlider, midiTransposeSlider;
com.martinleopold.pui.Button playhead1Backwards, playhead1Forwards, playhead1Toggle, playhead2Backwards, playhead2Forwards, playhead2Toggle, playhead3Backwards, playhead3Forwards, playhead3Toggle, playhead4Backwards, playhead4Forwards, playhead4Toggle, muteToggle;
com.martinleopold.pui.Label scalesTitle, midiTitle;
boolean playheadsMenuVisible = false;
boolean lengthMenuVisible = false;
boolean scalesMenuVisible = false;
boolean saveMenuVisible = false;
boolean loadMenuVisible = false;
boolean midiMenuVisible = false;
void createPuiLengthGroup() {
lengthMenuVisible = true;
stave.canEdit = false;
stave.startAlteringLength();
pui = PUI.init(this).size(276, height-40).theme("Grayday");
pui.padding(0.25, 0.5); // set padding (in grid units)
pui.font("deja.ttf"); // set font
pui.addLabel("Change Stave Length").large();
pui.addDivider();
pui.newRow();
pui.newRow();
pui.addLabel("Drag the orange marker to");
pui.addLabel("create a loop.");
pui.addButton().label("DONE").size(16,5).calls("removePuiLengthGroup");
}
void removePuiLengthGroup() {
stave.stopAlteringLength();
pui.hide();
lengthMenuVisible = false;
stave.canEdit = true;
if(bottomButtons[0].selected) {
bottomButtons[0].selected = false;
}
}
void createPuiPlayheadsGroup() {
stave.canEdit = false;
pui = PUI.init(this).size(710, height-40).theme("Grayday");
pui.padding(0.25, 0.5); // set padding (in grid units)
pui.font("deja.ttf"); // set font
// make controls for Playhead One
pui.addLabel("1.").large();
pui.newRow();
// pair of buttons for direction
pui.addLabel("Direction").medium();
pui.addDivider();
playhead1Backwards = pui.addButton().size(5,4).noLabel().calls("direction1Backwards").isPressed(false).deactivate();
playhead1Forwards = pui.addButton().size(5,4).noLabel().calls("direction1Forwards").isPressed(true).deactivate();
playhead1Forwards.label("FORWARDS");
pui.newRow();
pui.addLabel("Offset").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
offset1Slider = pui.addSlider().size(16,6).label("0").calls("offset1Value").min(0).max(400).value(0).deactivate();
pui.newRow();
pui.addLabel("Speed").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
speed1Slider = pui.addSlider().size(16,6).label(str(1)).min(0.25).max(4).value(1).deactivate();
pui.newRow();
playhead1Toggle = pui.addButton().label("ENABLED").size(16,5).isPressed(true).deactivate();
// make controls for Playhead Two
pui.newColumn();
pui.addLabel("2.").large();
pui.newRow();
// pair of buttons for direction
pui.addLabel("Direction").medium();
pui.addDivider();
playhead2Backwards = pui.addButton().size(5,4).noLabel().calls("direction2Backwards");
playhead2Forwards = pui.addButton().size(5,4).noLabel().calls("direction2Forwards");
if(playheadManager.playheads[1].isForwards()) {
direction2Forwards();
} else {
direction2Backwards();
}
pui.newRow();
pui.addLabel("Offset").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
offset2Slider = pui.addSlider().size(16,6).label(str((int)playheadManager.playheads[1].offset)).calls("offset2Value").min(0).max(400);
offset2Slider.value(playheadManager.playheads[1].offset);
pui.newRow();
pui.addLabel("Speed").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
speed2Slider = pui.addSlider().size(16,6).label(str(playheadManager.playheads[1].speed)).calls("speed2Value").min(0.25).max(4);
speed2Slider.value(playheadManager.playheads[1].speed);
pui.newRow();
playhead2Toggle = pui.addButton().noLabel().size(16,5).calls("togglePlayhead2");
if(playheadManager.playheads[1].active) {
playhead2Toggle.label("ENABLED");
} else {
playhead2Toggle.label("");
}
// make controls for Playhead Three
pui.newColumn();
pui.addLabel("3.").large();
pui.newRow();
// pair of buttons for direction
pui.addLabel("Direction").medium();
pui.addDivider();
playhead3Backwards = pui.addButton().size(5,4).noLabel().calls("direction3Backwards");
playhead3Forwards = pui.addButton().size(5,4).noLabel().calls("direction3Forwards");
if(playheadManager.playheads[2].isForwards()) {
direction3Forwards();
} else {
direction3Backwards();
}
pui.newRow();
pui.addLabel("Offset").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
offset3Slider = pui.addSlider().size(16,6).label(str((int)playheadManager.playheads[2].offset)).calls("offset3Value").min(0).max(400);
offset3Slider.value(playheadManager.playheads[2].offset);
pui.newRow();
pui.addLabel("Speed").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
speed3Slider = pui.addSlider().size(16,6).label(str(playheadManager.playheads[2].speed)).calls("speed3Value").min(0.25).max(4);
speed3Slider.value(playheadManager.playheads[2].speed);
pui.newRow();
playhead3Toggle = pui.addButton().noLabel().size(16,5).calls("togglePlayhead3");
if(playheadManager.playheads[2].active) {
playhead3Toggle.label("ENABLED");
} else {
playhead3Toggle.label("");
}
// make controls for Playhead Four
pui.newColumn();
pui.addLabel("4.").large();
pui.newRow();
// pair of buttons for direction
pui.addLabel("Direction").medium();
pui.addDivider();
playhead4Backwards = pui.addButton().size(5,4).noLabel().calls("direction4Backwards");
playhead4Forwards = pui.addButton().size(5,4).noLabel().calls("direction4Forwards");
if(playheadManager.playheads[3].isForwards()) {
direction4Forwards();
} else {
direction4Backwards();
}
pui.newRow();
pui.addLabel("Offset").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
offset4Slider = pui.addSlider().size(16,6).label(str((int)playheadManager.playheads[3].offset)).calls("offset4Value").min(0).max(400);
offset4Slider.value(playheadManager.playheads[3].offset);
pui.newRow();
pui.addLabel("Speed").medium();
pui.newRow();
pui.addDivider();
pui.newRow();
speed4Slider = pui.addSlider().size(16,6).label(str(playheadManager.playheads[3].speed)).calls("speed4Value").min(0.25).max(4);
speed4Slider.value(playheadManager.playheads[1].speed);
pui.newRow();
playhead4Toggle = pui.addButton().noLabel().size(16,5).calls("togglePlayhead4");
playhead4Toggle.isPressed(playheadManager.playheads[3].active);
if(playheadManager.playheads[3].active) {
playhead4Toggle.label("ENABLED");
} else {
playhead4Toggle.label("");
}
playheadsMenuVisible= true;
}
void removePuiPlayheadsGroup() {
playheadsMenuVisible= false;
pui.hide();
stave.canEdit = true;
// pui.setLayout(new Layout(width, height, 0, 0, 0));
}
// PUI interactions for Playhead 2
void direction2Forwards() {
setPlayheadDirection(2,1);
playhead2Forwards.deactivate();
playhead2Forwards.label("FORWARDS");
playhead2Backwards.isPressed(false);
playhead2Backwards.activate();
playhead2Backwards.label("");
}
void direction2Backwards() {
setPlayheadDirection(2,-1);
playhead2Forwards.activate();
playhead2Forwards.label("");
playhead2Backwards.deactivate();
playhead2Backwards.label("BACKWARDS");
}
void offset2Value(float v) {
float newValue = (float)(Math.round(v));
offset2Slider.value(newValue);
updatePlayheadOffset(2, (int)newValue);
offset2Slider.label(str((int)newValue));
}
void speed2Value(float v) {
float newValue = (float)(Math.floor(v/0.25)) * 0.25;
speed2Slider.value(newValue);
updatePlayheadSpeed(2, newValue);
speed2Slider.label(str(newValue));
}
void togglePlayhead2() {
enablePlayhead(2);
if(playheadManager.playheads[1].active) {
playhead2Toggle.isPressed(true);
playhead2Toggle.label("ENABLED");
} else {
playhead2Toggle.isPressed(false);
playhead2Toggle.label("");
}
}
// PUI interactions for Playhead 3
void direction3Forwards() {
setPlayheadDirection(3,1);
playhead3Forwards.deactivate();
playhead3Forwards.label("FORWARDS");
playhead3Backwards.isPressed(false);
playhead3Backwards.activate();
playhead3Backwards.label("");
}
void direction3Backwards() {
setPlayheadDirection(3,-1);
playhead3Forwards.activate();
playhead3Forwards.label("");
playhead3Backwards.deactivate();
playhead3Backwards.label("BACKWARDS");
}
void offset3Value(float v) {
float newValue = (float)(Math.round(v));
offset3Slider.value(newValue);
updatePlayheadOffset(3, (int)newValue);
offset3Slider.label(str((int)newValue));
}
void speed3Value(float v) {
float newValue = (float)(Math.floor(v/0.25)) * 0.25;
speed3Slider.value(newValue);
updatePlayheadSpeed(3, newValue);
speed3Slider.label(str(newValue));
}
void togglePlayhead3() {
enablePlayhead(3);
if(playheadManager.playheads[2].active) {
playhead3Toggle.isPressed(true);
playhead3Toggle.label("ENABLED");
} else {
playhead3Toggle.isPressed(false);
playhead3Toggle.label("");
}
}
// PUI interactions for Playhead 4
void direction4Forwards() {
setPlayheadDirection(4,1);
playhead4Forwards.deactivate();
playhead4Forwards.label("FORWARDS");
playhead4Backwards.isPressed(false);
playhead4Backwards.activate();
playhead4Backwards.label("");
}
void direction4Backwards() {
setPlayheadDirection(4,-1);
playhead4Forwards.activate();
playhead4Forwards.label("");
playhead4Backwards.deactivate();
playhead4Backwards.label("BACKWARDS");
}
void offset4Value(float v) {
float newValue = (float)(Math.round(v));
offset4Slider.value(newValue);
updatePlayheadOffset(4, (int)newValue);
offset4Slider.label(str((int)newValue));
}
void speed4Value(float v) {
float newValue = (float)(Math.floor(v/0.25)) * 0.25;
speed4Slider.value(newValue);
updatePlayheadSpeed(4, newValue);
speed4Slider.label(str(newValue));
}
void togglePlayhead4() {
enablePlayhead(4);
if(playheadManager.playheads[3].active) {
playhead4Toggle.isPressed(true);
playhead4Toggle.label("ENABLED");
} else {
playhead4Toggle.isPressed(false);
playhead4Toggle.label("");
}
}
// PUI Scales Interactions
void removePuiScalesGroup() {
scalesMenuVisible = false;
pui.hide();
stave.canEdit = true;
}
void createPuiScalesGroup() {
int startX, startY;
scalesMenuVisible = true;
stave.canEdit = false;
pui = PUI.init(this).size(800, height-40).theme("Grayday");
// pui.toggleGrid();
pui.padding(0.25, 0.5); // set padding (in grid units)
pui.font("deja.ttf"); // set font
scalesTitle = pui.addLabel("");
updateScalesTitle();
pui.newRow();
pui.newRow();
// black notes
startX = 20;
startY = 11;
String[] topScaleButtons = {"C#", "Eb", "F#", "Ab", "Bb"};
for (int i = 0; i < topScaleButtons.length; i++) {
String functionSafeName = topScaleButtons[i].replace("#", "sharp").replace("b", "flat");
String buttonName = "scale" + functionSafeName + "But";
com.martinleopold.pui.Button b = pui.addButton().label(topScaleButtons[i]).size(5,5).calls(buttonName);
int offset = 0;
if(i > 1) {
offset = 7;
}
b.position(startX + (i*7) + offset,startY);
}
pui.newRow();
// white notes
String[] bottomScaleButtons = {"C", "D", "E", "F", "G", "A", "B"};
startX = 17;
startY = 19;
for (int i = 0; i < bottomScaleButtons.length; i++) {
String buttonName = "scale" + bottomScaleButtons[i] + "But";
com.martinleopold.pui.Button b = pui.addButton().label(bottomScaleButtons[i].toUpperCase()).size(5,5).calls(buttonName);
println("This button is at",b.positionX(),b.positionY());
b.position(startX + (i*7),startY);
}
pui.columnWidth(100);
pui.padding(1,1);
startX = 2;
startY = 31;
String[] scaleTypes = { "major", "minor", "dorian", "lydian", "mixolydian", "phrygian", "locrian", "pentatonic", "blues", "chroma", "whole"};
for (int i = 0; i < scaleTypes.length; i++) {
String buttonName = "scaleType" + scaleTypes[i] + "But";
com.martinleopold.pui.Button b = pui.addButton().label(scaleTypes[i].toUpperCase()).size(5,5).calls(buttonName);
b.position(startX + (i*7),startY);
}
}
// PUI MIDI interactions
void removePuiMidiGroup() {
pui.hide();
midiMenuVisible = false;
stave.canEdit = true;
}
void createPuiMidiGroup() {
midiMenuVisible = true;
stave.canEdit = false;
pui = PUI.init(this).size(300, height-40).theme("Grayday");
pui.padding(1, 0.5); // set padding (in grid units)
pui.font("deja.ttf"); // set font
// pui.toggleGrid();
pui.columnWidth(30);
pui.addLabel("MIDI").large();
pui.newRow();
pui.addDivider();
midiTitle = pui.addLabel("");
pui.newRow();
if(midibox.currentBusName != null) {
midiTitle.text("Current port: " + midibox.currentBusName);
} else {
midiTitle.text("Current port: NONE");
}
String[] outputNames = midibox.midiBus.availableOutputs();
pui.addButton().label("NONE").size(5,5).calls("midiNone");
for(int i = 0; i < 9; i ++) {
if(i < outputNames.length) {
println("midi" + str(i));
pui.addButton().label(outputNames[i]).size(5,5).calls("midi" + str(i));
}
}
pui.newRow();
pui.addDivider();
pui.newRow();
pui.addLabel("Transpose");
pui.newRow();
midiTransposeSlider = pui.addSlider().size(16,4).label(str(midibox.transpose)).calls("midiTransposeValue").min(-3).max(3).value(midibox.transpose);
pui.newRow();
pui.addLabel("Gate Length");
pui.newRow();
midiGateSlider = pui.addSlider().size(16,4).label(str(midibox.gateDuration)).calls("midiGateValue").min(50).max(500).value(midibox.gateDuration);
pui.newRow();
pui.addButton().label("PANIC").size(5,5).calls("midiPanic");
muteToggle = pui.addButton().label("").size(5,5).calls("muteToggle");
if(soundbox.muted) {
muteToggle.label("UNMUTE AUDIO");
} else {
muteToggle.label("MUTE AUDIO");
}
}
void muteToggle() {
soundbox.muted = !soundbox.muted;
if(soundbox.muted) {
muteToggle.label("UNMUTE AUDIO");
} else {
muteToggle.label("MUTE AUDIO");
}
}
void midiNone() {
midibox.removeMidiBus();
midiTitle.text("Current port: NONE");
}
void midiTransposeValue(float v) {
int newValue = (int)(Math.round(v));
midiTransposeSlider.value(newValue);
midibox.transpose = newValue;
midiTransposeSlider.label(str(newValue));
}
void midiGateValue(float v) {
int newValue = (int)(Math.floor(v/50) * 50);
midiGateSlider.value(newValue);
midibox.gateDuration = newValue;
midiGateSlider.label(str(newValue)); //<>//
}
void midiPanic() {
midibox.panic();
}
void pickMidiPort(int port) {
String string = midibox.midiBus.availableOutputs()[port];
midibox.updateMidiBus(string);
midiTitle.text("Current port: " + midibox.currentBusName);
}
void midi0() {
pickMidiPort(0);
}
void midi1() {
pickMidiPort(1);
}
void midi2() {
pickMidiPort(2);
}
void midi3() {
pickMidiPort(3);
}
void midi4() {
pickMidiPort(4);
}
void midi5() {
pickMidiPort(5);
}
void midi6() {
pickMidiPort(6);
}
void midi7() {
pickMidiPort(7);
}
void midi8() {
pickMidiPort(8);
}
// PUI Save Load interactions
void createPuiSaveGroup() {
saveMenuVisible = true;
stave.canEdit = false;
pui = PUI.init(this).size(170, height-40).theme("Grayday");
pui.padding(1, 0.5); // set padding (in grid units)
pui.font("deja.ttf"); // set font
// pui.toggleGrid();
pui.addLabel("Save").large();
pui.addDivider();
int startX, startY, colSpacing;
startX = 2;
startY = 6;
colSpacing = 8;
// create Save Buttons
for (int i = 0; i < 4; i++) {
String buttonName = "save" + (i+1) + "But";
com.martinleopold.pui.Button b = pui.addButton().label(str(i+1)).size(5,5).calls(buttonName);
b.position(startX, startY + (i*colSpacing));
File f = new File(sketchPath("data/" + str(i+1) + ".xml"));
if(f.exists()) {
b.label(str(i+1));
} else {
b.label(str(i+1) + " (EMPTY)");
}
}
for (int i = 4; i < 8; i++) {
String buttonName = "save" + (i+1) + "But";
com.martinleopold.pui.Button b = pui.addButton().label(str(i+1)).size(5,5).calls(buttonName);
b.position(startX+colSpacing, startY + ((i-4)*colSpacing));
File f = new File(sketchPath("data/" + str(i+1) + ".xml"));
if(f.exists()) {
b.label(str(i+1));
} else {
b.label(str(i+1) + " (EMPTY)");
}
}
}
void removePuiSaveGroup() {
pui.hide();
saveMenuVisible = false;
stave.canEdit = true;
}
void createPuiLoadGroup() {
loadMenuVisible = true;
stave.canEdit = false;
pui = PUI.init(this).size(170, height-40).theme("Grayday");
pui.padding(1, 0.5); // set padding (in grid units)
pui.font("deja.ttf"); // set font
// pui.toggleGrid();
pui.addLabel("Load").large();
pui.addDivider();
int startX, startY, colSpacing;
startX = 2;
startY = 6;
colSpacing = 8;
// create Load Buttons
for (int i = 0; i < 4; i++) {
String buttonName = "load" + (i+1) + "But";
com.martinleopold.pui.Button b = pui.addButton().label(str(i+1)).size(5,5).calls(buttonName);
b.position(startX, startY + (i*colSpacing));
File f = new File(sketchPath("data/" + str(i+1) + ".xml"));
if(f.exists()) {
b.label(str(i+1));
} else {
b.label(str(i+1) + " (EMPTY)");
b.deactivate();
}
}
for (int i = 4; i < 8; i++) {
String buttonName = "load" + (i+1) + "But";
com.martinleopold.pui.Button b = pui.addButton().label(str(i+1)).size(5,5).calls(buttonName);
b.position(startX+colSpacing, startY + ((i-4)*colSpacing));
File f = new File(sketchPath("data/" + str(i+1) + ".xml"));
if(f.exists()) {
b.label(str(i+1));
} else {
b.label(str(i+1) + " (EMPTY)");
b.deactivate();
}
}
// create a clear button.
com.martinleopold.pui.Button b = pui.addButton().label("CLEAR").size(5,5).calls("clearStave");
b.position(startX, startY + (4*colSpacing));
}
void removePuiLoadGroup() {
pui.hide();
loadMenuVisible = false;
stave.canEdit = true;
}
// Mouse Interactions
void mouseDragged() {
if(stave.alteringLength && (mouseX > 270)) {
stave.updateWidthFromAbs(mouseX);
playheadManager.updatePlayheadsToWidth();
}
}
void mousePressed() {
if(stave.insideStave(mouseX,mouseY) && !stave.alteringLength) {
stave.click(mouseX, mouseY);
}
for (int i = 0; i < bottomButtons.length; i++ ) {
if (mouseX > bottomButtons[i].x && mouseX < bottomButtons[i].x+bottomButtons[i].buttonWidth &&
mouseY > bottomButtons[i].y && mouseY < bottomButtons[i].y + bottomButtons[i].buttonHeight) {
bottomButtons[i].click();
}
}
}
void keyPressed() {
switch (key) {
case 'p':
midibox.panic();
println("PANIC");
break;
}
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
//float mouseWheelScale = 2;
//e = e / mouseWheelScale;
int wheelDebounce = 2;
if(e > wheelDebounce) {
e = 4;
} else if(e < (0 - wheelDebounce)) {
e = -4;
}
playheadManager.modifyPositionBy(e);
}
public void resetButton() {
soundbox.reset();
stave.reset();
}
void updateScalesTitle() {
scalesTitle = scalesTitle.text("Current Scale: " + soundbox.currentScaleName()).large();
}
// begin scale root selection
void scaleCBut() {
selectScaleButton("c");
}
void scaleCsharpBut() {
selectScaleButton("c#");
}
void scaleDBut() {
selectScaleButton("d");
}
void scaleEflatBut() {
selectScaleButton("d#");
}
void scaleEBut() {
selectScaleButton("e");
}
void scaleFBut() {
selectScaleButton("f");
}
void scaleFsharpBut() {
selectScaleButton("f#");
}
void scaleGBut() {
selectScaleButton("g");
}
void scaleAflatBut() {
selectScaleButton("g#");
}
void scaleABut() {
selectScaleButton("a");
}
void scaleBflatBut() {
selectScaleButton("a#");
}
void scaleBBut() {
selectScaleButton("b");
}
// end scale root selection
// begin scale type selection
void scaleTypemajorBut() {
selectScaleTypeButton("major");
}
void scaleTypeminorBut() {
selectScaleTypeButton("minor");
}
void scaleTypedorianBut() {
selectScaleTypeButton("dorian");
}
void scaleTypelydianBut() {
selectScaleTypeButton("lydian");
}
void scaleTypemixolydianBut() {
selectScaleTypeButton("mixolydian");
}
void scaleTypephrygianBut() {
selectScaleTypeButton("phrygian");
}
void scaleTypelocrianBut() {
selectScaleTypeButton("locrian");
}
void scaleTypepentatonicBut() {
selectScaleTypeButton("pentatonic");
}
void scaleTypebluesBut() {
selectScaleTypeButton("blues");
}
void scaleTypechromaBut() {
selectScaleTypeButton("chroma");
}
void scaleTypewholeBut() {
selectScaleTypeButton("whole");
}
// end scale type selection
// begin save/load buttons
void save1But(){
saveTune("data/1.xml");
}
void save2But(){
saveTune("data/2.xml");
}
void save3But(){
saveTune("data/3.xml");
}
void save4But(){
saveTune("data/4.xml");
}
void save5But(){
saveTune("data/5.xml");
}
void save6But(){
saveTune("data/6.xml");
}
void save7But(){
saveTune("data/7.xml");
}
void save8But(){
saveTune("data/8.xml");
}
void load1But(){
loadTune("data/1.xml");
}
void load2But(){
loadTune("data/2.xml");
}
void load3But(){
loadTune("data/3.xml");
}
void load4But(){
loadTune("data/4.xml");
}
void load5But(){
loadTune("data/5.xml");
}
void load6But(){
loadTune("data/6.xml");
}
void load7But(){
loadTune("data/7.xml");
}
void load8But(){
loadTune("data/8.xml");
}
// end save/load buttons
void saveTune(String filename) {
store = new Storage(stave,soundbox);
tuneXml = store.tuneToXml();
saveXML(tuneXml, filename);
removePuiSaveGroup();
bottomButtons[0].deselectAll();
}
void loadTune(String filename) {
store = new Storage(stave,soundbox);
tuneXml = loadXML(filename);
store.xmlToTune(tuneXml);
removePuiLoadGroup();
bottomButtons[0].deselectAll();
}
void clearStave() {
// reset the soundbox
soundbox.scaleRoot = "c";
soundbox.scaleType = "major";
soundbox.updateScaleSounds();
// clear out any notes we've got
stave.reset();
// set default playhead to beginning
playheadManager.playheads[0].position = 0;
// disable all existing playheads > 0
for (int i = 1; i < playheadManager.playheads.length; i ++ ) {
playheadManager.playheads[i].deactivate();
playheadManager.playheads[i].speed = 1.0;
playheadManager.playheads[i].directionOffset = 1;
playheadManager.playheads[i].direction = 1;
playheadManager.playheads[i].offset = 0;
playheadManager.playheads[i].position = playheadManager.playheads[0].position;
}
removePuiLoadGroup();
bottomButtons[0].deselectAll();
}
void selectScaleButton(String shortName) {
String scaleRoot = soundbox.normalizeScaleName(shortName);
println("Setting scale to", scaleRoot);
soundbox.scaleRoot = scaleRoot;
soundbox.updateScaleSounds();
updateScalesTitle();
}
void selectScaleTypeButton(String scaleType) {
println("Updating scales title to ", scaleType);
soundbox.scaleType = scaleType;
soundbox.updateScaleSounds();
updateScalesTitle();
}
void enablePlayhead(int pN) {
int index = pN - 1;
Playhead p = playheadManager.playheads[index];
if(p.active) {
p.deactivate();
} else {
p.activate();
}
}
void togglePlayheadDirection(int pN) {
int index = pN - 1;
Playhead p = playheadManager.playheads[index];
if(p.directionOffset == 1) {
p.directionOffset = -1;
p.direction = 1 - p.direction;
} else {
p.directionOffset = 1;
p.direction = 1 - p.direction;
}
}
void setPlayheadDirection(int pN, int dirOff) {
int index = pN - 1;
Playhead p = playheadManager.playheads[index];
p.directionOffset = dirOff;
if(p.directionOffset > 0) {
p.direction = 1;
} else {
p.direction = 0;
}
}
void updatePlayheadOffset(int pN, int off) {
int index = pN - 1;
Playhead p = playheadManager.playheads[index];
println("Setting offset to ", off);
p.changeOffset(off, playheadManager.playheads[0].position);
println("Playhead offset is now ", p.offset);
}
void updatePlayheadSpeed(int pN, float s) {
int index = pN - 1;