-
Notifications
You must be signed in to change notification settings - Fork 4
/
DroneController.sc
1776 lines (1584 loc) · 63 KB
/
DroneController.sc
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
DroneController {
var deathArray, osc; // experimental
var <drawView, drawTask, <scp, dronegui, speakercircles, codescore;
var <>droneArray, <>machineArray; // arrays are used for drawing
var <droneDict, <chordDict, <satellitesDict, <machineDict, <interDict, <groupDict;
var <>hub, window, screendimension;
var drone, <>selected, <>selectedName, interDroneArray, <nameArray;
var speakers, <tuning, <scale, <fundamental;
var interpreter, states, interpret, oldy;
var <globalenv;
var drawFunc, mouseDownAct, mouseMoveAct;
var dronecount, leftoffset, speakercirlesview, midipadNames, midiout;
// var testwin;
*new { arg hub, tuning, scale, fundamental;
^super.new.initDroneController(hub, tuning, scale, fundamental);
}
initDroneController { |arghub, argtuning, argscale, argfundamental|
hub = arghub;
window = hub.window;
interpreter = hub.interpreter;
states = hub.states;
dronecount = 0;
droneArray = [];
deathArray = [];
machineArray = [];
droneDict = ();
chordDict = ();
satellitesDict = ();
groupDict = ();
machineDict = ();
interDict = (); // storing interpreted clusters
interDroneArray = [];
nameArray = [];
// this.initDicts();
speakers = hub.speakers;
selected = 0;
selectedName = "o_o";
globalenv = [3,3];
tuning = argtuning;
scale = argscale;
fundamental = argfundamental;
interpret = false;
midipadNames = {nil} ! 8; // the AKAI pad for exposingMIDI to drones
screendimension = Window.screenBounds.height;
leftoffset = if(hub.mode == \displayFS, {(Window.screenBounds.width-screendimension)/2}, {0});
//Pen.font = Font( "Helvetica-Bold", 14 );
thisThread.randSeed = hub.randomseed;
speakercircles = speakers.drawImg;
[\speakercircles, speakercircles].postln;
// speakercircles.plot;
// speakercircles.dump;
mouseDownAct = { |me, x, y, mod|
var seldrone, string;
var cursorDistCenter = sqrt(([0, 0] - [(hub.middle - x).abs, (hub.middle - y).abs]).squared.sum);
var cursorTheta = (Point((hub.middle - x),(hub.middle - y)).theta+pi);
oldy = y; // the offset for calculating mouse move rotation
droneArray.do({ |drone, i| drone.selected = false }); // deselect all drones
droneArray.do({ |drone, i|
var zeroCrossing = false;
var loc = drone.getDroneLook;
if(loc[2]+loc[3] > (2*pi), { // a drone crossing the zero line
if(
(cursorDistCenter>loc[0]) &&
(cursorDistCenter<loc[1]) &&
(( cursorTheta > loc[2] ) || ( cursorTheta < ((loc[2] + loc[3]) % (2*pi)))), {
selected = i;
drone.selected = true;
selectedName = drone.name.asString;
seldrone = drone;
});
}, {
if(
(cursorDistCenter>loc[0]) &&
(cursorDistCenter<loc[1]) &&
( cursorTheta > loc[2] ) &&
( cursorTheta < (loc[2] + loc[3])), {
selected = i;
drone.selected = true;
selectedName = drone.name.asString;
seldrone = drone;
});
});
});
// [\selectedspeed, seldrone.speed].postln;
// [\selectedName, selectedName].postln;
if(hub.post && seldrone.isNil.not, {
hub.postDroneState(selectedName, selected);
// Document.listener.string = ""; // clear post window
// string = "~"++selectedName++"\n"++
// "~"++selectedName++".type = \\"++seldrone.type++"\n"++
// "~"++selectedName++".harmonics = "++seldrone.harmonics++"\n"++
// "~"++selectedName++".amp = "++seldrone.amp++"\n"++
// "~"++selectedName++".degree = "++seldrone.degree++"\n"++
// "~"++selectedName++".ratio = "++seldrone.ratio++"\n"++
// "~"++selectedName++".env = "++seldrone.env++"\n"++
// "~"++selectedName++".octave = "++seldrone.octave++"\n";
// Document.listener.string = string; // add info
// hub.interpreter.postview.string_(string);
});
if(codescore.isNil.not, {
//"in here________________".postln;
codescore.removeTextScore; // remove the textual score view
});
};
mouseMoveAct = { |me, x, y, mod|
var change = (oldy-y)/300;
droneArray[selected].relRotation_(change);
oldy = y;
};
drawFunc = {
//speakers.draw;
droneArray.do({arg drone; drone.update; drone.draw.value});
deathArray.do({arg drone; drone.update; drone.draw.value}); // drones scheduled for death ... fading out
// machineArray.do({arg machine; machine.update; }); // machines have their own update
machineArray.do({arg machine; machine.draw.value }); // machines have their own update
//try{ Pen.stringAtPoint(droneArray[selected].name.asString, Point(20, screendimension-100)) }; // if there is no drone
Color.black.alpha_(0.5).set;
// try{ Pen.stringAtPoint("ooo", Point(20, 100)) }; // if there is no drone
try{ Pen.stringAtPoint(selectedName, Point(20, screendimension-100)) }; // if there is no drone
//try{ Pen.stringAtPoint("RIUFIF", Point(20, screendimension-130)) }; // if there is no drone
};
// window.view.backgroundImage = speakercircles; // WSLib
speakercirlesview = UserView.new(window, Rect(leftoffset, 0, screendimension, screendimension)).backgroundImage_(speakercircles);
// the circles drawn into a bitmap once
// UserView.new(window, Rect(0, 0, screendimension, screendimension)).drawFunc_({ speakers.drawImg });
// the drone wedges drawn repeatedly
drawView = UserView.new(window, Rect(leftoffset, 0, screendimension, screendimension))
.mouseDownAction_( mouseDownAct )
.mouseMoveAction_( mouseMoveAct )
.keyDownAction_({arg view, char, modifiers, unicode, keycode;
//[char, modifiers, unicode, keycode].postln;
switch(keycode)
{126}{ // up arrow
if(modifiers == 11010368, {
var name, collectivename, string;
selected = (selected-1).clip(0, droneArray.size-1);
name = droneArray[selected].name.asString;
droneArray.do({ arg drone; drone.selected = false }); // deselect all
if(name.contains("_"), { // it's a group of some sort
collectivename = name[0..name.findAll("_").last-1];
if(name.contains("chd_"), {
chordDict.keys.do({ |key|
if(key.asString == collectivename, {
chordDict[key].selected = true;
});
});
});
if(name.contains("sat_"), {
satellitesDict.keys.do({ |key|
if(key.asString == collectivename, {
satellitesDict[key].selected = true;
});
});
//satellitesDict[name[0..6].asSymbol].selected = true;
});
if(name.contains("grp_"), {
//var grpname = key.asString[0..key.asString.findAll("_")[1]-1];
groupDict.keys.do({ |key|
if(key.asString == collectivename, {
groupDict[key].selected = true;
});
});
});
selectedName = collectivename; // only the name of the group
block{ arg break;
droneArray.do({ arg drone, i;
if(drone.name.asString.contains("_"), {
if((drone.name.asString[0..drone.name.asString.findAll("_").last-1] == collectivename), {
selected = i;
break.value();
});
});
}); };
}, {
selectedName = droneArray[selected].name.asString;
droneArray[selected].selected = true;
});
if(hub.post, {
hub.postDroneState(selectedName, selected);
// Document.listener.string = ""; // clear post window
// string = "~"++selectedName++"\n"++
// "~"++selectedName++".type = \\"++droneArray[selected].type++"\n"++
// "~"++selectedName++".harmonics = "++droneArray[selected].harmonics++"\n"++
// "~"++selectedName++".amp = "++droneArray[selected].amp++"\n"++
// "~"++selectedName++".degree = "++droneArray[selected].degree++"\n"++
// "~"++selectedName++".ratio = "++droneArray[selected].ratio++"\n"++
// "~"++selectedName++".env = "++droneArray[selected].env++"\n"++
// "~"++selectedName++".octave = "++droneArray[selected].octave++"\n";
//
// Document.listener.string = string; // add info
//
// hub.interpreter.postview.string_(string);
});
}, { // increase amplitude
if(selectedName.contains("chd_"), {
chordDict.keys.do({ |key|
if(key.asString == selectedName, {
chordDict[key].amp_((chordDict[key].amp+0.01).clip(0, 2));
});
});
}, {
if(selectedName.contains("sat_"), {
satellitesDict.keys.do({ |key|
if(key.asString == selectedName, {
satellitesDict[key].amp_((satellitesDict[key].amp+0.01).clip(0, 2));
});
});
}, {
if(selectedName.contains("grp_"), {
groupDict.keys.do({ |key|
if(key.asString == selectedName, {
groupDict[key].amp_((groupDict[key].amp+0.01).clip(0, 2));
});
});
}, {
droneArray[selected].set(\amp, (droneArray[selected].amp + 0.01).clip(0, 2));
});
});
});
});
"up".postln;
}
{125}{
if(modifiers == 11010368, {
var name, collectivename, string;
var foundFlag = false;
var oldfoundFlag = false;
selected = (selected+1).clip(0, droneArray.size-1);
name = droneArray[selected].name.asString;
droneArray.do({ arg drone; drone.selected = false }); // deselect all
if(name.contains("_"), { // it's a group of some sort
collectivename = name[0..name.findAll("_").last-1];
if(name.contains("chd_"), {
chordDict.keys.do({ |key|
if(key.asString == collectivename, {
chordDict[key].selected = true;
});
});
});
if(name.contains("sat_"), {
satellitesDict.keys.do({ |key|
if(key.asString == collectivename, {
satellitesDict[key].selected = true;
});
});
});
if(name.contains("grp_"), {
groupDict.keys.do({ |key|
if(key.asString == collectivename, {
groupDict[key].selected = true;
});
});
});
selectedName = collectivename; // only the name of the group/sat/chord
block{ arg break;
droneArray[selected .. droneArray.size].do({ arg drone, i;
oldfoundFlag = foundFlag;
if(drone.name.asString.contains("_"), {
if(drone.name.asString[0..drone.name.asString.findAll("_").last-1] == collectivename, {
foundFlag = true;
},{
foundFlag = false;
});
}, {
foundFlag = false;
});
if((oldfoundFlag == true) && (foundFlag == false), { // we've reached a drone outside group
selected = (selected+i-1).clip(0, droneArray.size-1);
("selected down = "+selected).postln;
break.value;
});
});
}
}, {
selectedName = droneArray[selected].name.asString;
droneArray[selected].selected = true;
});
if(hub.post, {
hub.postDroneState(selectedName, selected);
// Document.listener.string = ""; // clear post window
// string = "~"++selectedName++"\n"++
// "~"++selectedName++".type = \\"++droneArray[selected].type++"\n"++
// "~"++selectedName++".harmonics = "++droneArray[selected].harmonics++"\n"++
// "~"++selectedName++".amp = "++droneArray[selected].amp++"\n"++
// "~"++selectedName++".degree = "++droneArray[selected].degree++"\n"++
// "~"++selectedName++".ratio = "++droneArray[selected].ratio++"\n"++
// "~"++selectedName++".env = "++droneArray[selected].env++"\n"++
// "~"++selectedName++".octave = "++droneArray[selected].octave++"\n";
// Document.listener.string = string; // add info
// hub.interpreter.postview.string_(string);
});
}, {
// decrease amplitude
if(selectedName.contains("chd_"), {
chordDict.keys.do({ |key|
if(key.asString == selectedName, {
chordDict[key].amp_((chordDict[key].amp-0.01).clip(0, 2));
});
});
}, {
if(selectedName.contains("sat_"), {
satellitesDict.keys.do({ |key|
if(key.asString == selectedName, {
satellitesDict[key].amp_((satellitesDict[key].amp-0.01).clip(0, 2));
});
});
}, {
if(selectedName.contains("grp_"), {
groupDict.keys.do({ |key|
if(key.asString == selectedName, {
groupDict[key].amp_((groupDict[key].amp-0.01).clip(0, 2));
});
});
}, {
droneArray[selected].set(\amp, (droneArray[selected].amp - 0.01).clip(0, 1));
});
});
});
});
"down".postln;
}
{123}{
// move drone around (fine movement if alt mod is down)
droneArray[selected].oppositemove = true;
if(modifiers == 11010368, {
droneArray[selected].rotation_(droneArray[selected].rotation-0.001);
},{
droneArray[selected].rotation_(droneArray[selected].rotation-0.01);
});
"left".postln;
}
{124}{
// move drone around (fine movement if alt mod is down)
droneArray[selected].oppositemove = true;
if(modifiers == 11010368, {
droneArray[selected].rotation_(droneArray[selected].rotation+0.001);
},{
droneArray[selected].rotation_(droneArray[selected].rotation+0.01);
});
"right".postln;
}
{51}{ // delete button
"delete drone/chord/satellite/group".postln;
//if(droneArray.size > 0, {
this.killDrone(); // only kill a unique drone when using delete button (not chord or sat)
//});
[\selectedName, selectedName].postln;
// the below would need the same treatment as amp up and down above, but I decided not to kill drone with delete button
// if(selectedName.contains("chd_"), {
// chordDict.keys.do({ |key|
// [\key, key.asString].postln;
// if(key.asString == selectedName, {
// chordDict[key].perform(".kill");
// chordDict.removeAt(key);
// });
// });
// }, {
// if(selectedName.contains("sat_"), {
// satellitesDict.keys.do({ |key|
// if(key.asString == selectedName, {
// satellitesDict[key].perform(".kill");
// satellitesDict.removeAt(key);
// });
// });
// }, {
// if(selectedName.contains("grp_"), {
// groupDict.keys.do({ |key|
// if(key.asString == selectedName, {
// groupDict[key].perform(".kill");
// groupDict.removeAt(key);
// });
// });
// }, {
// this.killDrone();
// });
// });
// });
}
{36}{"enter - NOT USED ATM ! ".postln;};
// play the drone in the chosen scale using numerical keys from 1 to 9
if((unicode > 48) && (unicode < 58), { // using unicode - keycode is not in right numerical order
var harm = false;
if(modifiers == 8388864, { harm = true });
if(selectedName.contains("chd_"), {
chordDict.keys.do({ |key|
if(key.asString == selectedName, {
chordDict[key].degree_(unicode-48);
});
});
}, {
if(selectedName.contains("sat_"), {
satellitesDict.keys.do({ |key|
if(key.asString == selectedName, {
satellitesDict[key].degree_(unicode-48);
});
});
}, {
if(selectedName.contains("grp_"), {
groupDict.keys.do({ |key|
if(key.asString == selectedName, {
groupDict[key].degree_(unicode-48);
});
});
}, {
droneArray[selected].degree_(unicode-48);
});
});
});
});
})
.drawFunc_( drawFunc );
this.start();
}
initDicts { // not used ATM // XXX
droneDict = ();
chordDict = ();
satellitesDict = ();
groupDict = ();
machineDict = ();
interDict = ();
interDroneArray = [];
nameArray = [];
}
start {
hub.states.startRecord();
drawTask = Task({
inf.do({ |i|
// if(droneArray.size>0, {droneArray[selected].getSynths.postln}); // XXX DEBUGGING CODE
// {testwin.isClosed.not.if({ testwin.refresh })}.defer;
{window.isClosed.not.if({ window.refresh })}.defer;
0.05.wait;
});
}).play;
}
stop { // this should probably stop the sound as well
drawTask.stop;
}
interpret { |function, name|
interpret = true;
interDroneArray = [];
function.value; // evaluate the function
interpret = false;
[\interpretNAME, name].postln;
if(interDroneArray.size > 0, {
name = name ?? {this.generateName("inter")};
interDict[name] = interDroneArray; // for accessing individual drones (not indexed in an array but a dict)
[\interDict, interDict].postln;
});
^("New interpretation created : " ++ name);
}
eval { |function|
function.value; // evaluate the function
^("SuperCollider code evaluated");
}
scope_ { | bool=true | // needs internal server
if(bool, {
"creating scope".postln;
if(Server.default != Server.internal, {"Internal server needed for the scope".postln});
switch(hub.speakers.nrChannels)
{ 1 }{ Synth.tail(RootNode(Server.default), \dronemixer2, [\out, 100]) }
{ 2 }{ Synth.tail(RootNode(Server.default), \dronemixer2, [\out, 100]) }
{ 4 }{ Synth.tail(RootNode(Server.default), \dronemixer4, [\out, 100]) }
{ 5 }{ Synth.tail(RootNode(Server.default), \dronemixer5, [\out, 100]) }
{ 8 }{ Synth.tail(RootNode(Server.default), \dronemixer8, [\out, 100]) };
scp = PlusFreqScope.new(window, window.bounds);
// scp = PlusFreqScope.new(SCWindow.new.front, Rect(0, 0, 400, 800));
scp.scope.background_(Color.clear);
scp.scope.waveColors_([Color.black]);
scp.inBus_(100); // make a synth that mixes to there
scp.active_(true);
scp.xZoom_(0.55);
scp.yZoom_(0.3);
}, {
"______________________ >>> killing scope".postln;
scp.kill;
scp.remove;
});
}
env_ {arg envt; // supporting passing in of both array [0, 1] (attack and release) and just an integer (for both A&R)
"Setting ENV".postln;
if(envt.isArray, { globalenv = envt }, {globalenv = [envt, envt]});
}
pushEnv_ {arg envt; // same as above, but pushing this env into all active Drones
if(envt.isArray, { globalenv = envt }, {globalenv = [envt, envt]});
droneArray.do({arg drone; drone.env_(globalenv)});
}
env {
^("Env time is : " ++ globalenv);
}
createDrone { | type=\saw, tonic=1, harmonics=3, amp=0.3, speed, length, angle, degree=1, ratio=1, name, env, octave, note |
var envelopearr, string;
// Document.listener.string_("");
// hub.interpreter.postview.string_("");
if(type==\args, {^("type, tonic, harmonics, amp, speed, length, angle, degree, ratio, name, env, octave, note") });
// if((type.isKindOf(Symbol) && tonic.isKindOf(SimpleNumber) && harmonics.isKindOf(SimpleNumber) && amp.isKindOf(SimpleNumber) && (speed.isKindOf(SimpleNumber) || speed.isKindOf(Nil) ) && (length.isKindOf(SimpleNumber) || length.isKindOf(Nil)) && (angle.isKindOf(SimpleNumber) || angle.isKindOf(Nil)) && degree.isKindOf(SimpleNumber) && ratio.isKindOf(SimpleNumber) && (name.isKindOf(Symbol) || name.isKindOf(Nil)) && (env.isKindOf(SimpleNumber) || env.isKindOf(Array) || env.isKindOf(Nil)) && (octave.isKindOf(SimpleNumber) || octave.isKindOf(Nil)) && post.isKindOf(Boolean)).not, {^"---> No drone created. Wrong argument types"});
dronecount = dronecount + 1;
name = this.generateName(name:name); // if name is nil, a new name is generated, if name, we check if it's used already
speed = speed ? 1.0.rand2; // get variations in speed
angle = angle ? 360.rand;
length = length ? (200+(160.rand));
if(env.isNil, {
envelopearr = globalenv;
}, {
if(env.isArray, { envelopearr = env }, { envelopearr = [env, env] });
});
drone = Drone.new(hub, tuning, scale, fundamental)
.createDrone(
type,
tonic,
harmonics,
amp,
speed, //1.rand2,
length,
angle,
degree,
ratio,
envelopearr,
octave,
note
).name_(name);
droneArray = droneArray.add(drone); // an array that takes care of drawing
droneDict[drone.name] = drone; // for accessing individual drones (not indexed in an array but a dict)
currentEnvironment.put(drone.name, drone); // this allows me to access drones through ~
if(interpret, { interDroneArray = interDroneArray.add(drone) });
//interDroneArray = interDroneArray.add(drone);
selectedName = drone.name.asString; // draw the latest drone name in the bottom left corner
if(drawTask.isPlaying.not, { drawTask.play }); // if cmd + period, then start the drawtask again
if(hub.post, {
// hub.postDroneState(drone.name, droneArray.size-1);
"------- New Drone Created: ".postln;
string = "~"++name++"\n"++
"~"++name++".type = "++drone.type++"\n"++
"~"++name++".tonic = "++drone.tonic++"\n"++
"~"++name++".freq = "++drone.freq++"\n"++
"~"++name++".harmonics = "++drone.harmonics++"\n"++
"~"++name++".amp = "++drone.amp++"\n"++
"~"++name++".speed = "++speed++"\n"++
"~"++name++".length = "++length++"\n"++
"~"++name++".angle = "++angle++"\n"++
"~"++name++".degree = "++drone.degree++"\n"++
"~"++name++".ratio = "++drone.ratio++"\n"++
"~"++name++".env = "++drone.env++"\n"++
"~"++name++".octave = "++drone.octave++"\n" ++
"~"++name++".note = "++drone.note++"\n";
//string.postln;
{hub.interpreter.postview.string_(string)}.defer;
});
^drone;
}
// working original: 1)
// killDrone { | name, releasetime |
// "KILLING DRONE (DroneController class): ".post; name.postln;
// // name = name ? droneArray[selected].name; // either the drone passed in (from Drone) or the selected one
// name = name ? if(droneArray.size>0, {droneArray[selected].name}); // either the drone passed in (from Drone) or the selected one
// droneArray.copy.do({arg drone, i;
// if(drone.name == name, {
// releasetime = releasetime ? drone.env[1]; // if no arg, use drone env
// droneArray[i].killDrone(releasetime);
// droneArray.removeAt(i);
// });
// });
// selected = (selected - 1).clip(0, droneArray.size-1);
// droneDict.removeAt(name);
// nameArray.removeAll(name);
// }
killDrone { | name, releasetime |
"KILLING DRONE (DroneController class): ".post; name.postln;
// name = name ? droneArray[selected].name; // either the drone passed in (from Drone) or the selected one
// this method is split into two times:
// (slightly complex as the user might create a drone with the same name before the former drone is dead)
{
// Time 1) - release the synths and start the fading out of the drone
[\selected, selected].postln;
[\droneArray, droneArray].postln;
// [\selectedname, droneArray[selected].name].postln;
name = name ? if(droneArray.size>0, {droneArray[selected].name}); // either the drone passed in (from Drone) or the selected one
droneArray.copy.do({arg drone, i;
if(drone.name == name, {
if(drone.dying == false, { // if it's alive
releasetime = releasetime ? drone.env[1]; // if no arg, use drone env
droneArray[i].killSynths(releasetime); // specific method created for the deathArray fadeout
drone.dying = true;
deathArray = deathArray.add(drone);
droneArray.removeAt(i);
droneDict.removeAt(name);
nameArray.removeAll(name);
// if(drone.selected, {
// //drone.selected = false; // unselect this drone
// // selected = (selected - 1).max(0);
// // selected = (selected - 1)%(droneArray.size);
// selected = ((selected - 1)%dronecount).clip(0, droneArray.size-2);
// dronecount = dronecount - 1;
// [\dronecount, dronecount].postln;
// [\selected, selected].postln;
// droneArray[selected].selected = true; // select the drone below
// selectedName = droneArray[selected].name; /// XXX - test
// });
});
});
});
if(droneArray.size>0, {
selected = ((selected - 1)%dronecount).clip(0, droneArray.size-1);
dronecount = (dronecount - 1).max(0);
[\dronecount, dronecount].postln;
[\selected, selected].postln;
droneArray[selected].selected = true; // select the drone below
selectedName = droneArray[selected].name; /// XXX - test
});
// droneArray[selected].selected = false;
// selected = (selected - 1).clip(0, droneArray.size-1);
// droneArray[selected].selected = true;
// Time 2) - kill the drone and remove completely it from arrays and dicts
{
deathArray.copy.do({arg drone, i;
if((drone.name == name) && drone.dying, {
deathArray.removeAt(i);
// droneArray.removeAt(i);
});
});
// droneDict.removeAt(name);
// nameArray.removeAll(name);
}.defer(releasetime);
}.value;
}
// themes
createChord { | type=\saw, chord=#[1,5,8], tonic=1, harmonics, amp=0.2, speed, length, angle, degree=1, ratio=1, env, octave, name, note |
var thischord, shortname, string;
//hub.interpreter.postview.string_("");
if(type==\args, {^("type, chord, tonic, harmonics, amp, speed, length, angle, degree, ratio, env, octave, name, note") });
// if((type.isKindOf(Symbol) && (chord.isKindOf(Symbol) || chord.isKindOf(Array)) && tonic.isKindOf(SimpleNumber) && (harmonics.isKindOf(SimpleNumber) || harmonics.isKindOf(Nil) ) && amp.isKindOf(SimpleNumber) && (speed.isKindOf(SimpleNumber) || speed.isKindOf(Nil) ) && (length.isKindOf(SimpleNumber) || length.isKindOf(Nil)) && (angle.isKindOf(SimpleNumber) || angle.isKindOf(Nil)) && degree.isKindOf(SimpleNumber) && ratio.isKindOf(SimpleNumber) && (name.isKindOf(Symbol) || name.isKindOf(Nil)) && (env.isKindOf(SimpleNumber) || env.isKindOf(Array) || env.isKindOf(Nil)) && (octave.isKindOf(SimpleNumber) || octave.isKindOf(Nil)) ).not, {^"---> No chord created. Wrong argument types"});
shortname = name; // get the user generated name for access through ~ global vars
name = this.generateName("chd", name); // create a unique system name which can't be duplicated
thischord = DroneChord.new(hub, name, scale).createChord(type, chord, tonic, harmonics, amp, speed, length, angle, degree, ratio, env, octave, note);
// thischord.tuning_(tuning);
chordDict[name] = thischord;
currentEnvironment.put(name, thischord); // this allows me to access drones through ~
if(shortname.isNil, {shortname = name});
currentEnvironment.put(shortname, thischord); // this allows me to access drones through ~
selectedName = name.asString; // draw the latest drone name in the bottom left corner
if(hub.post, {
"------- New Chord Created: ".postln;
string = "~"++shortname++"\n"++
"~"++shortname++".harmonics = "++thischord.dronearray[0].harmonics++"\n"++
"~"++shortname++".amp = "++amp++"\n"++
"~"++shortname++".speed = "++speed++"\n"++
"~"++shortname++".length = "++length++"\n"++
"~"++shortname++".angle = "++angle++"\n"++
"~"++shortname++".degree = "++degree++"\n"++
"~"++shortname++".ratio = "++ratio++"\n"++
"~"++shortname++".env = "++thischord.dronearray[0].env++"\n"++
"~"++shortname++".octave = "++thischord.dronearray[0].octave++"\n" ++
"~"++shortname++".note = "++note++"\n";
string.postln;
hub.interpreter.postview.string_(string);
});
// ("~"++shortname).postln;
// ("~"++shortname++".harmonics = "++thischord.dronearray[0].harmonics).postln;
// ("~"++shortname++".amp = "++amp).postln;
// ("~"++shortname++".speed = "++speed).postln;
// ("~"++shortname++".length = "++length).postln;
// ("~"++shortname++".angle = "++angle).postln;
// ("~"++shortname++".degree = "++degree).postln;
// ("~"++shortname++".ratio = "++ratio).postln;
// ("~"++shortname++".env = "++thischord.dronearray[0].env).postln;
// ("~"++shortname++".octave = "++thischord.dronearray[0].octave).postln;
// "\n".postln;
// {hub.interpreter.textview.string = "\n New drone created : ~" ++ drone.name++ "\n"}.defer;
// {hub.interpreter.postview.string = "\n New drone created : ~" ++ drone.name++ "\n"}.defer;
// {hub.interpreter.textview.string = hub.interpreter.textview.string ++ "\n~" ++ thischord.name}.defer;
^("New chord created : " ++ name);
}
defineChord { | ...args |
var name, tempname, dronearr, thischord;
args = args.flatten;
tempname = args.removeAt(0); // the first item is the name
name = this.generateName("chd", tempname);
dronearr = droneArray.reject({|item| args.includes(item.name).not });
thischord = DroneChord.new(hub, name).defineChord( dronearr );
//thischord.tuning_(tuning);
chordDict[name] = thischord;
currentEnvironment.put(name, thischord); // this allows me to access drones through ~
currentEnvironment.put(tempname, thischord); // this allows me to access drones through ~
^("New chord defined : " ++ name);
}
killChord { |name| // called from DroneChord:kill
chordDict.removeAt(name);
nameArray.removeAll(name);
}
killChords { // all chords
chordDict.do({arg chord; chord.dronearray.do({arg drone; drone.kill }) });
chordDict = ();
}
createSatellites { | type=\sine, ratios=#[1,2,3,4,5,6,7,8], tonic=2, harmonics, amp=0.2, speed, length, angle, num=10, spread=1, env, octave, name |
var thissatellites, shortname, string;
//{hub.interpreter.postview.string_("")}.defer; // needs to be deferred as it's called from .playScore
if(type==\args, {^("type, ratios, tonic, harmonics, amp, speed, length, angle, num, spread, env, octave, name") });
shortname = name; // the short name created by the user
name = this.generateName("sat", name); // long system name - both can be used
thissatellites = DroneSatellites.new(hub, name).createSatellites(type, ratios, tonic, harmonics, amp, speed, length, angle, num, spread, env, octave);
// thissatellites.tuning_(tuning);
satellitesDict[name] = thissatellites;
currentEnvironment.put(name, thissatellites); // this allows me to access drones through ~
// if(shortname.isNil, {shortname = name}); // xxx
if(shortname.isNil, {shortname = name.asString[4..6] }); // if the user didn't pass a name, it was generated and we're only interested in the pure name
[\shortname, shortname].postln;
currentEnvironment.put(shortname.asSymbol, thissatellites); // this allows me to access drones through ~
selectedName = name.asString; // draw the latest drone name in the bottom left corner
if(hub.post, {
"------- New Satellites Created: ".postln;
string = "~"++shortname++"\n"++
"~"++shortname++".harmonics = "++thissatellites.dronearray[0].harmonics++"\n"++
"~"++shortname++".amp = "++amp++"\n"++
"~"++shortname++".speed = "++speed++"\n"++
"~"++shortname++".length = "++length++"\n"++
"~"++shortname++".angle = "++angle++"\n"++
"~"++shortname++".env = "++thissatellites.dronearray[0].env++"\n"++
"~"++shortname++".octave = "++thissatellites.dronearray[0].octave++"\n";
string.postln;
hub.interpreter.postview.string_(string);
});
^("Satellites created : " ++ name);
}
killSatellite { |name| // called from Satellite:kill
satellitesDict.removeAt(name);
nameArray.removeAll(name);
}
killSatellites {
satellitesDict.do({arg satellites; satellites.dronearray.do({arg drone; drone.kill }) });
satellitesDict = ();
}
// create Group needs some work !
createGroup { | name, type, tonic, harmonics, amp, speed, length, angle, degree, ratio, env, octave | // create a new group
var thisgroup, groupname, refname, postname, string;
if(type==\args, {^("name, type, tonic, harmonics, amp, speed, length, angle, degree, ratio, env, octave") });
// hub.interpreter.postview.string_("");
groupname = name; // the name as stored in the dict
//name = name.asString;
//name = this.generateName("grp", name[4 .. (name.size-1)]); // the new name (new groups will add to the name)
[\name1, name].postln;
name = this.generateName("grp");
name = name++"_"++groupname; // special case, as I want to be able to run many groups e.g. \grp_oso_loki (where loki is the group template)
[\name2, name].postln;
thisgroup = DroneGroup.new(hub, name).createGroup( groupname, type, tonic, harmonics, amp, speed, length, angle, degree, ratio, env, octave );
// thisgroup.tuning_(tuning);
groupDict[name.asSymbol] = thisgroup;
currentEnvironment.put(name.asSymbol, thisgroup); // this allows me to access drones through ~
currentEnvironment.put((name[name.findAll("_")[0]+1..name.findAll("_")[1]-1]).asSymbol, thisgroup); // this allows me to access drones through ~
selectedName = name.asString; // draw the latest drone name in the bottom left corner
if(hub.post, {
"------- New Group Created, of type:".post; (groupname).postln;
postname = name[name.findAll("_")[0]+1..name.findAll("_")[1]-1];
string = "~"++postname++"\n"++
"~"++postname++".harmonics = "++thisgroup.dronearray[0].harmonics++"\n"++
"~"++postname++".amp = "++amp++"\n"++
"~"++postname++".speed = "++speed++"\n"++
"~"++postname++".length = "++length++"\n"++
"~"++postname++".angle = "++angle++"\n"++
"~"++postname++".degree = "++degree++"\n"++
"~"++postname++".ratio = "++ratio++"\n"++
"~"++postname++".env = "++thisgroup.dronearray[0].env++"\n"++
"~"++postname++".octave = "++thisgroup.dronearray[0].octave++"\n";
string.postln;
hub.interpreter.postview.string_(string)
});
^("New group created : " ++ name);
}
defineGroup { | ...args |
var thisgroup, name, tempname;
args = args.flatten;
tempname = args.removeAt(0); // the first item is the name
name = this.generateName("grp");
thisgroup = DroneGroup.new(hub, tempname).defineGroup( args );
name = name++"_"++tempname; // special case, as I want to be able to run many groups e.g. \grp_oso_loki (where loki is the group template)
groupDict[name.asSymbol] = thisgroup;
currentEnvironment.put(name.asSymbol, thisgroup); // this allows me to access drones through ~
currentEnvironment.put((name[name.findAll("_")[0]+1..name.findAll("_")[1]-1]).asSymbol, thisgroup); // this allows me to access drones through ~
^("New group defined : " ++ name);
}
killGroup { |name| // called from Satellite:kill
groupDict.removeAt(name);
nameArray.removeAll(name);
}
killGroups {
groupDict.do({arg groups; groups.do({arg drone; drone.kill }) });
groupDict = ();
}
groups { // avalable stored groups (stored in a file on disk)
^("Available groups: ".post; states.storedGroupsDict.keys.asArray);
}
createMachine { | type=\amp, target=\all, time=4, rate=1, transtime=5, range=1, name|
var machine;
//hub.interpreter.postview.string_("");
if(type==\args, {^("type, target, time, rate, transtime, range, name") });
name = name ?? {this.generateName("mach")};
machine = DroneMachine.new(hub, type, target, time, rate, transtime, range).name_(name);
machineArray = machineArray.add(machine); // an array that takes care of drawing
machineDict[name] = machine;
currentEnvironment.put(name, machine); // this allows me to access drones through ~
^("New machine created : " ++ machine);
}
killMachine { |name|
"killing machine !!! : ".post; name.postln;
[\machineArray1, machineArray].postln;
machineArray.copy.do({arg machine, i;
if(machine.name == name, {
"same name".postln;
machineArray.removeAt(i);
});
});
[\machineArray2, machineArray].postln;
machineDict.removeAt(name);
nameArray.removeAll(name);
}
killMachines {
// machineArray.do({arg machine; machine.kill() });
machineArray = [];
//machineDict.do({arg machines; machines.do({arg machine; machine.kill }) });
machineDict = ();
}
killAll { | releasetime |
// var rt;
// rt = if(releasetime.isNil, { globalenv[1] }, { releasetime })
droneArray.copy.do({arg drone; this.killDrone( drone.name, releasetime ) });
machineArray.do({arg machine; machine.kill });
// I should not need the below as all drones remove themselves from arrays and dicts
// droneArray = [];
// droneDict = ();
// chordDict = ();
// groupDict = ();
// satellitesDict = ();
// machineDict = ();
// nameArray = [];
}
freeSynths { | releasetime |
droneArray.do({arg drone; drone.freeSynths( releasetime ) });
}
// not finished yet
undo {
var cmd = hub.interpreter.lastCommand;
// HMMM !
[\lastcommand, hub.interpreter.lastCommand].postln;
if(cmd.contains("createDrone"), { hub.drones.droneArray.last.kill });
if(cmd.contains("tonic"), { "not ready yet".postln; }); // XXX - where to store the previous state?
}
rename { | oldname, newname |
var drone;
drone = droneDict.removeAt(oldname);
drone.name = newname;
droneDict[newname] = drone;
^("New drone name : "++newname);
}
names {
var dronenames;
dronenames = "";
droneDict.keys.do({ arg item; dronenames = dronenames ++ " | " ++ item });
dronenames = dronenames ++ " | ";
^dronenames;
}
select { |argname|
droneArray.do({arg drone; drone.selected = false });
droneDict[argname].selected = true;
droneArray.do({arg drone, i; drone.postln; if(drone.selected, { selected = i }) }); // global var
^("Drone selected : "++ argname);
}
deselect { |argname|
droneArray.do({arg drone; drone.selected = false });
^("Deselecting all drones");
}
tuning_ { |argtuning, dur|
var temptuning;
tuning = argtuning;
temptuning = Tuning.newFromKey(tuning.asSymbol);
if(temptuning.isNil, { temptuning = DroneScale.new(tuning) });
if(temptuning.isNil.not, {
droneArray.do({arg drone; drone.tuning_(tuning, dur) });
if(speakers.drawscale, {
speakercircles = speakers.drawImg(tuning);
speakercirlesview.backgroundImage = speakercircles;
}, {
"This tuning does not exist".postln;
});
});
^("Global tuning set to: " ++ argtuning);
}
scale_ { |argscale|
scale = argscale;
hub.scale = scale;
droneArray.do({arg drone; drone.scale_(argscale) });
speakers.setScale_(scale);
speakercircles = speakers.drawImg(tuning);
speakercirlesview.backgroundImage = speakercircles;
^( "Global scale set to: " ++ argscale );
}
tunings {
var tunings, tuningstring = "";
tunings = Tuning.directory.asArray;
tunings.do({ |tuning| tuningstring = tuningstring ++ "" ++ tuning.asString });
tuningstring = tuningstring ++ "";
{if(hub.post, {hub.interpreter.postview.string_(tuningstring)})}.defer;
^tuningstring;
}
scales {
var scales, scalesstring;
scalesstring = "";
scales = Scale.directory.asArray;
scales.do({ |scale| scalesstring = scalesstring ++ "" ++ scale.asString });
scalesstring = scalesstring ++ "";
{if(hub.post, {hub.interpreter.postview.string_(scalesstring)})}.defer;
^scalesstring