aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2016-07-09 18:09:48 +0200
committerDavid Runge <dave@sleepmap.de>2016-07-09 18:09:48 +0200
commitc590deb4aca8205c7090b3f38ca2c011e3bb674f (patch)
treec1cd62eea97249d643bce53a67f9c9fcc4734b30
parent59595414c7cb126f12fcdccb0d99300cfba49b2f (diff)
downloadbowelyzer-c590deb4aca8205c7090b3f38ca2c011e3bb674f.tar.gz
bowelyzer-c590deb4aca8205c7090b3f38ca2c011e3bb674f.tar.bz2
bowelyzer-c590deb4aca8205c7090b3f38ca2c011e3bb674f.tar.xz
bowelyzer-c590deb4aca8205c7090b3f38ca2c011e3bb674f.zip
classes/Bowelyzer.sc: Refactoring functionality from /free and /add OSCdefs into separate functions. Adding functionality to load a new setup.0.7
-rw-r--r--classes/Bowelyzer.sc153
1 files changed, 102 insertions, 51 deletions
diff --git a/classes/Bowelyzer.sc b/classes/Bowelyzer.sc
index ba5eeb8..6c0d963 100644
--- a/classes/Bowelyzer.sc
+++ b/classes/Bowelyzer.sc
@@ -30,6 +30,7 @@ Bowelyzer{
{"scsynth failed to start!".postln});
}
+ // add OSCdefs listening for GUI events
addGUIListeners{
// listen for control changes
OSCdef.newMatching(
@@ -48,6 +49,7 @@ Bowelyzer{
path: "/controls",
srcID: NetAddr.new("127.0.0.1", NetAddr.langPort)
);
+
// listen for input changes (rename and input channel)
OSCdef.newMatching(
key: \inputs,
@@ -112,6 +114,7 @@ Bowelyzer{
path: "/inputs",
srcID: NetAddr.new("127.0.0.1", NetAddr.langPort)
);
+
// listen for toggling messages to "mute" channel
OSCdef.newMatching(
key: \toggle,
@@ -202,8 +205,37 @@ Bowelyzer{
var name = msg[0],
fileName = msg[1];
postln("Received: "++msg);
- //TODO: destroy current GUI elements
- //TODO: load channels, etc.
+ // free all channels
+ config.config.at(\inputs).keysDo({ |name|
+ this.freeChannel(name);
+ });
+ // read the configuration file
+ if(config.readConfigurationFile(fileName),{
+ hub.setupNetAddressesFromConfig(config.config);
+ hub.setupSynthListenersFromConfig(config.config);
+ analyzer.setupSynthsFromConfig(config.config);
+ config.config.at(\inputs).keysDo({ |name|
+ Routine{
+ // resize the container View
+ gui.channelContainerView.maxSize_(((gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth)@gui.channelViewHeight);
+ gui.channelContainerView.asView.bounds_(Rect(0, 0, (gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth, gui.channelViewHeight));
+ // add a new channel View for the controls
+ gui.setupChannelView(name, config.config);
+ }.play(AppClock);
+ // setup a LevelListener for the new Synth
+ this.setupLevelListener(name, hub.synthServer);
+ // setup a OSC listener for the Synth by name
+ hub.addSynthListener(name);
+ });
+ // reload the addresses and ports Views
+ Routine{
+ gui.removeAddressesAndPorts;
+ 0.5.wait;
+ gui.setupAddressesAndPorts(gui.settingsView, config.config);
+ }.play(AppClock);
+ },{
+ ("Configuration could not be read: "++fileName).error;
+ });
},
path: "/load",
srcID: hub.local
@@ -216,35 +248,7 @@ Bowelyzer{
var type = msg[0],
name = msg[1];
postln("Received: "++msg);
- // remove OSCdefs for the channel
- OSCdef.all.pairsDo({|key, value|
- if(key == name.asSymbol,{
- ("Freeing OSCdef: "++name).postln;
- value.free;
- });
- if(key == ("levels_"++name).asSymbol,{
- ("Freeing OSCdef: levels_"++name).postln;
- value.free;
- });
- });
- // free Synth
- analyzer.freeAnalysisSynth(name);
- // remove configurations for the channel
- config.config.at(\inputs).removeAt(name);
- config.config.at(\controls).removeAt(name);
- // remove fadeout task for OSC indicator
- gui.freeOSCIndicatorFadeOutTask(name);
- // remove GUI elements
- {
- gui.channels.do({|channel,i|
- if(channel.name == name.asString, {
- channel.remove;
- gui.channels.remove(channel);
- });
- });
- // resize the channelContainerView according to new amount of channels
- gui.channelContainerView.maxSize_(((gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth)@gui.channelViewHeight);
- }.defer;
+ this.freeChannel(name);
},
path: "/free",
srcID: NetAddr.new("127.0.0.1", NetAddr.langPort)
@@ -257,26 +261,7 @@ Bowelyzer{
var type = msg[0],
name;
postln("Received: "++msg);
- // add a new input to the config
- name = config.addInput;
- // initialize a new channelView with the name and controls
- Routine{
- // resize the container View
- gui.channelContainerView.maxSize_(((gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth)@gui.channelViewHeight);
- gui.channelContainerView.asView.bounds_(Rect(0, 0, (gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth, gui.channelViewHeight));
- // add a new channel View for the controls
- gui.setupChannelView(name, config.config);
- }.play(AppClock);
- // add and start a new Synth by the given name
- Routine{
- analyzer.addSynthWithName(name);
- 1.wait;
- analyzer.startSynthWithNameAndControls(name, config.config.at(\controls).at(name), config.config.at(\inputs).at(name));
- }.play;
- // setup a LevelListener for the new Synth
- this.setupLevelListener(name, hub.synthServer);
- // setup a OSC listener for the Synth by name
- hub.addSynthListener(name);
+ this.addChannel;
},
path: "/add",
srcID: NetAddr.new("127.0.0.1", NetAddr.langPort)
@@ -331,4 +316,70 @@ Bowelyzer{
srcID: server
);
}
+
+ // add a new channel by name
+ addChannel{
+ arg extName;
+ // add a new input to the config
+ var name;
+ if(extName.isNil,{
+ name = config.addInput;
+ },{
+ name = config.addInput(extName);
+ });
+ // initialize a new channelView with the name and controls
+ Routine{
+ // resize the container View
+ gui.channelContainerView.maxSize_(((gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth)@gui.channelViewHeight);
+ gui.channelContainerView.asView.bounds_(Rect(0, 0, (gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth, gui.channelViewHeight));
+ // add a new channel View for the controls
+ gui.setupChannelView(name, config.config);
+ }.play(AppClock);
+ // add and start a new Synth by the given name
+ Routine{
+ analyzer.addSynthWithName(name);
+ 1.wait;
+ analyzer.startSynthWithNameAndControls(name, config.config.at(\controls).at(name), config.config.at(\inputs).at(name));
+ }.play;
+ // setup a LevelListener for the new Synth
+ this.setupLevelListener(name, hub.synthServer);
+ // setup a OSC listener for the Synth by name
+ hub.addSynthListener(name);
+ }
+
+ // free (remove) a channel
+ freeChannel{
+ arg name;
+ ("Removing channel: "++name).postln;
+ // remove OSCdefs for the channel
+ OSCdef.all.pairsDo({|key, value|
+ if(key == name.asSymbol,{
+ ("Freeing OSCdef: "++name).postln;
+ value.free;
+ });
+ if(key == ("levels_"++name).asSymbol,{
+ ("Freeing OSCdef: levels_"++name).postln;
+ value.free;
+ });
+ });
+ // free Synth
+ analyzer.freeAnalysisSynth(name);
+ // remove configurations for the channel
+ config.config.at(\inputs).removeAt(name);
+ config.config.at(\controls).removeAt(name);
+ // remove fadeout task for OSC indicator
+ gui.freeOSCIndicatorFadeOutTask(name);
+ // remove GUI elements
+ {
+ gui.channels.do({|channel,i|
+ if(channel.name == name.asString, {
+ channel.remove;
+ gui.channels.remove(channel);
+ });
+ });
+ // resize the channelContainerView according to new amount of channels
+ gui.channelContainerView.maxSize_(((gui.channelViewWidth*config.config.at(\inputs).size)+gui.buttonWidth)@gui.channelViewHeight);
+ }.defer;
+ }
+
}