forked from supercollider-quarks/ddwVoicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoicerProxy.sc
328 lines (272 loc) · 7.89 KB
/
VoicerProxy.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
VoicerProxy {
var <voicer, // the destination
<controlProxies, // proxies to voicer's global controls
<processes, // processes to be played on the destination
<editor, // my gui -- I'll probably have to write a custom setter
<moreVoicers, // voicer is the one that gets gui'ed;
// items in this array are also recipients of play messages
// todo: how to handle global controls
<>moreVoicerProb = 1.0, // probability of other voicers being triggered
<>maxControlProxies;
*new { arg v;
^super.new.init(v)
}
init { arg v;
controlProxies = Array.new;
processes = Array.new;
moreVoicers = Array.new;
this.voicer_(v);
}
free {
voicer.proxy_(nil);
controlProxies.do({ |cp| cp.free });
processes.do({ |pr| pr.free });
editor.notNil.if({ editor.remove });
this.releaseDependants;
}
proxify { ^this }
voicer_ { arg v;
// to clear old voicer's proxy variable: voicer must not be nil
// and voicer's current proxy must be this
// if voicer is now pointing to another proxy (which is the case if
// we're in the middle of reassigning voicers and proxies), I shouldn't change it
(voicer.notNil and: { voicer.proxy == this }).if({
voicer.proxy_(nil); // break old connection
});
voicer = v ?? { NullVoicer.new }; // change voicer object
voicer.proxy_(this); // make new connection
editor.notNil.if({ editor.updateStatus; });
}
draggedIntoVoicerGUI { arg dest;
voicer.draggedIntoVoicerGUI(dest);
}
addControlProxy { arg gcproxy, addAlways = false;
(this.canAddControlProxies and: {
addAlways or: { controlProxies.includes(gcproxy).not } }).if({
controlProxies = controlProxies.add(gcproxy
?? { VoicerGCProxy(nil, this) });
});
}
removeControlProxy { arg gc; // gc may be symbolic name, gc, or gcproxy
gc.isSymbol.if({
gc = controlProxies.select({ |x| x.gc.name == gc }).at(0);
});
gc.isKindOf(VoicerGlobalControl).if({ gc = gc.proxy });
controlProxies.remove(gc);
}
getFreeControlProxy { arg gcmodel; // if I need to make a new proxy, this will be the model
var gcproxy;
// loop thru controlProxies array
// gcproxy gets the first element of controlProxies whose model is nil
maxControlProxies.isNil.if({ controlProxies }, { controlProxies[0..maxControlProxies-1] })
.do({ |pr, i|
(gcproxy.isNil && pr.tryPerform(\gc).isNil).if({ gcproxy = pr });
});
// if none was free, it's my responsibility to make it and add it to me
gcproxy.isNil.if({
// but, we may do it only if there's no limit
this.canAddControlProxies.if({
gcproxy = VoicerGCProxy(gcmodel, this);
this.addControlProxy(gcproxy);
}, {
"This VoicerProxy may have no more than % control proxies."
.format(maxControlProxies).warn;
});
}, {
gcproxy.gc_(gcmodel); // make sure proxy knows who it's talking to
});
^gcproxy
}
switchControlProxies { // my controlproxies should point to my voicer's controls
var i;
// take guiable proxies in order, sort in order of creation
voicer.globalControlsByCreation.do({ |gc|
this.getFreeControlProxy(gc);
});
// when this proxy receives a voicer with fewer controls than I have proxies,
// remaining proxies must be set to nil
i = voicer.globalControls.size;
{ i < controlProxies.size }.while({
controlProxies[i].gc_(nil);
i = i+1;
});
}
clearControlProxies { // called when setting a voicer's proxy to nil
controlProxies.do({ |gcpr|
gcpr.gc_(nil);
});
}
canAddControlProxies { ^controlProxies.size < (maxControlProxies ? inf) }
modelWasFreed {
this.voicer_(NullVoicer.new);
editor.notNil.if({
editor.updateStatus
}, {
// if voicer is gone and there is no gui, no need for this object to exist
this.free;
});
}
editor_ { |gui|
editor = gui;
// if editor dies and there is no voicer, again, kill the proxy
(gui.isNil and: { this.active.not }).if({
this.free;
});
}
// change the voicer's target to the mixer in this gui
// does not affect currently playing notes
// if the gui is empty, the drag-n-drop will be ignored
draggedIntoMixerGUI { |gui|
voicer.notNil.if({
voicer.draggedIntoMixerGUI(gui)
});
}
clock {
^voicer.clock;
}
addVoicer { arg v;
moreVoicers = moreVoicers.add(v);
}
removeVoicer { arg v;
^moreVoicers.remove(v);
}
//////// things voicer used to manage, now managed by voicerproxy
addProcess { arg states, type; // adds a VoicerProcessGroup
var class, process;
class = (type == \toggle).if(ProcessToggleGroup, VoicerProcessGroup);
process = class.new(this, states);
processes = processes.add(process);
^process
// gui should update automatically if it exists--or should I tell it to?
}
removeProcess { arg p;
var i;
i = processes.indexOf(p);
i.notNil.if({ ^this.removeProcessAt(i) }, { ^nil });
}
removeProcessAt { arg i;
var process;
process = processes.removeAt(i);
process.free;
^process
}
//////// things Voicer normally does but which should be available thru the proxy as well
mapGlobal { arg name, bus, value, spec, allowGUI = true;
var gc, gcproxy;
gc = voicer.mapGlobal(name, bus, value, spec, allowGUI);
this.addControlProxy(gcproxy = VoicerGCProxy.new(gc, this));
^gcproxy // when you mapGlobal on a voicerproxy, you should get a voicergcproxy
// so that guis and midi mappings are hot swappable
}
unmapGlobal { arg name;
voicer.unmapGlobal(name);
// does not free the proxy, because proxies must be explicitly discarded
// no need to update the gui here, b/c when gc gets freed, its proxy is updated
}
//////// play methods sent directly on to voicer
active {
^voicer.active;
}
run { |bool = true|
voicer.notNil.if({ voicer.run(bool) });
}
isRunning { voicer.notNil.if({ ^voicer.isRunning }, { ^true }); }
panic {
voicer.panic;
}
cleanup {
voicer.cleanup;
}
set { arg args;
voicer.set(args)
}
trigger1 { arg freq, gate = 1, args, lat = -1;
moreVoicers.do({ |v|
moreVoicerProb.coin.if({
v.trigger1(freq, gate, args, lat)
});
});
^voicer.trigger1(freq, gate, args, lat)
}
trigger { arg freq, gate = 1, args, lat = -1;
moreVoicers.do({ |v|
moreVoicerProb.coin.if({
v.trigger(freq, gate, args, lat)
});
});
^voicer.trigger(freq, gate, args, lat)
}
gate1 { arg freq, dur, gate = 1, args, lat = -1;
moreVoicers.do({ |v|
moreVoicerProb.coin.if({
v.gate1(freq, dur, gate, args, lat)
});
});
^voicer.gate1(freq, dur, gate, args, lat)
}
gate { arg freq, dur, gate = 1, args, lat = -1;
moreVoicers.do({ |v|
moreVoicerProb.coin.if({
v.gate(freq, dur, gate, args, lat)
});
});
^voicer.gate(freq, dur, gate, args, lat)
}
release1 { arg freq, lat = -1;
moreVoicers.do({ |v| v.release1(freq, lat) });
^voicer.release1(freq, lat)
}
release { arg freq, lat = -1;
moreVoicers.do({ |v| v.release(freq, lat) });
^voicer.release(freq, lat)
}
releaseAll {
moreVoicers.do({ |v| v.releaseAll });
^voicer.releaseAll;
}
releaseNow1 { arg freq, sec;
moreVoicers.do({ |v| v.releaseNow1(freq, sec) });
^voicer.releaseNow1(freq, sec)
}
releaseNow { arg freq, sec;
moreVoicers.do({ |v| v.releaseNow(freq, sec) });
^voicer.releaseNow(freq, sec)
}
// hmm... this will not work well for moreVoicers...
releaseNode { |node, freq, releaseGate = 0, lat = -1|
voicer.releaseNode(node, freq, releaseGate, lat);
}
prGetNodes { |numNodes = 1| ^voicer.prGetNodes(numNodes) }
setArgsInEvent { |event| ^voicer.setArgsInEvent(event) }
guiClass {
^VoicerProxyGui
}
asString {
^voicer.asString;
}
//////// getters and setters
latency {
^voicer.latency;
}
latency_ { arg l;
moreVoicers.do({ |v| v.latency_(l) });
^voicer.latency_(l);
}
globalControls {
^voicer.globalControls;
}
globalControlsByCreation {
^voicer.globalControlsByCreation
}
target {
^voicer.target;
}
bus {
^voicer.bus;
}
susPedal { ^voicer.susPedal }
sustainPedal { |sustain|
moreVoicers.do(_.sustainPedal(sustain));
voicer.sustainPedal(sustain);
}
}