From f1b95d253283fe451d525d9386e60880f38a2160 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 10 Jul 2016 20:10:46 +0200 Subject: classes/Bowelyzer.sc: Refactoring all GUI functions, formerly using defer to BowelyzerGUI, where they are all deferred to AppClock. classes/BowelyzerGUI.sc: Adding helper functions to properly defer all needed functionality to AppClock. Renaming setChannelName to setChannelText. The function setChannelName now renames the channelView, whereas setChannelText renames the TextField of a channel. --- classes/Bowelyzer.sc | 70 +++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 55 deletions(-) (limited to 'classes/Bowelyzer.sc') diff --git a/classes/Bowelyzer.sc b/classes/Bowelyzer.sc index a877a89..e1fba76 100644 --- a/classes/Bowelyzer.sc +++ b/classes/Bowelyzer.sc @@ -70,19 +70,12 @@ Bowelyzer{ // rename the input config.config.at(\inputs).put(update.asSymbol, config.config.at(\inputs).at(name)); config.config.at(\inputs).removeAt(name); - //TODO: refactor into gui function - Routine{ - // rename the channel View - gui.channels.do({|channel| - if(channel.name.asSymbol == name.asSymbol, { - channel.name = update.asSymbol; - }); - }); - // OSC indicator: stop old task, remove it and create a new one with updated name - gui.indicators.at(name).stop; - gui.indicators.removeAt(name); - gui.addOSCIndicatorFadeOutTask(update); - }.play(AppClock); + // rename the channelView + gui.setChannelName(name, update); + // free the old OSC indicator fadeout Task + gui.freeOSCIndicatorFadeOutTask(name); + // add a new OSC indicator fadeout Task using the new name + gui.addOSCIndicatorFadeOutTask(update); // stop the listener for LevelIndicator by name and start a new one based upon the updated name OSCdef(("levels_"++name).asSymbol).free; this.setupLevelListener(update, hub.synthServer); @@ -104,7 +97,7 @@ Bowelyzer{ hub.startSynthListener(update); },{ ("New name not valid: "++update).error; - gui.setChannelName(name, name); + gui.setChannelText(name, name); }); }, \input,{ @@ -186,9 +179,7 @@ Bowelyzer{ var path = msg[1]; postln("Received: "++msg); if(config.configFilePath.isNil || config.configFilePath == "",{ - { - gui.saveAsAction(nil); - }.defer; + gui.saveAsAction(nil); },{ config.writeConfigurationFile; }); @@ -227,24 +218,15 @@ Bowelyzer{ 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); + gui.setupChannelView(name, config.config); // 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); + gui.removeAddressesAndPorts; + gui.setupAddressesAndPorts(config.config); },{ ("Configuration could not be read: "++fileName).error; }); @@ -296,13 +278,8 @@ Bowelyzer{ key: \indicate, func: {|msg, time, addr, recvPort| var name = msg[1]; -// postln("Indicate for "++name); if(config.config.at(\inputs).includesKey(name),{ - if(gui.indicators.includesKey(name),{ - gui.indicators.at(name).stop; - gui.indicators.at(name).reset; - gui.indicators.at(name).start(AppClock); - }); + gui.pingOSCIndicator(name); }); }, path: "/indicate", @@ -320,9 +297,7 @@ Bowelyzer{ var name = msg[0].asString.replace("/levels/", "").asSymbol, value = msg[3].ampdb.linlin(-40, 0, 0, 1), peak = msg[4].ampdb.linlin(-40, 0, 0, 1); - { - gui.setLevel(name, value, peak); - }.defer; + gui.setLevel(name, value, peak); }, path: "/levels/"++name, srcID: server @@ -340,13 +315,7 @@ Bowelyzer{ 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); + gui.setupChannelView(name, config.config); // add and start a new Synth by the given name Routine{ analyzer.addSynthWithName(name); @@ -382,16 +351,7 @@ Bowelyzer{ // 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; + gui.removeChannelView(name, config.config.at(\inputs).size); } } -- cgit v1.2.3-70-g09d2