Skip to content

Commit 69bd8f8

Browse files
committed
added merging of soundscape files
1 parent 47689ae commit 69bd8f8

File tree

4 files changed

+191
-116
lines changed

4 files changed

+191
-116
lines changed

classes/rc_config.sc

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
RcConfig {
22
var <>loadButton;
33
var <>saveButton;
4+
var <>mergeButton;
5+
46
var <>guiMgr;
57
var <>optsDir;
68
var <>s;
@@ -12,18 +14,27 @@ RcConfig {
1214

1315
init { |oDir, gu, server|
1416
optsDir = oDir;
15-
guiMgr = gu;
16-
s = server;
17+
guiMgr = gu;
18+
s = server;
1719
}
1820

1921
setupGui { |mainWindow|
20-
loadButton = Button(mainWindow, Rect(10, 10, 120, 25));
21-
loadButton.states = [["Load Scape", Color.black, Color.white]];
22-
loadButton.action = { this.loadWithDialog };
22+
var view = FlowView(mainWindow, Rect(10,10,270,29));
23+
view.background = Color.grey;
24+
25+
RcHelpers.addStaticText(view, "Scape:", 60@25);
26+
27+
loadButton = RcHelpers.buttonBW(
28+
"Load", view, 50@25, { this.loadWithDialog }
29+
);
30+
31+
saveButton = RcHelpers.buttonBW(
32+
"Save", view, 50@25, { this.saveWithDialog }
33+
);
2334

24-
saveButton = Button(mainWindow, Rect(150, 10, 120, 25));
25-
saveButton.states = [["Save Scape", Color.black, Color.white]];
26-
saveButton.action = { this.saveWithDialog };
35+
mergeButton = RcHelpers.buttonBW(
36+
"Merge", view, 50@25, { this.mergeWithDialog }
37+
);
2738
}
2839

2940
filename { |tstamp=nil|
@@ -43,14 +54,20 @@ RcConfig {
4354
}, path: this.filename);
4455
}
4556

57+
mergeWithDialog {
58+
Dialog.openPanel( { |path|
59+
guiMgr.mergeConfigFile(path, addSample);
60+
}, path: this.filename);
61+
}
62+
4663
saveWithoutDialog { |tstamp=nil|
4764
var path = this.filename(tstamp);
4865
guiMgr.saveConfigToFile(path, s.volume.volume);
4966

5067
AppClock.sched(0, {
51-
saveButton.states = [["Save Scape", Color.white, Color.green]];
68+
saveButton.states = [["Save", Color.white, Color.green]];
5269
AppClock.sched(1, {
53-
saveButton.states = [["Save Scape", Color.black, Color.white]];
70+
saveButton.states = [["Save", Color.black, Color.white]];
5471
nil
5572
});
5673
nil

classes/rc_gui.sc

Lines changed: 91 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,20 @@ RcGui {
103103
^pad;
104104
}
105105

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+
106118
padTaken { |midiControlNum|
107-
var pad = pads[midiToPadIdx[midiControlNum]];
108-
^(if ( pad.notNil, { pad.isDefined }, { false } ));
119+
^pads[midiToPadIdx[midiControlNum]].tryPerform(\isDefined);
109120
}
110121

111122
setActivePad { |pad|
@@ -123,15 +134,18 @@ RcGui {
123134

124135
releasePad { |pad|
125136
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+
128146
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; }); });
135149
if ( activePad == pad, { activePad = nil });
136150
});
137151
}
@@ -237,10 +251,33 @@ RcGui {
237251
"Saved Config to %\n".postf(path);
238252
}
239253

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); };
244281
}
245282

246283
loadConfigFromFile { |path, loadSample|
@@ -270,56 +307,56 @@ RcGui {
270307
});
271308
};
272309

273-
dataDict["allPadIds"].do { |pdid|
274-
var padData = dataDict[pdid];
310+
dataDict["allPadIds"].do { |pdid| this.loadPad_(dataDict,pdid); };
275311

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+
}
282314

283-
var initVals = padData["values"].collect { |a| a.asInteger };
284-
var synthValues = initVals ++ (0!6);
315+
loadPad_ { |dataDict,pdid|
316+
var padData = dataDict[pdid];
285317

286-
var note = nil;
318+
var synthDef = synthLookup.reject { |a|
319+
a.first != padData["synth"]
320+
}.first;
321+
var padMidiNum = this.padIdxToMidi( padData["padnum"] );
287322

288-
this.synthType = synthLookup.indexOf( synthDef );
323+
var initVals = padData["values"].collect { |a| a.asInteger };
324+
var synthValues = initVals ++ (0!6);
289325

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;
301327

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 );
306329

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+
});
309341

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 );
311346

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();
321349

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+
});
323360
}
324361

325362
updateMappingTable { |keymappings, chan|

classes/rc_helpers.sc

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
RcHelpers {
2-
32
*drpdwnSetValue { |val, drpList, callValueAction=true|
43
if ( val > 64, {
54
drpList.value = (drpList.value + 1).min(drpList.items.size-1);
@@ -9,11 +8,11 @@ RcHelpers {
98
if ( callValueAction, { drpList.valueAction_(drpList.value) });
109
}
1110

12-
*addStaticText { |view,txtStr|
13-
var txt = StaticText.new(view, 250@25);
11+
*addStaticText { |view,txtStr,loc=nil|
12+
var txt = StaticText.new(view, if ( loc.isNil, { 250@25; }, { loc }));
1413
txt.string = txtStr;
1514
txt.stringColor = Color.white;
16-
15+
^txt;
1716
}
1817

1918
*setValueIfEnabled { |linkMidi,checkbox|
@@ -23,4 +22,45 @@ RcHelpers {
2322
*toggleValueIfEnabled { |linkMidi|
2423
if ( linkMidi.enabled, { linkMidi.valueAction = linkMidi.value.not; });
2524
}
25+
26+
*buttonBW{ |txt,view,sze,action|
27+
var btn = Button(view, sze);
28+
btn.states = [[txt, Color.black, Color.white]];
29+
btn.action = action;
30+
^btn;
31+
}
32+
33+
*modalView { |txt|
34+
var vw = Window(txt,
35+
resizable: false,
36+
bounds: Rect(
37+
Window.screenBounds.width / 2,
38+
(Window.screenBounds.height-180) / 2,
39+
330, 230
40+
)
41+
).front;
42+
vw.alwaysOnTop = true;
43+
^vw;
44+
}
45+
46+
*messageView { |message|
47+
var w = RcHelpers.modalView("Message");
48+
49+
RcHelpers.addStaticText(
50+
w, message, Rect(20, 20, 300, 150)
51+
).stringColor = Color.black;
52+
53+
RcHelpers.buttonBW("Ok", w, Rect(100, 180, 120, 25), { w.close; });
54+
}
55+
56+
*confirmExit { |action|
57+
var w = RcHelpers.modalView("Really Quit?");
58+
59+
RcHelpers.addStaticText(
60+
w, "Really Quit?", Rect(130, 60, 200, 30)
61+
).stringColor = Color.black;
62+
63+
RcHelpers.buttonBW("Cancel", w, Rect(10, 180, 120, 25), { w.close; });
64+
RcHelpers.buttonBW("Yes Quit", w, Rect(200, 180, 120, 25), action );
65+
}
2666
}

0 commit comments

Comments
 (0)