-
Notifications
You must be signed in to change notification settings - Fork 2
/
XiiLang.sc
3445 lines (3177 loc) · 134 KB
/
XiiLang.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
// use "~/Documents/ixilang".standardizePath as the path for projects
/*
GPL license (c) thor magnusson - ixi audio, 2009-2012
// XiiLang.new("project", "key") - "project" stands for the name of the folder where soundfiles are kept. in this folder a keyMapping.ixi file can be found that maps letters to sounds. if there is no file, then the mapping will be random
TODO: Add parameter effect control
TODO: Check the use of String:drop(1) and String:drop(-1)
*/
// new in ixi lang v3
// midiout
// midiclients
// languages (you can write in your native language, or create your own language semantics for ixi lang)
// fractional time multiplication
// snapshots store and register effect states
// matrix
// coder (keys)
// store and load sessions
// suicide hotline added (you can now change your mind, in case performance has picked up)
// automatic code writing (autocode 4)
// future now works in bars as well as in seconds
// added multiplication of sustain (1242~8) - here the whole part note (1) is 8 times as long
// amplitude control added as a verb (can be used with future then: future 1:10 >> (( john - which would fade the agent john down)
// adding scheme-like functions for post score arguments - also working with future
// microtonal transposition in melodic mode
// intoxicants
// added XiiLangGUI() for mapping keys and for starting in .app mode
// added savescore and play score (to repeat performances)
// added panning arguments as postfix
// Add color customisation to GUI
// Recording sound file functionality
// Added pitch argument (in MIDI degrees) for rhythmic and concrete modes
// Synthdefs added to the mapping file (no distinction between samples and synths)
// scheme-like operators [+ agentname 12]
// added full stops as equivalent to spaces
// new in v4
// gui method for getting the gui
// bugfix: kill kills routines as well
// added a "replace" method that replaces items in scores with new values
// added an "insert" method that adds items in scores with new values
// added a "remove" method that removes items in scores
// added intoxicants for effecting the agents' musical timing ("hash", "beer", "coffee", "LSD", "detox") (this is experimental)
// added @ (times) postfix arg (@2) will play the score twice
// added metaagents (xx -> ~ agA 2 agB 1 ~) will play agentA twice and agentB once
// added groups as part of meta agents, so a parallel sequence of a group can be inserted into a meta agent
// changed @ to % in morph mode
// changed ~ to _ in the (duration postfix arguments - so what was (1~4) becomes (1_4))
// added support for BenoitLib networked clocks (Thanks Patrick B)
// multichannel support thanks to John Thompson (although still maintainting the stereo ixi lang, for users who use Pan2 in their synthdefs)
// live recording into buffers (using fn+Enter)
// tap timing (using ctrl + "," and "." (the "<" and ">" buttons)
// FIXED BUG: snapshots do not perk up agents that have been dozed
// FIXED BUG: Snapshots do not recall the effect state
// FIXED BUG: single character percussive mode agents wont >shift
// FIXED BUG: future bug
// FIXED BUG: the active agent is found by comparing strings in dict and on doc. (in case of many agents on doc with same name)
// FIXED BUG: location of cursor when above agent and using future
// FIXED BUG: nap and perk would not work in concrete mode
// FIXED BUG: implemented Panning in all synthdefs (was neglected in some)
// Add: ptpd support for netclocks
// �sudo ./ptpd -cd
// �http://sourceforge.net/projects/ptpd/develop
/*
Dependencies:
TempoClock:sync (by f0)
MIDIClockOut (Crucial Lib -> for slaving other apps to ixi lang)
ixiViews (for MIDIKeyboard in the XiiLangGUI)
*/
// add slide (from Array helpfile)
// TODO: add a "kill invisible" function that silences all agents that have been deleted from the score
// TODO: add a "reorgan/inject" function that injects new chars in percussive mode
// TODO: how about visualising the actions of the user in ixi lang. Data visualise it. Compare the automation and user data.
// TODO: Use autuconductor to apply actions to different agents.
// TODO: think about NRT rendering of playscores
// TODO: make a note that a particular project does not exist and that the new project was created.
// TODO NOW : fix repeats in groups (DONE, but check)
// - make all synthdefs panable (Pan2 & PanAz)
// Freeall bug, recursion not working properly (try this code):
/*
XiiLang(txt:true)
ag1 -> |b d cc cb f cb|@1
ag2 -> | c c cc |@1
ag3 -> xylo[ 1 5 2 1 ]@1
ag4 -> wood[ 211 5 ]@1
shake cc
group gr1 -> ag3 ag4
ma1 -> ~ ag1 1 gr1 1 ~
// when freeing the below, there is an error
ma2 -> ~ ag1 1 ma1 1 ~
*/
XiiLang {
classvar globaldocnum;
var <>doc, docnum, <doccolor, <oncolor, activecolor, offcolor, deadcolor, proxyspace, groups, score;
var agentDict, instrDict, ixiInstr, effectDict, varDict, snapshotDict, scoreArray, metaAgentDict;
var scale, tuning, chosenscale, tonic;
var midiclient, <inbus, eventtype, suicidefork;
var langCommands, englishCommands, language, english;
var matrixArray, initargs; // matrix vars
var projectname, key, randomseed;
var time, tempo, tapping = false, tapcount = 0;
var thisversion = 4;
var numChan;
var win;
*new { arg project="default", keyarg="C", txt=false, newdoc=false, language, dicts, score, numChannels=2;
^super.new.initXiiLang( project, keyarg, txt, newdoc, language, dicts, score, numChannels);
}
initXiiLang {arg project, keyarg, txt, newdoc, lang, dicts, score, numChannels;
// "project, keyarg, txt, newdoc, lang, dicts, score, numChannels".postln;
// [project, keyarg, txt, newdoc, lang, dicts, score, numChannels].postln;
if(score.isNil, {
randomseed = 1000000.rand;
},{
randomseed = score[0];
});
thisThread.randSeed = randomseed;
if(globaldocnum.isNil, {
globaldocnum = 0;
}, {
globaldocnum = globaldocnum+1;
});
key = keyarg;
numChan = numChannels;
initargs = [project, key, txt, newdoc, lang, numChan];
XiiLangSingleton.new(this, globaldocnum);
// the number of this document (allows for multiple docs using same variable names)
docnum = globaldocnum; // this number is now added in front of all agent names
chosenscale = Scale.major; // this is scale representation
scale = chosenscale.semitones.copy.add(12); // this is in degrees
tuning = \et12; // default tuning
tonic = 60 + [\C, \CS, \D, \DS, \E, \F, \FS, \G, \GS, \A, \AS, \B].indexOf(key.toUpper.asSymbol); // midinote 60 is the default
inbus = 8;
if(dicts.isNil, {
agentDict = IdentityDictionary.new; // dicts are sent from "load"
metaAgentDict = (); //
varDict = IdentityDictionary.new;
snapshotDict = IdentityDictionary.new; // dicts are sent from "load"
groups = ();
scoreArray = []; // the score (timeline of the performance)
},{
agentDict = dicts[0]; // dicts are sent from "load"
varDict = IdentityDictionary.new;
snapshotDict = dicts[1]; // dicts are sent from "load"
groups = dicts[2];
docnum = dicts[3];
});
TempoClock.default.tempo = 120/60;
projectname = project;
midiclient = 0;
try{ // try necessary, since a user without MIDI IAC busses reported that the next two lines gave errors
MIDIClient.init;
// midiclient = MIDIOut(0, MIDIClient.destinations[0].uid);
midiclient = MIDIOut(0);
};
eventtype = \note;
this.makeEffectDict; // in a special method, as it has to be called after every cmd+dot
this.envirSetup( txt, newdoc, project );
ixiInstr = XiiLangInstr.new(project, numChannels: numChan);
instrDict = ixiInstr.makeInstrDict;
SynthDescLib.read;
proxyspace = ProxySpace.new.know_(true);
CmdPeriod.add({
16.do({arg i; try{midiclient.allNotesOff(i)} });
this.makeEffectDict;
groups = ();
agentDict = IdentityDictionary.new;
metaAgentDict = ();
//varDict = IdentityDictionary.new; // I might uncomment this line
snapshotDict = IdentityDictionary.new;
proxyspace = ProxySpace.new.know_(true);
scoreArray = [];
});
englishCommands = ["group", "sequence", "future", "snapshot", "->", "))", "((", "|", "[", "{", "~", ")",
"$", ">>", "<<", "tempo", "scale", "scalepush", "tuning", "tuningpush", "remind", "help",
"tonality", "instr", "tonic", "grid", "kill", "doze", "perk", "nap", "shake", "swap", "replace",
"insert", "remove", ">shift", "<shift", "invert", "expand", "revert", "up", "down", "yoyo",
"order", "dict", "store", "load", "midiclients", "midiout", "matrix", "autocode", "coder", "twitter",
"+", "-", "*", "/", "!", "^", "(", "<", "@", "hash", "beer", "coffee", "LSD", "detox", "new", "gui",
"savescore", "playscore", "suicide", "hotline", "newrec", "input"]; // removed "." XXX
if(lang.isNil, {
english = true; // might not need this;
langCommands = englishCommands;
}, {
english = false;
language = XiiLangDicts.getDict(lang.asSymbol);
langCommands = XiiLangDicts.getList(lang.asSymbol);
});
// [\langCommands, langCommands].postln;
if(score.isNil.not, {
this.playScore(score[1]);
});
this.addixiMenu;
}
makeEffectDict { // more to come here + parameter control - for your own effects, simply add a new line to here and it will work out of the box
effectDict = IdentityDictionary.new;
effectDict[\reverb] = {arg sig; (sig*0.6)+FreeVerb.ar(sig, 0.85, 0.86, 0.3)};
effectDict[\reverbL] = {arg sig; (sig*0.6)+FreeVerb.ar(sig, 0.95, 0.96, 0.7)};
effectDict[\reverbS] = {arg sig; (sig*0.6)+FreeVerb.ar(sig, 0.45, 0.46, 0.2)};
effectDict[\delay] = {arg sig; sig + AllpassC.ar(sig, 1, 0.15, 1.3 )};
effectDict[\lowpass] = {arg sig; RLPF.ar(sig, 1000, 0.2)};
effectDict[\tremolo] = {arg sig; (sig * SinOsc.ar(2.1, 0, 5.44, 0))*0.5};
effectDict[\vibrato] = {arg sig; PitchShift.ar(sig, 0.008, SinOsc.ar(2.1, 0, 0.11, 1))};
effectDict[\techno] = {arg sig; RLPF.ar(sig, SinOsc.ar(0.1).exprange(880,12000), 0.2)};
effectDict[\technosaw] = {arg sig; RLPF.ar(sig, LFSaw.ar(0.2).exprange(880,12000), 0.2)};
effectDict[\distort] = {arg sig; (3111.33*sig.distort/(1+(2231.23*sig.abs))).distort*0.02};
effectDict[\cyberpunk] = {arg sig; Squiz.ar(sig, 4.5, 5, 0.1)};
effectDict[\bitcrush] = {arg sig; Latch.ar(sig, Impulse.ar(11000*0.5)).round(0.5 ** 6.7)};
effectDict[\antique] = {arg sig; LPF.ar(sig, 1700) + Dust.ar(7, 0.6)};
}
//set up document and the keydown control
envirSetup { arg txt, newdoc, project;
var recdoc;
/*
//GUI.cocoa;
//if(newdoc, {
// doc = Document.new;
//}, {
// doc = Document.current;
//});
// color scheme
try{ // check if the color file exists
#doccolor, oncolor, activecolor, offcolor, deadcolor = Object.readArchive(Platform.userAppSupportDir ++"/ixilang/"++project++"/colors.ixi")
};
if(doccolor.isNil, {
doccolor = Color.white;
oncolor = Color.black;
activecolor = Color.green;//Color.yellow;
offcolor = Color.blue; //Color.green;
deadcolor = Color.red;
});
win = Window.new("ixi lang - project :" + project.quote + " - window nr:" + docnum.asString);
win.bounds_(Rect(400,300, 1000, 600));
win.front;
doc = TextView(win.asView, Rect(10, 10, 980,580)).focus(true);
doc.enterInterpretsSelection = true;
//doc.setBackground(doccolor);
//doc.setStringColor(oncolor);
if(txt == false, { doc.setString("") });
win.name_("ixi lang - project :" + project.quote + " - window nr:" + docnum.asString);
doc.setFont(Font("Monaco",20));
//doc.promptToSave_(false);
*/
if(newdoc, {
//doc = Document.new;
// doc = TextView.new(Window.new("", Rect(100, 100, 600, 700)).front, Rect(0, 0, 600, 700)).resize_(5);
}, {
//doc = Document.current;
// doc = TextView.new(Window.new("", Rect(100, 100, 600, 700)).front, Rect(0, 0, 600, 700)).resize_(5);
});
doc = TextView.new(Window.new("", Rect(100, 100, 600, 700)).background_(Color.white.alpha_(0.0)).front, Rect(0, 0, 600, 700)).resize_(5);
// color scheme
try{ // check if the color file exists
#doccolor, oncolor, activecolor, offcolor, deadcolor = Object.readArchive("ixilang/"++project++"/colors.ixi")
};
if(doccolor.isNil, {
doccolor = Color.black;
oncolor = Color.white;
activecolor = Color.yellow;
offcolor = Color.green;
deadcolor = Color.red;
});
//doc.parent.bounds_(Rect(400,300, 1000, 600));
doc.background_(doccolor);
doc.background_(Color.white.alpha_(0.0));
//doc.background_(Color.white.alpha_(0.0));
doc.parent.name_("ixi lang - project :" + project.quote + " - window nr:" + docnum.asString);
doc.font_(Font("Monaco", 16));
if(txt == false, { doc.string_("oo -> |asdf|
matrix 8
oxo -> |Sdfsdf| \n\n\n") });
doc.setProperty(\styleSheet, "color:white"); // set the cursor to white
doc.setStringColor(oncolor, 0, 100000); // then set the text color to whatever the user has specified
doc.keyDownAction_({|doc, char, mod, unicode, keycode |
var string;
//keycode.postln;
// evaluating code (the next line will use .isAlt, when that is available
if(((mod == 524288) || (mod == 2621440))&& ((keycode==124)||(keycode==123)||(keycode==125)||(keycode==126)||(keycode==111)||(keycode==113)||(keycode==114)||(keycode==116)), { // alt + left or up or right or down arrow keys
"eval".postln;
//linenr = doc.string[..doc.selectionStart-1].split($\n).size;
//doc.selectLine(linenr);
string = doc.selectedString; // ++ "\n";
(string.size < 1).if({"Hilight some text!".warn});
if(keycode==123, { // not 124, 125,
this.freeAgent(string);
}, {
this.opInterpreter(string);
});
});
// create a live sampler doc (fn+Enter)
if((mod == 8388864) && (unicode == 3), {
ixiInstr.createRecorderDoc(this, numChan);
});
// tempo tap function (ctrl+, for starting and ctrl+. for stopping (the < and > keys))
if(((mod == 262145)||(mod==262401)) && (unicode == 44), {
if(tapping == false, {
time = Main.elapsedTime;
tapping = true;
});
tapcount = tapcount + 1;
});
if(((mod == 262145)||(mod==262401)) && (unicode == 46), {
time = Main.elapsedTime - time;
tempo = tapcount / time;
tapping = false;
tapcount = 0;
" ---> ixi lang Tempo : set to % BPM\n".postf(tempo*60);
TempoClock.default.tempo = tempo;
});
});
doc.keyUpAction_({|doc, char, mod, unicode, keycode |
if(mod == 8388864, {
recdoc.close;
});
});
doc.onClose_({
// xxx free buffers
ixiInstr.freeBuffers; // not good as playscore reads a new doc (NEED TO FIX)
proxyspace.end(4); // free all proxies
agentDict.do({arg agent;
agent[2].stop;
agent[2] = nil;
});
snapshotDict[\futures].stop;
});
// these two folders are created if the user is downloading from github and hasn't created the ixilang folder in their SC folder
if((Platform.userAppSupportDir ++"/ixilang").pathMatch==[], {
//("mkdir -p" + (Platform.userAppSupportDir ++"/ixilang")).unixCmd; // create the scores folder
File.mkdir(Platform.userAppSupportDir ++"/ixilang");
"ixi-lang NOTE: an ixi lang folder was not found in your SuperCollider directory (in ~Library/Application Support) - It was created".postln;
});
if((Platform.userAppSupportDir ++"/ixilang/default").pathMatch==[], {
File.mkdir(Platform.userAppSupportDir ++"/ixilang/default");
//("mkdir -p" + (Platform.userAppSupportDir ++"/ixilang/default")).unixCmd; // create the scores folder
"ixi-lang NOTE: an ixi lang default folder was not found in your ixi lang directory - It was created".postln;
});
// just make sure that all folders are in place
if((Platform.userAppSupportDir ++"/ixilang/"++project++"/scores").pathMatch==[], {
File.mkdir(Platform.userAppSupportDir ++"/ixilang/"++project++"/scores");
//("mkdir -p" + (Platform.userAppSupportDir ++"/ixilang/"++project++"/scores")).unixCmd; // create the scores folder
"ixi-lang NOTE: a scores folder was not found for saving scores - It was created".postln;
});
if((Platform.userAppSupportDir ++"/ixilang/"++project++"/recordings").pathMatch==[], {
File.mkdir(Platform.userAppSupportDir ++"/ixilang/"++project++"/recordings");
// ("mkdir -p" + (Platform.userAppSupportDir ++"/ixilang/"++project++"/recordings")).unixCmd; // create the recordings folder
"ixi-lang NOTE: a recordings folder was not found for saving scores - It was created".postln;
});
if((Platform.userAppSupportDir ++"/ixilang/"++project++"/sessions").pathMatch==[], {
File.mkdir(Platform.userAppSupportDir ++"/ixilang/"++project++"/sessions");
// ("mkdir -p" + (Platform.userAppSupportDir ++"/ixilang/"++project++"/sessions")).unixCmd; // create the sessions folder
"ixi-lang NOTE: a sessions folder was not found for saving scores - It was created".postln;
});
if((Platform.userAppSupportDir ++"/ixilang/"++project++"/samples").pathMatch==[], {
File.mkdir(Platform.userAppSupportDir ++"/ixilang/"++project++"/samples");
//("mkdir -p" + (Platform.userAppSupportDir ++"/ixilang/"++project++"/samples")).unixCmd; // create the samples folder
"ixi-lang NOTE: a samples folder was not found for saving scores - It was created".postln;
});
}
// the interpreter of thie ixi lang
opInterpreter {arg string, return=false;
var oldop, operator; // the various operators of the language
var methodFound = false;
//string = string.reject({ |c| c.ascii == 78 }); // get rid of char return XXX TESTING (before Helsinki GIG)
scoreArray = scoreArray.add([Main.elapsedTime, string]); // recording the performance
operator = block{|break| // better NOT mess with the order of the following... (operators using -> need to be before "->")
langCommands.do({arg op; var suggestedop, space;
var c = string.find(op);
if(c.isNil.not, {
space = string[c..string.size].find(" "); // allowing for longer operators with same beginning as shorter
if(space.isNil.not, {
suggestedop = string[c..(c+(space-1))];
},{
suggestedop = op;
});
if(suggestedop.size == op.size, { // this is a bit silly (longer op always has to be after the short)
methodFound = true;
break.value(op);
});
});
});
if(methodFound == false, {" ---> ixi lang error : OPERATOR NOT FOUND !!!".postln; });
};
if(english.not, { // this is the only place of non-english code apart from in the init function
oldop = operator;
operator = try{ language[oldop.asSymbol] } ? operator; // if operator exists in the lang dict, else use the given
operator = operator.asString;
string = string.replace(oldop, operator);
});
switch(operator)
{"dict"}{ // TEMP: only used for debugging
"-- Groups : ".postln;
Post << groups; "\n".postln;
"-- agentDicts : ".postln;
Post << agentDict.keys; "\n".postln;
Post << agentDict; "\n".postln;
"-- snapshotDicts : ".postln;
Post << snapshotDict; "\n".postln;
"-- proxyspace : ".postln;
Post << proxyspace; "\n".postln;
"-- metaAgentDict : ".postln;
Post << metaAgentDict; "\n".postln;
// "-- scoreArray : ".postln;
// Post << scoreArray; "\n".postln;
// "-- buffers : ".postln;
// Post << ixiInstr.returnBufferDict; "\n".postln;
}
{"store"}{
var sessionstart, sessionend, session;
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string++" "; // add a space in order to find end of agent (if no argument)
sessionstart = string.findAll(" ")[0];
sessionend = string.findAll(" ")[1];
session = string[sessionstart+1..sessionend-1];
[projectname, key, language, doc.string, agentDict, snapshotDict, groups, docnum].writeArchive(Platform.userAppSupportDir ++"/ixilang/"++projectname++"/sessions/"++session++".ils");
}
{"load"}{
var sessionstart, sessionend, session, key, language, project;
var tempAgentDict, tempSnapshotDict;
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string++" "; // add a space in order to find end of agent (if no argument)
sessionstart = string.findAll(" ")[0];
sessionend = string.findAll(" ")[1];
session = string[sessionstart+1..sessionend-1];
doc.onClose; // call this to end all agents and groups in this particular doc if it has been running agents
#project, key, language, string, agentDict, snapshotDict, groups, docnum = Object.readArchive(Platform.userAppSupportDir ++"/ixilang/"++projectname++"/sessions/"++session++".ils");
doc.string = string;
XiiLang.new( project, key, true, false, language, [agentDict, snapshotDict, groups, docnum]);
}
{"snapshot"}{
this.parseSnapshot(string);
}
{"->"}{
var mode;
mode = block{|break|
["|", "[", "{", ")", "$", "~"].do({arg op, i;
var c = string.find(op);
if(c.isNil.not, {break.value(i)});
});
};
[\mode, mode].postln;
switch(mode)
{0} { ^this.parseScoreMode0(string, return) }
{1} { ^this.parseScoreMode1(string, return) }
{2} { ^this.parseScoreMode2(string, return) }
{3} { this.parseChord(string, \c) }
{4} { this.parseChord(string, \n) }
{5} { this.createMetaAgent(string) };
}
{"future"}{
// future 8:4 >> swap thor // every 8 SECONDS the action is performed (here 4 times)
// future 4b:4 >> swap thor // every 8 BARS the action is performed (here 4 times)
// future << thor // cancel the scheduling
var command, commandstart, colon, seconds, times, agent, pureagent, agentstart, agentend, argument;
var cursorPos, testcond, snapshot, barmode, argumentarray, tempstring;
string = string.reject({ |c| c.ascii == 10 }); // get rid of char return
// allow for some sloppyness in style
string = string++" "; // add a space in order to find end of agent (if no argument)
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string.replace(" ", " ");
if(string.contains(">>"), { // setting future event(s)
commandstart = string.find(">");
colon = string.find(":");
if(string[6..colon-1].contains("b") || string[6..colon-1].contains("B"), {
barmode = true;
seconds = string[6..colon-1].tr($b, \).asFloat; // remove the b and get the beats
},{
barmode = false; // is the future working in seconds or bars ?
seconds = string[6..colon-1].asFloat;
});
times = string[colon+1..commandstart-1].asInteger;
if(string[commandstart+3..commandstart+10] == "snapshot", { // it's the "choose snapshot" future
if(snapshotDict.size > 1, {
snapshotDict[\futures].stop; // futures is when future is choosing a random snapshot
snapshotDict[\futures] = // don't need to store the name, just a unique name
{
times.do({arg i;
seconds.wait;
testcond = false;
while({ testcond.not }, {
snapshot = snapshotDict.keys.choose;
if(snapshot != \futures, { testcond = true });
});
{
cursorPos = doc.selectionStart; // get cursor pos
this.parseSnapshot("snapshot " ++ snapshot.asString);
//doc.selectRange(cursorPos); // set cursor pos again
doc.select(cursorPos,0); // xxx
}.defer;
})
}.fork(TempoClock.new) // not using default clock, since new tempo affects wait (strange?/bug?)
}, {
" ---> ixi lang: you haven't stored more than one snapshot!".postln;
});
}, {
agentstart = string.findAll(" ")[3];
agentend = string.findAll(" ")[4];
pureagent = string[agentstart+1..agentend-1];
agent = (docnum.asString++pureagent).asSymbol;
command = string[commandstart+3..agentstart-1];
argument = string[agentend..string.size-1];
argumentarray = [];
tempstring = "";
argument.do({arg item;
if(item.isAlphaNum || (item == $_), {
tempstring = tempstring ++ item;
}, {
if(tempstring != "", {argumentarray = argumentarray.add(tempstring)}); // removed .asInteger here XXX !!! could cause bugs
tempstring ="";
});
});
if(argumentarray == [], {argumentarray = [argument]}); // removed .asInteger here XXX !!! could cause bugs
//if future argument contains many args then put them into a list that will be wrappedAt in the future task
if(groups.at(agent).isNil.not, { // the "agent" is a group so we need to set routine to each of the agents in the group
groups.at(agent).do({arg agentx, i;
{ var agent; // this var and the value statement is needed to individualise the agents in the future
agent = (docnum.asString++agentx).asSymbol;
agentDict[agent][2] = agentDict[agent][2].add(
{
times.do({arg i;
if(barmode, {
((seconds*agentDict[agent][1].durarr.sum)/TempoClock.default.tempo).wait;
},{
seconds.wait;
});
{
scoreArray = scoreArray.add([Main.elapsedTime, command+agentx+argumentarray.wrapAt(i).asString]);
this.parseMethod(command+agentx+argumentarray.wrapAt(i).asString); // do command
}.defer;
});
}.fork(TempoClock.new)
);
}.value;
});
}, { // it is a real agent, not a group, then we ADD
agentDict[agent][2] = agentDict[agent][2].add(
{
times.do({arg i;
if(barmode, {
((seconds*agentDict[agent][1].durarr.sum)/TempoClock.default.tempo).wait;
},{
seconds.wait;
});
{
scoreArray = scoreArray.add([Main.elapsedTime, command+pureagent+argumentarray.wrapAt(i).asString]);
this.parseMethod(command+pureagent+argumentarray.wrapAt(i).asString); // do command
}.defer;
});
// agentDict[agent][2] = nil; // set it back to nil after routine is finished
}.fork(TempoClock.new)
);
});
});
}, { // removing future scheduling (syntax: future << agent)
agentstart = string.findAll(" ")[1];
agentend = string.findAll(" ")[2];
agent = string[agentstart+1..agentend-1];
agent = (docnum.asString++agent).asSymbol;
if(groups.at(agent).isNil.not, { // the "agent" is a group so we need to set routine to each of the agents in the group
groups.at(agent).do({arg agentx, i;
agent = (docnum.asString++agentx).asSymbol;
agentDict[agent][2].do({arg routine; routine.stop});
agentDict[agent][2] = [];
});
},{
agentDict[agent][2].do({arg routine; routine.stop});
agentDict[agent][2] = [];
});
});
}
{">>"}{
this.initEffect(string);
}
{"<<"}{
this.removeEffect(string);
}
{"))"}{
this.increaseAmp(string);
}
{"(("}{
this.decreaseAmp(string);
}
{"tempo"}{
var newtemp, time, op;
var nrstart = string.find("o")+1;
if(string.contains(":"), {
string = string.tr($ , \);
op = string.find(":");
newtemp = string[nrstart..op].asInteger/60;
time = string[op+1..string.size-1].asInteger;
TempoClock.default.sync(newtemp, time);
}, {
newtemp = string[nrstart+1..string.size-1].asInteger / 60;
TempoClock.default.tempo = newtemp;
});
"---> Setting tempo to : ".post; (newtemp*60).postln;
}
{"scale"}{
var agent, firstarg;
string = string++" ";
firstarg = string[string.findAll(" ")[0]+1..(string.findAll(" ")[1])-1];
agent = (docnum.asString++firstarg).asSymbol;
if(agentDict.keys.includes(agent), {
this.parseMethod(string); // since future will use this, I need to parse the method
}, {
chosenscale = ("Scale."++firstarg).interpret;
chosenscale.tuning_(tuning.asSymbol);
scale = chosenscale.semitones.copy.add(12); // used to be degrees, but that doesn't support tuning
});
}
{"scalepush"}{
var scalestart, scalestr;
var dictscore, mode;
scalestart = string.find("h");
scalestr = string.tr($ , \);
scalestr = scalestr[scalestart+1..scalestr.size-1];
chosenscale = ("Scale."++scalestr).interpret;
chosenscale.tuning_(tuning.asSymbol);
scale = chosenscale.semitones.copy.add(12); // used to be degrees, but that doesn't support tuning
agentDict.do({arg agent;
dictscore = agent[1].scorestring;
dictscore = dictscore.reject({ |c| c.ascii == 34 }); // get rid of quotation marks
mode = block{|break|
["|", "[", "{", ")"].do({arg op, i; var c = dictscore.find(op);
if(c.isNil.not, {break.value(i)});
});
};
switch(mode)
{0} { this.parseScoreMode0(dictscore, false) }
{1} { this.parseScoreMode1(dictscore, false) };
// {2} { this.parseScoreMode2(dictscore) }; // not relevant
if(agent[1].playstate == true, {
proxyspace[agent].play;
});
});
}
{"tuning"}{
var tuningstart, tuningstr;
tuningstart = string.find("g");
tuningstr = string.tr($ , \);
tuning = tuningstr[tuningstart+1..tuningstr.size-1];
tuning = tuning.reject({ |c| c.ascii == 10 }); // get rid of char return
chosenscale.tuning_(tuning.asSymbol);
scale = chosenscale.semitones.copy.add(12);
}
{"tuningpush"}{
var tuningstart, tuningstr;
var dictscore, mode;
tuningstart = string.find("g");
tuningstr = string.tr($ , \);
tuning = tuningstr[tuningstart+1..tuningstr.size-1];
tuning = tuning.reject({ |c| c.ascii == 10 }); // get rid of char return
chosenscale.tuning_(tuning.asSymbol);
scale = chosenscale.semitones.copy.add(12);
agentDict.do({arg agent;
dictscore = agent[1].scorestring;
dictscore = dictscore.reject({ |c| c.ascii == 34 }); // get rid of quotation marks
mode = block{|break|
["|", "[", "{", ")"].do({arg op, i; var c = dictscore.find(op);
if(c.isNil.not, {break.value(i)});
});
};
switch(mode)
{0} { this.parseScoreMode0(dictscore, false) }
{1} { this.parseScoreMode1(dictscore, false) };
// {2} { this.parseScoreMode2(dictscore) }; // not relevant
if(agent[1].playstate == true, {
proxyspace[agent].play;
});
});
}
{"remind"}{
this.getMethodsList;
}
{"help"}{
//XiiLang.openHelpFile; // ixi lang doesn't have the new helpfile format
//(XiiLang.filenameSymbol.asString.dirname++"/XiiLang.html").openTextFile;
WebView.new(Window.new("", Rect(100, 100, 600, 700)).front, Rect(0, 0, 600, 700)).resize_(5).url_(XiiLang.filenameSymbol.asString.dirname++"/XiiLang.html").enterInterpretsSelection_(true);
}
{"tonality"}{
var doc;
// doc = Document.new;
doc = TextView.new(Window.new("", Rect(100, 100, 600, 700)).background_(Color.white.alpha_(0.0)).front, Rect(0, 0, 600, 700)).resize_(5);
//doc.name_("scales");
//doc.promptToSave_(false);
//doc.setStringColor(Color.green, 0, 1000000);
//doc.bounds_(Rect(10, 500, 500, 800));
//doc.font_(Font("Monaco",16));
/*
doc.string_("Scales: " + ScaleInfo.scales.keys.asArray.sort.asCompileString
+"\n\n Tunings: "+
"et12, pythagorean, just, sept1, sept2, mean4, mean5, mean6, kirnberger, werkmeister, vallotti, young, reinhard, wcHarm, wcSJ");
*/
//doc.background_(Color.black);
doc.string_("Scales: " + Scale.names.asCompileString
+"\n\n Tunings: "+
"et12, pythagorean, just, sept1, sept2, mean4, mean5, mean6, kirnberger, werkmeister, vallotti, young, reinhard, wcHarm, wcSJ");
}
{"instr"}{
this.getInstrumentsList;
}
{"tonic"}{
var tonicstart, tstring, tonicstr;
tonicstart = string.find("c");
tstring = string.tr($ , \);
tonicstr = tstring[tonicstart+1..tstring.size-1];
tonicstr = tonicstr.reject({ |c| c.ascii == 10 }); // get rid of char return
if(tonicstr.asInteger == 0, { // it's a string
tonic = 60 + [\C, \CS, \D, \DS, \E, \F, \FS, \G, \GS, \A, \AS, \B].indexOf(tonicstr.toUpper.asSymbol); // midinote 60 is the default
}, {
tonic = tonicstr.asInteger;
});
}
{"grid"}{
var cursorPos, gridstring, meter, grids, gridstart;
cursorPos = doc.selectionStart; // get cursor pos
meter = string[string.find(" ")..string.size-1].asInteger;
if(meter == "grid", {meter = 1});
gridstring = "";
50.do({arg i; gridstring = gridstring++if((i%meter)==0, {"|"}, {" "}) });
doc.string_(doc.string.replace(string, gridstring++"\n"));
}
{"kill"}{
proxyspace.end;
proxyspace = ProxySpace.new.know_(true);
snapshotDict[\futures].stop; // ooo not working
agentDict.do({arg agent;
agent[2].do({arg routine; routine.stop});
});
agentDict.do({arg agent;
agent[2].stop;
agent[2] = nil;
});
}
{"group"}{
var spaces, groupname, op, groupitems;
// allow for some sloppyness in style
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string++" "; // add an extra space at the end
string = string.replace(" ", " ");
string = string.reject({ |c| c.ascii == 10 }); // get rid of char return
spaces = string.findAll(" ");
groupname = string[spaces[0]+1..spaces[1]-1];
" ---> ixi lang : MAKING A GROUP : ".post; groupname.postln;
groupname = (docnum.asString++groupname).asSymbol; // multidoc support
op = string.find("->");
groupitems = [];
(spaces.size-1).do({arg i;
if(spaces[i] > op, { groupitems = groupitems.add( string[spaces[i]+1..spaces[i+1]-1].asSymbol ) })
});
groups.add(groupname -> groupitems);
}
{"sequence"}{
var spaces, sequenceagent, op, seqagents, typecheck, firsttype, sa, originalstring, originalagents, fullscore;
var notearr, durarr, sustainarr, instrarr, attackarr, amparr, panarr, score, instrument, quantphase, newInstrFlag = false;
typecheck = 0;
notearr = [];
durarr = [];
sustainarr = [];
attackarr = [];
amparr = [];
panarr = [];
instrarr = [];
score = "";
originalstring = string;
" ---> ixi lang : MAKING A SEQUENCE : ".postln;
// allow for some sloppyness in style
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string.replace(" ", " ");
string = string++" "; // add an extra space at the end
string = string.reject({ |c| c.ascii == 10 }); // get rid of char return
spaces = string.findAll(" ");
sequenceagent = string[spaces[0]+1..spaces[1]-1];
sa = sequenceagent;
sequenceagent = (docnum.asString++sequenceagent).asSymbol; // multidoc support
op = string.find("->");
seqagents = [];
originalagents = [];
(spaces.size-1).do({arg i;
if(spaces[i] > op, {
seqagents = seqagents.add((docnum.asString++string[spaces[i]+1..spaces[i+1]-1]).asSymbol);
originalagents = originalagents.add(string[spaces[i]+1..spaces[i+1]-1]);
});
});
// check if all items are of same type
firsttype = agentDict[seqagents[0]][1].mode;
seqagents.do({arg agent; typecheck = typecheck + agentDict[agent][1].mode; });
// then merge their score into one string (see below the dict idea)
if((typecheck/seqagents.size) != firsttype, {
" ---> ixi lang: ERROR! You are trying to mix playmodes".postln;
}, {
switch(firsttype)
{0} {
seqagents.do({arg agent, i;
notearr = agentDict[agent][1].notearr;
durarr = durarr ++ agentDict[agent][1].durarr;
sustainarr = sustainarr ++ agentDict[agent][1].sustainarr;
instrarr = instrarr ++ agentDict[agent][1].instrarr;
attackarr = attackarr ++ agentDict[agent][1].attackarr;
panarr = panarr ++ agentDict[agent][1].panarr;
score = score ++ agentDict[agent][1].score; // just for creating the score in the doc
});
fullscore = (sa++" -> |"++score++"|");
if(agentDict[sequenceagent].isNil, {
agentDict[sequenceagent] = [ (), ().add(\amp->0.3), nil];
}, {
if(agentDict[sequenceagent][1].scorestring.contains("{"), {newInstrFlag = true }); // free if { instr (Pmono is always on)
}); // 1st = effectRegistryDict, 2nd = scoreInfoDict, 3rd = placeholder for a routine
quantphase = agentDict[seqagents[0]][1].quantphase;
agentDict[sequenceagent][1].scorestring = fullscore.asCompileString;
agentDict[sequenceagent][1].instrument = "rhythmtrack";
agentDict[sequenceagent][1].durarr = durarr;
agentDict[sequenceagent][1].notearr = notearr;
agentDict[sequenceagent][1].sustainarr = sustainarr;
agentDict[sequenceagent][1].instrarr = instrarr;
agentDict[sequenceagent][1].attackarr = attackarr;
agentDict[sequenceagent][1].panarr = panarr;
agentDict[sequenceagent][1].score = score;
agentDict[sequenceagent][1].quantphase = quantphase;
doc.string_(doc.string.replace(originalstring, fullscore++"\n"));
this.playScoreMode0(sequenceagent, notearr, durarr, instrarr, sustainarr, attackarr, panarr, quantphase, newInstrFlag, agentDict[sequenceagent][1].morphmode, agentDict[sequenceagent][1].repeats, false);
}
{1} {
seqagents.do({arg agent, i;
durarr = durarr ++ agentDict[agent][1].durarr;
sustainarr = sustainarr ++ agentDict[agent][1].sustainarr;
notearr = notearr ++ agentDict[agent][1].notearr;
attackarr = attackarr ++ agentDict[agent][1].attackarr;
score = score ++ agentDict[agent][1].score; // just for creating the score in the doc
});
quantphase = agentDict[seqagents[0]][1].quantphase;
instrument = agentDict[seqagents[0]][1].instrument;
fullscore = (sa++" -> "++ instrument ++"["++score++"]");
if(agentDict[sequenceagent].isNil, {
agentDict[sequenceagent] = [ (), ().add(\amp->0.3), nil];
}, {
if(agentDict[sequenceagent][1].scorestring.contains("{"), {newInstrFlag = true }); // free if { instr (Pmono is always on)
}); // 1st = effectRegistryDict, 2nd = scoreInfoDict, 3rd = placeholder for a routine
agentDict[sequenceagent][1].scorestring = fullscore.asCompileString;
agentDict[sequenceagent][1].instrument = instrument;
agentDict[sequenceagent][1].durarr = durarr;
agentDict[sequenceagent][1].sustainarr = sustainarr;
agentDict[sequenceagent][1].notearr = notearr;
agentDict[sequenceagent][1].attackarr = attackarr;
agentDict[sequenceagent][1].panarr = panarr;
agentDict[sequenceagent][1].score = score;
agentDict[sequenceagent][1].quantphase = quantphase;
doc.string_(doc.string.replace(originalstring, fullscore++"\n"));
this.playScoreMode1(sequenceagent, notearr, durarr, sustainarr, attackarr, panarr, instrument, quantphase, newInstrFlag, agentDict[sequenceagent][1].repeats, false);
}
{2} {
seqagents.do({arg agent, i;
durarr = durarr ++ agentDict[agent][1].durarr;
amparr = notearr ++ agentDict[agent][1].amparr;
attackarr = attackarr ++ agentDict[agent][1].attackarr;
score = score ++ agentDict[agent][1].score; // just for creating the score in the doc
});
quantphase = agentDict[seqagents[0]][1].quantphase;
instrument = agentDict[seqagents[0]][1].instrument;
fullscore = (sa++" -> "++ instrument ++"{"++score++"}");
if(agentDict[sequenceagent].isNil, {
agentDict[sequenceagent] = [ (), ().add(\amp->0.3), nil];
}, {
if(agentDict[sequenceagent][1].scorestring.contains("{"), {newInstrFlag = true }); // free if { instr (Pmono is always on)
}); // 1st = effectRegistryDict, 2nd = scoreInfoDict, 3rd = placeholder for a routine
agentDict[sequenceagent][1].scorestring = fullscore.asCompileString;
agentDict[sequenceagent][1].instrument = instrument;
agentDict[sequenceagent][1].durarr = durarr;
agentDict[sequenceagent][1].amparr = amparr;
agentDict[sequenceagent][1].panarr = panarr;
agentDict[sequenceagent][1].score = score;
agentDict[sequenceagent][1].quantphase = quantphase;
doc.string_(doc.string.replace(originalstring, fullscore++"\n"));
this.playScoreMode2(sequenceagent, amparr, durarr, panarr, instrument, quantphase, newInstrFlag, agentDict[sequenceagent][1].repeats, false);
};
});
}
// methods (called verbs in ixi lang) dealt with in the parsMethod below (these change string in doc)
{"doze"} {
this.parseMethod(string);
}
{"perk"}{
this.parseMethod(string);
}
{"nap"}{
this.parseMethod(string);
}
{"shake"}{
this.parseMethod(string);
}
{"swap"}{
this.parseMethod(string);
}
{"replace"}{
this.parseMethod(string);
}
{"insert"}{
this.parseMethod(string);
}
{"remove"}{
this.parseMethod(string);
}
{">shift"}{
this.parseMethod(string);