-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModule.sc
317 lines (254 loc) · 7.52 KB
/
Module.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
MidiOscObject {
var <>group, <>synthGroup, <>bigSynthGroup, <>win, <>oscMsgs, <>controls, assignButtons, paused=false;
var waitForSetNum, modName, dontLoadControls, <>synths, visibleArray, isGlobalController, path, waitToLoad = false;
initControlsAndSynths {arg num;
//oscMsgs holds the
oscMsgs = List.newClear(num);
controls = List.newClear(0);
assignButtons = List.newClear(num);
//put a number in this List if you don't want the object to initialize itself upon loading from a file
dontLoadControls = List.newClear(0);
synths = List.newClear(0);
}
sendGUIVals {
var vals;
controls.do{arg item, i;
vals = item.value;
if(vals.size<2,{
if(vals!=nil,{
this.sendOSC(i, vals)
});
},{
//this means it is a TypeOSCFuncObject
try {this.sendOSC(i, vals[1])}
})
};
if(this.isKindOf(MainMixer),{
this.sendGUIMixer;
});
}
sendOSC {|num, val|
var unmapped, temp;
if(oscMsgs[num]!=nil) {
/* if(oscMsgs[num].asString.contains("/Switches")) {
if(controls[num].value==1,{
Lemur_Mod.sendSwitchOSC(oscMsgs[num].asString)
});
}{*/
if(val.size<2){
try {unmapped = controls[num].controlSpec.unmap(val)} {unmapped = val};
//Lemur_Mod.sendOSC(oscMsgs[num], unmapped);
temp = oscMsgs[num].asString;
OSCReceiver_Mod.sendOSC(temp.copyRange(0, temp.size-3), unmapped);
}
//}
}
}
setOscMsg {arg msg;
msg = msg.asString;
if(msg.contains("/z")){
msg = msg.replace("/z", "/x");
};
oscMsgs.put(waitForSetNum, msg.asSymbol);
}
clearMidiOsc {
//should just have to send all osc message to MidiOscControl for deletion
oscMsgs.do{|msg| MidiOscControl.clearController(group.server, msg)};
oscMsgs = List.newClear(oscMsgs.size);
}
addAssignButton {|num, type, rect|
var temp, oscMsg;
if(rect!=nil, {temp = AssignButton.new(win, rect)},{temp = AssignButton.new()});
assignButtons.put(num, temp
.instantAction_{|butt|
if(butt.value==1,{
waitForSetNum = num;
if(isGlobalController==true,{
MidiOscControl.requestInstantAssign(this, controls[num], type, \global, nil);
},{
MidiOscControl.requestInstantAssign(this, controls[num], type, group.server);
});
},{
MidiOscControl.clearInstantAssign;
//because MultiBall has to clear 3 functions
oscMsg = oscMsgs[num].asString;
if(oscMsg.contains("MultiBall"), {
oscMsg = ["x","y","z"].collect{arg item; oscMsg.copyRange(0, oscMsg.size-2)++item};
},{
oscMsg = [oscMsg]
});
oscMsg.do{|msg|
if(isGlobalController==true,{
MidiOscControl.clearController(\global, msg);
},{
MidiOscControl.clearController(group.server, msg); //send a message to clear the OSC data from the MidiOscControl
});
};
oscMsgs.put(num, nil);
})
});
}
addTypeOSCAssignButton {|num|
var temp, tempString;
temp = TypeOSCAssignButton.new()
.instantAction_{|butt|
if(butt.value==1,{
MidiOscControl.requestInstantTypeAssign(controls[num].textField, group.server);
},{
MidiOscControl.clearInstantAssign;
tempString = controls[num].textField.string;
controls[num].textField.valueAction_(controls[num].textField.string);
})
};
^temp
}
saveExtra{}//does nothing unless the module overrides this method
save {
var saveArray, temp;
saveArray = List.newClear(0);
saveArray.add(modName); //name first
temp = List.newClear(0); //controller settings
controls.do{arg item;
temp.add(item.value);
};
saveArray.add(temp); //controller messages
saveArray.add(oscMsgs);
if(win!=nil,{
saveArray.add(win.bounds);
},{
saveArray.add(nil);
});
this.saveExtra(saveArray);
^saveArray
}
loadExtra{}//does nothing unless the module overrides this method
load {arg loadArray;
Routine({
while{waitToLoad==true}{"waiting".postln;0.2.wait};
loadArray[1].do{arg controlLevel, i;
var control;
try { control=controls[i] } { control = nil };
if(control!=nil,{
//it will not load the value if the value is already correct (because Button seems messed up) or if dontLoadControls contains the number of the controller
//controls[i].valueAction_(controlLevel);
if(dontLoadControls.includes(i).not){
try {
if(controls[i].value!=controlLevel)
{
controls[i].valueAction_(controlLevel);
}
}{}
}{
if((controls[i].class==TypeOSCFuncObject)||controls[i].class==TextObject)
{
//if we aren't loading the value of a TypeOSCFuncObject, still load the label
controls[i].valueAction_(controlLevel[0]);
}
}
});
};
loadArray[2].do{arg msg, i;
var control;
waitForSetNum = i;
try { control=controls[i] } { control = nil;};
if((msg!=nil)&&(control!=nil)&&(control.class!=TypeOSCFuncObject),{
if(isGlobalController==true,{
//this is only true for the server switcher and Modular Inputs Array
MidiOscControl.getFunctionNSetController(this, controls[i], msg, 'global');
},{
MidiOscControl.getFunctionNSetController(this, controls[i], msg, group.server);
});
if(assignButtons[i]!=nil){
{assignButtons[i].instantButton.value_(1)}.defer;
}
})
};
if(win!=nil,{
win.bounds_(loadArray[3]);
win.visible_(false);
});
this.loadExtra(loadArray[4]);
this.sendGUIVals;
}).play(AppClock)
}
}
Module_Mod : MidiOscObject {
var <>outBus, <>mixerToSynthBus, xmlSynth, numChannels = 2, rout;
*new {arg group, outBus;
^super.new.group_(group).outBus_(outBus).init;
}
makeWindow {arg name, rect;
if(rect!=nil, {win = Window.new(name, rect)},{win = Window.new(name)});
win.userCanClose_(false);
path = PathName(this.class.filenameSymbol.asString).pathOnly;
modName = name;
}
makeMixerToSynthBus {arg numChannels;
numChannels ?? {numChannels = 1};
mixerToSynthBus = Bus.audio(group.server, numChannels);
}
getInternalBus {
^mixerToSynthBus;
}
pause {
synths.flat.do{|item| if(item!=nil) {item.set(\pauseGate, 0)}};
if(bigSynthGroup!=nil){bigSynthGroup.set(\pauseGate, 0);bigSynthGroup.run(false)};
paused = true;
}
unpause {
synths.flat.do{|item| if(item!=nil) {item.set(\pauseGate, 1); item.run(true);}};
if(bigSynthGroup!=nil){bigSynthGroup.run(true); bigSynthGroup.set(\pauseGate, 1)};
paused = false;
}
show {
win.visible = true;
win.front;
}
hide {
win.visible = false;
}
numBusses {
^mixerToSynthBus.numChannels;
}
killMe {
oscMsgs.do{arg item; MidiOscControl.clearController(group.server, item)};
win.close;
mixerToSynthBus.free;
synths = synths.flat;
if(synths!=nil,{
synths.do{arg item; if(item!=nil,{item.set(\gate, 0)})};
});
this.killMeSpecial;
}
killMeSpecial {
}
}
TypeOSCModule_Mod : Module_Mod {
load {arg loadArray;
loadArray[1].do{arg controlLevel, i;
var control;
try { control=controls[i] } { control = nil; };
if(control!=nil,{
//it will not load the value if the value is already correct (because Button seems messed up) or if dontLoadControls contains the number of the controller
if(dontLoadControls.includes(i).not){
if(controls[i].value!=controlLevel)
{
controls[i].valueAction_(controlLevel);
}
}{
if(controls[i].class==TypeOSCFuncObject)
{
//if we aren't loading the value of a TypeOSCFuncObject, still load the label
controls[i].valueAction_(controlLevel[0]);
}
}
});
};
if(win!=nil,{
win.bounds_(loadArray[3]);
win.visible_(false);
});
this.loadExtra(loadArray[4]);
this.sendGUIVals;
}
}