-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_basic.scd
156 lines (119 loc) · 2.93 KB
/
template_basic.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
(
s.quit;
Window.closeAll;
s = Server.local;
ServerOptions.devices; // find the one you want and copy in the next lines
s.options.outDevice_("External Headphones"); // "LG UltraFine Display Audio"
s.options.numOutputBusChannels_(2);
s.options.inDevice_("LG UltraFine Display Audio");
s.options.numInputBusChannels_(2);
s.options.sampleRate_(44100);//(44100);//(48000);//(nil);//
s.options.memSize; // default 8.192KB
s.options.memSize_(2.pow(18)); // around 262 MB
s.newBusAllocators;
ServerBoot.removeAll;
ServerTree.removeAll;
ServerQuit.removeAll;
// 2. initialize global vairables ----
~out = 0; // very useful when changing interfaces with multiple outputs
~samplesPath = PathName(thisProcess.nowExecutingPath).parentPath++"samples/";
// 3. define piece-specific functions ---
// automatically deactivate midi notes on CMD+.
CmdPeriod.add({(0..127).do{arg n; m.noteOff(0, n);};});
// function to read sound buffers from a folder
~makeBuffers = {
b = Dictionary.new;
PathName(~samplesPath).entries.do{
arg subfolder;
b.add(
subfolder.folderName.asSymbol ->
Array.fill(
subfolder.entries.size,
{
arg i;
Buffer.read(s, subfolder.entries[i].fullPath);
}
)
);
};
};
~makeBusses = {
~bus = Dictionary.new;
// ~bus.add(\reverb -> Bus.audio(s,2));
};
~cleanup = {
s.newBusAllocators;
ServerBoot.removeAll;
ServerTree.removeAll;
ServerQuit.removeAll;
};
~makeNodes = {
s.bind({
~mainGrp = Group.new;
// other groups, for example a reverb
/* ~revverbGrp = Group.new;
~reverbSynth = Synth.new(
\reverb,
[
\amp, 1,
\predelay, 0.1,
//...
]
);*/
});
};
~makeEvents = {
e = Dictionary.new;
e.add(\event1 -> {"event1".postln;});
e.add(\event2 -> {"event2".postln;});
e.add(\event3 -> {"event3".postln;});
MIDIdef.cc(\controller, {nil});
};
// 4. register functions with ServerBoot/Quit/Tree ---
ServerBoot.add(~makeBuffers);
ServerBoot.add(~makeBusses);
ServerQuit.add(~cleanup);
// 5. boot server ---
s.waitForBoot({
s.sync;
// 6.a register SynthDefs
SynthDef(\bpfsaw2, {
arg atk=2, sus=0, rel=3, c1=1, c2=(-1), freq=500, detune=0.2, pan=0,
cfhzmin=0.1, cfhzmax=0.3, cfmin=500, cfmax=2000, rqmin=0.1, rqmax=0.2,
lsf=200, ldb=0, amp=1, out=0;
var sig, env;
env = EnvGen.kr(Env([0,1,1,0], [atk, sus, rel], [c1, 0, c2]), doneAction: 2);
sig = Saw.ar(freq * {LFNoise1.kr(0.5, detune).midiratio}!2);
sig = BPF.ar(
sig,
{
LFNoise1.kr(
LFNoise1.kr(4).exprange(cfhzmin, cfhzmax)
).exprange(cfmin, cfmax)
}!2,
{
LFNoise1.kr(0.1).exprange(rqmin, rqmax)
}!2
);
sig = BLowShelf.ar(sig, lsf, 0.5, ldb);
sig = Balance2.ar(sig[0], sig[1], pan);
sig = sig * env * amp;
Out.ar(out, sig);
}).add;
s.sync;
// 6.b register remaining functions
ServerTree.add(~makeNodes);
ServerTree.add(~makeEvents);
s.freeAll;
s.sync;
"READY".postln;
});
)
// *** utils ***
s.boot;
s.reboot;
s.meter;
s.plotTree;
s.scope;
s.quit;
thisProcess.nowExecutingPath;