From 0f883cd9df74327a904da5a98ca35d4e7b82a90d Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 22 Jun 2016 02:07:01 +0200 Subject: Bowelyzer.sc: Adding functionality to listen for OSC messages sent by GUI elements. BowelyzerGUI.sc: Adding first version of class for GUI of bowelyzer. --- Bowelyzer.sc | 92 ++++++++++++++- BowelyzerGUI.sc | 353 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 444 insertions(+), 1 deletion(-) create mode 100644 BowelyzerGUI.sc diff --git a/Bowelyzer.sc b/Bowelyzer.sc index 3d01b1a..3071588 100644 --- a/Bowelyzer.sc +++ b/Bowelyzer.sc @@ -22,10 +22,100 @@ Bowelyzer{ server.waitForBoot({ hub = BowelyzerOSCHub.new(config.config); analyzer = BowelyzerAnalyzer.new(config.config); - //gui = BowelyzerGUI.new(config.config); + gui = BowelyzerGUI.new(config.config); + this.addGUIListeners; }, 5, {"scsynth failed to start!".postln}); } + addGUIListeners{ + OSCdef.newMatching( + key: \controls, + func: {|msg, time, addr, recvPort| + postln("Received: "++msg); + // if the control exists, change it + if(msg[1].notNil && msg[2].notNil && msg[3].notNil,{ + if(config.config.at(\controls).includesKey(msg[1]),{ + if(config.config.at(\controls).at(msg[1]).includesKey(msg[2]),{ + config.config.at(\controls).at(msg[1]).put(msg[2], config.getControlValue(msg[2], msg[3])); + }); + }); + }); + }, + path: "/controls", + srcID: NetAddr.new("127.0.0.1", NetAddr.langPort) + ); + OSCdef.newMatching( + key: \inputs, + func: {|msg, time, addr, recvPort| + postln("Received: "++msg); + if(msg[1].notNil && msg[2].notNil && msg[3].notNil,{ + if(config.config.at(\inputs).includesKey(msg[1]) && config.config.at(\controls).includesKey(msg[1]),{ + switch(msg[2], + \name,{ + //if the name exists and the new name is not empty, change it + if(msg[3]!= "",{ + //move the controls + config.config.at(\controls).put(msg[3].asSymbol, config.config.at(\controls).at(msg[1])); + config.config.at(\controls).removeAt(msg[1].asSymbol); + // rename the input + config.config.at(\inputs).put(msg[3].asSymbol, config.config.at(\inputs).at(msg[1])); + config.config.at(\inputs).removeAt(msg[1]); + // rename the GUI element in channelView + Routine{ + gui.channels.keysValuesDo({|name, channelView| + postln(name++"->"++channelView.name); + if(channelView.name.asSymbol == msg[1].asSymbol, { + channelView.name = msg[3].asSymbol; + }); + }); + //TODO: rename the LevelListener + }.play(AppClock); + // free the synth on the server and start a new one according to the config + analyzer.freeAnalysisSynth(msg[1].asSymbol); + analyzer.addSynthWithName(msg[3]); + Routine{ + 1.wait; + analyzer.startSynthWithNameAndControls(msg[3].asSymbol, config.config.at(\controls).at(msg[3]), config.config.at(\inputs).at(msg[3])); + }.play; + hub.freeSynthListener(msg[1]); + hub.addSynthListener(msg[3]); + hub.startSynthListener(msg[3]); + }); + }, + \input,{ + // if the input name exists and the new is an Integer and greater/equal 0 + if(((msg[3].isInteger) && (msg[3].asInteger >= 0)),{ + // change the input in configuration + config.config.at(\inputs).put(msg[1], msg[3].asInteger); + analyzer.setSynthControl(msg[1].asSymbol, \inputChannel, msg[3].asInteger); + }); + } + ); + }); + }); + }, + path: "/inputs", + srcID: NetAddr.new("127.0.0.1", NetAddr.langPort) + ); + OSCdef.newMatching( + key: \toggle, + func: {|msg, time, addr, recvPort| + postln("Received: "++msg); + if(msg[1].notNil && msg[2].notNil && msg[3].notNil,{ + if(config.config.at(\inputs).includesKey(msg[1]),{ + switch(msg[3], + 0,{analyzer.startAnalysisSynth(msg[1])}, + 1,{analyzer.stopAnalysisSynth(msg[1])} + ); + }); + }); + }, + path: "/toggle", + srcID: NetAddr.new("127.0.0.1", NetAddr.langPort) + ); + } + //TODO: add SimpleController + //TODO: delegate changes to BowelyzerConfig.config and update analyzer and GUI with it } diff --git a/BowelyzerGUI.sc b/BowelyzerGUI.sc new file mode 100644 index 0000000..f50ac63 --- /dev/null +++ b/BowelyzerGUI.sc @@ -0,0 +1,353 @@ +BowelyzerGUI{ + + var mainView, + channelContainerView, +