-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModularServers.sc
339 lines (260 loc) · 7.61 KB
/
ModularServers.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
ModularServer_ID {
classvar <id=57100;
*initClass { id = 57100; }
*next { ^id = id + 1; }
*path {this.filenameSymbol.postln}
}
ModularServerObject {
var <>serverName, <>blockSize, <>server, <>objectBusses, mainGroup, <>inGroup, <>preSynthGroup, <>mixerGroup, <>postMixerGroup, <>mixerDirectInBus, synthGroup, <>synthGroups, <>inBusses, <>preSynthBusses, <>stereoInBusIndexes, volumeInRack, modularObjects, dimensions, <>mainMixer, mainWindow, <>busMap, <>isVisible, id, directIns, <>globalControlBus;
*new {|serverName, blockSize|
^super.new.serverName_(serverName).blockSize_(blockSize).init;
}
*initClass {
StartUp.add {
SynthDef("directInputs_mod", {arg outBus;
Out.ar(outBus, SoundIn.ar((0..21)));
}).writeDefFile;
};
}
init {
id = ModularServer_ID.next;
while( {("lsof -i:"++id).unixCmdGetStdOut.size > 0},{id = ModularServer_ID.next});
blockSize ?? {"set blockSize".postln; blockSize = 128};
Server.local.options.blockSize_(blockSize);
server = Server.new(serverName, NetAddr("localhost", id), Server.local.options);
server.waitForBoot({
//set up groups
server.sync;
mainGroup = Group.tail(server);
server.sync;
1.wait;
inGroup = Group.tail(mainGroup);
preSynthGroup = Group.tail(mainGroup);
synthGroup = Group.tail(mainGroup);
mixerGroup = Group.tail(mainGroup);
postMixerGroup = Group.tail(mainGroup);
mixerDirectInBus = Bus.audio(server, 22);
directIns = Synth("directInputs_mod", [\outBus, mixerDirectInBus], inGroup);
//set up the inputs and outputs
inBusses = List.new;
8.do{arg i; //right now the number of input channels is hardcoded to 8
inBusses.add(Bus.audio(server,1));
};
preSynthBusses = List.fill(8, {Bus.audio(server,2)});
//create objectBusses and groups in the shape of the dimensions array
//objectBusses = List.new;
dimensions = [5,5]; //for now this is hard-coded
objectBusses = List.fill((dimensions[0]*dimensions[1]), {Bus.audio(server,2)});
server.sync;
//make the global control bus to pass control data between Modules
globalControlBus = Bus.control(server,256);
server.sync;
synthGroups = List.fill((dimensions[0]*dimensions[1]), {Group.tail(synthGroup)});
server.sync;
0.1.wait;
//create the Array of ModularObjects
modularObjects = List.new;
isVisible = true;
(dimensions[0]*dimensions[1]).do{arg i;
modularObjects.add(
ModularObjectPanel(server, synthGroups[i], i)
);
};
mainWindow = MainProcessingWindow.new(mainGroup, modularObjects);
mainMixer = MainMixer.new(mixerGroup, 0).init2(4, true);
LiveModularInstrument.readyToRoll();
})
}
sendGUIVals {
modularObjects.do{arg item; item.sendGUIVals};
mainMixer.sendGUIVals;
}
makeBusMap {arg loadArray;
busMap = Array.fill(3, {Dictionary.new});
11.do{arg i; busMap.add((loadArray[0].asInteger+(i*2)).asSymbol -> (i*2))};
loadArray[1].do{arg item, i; busMap[1].add(item.asSymbol -> i)};
loadArray[2].do{arg item, i; busMap[2].add(item.asSymbol -> objectBusses[i].index)};
}
getBusFromMap {arg busIn;
var temp;
temp = busMap[0][busIn];
if(temp!=nil,{
temp = "D"++temp.asString;
},{
temp = busMap[1][busIn];
if(temp!=nil,{
temp = "S"++temp.asString
},{
temp = busMap[2][busIn];
})
});
^temp
}
save {
var saveServer, temp;
//save and load inputsArray
saveServer = List.newClear(0);
saveServer.add(mainWindow.save);
saveServer.add(mixerDirectInBus.index);
temp = List.newClear(0);
inBusses.do{arg item;
temp.add(item.index); //add busses
};
saveServer.add(temp);
temp = List.newClear(0);
objectBusses.do{arg item;
temp.add(item.index); //add busses
};
saveServer.add(temp);
temp = List.newClear(0);
modularObjects.do{arg mop, i;
temp.add(mop.save);
};
saveServer.add(temp);
saveServer.add(mainMixer.save);
^saveServer;
}
load {arg loadArray;
var inBusTemp, stereoInBusTemp, internalBusTemp, flatObjectBus, flatMOPs, mopData;
mainWindow.load(loadArray[0]);
this.makeBusMap(loadArray.copyRange(1,3));
loadArray[4].do{arg item, i;
if(item.size>0){
modularObjects[i].load(item);
};
};
mainMixer.load(loadArray[5]);
}
makeVisible {arg val;
isVisible = val;
if(val==true,{
mainWindow.show;
mainMixer.unhide;
},{
mainWindow.hide;
mainMixer.hide;
});
}
showAndPlay {arg bool;
if(bool,{
if(isVisible,{
mainWindow.show;
mainMixer.unhide;
modularObjects.do{|item| item.resume};
});
mainMixer.unmute;
},{
modularObjects.do{|item| item.pause};
mainWindow.hide;
mainMixer.hide;
mainMixer.mute;
});
}
name {
^server.name
}
killMe {
mainGroup.free;
inBusses.free;
directIns.free;
}
}
ModularServers {
classvar <>numServers, <>inBusses;
classvar <>servers, <>modularInputsArray, <>serverSwitcher, <>device;
*boot {arg numServersIn, inBussesIn, blockSizesIn;
numServers = numServersIn; inBusses = inBussesIn;
servers = Dictionary.new(0);
//doing this to "warm up" the booting process
Server.local.waitForBoot({
Server.local.quit({
{
"now for real".postln;
numServers.do{arg i;
servers.add(("lmi"++(i+1)).asSymbol-> ModularServerObject.new("lmi"++(i+1), blockSizesIn[i]));
0.5.wait;
}
}.fork(AppClock);
})
});
}
*save {arg path, serverName;
var saveServers, temp;
saveServers = List.newClear(0);
saveServers.add(modularInputsArray.save); //save the inputs array
if(numServers>1,{
saveServers.add(serverSwitcher.save);
},{
saveServers.add(nil)
});
temp = List.newClear(0);
if(serverName==nil,{
numServers.do{arg i;
temp.add(servers[("lmi"++(i+1)).asSymbol].save)
}; //save the servers
},{
temp.add(servers[serverName.asSymbol].save)
});
saveServers.add(temp);
//saveServers = saveServers.asCompileString;
saveServers.writeArchive(path); //write the archive
}
*load {arg path, serverName;
var loadArray, numServersInFile, file;
loadArray = Object.readArchive(path);
if(serverName==nil,{
modularInputsArray.load(loadArray[0]);
numServersInFile = loadArray[2].size;
{
1.wait;
min(numServersInFile, numServers).do{arg i;
servers[("lmi"++(i+1)).asSymbol].load(loadArray[2][i]);
0.5.wait;
};
//load the serverSwitcher last so that it can update the server windows
if(loadArray[1]!=nil,{
serverSwitcher.load(loadArray[1]);
});
//Window.allWindows.do{arg item; item.front};
}.fork(AppClock);
}, {
AppClock.sched(rrand(1.0,3), {servers[serverName.asSymbol].load(loadArray[2][0])});
});
}
*addInputsArray {arg inBusses;
modularInputsArray = ModularInputsArray.new;
modularInputsArray.init2(inBusses);
}
*updateServerSwitcher {
if(serverSwitcher!=nil,{
serverSwitcher.reset;
},{
serverSwitcher = ServerSwitcher2.new();
});
}
*addServer{
var num;
num = numServers+1;
servers.add(("lmi"++num.asString).asSymbol-> ModularServerObject.new(Server.new(("lmi"++num.asString).asSymbol, NetAddr("localhost", 57111+numServers), Server.local.options)));
numServers = numServers+1;
this.updateServerSwitcher;
}
*getSoundInBusses {arg serverName;
^servers[serverName.asSymbol].inBusses.collect({arg item; item.index});
}
*getPreSynthBusses {arg serverName;
^servers[serverName.asSymbol].preSynthBusses.collect({arg item; item.index});
}
*getDirectInBus {arg serverName;
^servers[serverName.asSymbol].mixerDirectInBus.index;
}
*getObjectBusses {arg serverName;
^servers[serverName.asSymbol].objectBusses;
}
/* *getSynthGroup {arg serverName, location;
^servers[serverName.asSymbol].synthGroups[location];
}
*getMixerGroup {arg serverName;
^servers[serverName.asSymbol].mixerGroup;
}*/
}