@@ -103,9 +103,20 @@ RcGui {
103
103
^pad;
104
104
}
105
105
106
+ freePads {
107
+ ^pads.reject { |a| a.tryPerform(\isDefined ) };
108
+ }
109
+
110
+ countFreePads {
111
+ ^this .freePads.size;
112
+ }
113
+
114
+ padIdxToMidi { |idx|
115
+ ^midiToPadIdx.findKeyForValue( idx.asInteger );
116
+ }
117
+
106
118
padTaken { |midiControlNum|
107
- var pad = pads[midiToPadIdx[midiControlNum]];
108
- ^(if ( pad.notNil, { pad.isDefined }, { false } ));
119
+ ^pads[midiToPadIdx[midiControlNum]].tryPerform(\isDefined );
109
120
}
110
121
111
122
setActivePad { |pad|
@@ -123,15 +134,18 @@ RcGui {
123
134
124
135
releasePad { |pad|
125
136
if ( pad.notNil, {
126
- pad.synth.set(\fadeTime , 2 );
127
- pad.synth.release;
137
+ var buf = pad.buffer;
138
+ var synth = pad.synth;
139
+
140
+ pad.buffer = nil ;
141
+ pad.synth = nil ;
142
+
143
+ synth.set(\fadeTime , 2 );
144
+ synth.release;
145
+
128
146
pad.reset;
129
- if ( pad.buffer.notNil, {
130
- AppClock .sched(2.3 , {
131
- pad.buffer.free;
132
- pad.buffer = nil ;
133
- });
134
- });
147
+
148
+ if ( buf.notNil, { AppClock .sched(2.3 , { buf.free; nil ; }); });
135
149
if ( activePad == pad, { activePad = nil });
136
150
});
137
151
}
@@ -237,10 +251,33 @@ RcGui {
237
251
"Saved Config to %\n " .postf(path);
238
252
}
239
253
240
- padIdxToMidi { |idx|
241
- ^midiToPadIdx.findKeyForValue(
242
- idx.asInteger
243
- );
254
+ mergeConfigFile { |path, loadSample|
255
+ var dataDict = path.parseYAMLFile;
256
+ var emptyPads = this .freePads;
257
+
258
+ if ( dataDict["allPadIds" ].size > this .countFreePads, {
259
+ RcHelpers .messageView(
260
+ format("Not enough samples free to accomodate new scape " ++
261
+ " file. You need to free % samples before merging." ,
262
+ dataDict["allPadIds" ].size - this .countFreePads)
263
+ );
264
+ ^nil ;
265
+ });
266
+
267
+ format( "Merging config: %" , path ).postln;
268
+
269
+ playingNotes.reject { |n| n.isNil }.do { |n|
270
+ if ( n.synth.notNil, { n.hideAndRelease; })
271
+ };
272
+
273
+ dataDict["allPadIds" ].do { |pdid,idx|
274
+ if ( dataDict[pdid]["filename" ].notNil, {
275
+ loadSample.value( dataDict[pdid]["filename" ] );
276
+ });
277
+ dataDict[pdid]["padnum" ] = pads.indexOf(emptyPads[idx]);
278
+ };
279
+
280
+ dataDict["allPadIds" ].do { |pdid| this .loadPad_(dataDict,pdid); };
244
281
}
245
282
246
283
loadConfigFromFile { |path, loadSample|
@@ -270,56 +307,56 @@ RcGui {
270
307
});
271
308
};
272
309
273
- dataDict["allPadIds" ].do { |pdid|
274
- var padData = dataDict[pdid];
310
+ dataDict["allPadIds" ].do { |pdid| this .loadPad_(dataDict,pdid); };
275
311
276
- var synthDef = synthLookup.reject { |a|
277
- a.first != padData["synth" ]
278
- }.first;
279
- var padMidiNum = midiToPadIdx.findKeyForValue(
280
- padData["padnum" ].asInteger
281
- );
312
+ ^dataDict["serverVolume" ].asFloat;
313
+ }
282
314
283
- var initVals = padData[ "values" ].collect { |a| a.asInteger };
284
- var synthValues = initVals ++ ( 0 ! 6 ) ;
315
+ loadPad_ { |dataDict,pdid|
316
+ var padData = dataDict[pdid] ;
285
317
286
- var note = nil ;
318
+ var synthDef = synthLookup.reject { |a|
319
+ a.first != padData["synth" ]
320
+ }.first;
321
+ var padMidiNum = this .padIdxToMidi( padData["padnum" ] );
287
322
288
- this .synthType = synthLookup.indexOf( synthDef );
323
+ var initVals = padData["values" ].collect { |a| a.asInteger };
324
+ var synthValues = initVals ++ (0 !6 );
289
325
290
- if ( padData["filename" ].isNil, {
291
- note = synthDef[2 ].value(padData["note" ].asInteger,
292
- initVals[0 ],initVals);
293
- synthValues[12 ] = inf ;
294
- }, {
295
- var sampleIdx = allSamples.collect { |a|
296
- a.filename
297
- }.indexOfEqual( padData["filename" ] );
298
- synthValues[12 ] = sampleIdx;
299
- note = synthDef[2 ].value( sampleIdx, initVals[0 ],initVals);
300
- });
326
+ var note = nil ;
301
327
302
- // give the gui and the app one secound to clean up all the
303
- // pendulums that got stopped at the beginning of this method.
304
- AppClock .sched(0.7 + 0.3 .rand, {
305
- var pad = this .setupPad( padMidiNum, synthValues, note );
328
+ this .synthType = synthLookup.indexOf( synthDef );
306
329
307
- note.synth.set(\padNr , padMidiNum);
308
- note.hide();
330
+ if ( padData["filename" ].isNil, {
331
+ note = synthDef[2 ].value(padData["note" ].asInteger,
332
+ initVals[0 ],initVals);
333
+ synthValues[12 ] = inf ;
334
+ }, {
335
+ var sampleIdx = allSamples.collect { |a|
336
+ a.filename
337
+ }.indexOfEqual( padData["filename" ] );
338
+ synthValues[12 ] = sampleIdx;
339
+ note = synthDef[2 ].value( sampleIdx, initVals[0 ],initVals);
340
+ });
309
341
310
- try { this .padCtrl.padOn( padData["padnum" ].asInteger ) } {};
342
+ // give the gui and the app one secound to clean up all the
343
+ // pendulums that got stopped at the beginning of this method.
344
+ AppClock .sched(0.7 + 0.3 .rand, {
345
+ var pad = this .setupPad( padMidiNum, synthValues, note );
311
346
312
- padData["pendulums" ].do { |pendId|
313
- var pend = RcPendulumBase .newWithPad(dataDict[pendId],pad);
314
- if ( pend.notNil, {
315
- pad.pushPendulum(pend.startFromYamlLoad);
316
- });
317
- };
318
- nil
319
- });
320
- };
347
+ note.synth.set(\padNr , padMidiNum);
348
+ note.hide();
321
349
322
- ^dataDict["serverVolume" ].asFloat;
350
+ try { this .padCtrl.padOn( padData["padnum" ].asInteger ) } {};
351
+
352
+ padData["pendulums" ].do { |pendId|
353
+ var pend = RcPendulumBase .newWithPad(dataDict[pendId],pad);
354
+ if ( pend.notNil, {
355
+ pad.pushPendulum(pend.startFromYamlLoad);
356
+ });
357
+ };
358
+ nil
359
+ });
323
360
}
324
361
325
362
updateMappingTable { |keymappings, chan|
0 commit comments