Permalink
Browse files

simplify initializing keyboard

CVCenter:*finishGui, CVWidgetSpecsEditor:*new, Synth:-cvcGui,
NodeProxy:-cvcGui, Patch:-cvcGui take a completion function now which
allows us to execute CVCenterKeyboard:-addWidgetActionsForKeyboard
automatically.

Signed-off-by: Stefan Nussbaumer <st9fan@gmail.com>
  • Loading branch information...
nuss committed Aug 2, 2018
1 parent 868d757 commit 3971a1c4d1c644b47acea0e893a831188c333c98
Showing with 44 additions and 20 deletions.
  1. +26 −11 CVCenter/CVCenterKeyboard.sc
  2. +4 −3 CVCenter/CVWidgetSpecsEditor.sc
  3. +14 −6 CVCenter/extObject.sc
@@ -1,10 +1,10 @@
CVCenterKeyboard {
classvar <all;
var <synthDefName, <keyboardArg = \freq, <ampArg = \amp, <bendArg;
var <synthDefName, <keyboardArg = \freq, <velocArg = \veloc, <bendArg = \bend;
var on, off, bend;
*new { |synthDefName, keyboardArg, ampArg, bendArg|
^super.newCopyArgs(synthDefName, keyboardArg, ampArg, bendArg).init;
*new { |synthDefName|
^super.newCopyArgs(synthDefName).init;
}
init {
@@ -30,12 +30,23 @@ CVCenterKeyboard {
// keyboardArg is the arg that will be set through playing the keyboard
// bendArg will be the arg that's set through the pitch bend wheel
setUpControls { |widgetsPrefix, tab, server|
setUpControls { |keyboardControl, velocControl, bendControl, widgetsPrefix, tab, server|
var testSynth, notesEnv;
var args = [];
server ?? { server = Server.default };
keyboardControl !? { keyboardArg = keyboardControl };
velocControl !? { velocArg = velocControl };
bendControl !? { bendArg = bendControl };
// in case you're re-initializing
CVCenter.scv[synthDefName] !? {
"re-initializing!".postln;
this.free;
CVCenter.scv.put(synthDefName, Array.newClear(128));
};
/*if (server.serverRunning.not) {
Error("The server '%' must be running before calling CVCenter:*midiKeyboardGated").throw;
};*/
@@ -55,20 +66,22 @@ CVCenterKeyboard {
).throw;
};
args = SynthDescLib.at(synthDefName).controlDict.keys.asArray.takeThese({ |it|
it === keyboardArg or: {it === ampArg or: { it === bendArg or: { it === \gate }}}
});
/*args = SynthDescLib.at(synthDefName).controlDict.keys.asArray.takeThese({ |it|
it === keyboardArg or: { it === velocArg or: { it === bendArg or: { it === \gate }}}
});*/
server.waitForBoot {
// SynthDef *should* have an \amp arg, otherwise it will sound for moment
testSynth = Synth(synthDefName);
// \gate will be set internally
testSynth.cvcGui(prefix: widgetsPrefix, excemptArgs: [keyboardArg, \gate], tab: tab);
testSynth.cvcGui(prefix: widgetsPrefix, excemptArgs: [keyboardArg, velocArg, \gate], tab: tab, completionFunc: {
this.addWidgetActionsForKeyboard(widgetsPrefix, true);
});
testSynth.release;
}
}
addWidgetActionsForKeyboard { |notesEnvironment, widgetsPrefix, deactivateDefaultActions = true|
addWidgetActionsForKeyboard { |widgetsPrefix, deactivateDefaultActions = true|
var args = SynthDescLib.at(synthDefName).controlDict.keys.asArray;
var wdgtName, nameString, namesCVs = [];
@@ -102,16 +115,18 @@ CVCenterKeyboard {
};
on = MIDIFunc.noteOn({ |veloc, num, chan, src|
var argsValues = [keyboardArg, num.midicps, ampArg, veloc * 0.005] ++ namesCVs.deepCollect(2, _.value);
var argsValues = [keyboardArg, num.midicps, velocArg, veloc * 0.005] ++ namesCVs.deepCollect(2, _.value);
// "on".postln;
CVCenter.scv[synthDefName][num] = Synth(synthDefName, argsValues);
});
off = MIDIFunc.noteOff({ |veloc, num, chan, src|
// "off".postln;
CVCenter.scv[synthDefName][num].release;
});
bend = MIDIFunc.bend({ |bendVal, chan, src|
"bend: %\n".postf(bendVal);
// "bend: %\n".postf(bendVal);
});
}
@@ -18,11 +18,11 @@
CVWidgetSpecsEditor {
var <window;
*new { |displayDialog, object, wdgtName, controlsDict, prefix, pairs2D, metadata, environment, tab|
^super.new.init(displayDialog, object, wdgtName, controlsDict, prefix, pairs2D, metadata, environment, tab)
*new { |displayDialog, object, wdgtName, controlsDict, prefix, pairs2D, metadata, environment, tab, completionFunc|
^super.new.init(displayDialog, object, wdgtName, controlsDict, prefix, pairs2D, metadata, environment, tab, completionFunc)
}
init { |displayDialog, obj, name, controls, prefix, pairs2D, metadata, environment, tab|
init { |displayDialog, obj, name, controls, prefix, pairs2D, metadata, environment, tab, completionFunc|
var object;
var wdgtName, windowTitle;
var specsList, specsListSpecs, selectMatch, thisSpec;
@@ -364,6 +364,7 @@ CVWidgetSpecsEditor {
CVCenter.finishGui(obj, el, environment, vals);
});
window.close;
completionFunc.value;
})
;
View
@@ -98,7 +98,7 @@
+Synth {
cvcGui { |displayDialog=true, prefix, pairs2D, environment, excemptArgs, tab|
cvcGui { |displayDialog=true, prefix, pairs2D, environment, excemptArgs, tab, completionFunc|
var sDef, def, cDict = (), metadata;
var thisType, thisControls, thisSpec, thisSlots, thisName, done=[];
sDef = SynthDescLib.global[this.defName.asSymbol];
@@ -113,7 +113,10 @@
}
});
if(displayDialog, {
CVWidgetSpecsEditor(displayDialog, this, this.defName.asSymbol, cDict, prefix, pairs2D, metadata, environment, tab: tab);
CVWidgetSpecsEditor(
displayDialog, this, this.defName.asSymbol, cDict, prefix, pairs2D, metadata,
environment, tab: tab, completionFunc: if (displayDialog) { completionFunc }
)
}, {
cDict.pairsDo({ |cName, vals|
block { |break|
@@ -175,7 +178,8 @@
enterTab: if (tab.notNil) { tab.asSymbol } { this.defName.asSymbol },
controls: thisControls,
slots: thisSlots,
specSelect: thisSpec
specSelect: thisSpec,
completionFunc: if (displayDialog.not) { completionFunc }
))
})
})
@@ -185,7 +189,7 @@
+NodeProxy {
cvcGui { |displayDialog=true, prefix, pairs2D, excemptArgs, tab|
cvcGui { |displayDialog=true, prefix, pairs2D, excemptArgs, tab, completionFunc|
var cDict = (), name;
var thisType, thisControls, thisSpec, thisSlots, thisName, done=[];
this.getKeysValues.do({ |pair|
@@ -203,7 +207,10 @@
name = nil;
});
if(displayDialog, {
CVWidgetSpecsEditor(displayDialog, this, name, cDict, prefix, pairs2D, tab: tab);
CVWidgetSpecsEditor(
displayDialog, this, name, cDict, prefix, pairs2D,
tab: tab, completionFunc: if (displayDialog) { completionFunc }
)
}, {
cDict.pairsDo({ |cName, vals|
block { |break|
@@ -249,7 +256,8 @@
enterTab: if (tab.notNil) { tab.asSymbol } { name },
controls: thisControls,
slots: thisSlots,
specSelect: thisSpec
specSelect: thisSpec,
completionFunc: if (displayDialog.not) { completionFunc }
))
})
})

0 comments on commit 3971a1c

Please sign in to comment.