-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path08. ProcModR.scd
914 lines (810 loc) · 24 KB
/
08. ProcModR.scd
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
//triggering - ProcModR & ProcEvents
"ProcModR".openHelpFile; //help not available currently
//0 groups and buses
//1 basic proc
//2 functinoal
//procevents
//perfgui, pracgui
//releaseFunc, onReleaseFunc
//recording
//procsink
//Process
//Modular
//Record
//------------------------------------------
// CtkGroup - simple example (no sound)
//------------------------------------------
s.reboot;
s.boot;
s.queryAllNodes; //post to window
s.plotTree; //GUI!
//first - no explicit group:
(
var synths, procs;
var firstOutputChannel;
firstOutputChannel = 0;
s.waitForBoot({
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur, gate = 1;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env([0, 1, 0], [1, 2], \lin, 1), gate: gate, doneAction: 2) * amp,
Rand.new(-1.0, 1.0)
)
)
})
);
~note = synths[\singrain].note.freq_(rrand(440, 1760)).amp_(-12.dbamp).outbus_(firstOutputChannel).play;
});
)
~note.release;
//same, multiple notes
(
var synths, procs;
var firstOutputChannel;
firstOutputChannel = 0;
s.waitForBoot({
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur, gate = 1;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env([0, 1, 0], [1, 2], \lin, 1), gate: gate, doneAction: 2) * amp,
Rand.new(-1.0, 1.0)
)
)
})
);
~note = 10.collect({
synths[\singrain].note.freq_(rrand(440, 1760)).amp_(-12.dbamp).outbus_(firstOutputChannel).play;
});
});
)
~note;
~note.do({|thisNote| thisNote.release});
//now - put them in a group
(
var synths, group;
var firstOutputChannel;
firstOutputChannel = 0;
s.waitForBoot({
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur, gate = 1;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env([0, 1, 0], [1, 2], \lin, 1), gate: gate, doneAction: 2) * amp,
Rand.new(-1.0, 1.0)
)
)
})
);
group = CtkGroup.play;
~group = group; //assign global variable to it
10.do({ //no need to collect!
synths[\singrain].note(target: group).freq_(rrand(440, 1760)).amp_(-12.dbamp).outbus_(firstOutputChannel).play; //note we're specifying target - a group
});
});
)
~group.release; //releases all notes in a group
~group.free; //free when you're done with it
//and multiple groups
(
var synths, group, group2;
var firstOutputChannel;
firstOutputChannel = 0;
s.waitForBoot({
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur, gate = 1;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env([0, 1, 0], [1, 2], \lin, 1), gate: gate, doneAction: 2) * amp,
Rand.new(-1.0, 1.0)
)
)
})
);
group = CtkGroup.play;
group2 = CtkGroup.play;
~group = group; //assign global variable to it
~group2 = group2; //assign global variable to it
10.do({ //no need to collect!
synths[\singrain].note(target: group).freq_(rrand(640, 1760)).amp_(-19.dbamp).outbus_(firstOutputChannel).play; //note we're specifying target - a group
});
10.do({ //no need to collect!
synths[\singrain].note(target: group2).freq_(rrand(140, 260)).amp_(-16.dbamp).outbus_(firstOutputChannel).play; //note we're specifying target - a group
});
});
)
~group.release; //releases all notes in a group
~group2.release; //releases all notes in a group
~group.free; ~group2.free; //free when you're done with it
//and now: -> ProcModR
//------------------------------------------
// ProcModR - simple example (no sound)
//------------------------------------------
s.boot;
(
// create a new ProcModR, and assign a function to it
~pm1 = ProcModR.new(
Env([0, 1, 0], [0.1, 0.1], \sin, 1), //global envelope - not attack/decay time
0.dbamp, //global amplitude
2, //number of channels
0, //output bus
\slowSines, //id (any name - a Symbol)... will become handy
server: s);
~pm1.function_({arg group, routebus, server;
//inside the function you want to have a Task
Task({
"one potato".postln;
1.wait;
"two potatoes".postln;
1.wait;
"three potatoes".postln;
0.75.wait;
"four".postln;
});
});
)
~pm1.play;
~pm1.release;
~pm1.isRunning
if(~pm1.isRunning, {~pm1.release;}); ~pm1.play;
//------------------------------------------
// ProcModR - basic
//------------------------------------------
(
var synths, procs;
var firstOutputChannel;
firstOutputChannel = 0;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
})
);
// create a new ProcModR, and assign a function to it
~pm1 = ProcModR.new(
Env([0, 1, 0], [1, 1], \sin, 1), //global envelope
0.dbamp, //global amplitude
2, //number of channels
firstOutputChannel, //output bus
\slowSines, //id (any name - a Symbol)... will become handy
server: s);
~pm1.function_({arg group, routebus, server; //routebus is an output bus for this ProcModR; use it as output in your synths
//inside the function you want to have a Task
Task({
1.do({
// start a new synth... run it inside this ProcModR's group
synths[\singrain].note(server: server, target: group).freq_(rrand(440, 1760)).amp_(-12.dbamp).dur_(500).outbus_(routebus).play; //note we're specifying target (procmod's group) and server
0.5.wait;
})
});
});
)
~pm1.play;
~pm1.release;
//------------------------------------------
// ProcModR - functional creation
//------------------------------------------
(
var synths, procs;
var firstOutputChannel;
firstOutputChannel = 0;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
})
);
// create a Function with some arguments, create proc inside, use arguments inside, return procmod
~pmFunc1 = {arg minFreq = 440, maxFreq = 1760; //parameters we'd like to have control over
var proc;
proc = ProcModR.new(
Env([0, 1, 0], [1, 1], \sin, 1), //global envelope
0.dbamp, //global amplitude
2, //number of channels
firstOutputChannel, //output bus
\slowSines, //id (any name - a Symbol)... will become handy
server: s);
proc.function_({arg group, routebus, server;
Task({
inf.do({
synths[\singrain].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-12.dbamp)
.dur_(5)
.outbus_(routebus)
.play; //this is one line of code, BTW
0.5.wait;
})
});
});
proc; //make sure the function returns this proc
};
)
~pm1 = ~pmFunc1.(); //same as ~pmFunc1.value()
~pm1.play;
~pm1.release;
~pm2 = ~pmFunc1.(100, 302); //same as ~pmFunc1.value(100, 302)
~pm2.play;
~pm2.release;
//------------------------------------------
// ProcModR - functional creation - more args
//------------------------------------------
(
var synths, procs;
var firstOutputChannel;
firstOutputChannel = 0;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
})
);
// we want to have control over more things, probably; you choose the order as far as the function goes
~pmFunc1 = {arg id = \slowSine, amp = 0.dbamp, minFreq = 440, maxFreq = 1760, att = 1, rel = 5;
var proc;
proc = ProcModR.new(
Env([0, 1, 0], [att, rel], \sin, 1), //note att and rel here
amp, //amp here
2,
firstOutputChannel,
id, //id - from args
server: s);
proc.function_({arg group, routebus, server;
Task({
inf.do({
synths[\singrain].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(routebus)
.play; //this is one line of code, BTW
0.5.wait;
})
});
});
proc; //make sure the function returns this proc
};
)
~pm1 = ~pmFunc1.(\nameOne, -12.dbamp, 880, 1760, rel: 1);
~pm1.play;
~pm1.release;
~pm2 = ~pmFunc1.(\nameTwo, -3.dbamp, 100, 302, rel: 10);
~pm2.play;
~pm2.release;
//------------------------------------------
// ProcEvents - putting events (in order)
//------------------------------------------
"ProcEvents".openHelpFile
//also - bye bye, global vars!
(
var synths, pmFunc1, pEvents;
var firstOutputChannel;
firstOutputChannel = 0;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
})
);
// we want to have control over more things, probably; you choose the order as far as the function goes
pmFunc1 = {arg id = \slowSine, amp = 0.dbamp, minFreq = 440, maxFreq = 1760, att = 1, rel = 5;
var proc;
proc = ProcModR.new(
Env([0, 1, 0], [att, rel], \sin, 1), //note att and rel here
amp, //amp here
2,
firstOutputChannel,
id, //id - from args
server: s);
proc.function_({arg group, routebus, server;
Task({
inf.do({
synths[\singrain].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(routebus)
.play; //this is one line of code, BTW
0.5.wait;
})
});
});
proc; //make sure the function returns this proc
};
//ProcEvents
//*new(events, amp, initmod, killmod, id, server)
//events - an array of events (ProcModRs or a function) to play / release in the following format: [[ProcModR, ProcModR.id to release]] or [[ProcModR, ProcModR2], [ProcModR.id to release, ProcModR.id to release]]
pEvents = ProcEvents.new(
[
[//event 0
[pmFunc1.(\nameOne, -12.dbamp, 880, 1760, rel: 1), pmFunc1.(\nameOneAndAHalf, -12.dbamp, 1880, 2760, rel: 1)],
nil //nothing to release
], [//event 1
pmFunc1.(\nameTwo, -3.dbamp, 100, 302, rel: 10),
nil,
], [//event 2
nil, //nothing to start
\nameOne //release this one
], [//event 3
nil,
[\nameTwo, \nameOneAndAHalf]
]
], //all events array
0.dbamp, //global amp
nil, //initial procModR, starts with the first event
ProcMod.new.function_({"I run after closing procevents window, use me to free buffers etc".postln}), //killmod, runs after closing ProcEvents Gui - needs to be a procmod, I'm creating one here with just one function
server: s
);
// pEvents.perfGUI; //gui for advancing
pEvents.pracGUI; //gui for practice - either that or just perfGUI
)
//------------------------------------------
// ProcMod - releaseFunc, onReleaseFunc
//------------------------------------------
(
var synths, pmFunc1, pEvents;
var firstOutputChannel;
firstOutputChannel = 0;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
}),
SynthDef(\percsin, {arg outbus, freq, amp, dur, att = 0.01;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.perc(att, dur - att, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
})
);
pmFunc1 = {arg id = \slowSine, amp = 0.dbamp, minFreq = 440, maxFreq = 1760, att = 1, rel = 5;
var proc;
proc = ProcModR.new(
Env([0, 1, 0], [att, rel], \sin, 1), //note att and rel here
amp, //amp here
2,
firstOutputChannel,
id, //id - from args
server: s);
proc.function_({arg group, routebus, server;
Task({
inf.do({
synths[\singrain].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(routebus)
.play; //this is one line of code, BTW
0.5.wait;
})
});
});
proc.onReleaseFunc_({arg group, routebus, server;
"I'm triggered when the release STARTS".postln;
synths[\percsin].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(routebus)
.play;
});
proc.releaseFunc_({
id.post; " is done. You can free resources needed for this procmodr (like Buses) here.".postln;
});
proc; //make sure the function returns this proc
};
//events - an array of events (ProcModRs or a function) to play / release in the following format: [ProcModR, ProcModR.id to release]
pEvents = ProcEvents.new(
[
[//event 0
pmFunc1.(\nameOne, -12.dbamp, 880, 1760, rel: 1),
nil //nothing to release
], [//event 1
pmFunc1.(\nameTwo, -3.dbamp, 100, 302, rel: 10),
nil,
], [//event 2
nil, //nothing to start
\nameOne //release this one
], [//event 3
nil,
\nameTwo
]
], //all events array
0.dbamp, //global amp
nil, //initial procModR, starts with the first event
ProcModR.new(Env.perc, 1, 2).function_({"I run after closing procevents window, use me to free buffers etc".postln}),
//killmod, runs after closing ProcEvents Gui - needs to be a procmod
server: s
);
// pEvents.perfGUI; //gui for advancing
pEvents.pracGUI; //gui for practice
)
//------------------------------------------
// ProcMod - releaseFunc, onReleaseFunc - practical example with a bus and a buffer
//------------------------------------------
(
var synths, pmFunc1, pEvents;
var firstOutputChannel;
firstOutputChannel = 0;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
}),
SynthDef(\percsin, {arg outbus, freq, amp, dur, att = 0.01;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.perc(att, dur - att, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
}),
SynthDef(\tapdelay, {arg outbus, inbus, buffer;
Out.ar(outbus,
MultiTap.ar(
`[[0.1, 0.32, 0.43, 0.54], [0.2, 0.42, 0.53, 0.64]],
`[1, 0.8, 0.97, 0.9],
In.ar(inbus, 2),
bufnum: buffer
)
)
})
);
pmFunc1 = {arg id = \slowSine, amp = 0.dbamp, minFreq = 440, maxFreq = 1760, att = 1, rel = 5;
var proc, fxBus, delayBuffer; //declare whatever you need to free afterwards here (Buses, Buffers etc)
proc = ProcModR.new(
Env([0, 1, 0], [att, rel], \sin, 1), //note att and rel here
amp, //amp here
2,
firstOutputChannel,
id, //id - from args
server: s
);
proc.function_({arg group, routebus, server;
Task({
fxBus = CtkAudio(2, server: s);
delayBuffer = CtkBuffer(size: s.sampleRate * 2, numChannels: 2, server: server).load; //loading buffer here might not be the best since it takes time;
server.sync; //wait for the server to load the buffer!
synths[\tapdelay].note(server: server, target: group, addAction: \tail).outbus_(routebus).inbus_(fxBus).buffer_(delayBuffer).play; //start delay
inf.do({
synths[\percsin].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(fxBus)
// .outbus_(routebus)
.play; //this is one line of code, BTW
1.5.wait;
})
});
});
/* proc.onReleaseFunc_({arg group, routebus, server;
"I'm triggered when the release STARTS".postln;
synths[\percsin].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(routebus)
.play;
});*/
proc.releaseFunc_({
id.post; " is done. You can free resources needed for this procmod (like Buses) here.".postln;
delayBuffer.free;
fxBus.free;
// [delayBuffer, fxBus].do(_.free); // <-- free the bus and the buffer here!
});
proc; //make sure the function returns this proc
};
//events - an array of events (ProcMods or a function) to play / release in the following format: [ProcMod, ProcMod.id to release]
pEvents = ProcEvents.new(
[
[//event 0
pmFunc1.(\nameOne, -12.dbamp, 880, 1760, rel: 1),
nil //nothing to release
], [//event 1
pmFunc1.(\nameTwo, -3.dbamp, 100, 302, rel: 10),
nil,
], [//event 2
nil, //nothing to start
\nameOne //release this one
], [//event 3
nil,
\nameTwo
]
], //all events array
0.dbamp, //global amp
nil, //initial procMod, starts with the first event
ProcMod.new.function_({"I run last, use me to free buffers etc".postln}),
//killmod, runs after closing ProcEvents Gui - needs to be a procmod or ProcModR
server: s
);
// pEvents.perfGUI; //gui for advancing
pEvents.pracGUI; //gui for practice
)
//------------------------------------------
// ProcModR - recording - NOT WORKING CURRENTLY?
//------------------------------------------
(
var synths, pmFunc1, pEvents;
var firstOutputChannel, recordProcsToDisk, recordPath;
firstOutputChannel = 0;
recordProcsToDisk = false; //so we can switch it on/off easily
recordPath = "".resolveRelative; //just the same path as our SC file
recordPath.postln;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
}),
SynthDef(\percsin, {arg outbus, freq, amp, dur, att = 0.01;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.perc(att, dur - att, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
}),
SynthDef(\tapdelay, {arg outbus, inbus, buffer;
Out.ar(outbus,
MultiTap.ar(
`[[0.1, 0.32, 0.43, 0.54], [0.2, 0.42, 0.53, 0.64]],
`[1, 0.8, 0.67, 0.6],
In.ar(inbus, 2),
bufnum: buffer
)
)
})
);
pmFunc1 = {arg id = \slowSine, amp = 0.dbamp, minFreq = 440, maxFreq = 1760, att = 1, rel = 5;
var proc, fxBus, delayBuffer;
proc = ProcModR.new(
Env([0, 1, 0], [att, rel], \sin, 1), //note att and rel here
amp, //amp here
2,
firstOutputChannel,
id, //id - from args
server: s
);
// recordProcsToDisk.postln;
// recordPath.postln;
if(recordProcsToDisk, {
proc.recordPM(recordPath); //init recording here
});
proc.function_({arg group, routebus, server;
Task({
fxBus = CtkAudio(2, server: s);
delayBuffer = CtkBuffer(size: s.sampleRate * 2, numChannels: 2, server: server).load(sync: true); //loading buffer here might not be the best since it takes time;
server.sync; //wait for the buffor to load
synths[\tapdelay].note(server: server, target: group, addAction: \tail).outbus_(routebus).inbus_(fxBus).buffer_(delayBuffer).play; //start delay
inf.do({
synths[\percsin].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(fxBus)
// .outbus_(routebus)
.play; //this is one line of code, BTW
"here".postln;
1.5.wait;
});
});
});
proc.onReleaseFunc_({arg group, routebus, server;
"I'm triggered when the release STARTS".postln;
synths[\percsin].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(routebus)
.play;
});
proc.releaseFunc_({
id.post; " is done. You can free resources needed for this procmod (like Buses) here.".postln;
[delayBuffer, fxBus].do(_.free); // <-- free the bus and the buffer here!
"This will not get triggered if you never play and release the proc... plan accordingly!".postln;
});
proc; //make sure the function returns this proc
};
//events - an array of events (ProcMods or a function) to play / release in the following format: [ProcMod, ProcMod.id to release]
pEvents = ProcEvents.new(
[
[//event 0
pmFunc1.(\nameOne, -12.dbamp, 880, 1760, rel: 1),
nil //nothing to release
], [//event 1
pmFunc1.(\nameTwo, -3.dbamp, 100, 302, rel: 10),
nil,
], [//event 2
nil, //nothing to start
\nameOne //release this one
], [//event 3
nil,
\nameTwo
]
], //all events array
0.dbamp, //global amp
nil, //initial procMod, starts with the first event
ProcMod.new.function_({"I run last, use me to free buffers etc".postln}),
//killmod, runs after closing ProcEvents Gui - needs to be a procmod or ProcModR
server: s
);
pEvents.perfGUI; //gui for advancing
// pEvents.pracGUI; //for some reason recording works only with practice gui
)
//------------------------------------------
// ProcEvents - more procs at the same time
//------------------------------------------
(
var synths, pmFuncs, pEvents;
var firstOutputChannel, recordProcsToDisk, recordPath;
firstOutputChannel = 0;
recordProcsToDisk = false; //so we can switch it on/off easily
recordPath = "".resolveRelative; //just the same path as our SC file
recordPath.postln;
pmFuncs = IdentityDictionary.new;
~maxFreqGlobal = 1800;
synths = CtkProtoNotes(
SynthDef(\singrain, {arg outbus, freq, amp, dur;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
}),
SynthDef(\percsin, {arg outbus, freq, amp, dur, att = 0.01;
Out.ar(outbus,
Pan2.ar(
SinOsc.ar(freq, 0, amp) * EnvGen.kr(Env.perc(att, dur - att, amp), doneAction: 2),
Rand.new(-1.0, 1.0)
)
)
}),
SynthDef(\tapdelay, {arg outbus, inbus, buffer;
Out.ar(outbus,
MultiTap.ar(
`[[0.1, 0.32, 0.43, 0.54], [0.2, 0.42, 0.53, 0.64]],
`[1, 0.8, 0.67, 0.6],
In.ar(inbus, 2),
bufnum: buffer
)
)
})
);
pmFuncs[\slow] = {arg id = \slowSine, amp = 0.dbamp, minFreq = 440, maxFreq = 1760, att = 1, rel = 5;
var proc, fxBus, delayBuffer;
proc = ProcModR.new(
Env([0, 1, 0], [att, rel], \sin, 1), //note att and rel here
amp, //amp here
2,
firstOutputChannel,
id, //id - from args
server: s
);
// recordProcsToDisk.postln;
// recordPath.postln;
if(recordProcsToDisk, {
proc.recordPM(recordPath); //init recording here
});
proc.function_({arg group, routebus, server;
Task({
fxBus = CtkAudio(2, server: s);
delayBuffer = CtkBuffer(size: s.sampleRate * 2, numChannels: 2, server: server).load; //loading buffer here might not be the best since it takes time;
server.sync;
synths[\tapdelay].note(server: server, target: group, addAction: \tail).outbus_(routebus).inbus_(fxBus).buffer_(delayBuffer).play; //start delay
inf.do({
synths[\percsin].note(server: server, target: group)
.freq_(rrand(minFreq, if(maxFreq.isKindOf(Function), {
maxFreq.value
}, {
maxFreq
}))) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(fxBus)
// .outbus_(routebus)
.play; //this is one line of code, BTW
1.5.wait;
})
});
});
proc.onReleaseFunc_({arg group, routebus, server;
"I'm triggered when the release STARTS".postln;
synths[\percsin].note(server: server, target: group)
.freq_(rrand(minFreq, maxFreq)) //<<--- see args here
.amp_(-9.dbamp)
.dur_(5)
.outbus_(routebus)
.play;
});
proc.releaseFunc_({
id.post; " is done. You can free resources needed for this procmod (like Buses) here.".postln;
[delayBuffer, fxBus].do(_.free); // <-- free the bus and the buffer here!
"This will not get triggered if you never play and release the proc... plan accordingly!".postln;
});
proc; //make sure the function returns this proc
};
pmFuncs[\fast] = {arg id = \fastPerf, amp = 0.dbamp, att = 1, rel = 5, numGrains = 100;
var proc, fxBus, delayBuffer;
proc = ProcModR.new(
Env([0, 1, 0], [att, rel], \sin, 1), //note att and rel here
amp, //amp here
2,
firstOutputChannel,
id, //id - from args
server: s
);
if(recordProcsToDisk, {
proc.recordPM(recordPath); //init recording here
});
proc.function_({arg group, routebus, server;
Task({
numGrains.do({|i|
synths[\percsin].note(server: server, target: group).freq_(rrand(40, 6450)).amp_(-18.dbamp).play;
(0.01 + 0.05.rand).wait;
});
});
});
proc; //make sure the function returns this proc
};
//events - an array of events (ProcMods or a function) to play / release in the following format: [ProcMod, ProcMod.id to release]
pEvents = ProcEvents.new(
[
[//event 0
pmFuncs[\slow].(\nameOne, -12.dbamp, 880, {~maxFreqGlobal}, rel: 1),
nil //nothing to release
], [//event 1
[
pmFuncs[\slow].(\nameTwo, -3.dbamp, 100, 302, rel: 10),
pmFuncs[\fast].(\nameFast, -3.dbamp, numGrains: 200),
],
nil,
], [//event 2
nil, //nothing to start
[\nameOne, \nameFast] //release these ones
], [//event 3
nil,
\nameTwo
]
], //all events array
0.dbamp, //global amp
nil, //initial procMod, starts with the first event
ProcMod.new.function_({"I run last, use me to free buffers etc".postln}),
//killmod, runs after closing ProcEvents Gui - needs to be a procmod or ProcModR
server: s
);
// pEvents.perfGUI; //gui for advancing
pEvents.pracGUI; //for some reason recording works only with practice gui
)
~maxFreqGlobal = 3;