diff options
author | David Runge <dave@sleepmap.de> | 2016-07-08 20:44:20 +0200 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2016-07-08 20:44:20 +0200 |
commit | 0ead8c750802a7924d8d68a8b20a3ccf93ef6979 (patch) | |
tree | e4a30c004ec2395d8719067d30ec44fe93a27c06 /classes | |
parent | 8641328aa6eba6b24391dca1d7f6516beaea8d04 (diff) | |
download | bowelyzer-0ead8c750802a7924d8d68a8b20a3ccf93ef6979.tar.gz bowelyzer-0ead8c750802a7924d8d68a8b20a3ccf93ef6979.tar.bz2 bowelyzer-0ead8c750802a7924d8d68a8b20a3ccf93ef6979.tar.xz bowelyzer-0ead8c750802a7924d8d68a8b20a3ccf93ef6979.zip |
classes/Bowelyzer.sc: Adding /free OSC listener, to be able to close channels. Moving the update functionality for LevelIndicators to BowelyzerGUI.sc. Naming OSCdefs properly using Symbols. classes/BowelyzerGUI.sc: Adding close Button for each channel. Adding free function for the OSC indicator fadeout Tasks. Naming more objects, if possible.
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Bowelyzer.sc | 68 | ||||
-rw-r--r-- | classes/BowelyzerGUI.sc | 93 |
2 files changed, 127 insertions, 34 deletions
diff --git a/classes/Bowelyzer.sc b/classes/Bowelyzer.sc index 4c4f079..2ff0e75 100644 --- a/classes/Bowelyzer.sc +++ b/classes/Bowelyzer.sc @@ -82,7 +82,7 @@ Bowelyzer{ gui.addOSCIndicatorFadeOutTask(update); }.play(AppClock); // stop the listener for LevelIndicator by name and start a new one based upon the updated name - OSCdef(\levels_++name).free; + OSCdef(("levels_"++name).asSymbol).free; this.setupLevelListener(update, hub.synthServer); // free the synth on the server and start a new one according to the config analyzer.freeAnalysisSynth(name.asSymbol); @@ -202,13 +202,54 @@ Bowelyzer{ var name = msg[0], fileName = msg[1]; postln("Received: "++msg); - config.writeConfigurationFile(fileName); //TODO: destroy current GUI elements //TODO: load channels, etc. }, path: "/load", srcID: hub.local ); + + // listen for messages to free (close) channels + OSCdef.newMatching( + key: \free, + func: {|msg, time, addr, recvPort| + 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.channelViewHeight); + }.defer; + }, + path: "/free", + srcID: NetAddr.new("127.0.0.1", NetAddr.langPort) + ); + } // add OSCdefs listening for messages coming from scsynth, to update the GUI @@ -246,32 +287,13 @@ Bowelyzer{ arg name, server; postln("Setting up LevelListener for: "++name); OSCdef.newMatching( - key: \levels_++name, + key: ("levels_"++name).asSymbol, func: {|msg, time, addr, recvPort| 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); - //postln("Receiving: "++msg); { - gui.channels.do({|channel| - if(channel.name.asSymbol == name,{ - channel.children.do({|channelChild| - if(channelChild.name.asSymbol == \meterAndControls,{ - channelChild.children.do({|meterAndControls| - if(meterAndControls.name.asSymbol == \meterView, { - meterAndControls.children.do({|meterView| - if(meterView.isKindOf(LevelIndicator), { - //postln("Setting up LevelIndicator for "++name); - meterView.value = value; - meterView.peakLevel = peak; - }); - }); - }); - }); - }); - }); - }); - }); + gui.setLevel(name, value, peak); }.defer; }, path: "/levels/"++name, diff --git a/classes/BowelyzerGUI.sc b/classes/BowelyzerGUI.sc index 675e100..ad4507c 100644 --- a/classes/BowelyzerGUI.sc +++ b/classes/BowelyzerGUI.sc @@ -8,8 +8,8 @@ BowelyzerGUI{ fadeOutSteps = 20, minWidth=1280, minHeight=720, - channelViewHeight = 700, - channelViewWidth = 300, + <channelViewHeight = 700, + <channelViewWidth = 300, channelViewSize, controlMeterContainerViewHeight = 700, controlMeterContainerViewWidth = 300, @@ -54,6 +54,12 @@ BowelyzerGUI{ mainView = PageLayout.new("Bowelyzer"); mainView.asView.background = Color.fromHexString("#DBDBDB"); layout = mainView.asView.addFlowLayout(0@0, 0@0); + mainView.onClose_({ + |view| + view.close; + }); + + //settings settingsView = View(mainView.asView, Rect(0, 0, settingsViewSize.x, settingsViewSize.y)); settingsView.asView.background = Color.fromHexString("#99EF99"); settingsView.layout = HLayout(); @@ -135,6 +141,8 @@ BowelyzerGUI{ channelContainerView.layout = HLayout(); channelContainerView.layout.spacing = 0; channelContainerView.layout.margins = [0,0,0,0]; + channelContainerView.name = \channelContainerView; + //channelContainerView.minSize_(channelViewWidth@channelViewHeight); channelContainerView.maxSize_((channelViewWidth*config.at(\inputs).size)@channelViewHeight); } @@ -143,14 +151,15 @@ BowelyzerGUI{ arg config; var channelView, headView, controlMeterContainerView, meterView, controlsView, controlsFromConfig, levelIndicator; config.at(\inputs).keysValuesDo({|name, input| - //channelView = View(mainView.asView, Rect(0, 0, mainView.bounds.width/config.at(\inputs).size, mainView.bounds.height)); channelView = View(mainView.asView, Rect(0, 0, channelViewWidth, channelViewHeight)); channelView.asView.background = Color.fromHexString("#FEEFEF"); - channelView.name = name; + channelView.name = name.asString; channelView.layout = VLayout(); channelView.layout.spacing = 0; channelView.layout.margins = [2,0,2,0]; channelView.maxSize_(300@700); + channelView.deleteOnClose_(true); + // adding name textfield of input headView = View(channelView.asView, Rect(0, 0, headViewWidth, headViewHeight)); headView.asView.background = Color.fromHexString("#DDEFDD"); @@ -164,9 +173,10 @@ BowelyzerGUI{ if(item.isKindOf(TextField),{item.align_(\right)}); }); this.setupEZNumber(headView, "input", config.at(\inputs).at(name)).children.do({|item| - item.postln; if(item.isKindOf(StaticText),{item.align_(\left)}); - item.postln; if(item.isKindOf(NumberBox),{item.align_(\right)}); + if(item.isKindOf(StaticText),{item.align_(\left)}); + if(item.isKindOf(NumberBox),{item.align_(\right)}); }); + this.setupChannelCloseButton(headView, name); controlMeterContainerView = View(channelView.asView, Rect(0, 0, controlMeterContainerViewWidth, controlMeterContainerViewHeight)); controlMeterContainerView.asView.background = Color.fromHexString("#DDDDEF"); @@ -262,8 +272,13 @@ BowelyzerGUI{ ); } + // free an OSCIndicatorFadeOutTask by name freeOSCIndicatorFadeOutTask{ - + arg name; + if(indicators.includesKey(name.asSymbol), { + indicators.at(name).stop; + indicators.removeAt(name); + }); } setupLevelIndicator{ @@ -271,7 +286,6 @@ BowelyzerGUI{ ^LevelIndicator( parent ).maxSize_(buttonWidth@600) - .style_(\led) .drawsPeak_(true); } @@ -366,6 +380,25 @@ BowelyzerGUI{ ; } + // setup a button to free (close) a channel + setupChannelCloseButton{ + arg parent, name; + ^Button(parent, Rect(0, 0, buttonHeight, buttonHeight)) + .states_([ + ["X", Color.black, Color.fromHexString("#FF9999")] + ]) + .action_({ + arg controlUnit; + var address = NetAddr.new("127.0.0.1", NetAddr.langPort), + type = "/free"; + postln("Sending: ["++type++", "++name++"]"); + address.sendMsg(type, name); + }) + .maxSize_(buttonHeight@buttonHeight) + .name_("close") + ; + } + // setup a StaticText and a TextField setupEZText{ arg parent, control, value; @@ -378,6 +411,10 @@ BowelyzerGUI{ labelWidth = 60; textWidth = 80; }); + if(control == "name", { + bounds = 140@buttonHeight; + textWidth = 84; + }); ^EZText( parent: parent, bounds: bounds, @@ -406,6 +443,7 @@ BowelyzerGUI{ margin: nil ) .view.maxHeight_(buttonHeight) + .asView.name_(control) ; } @@ -421,6 +459,11 @@ BowelyzerGUI{ labelWidth = 70; numberWidth = 70; }); + if(control == "input", { + bounds = 124@buttonHeight; + labelWidth = 48; + numberWidth = 76; + }); ^EZNumber( parent: parent, bounds: bounds, @@ -450,6 +493,7 @@ BowelyzerGUI{ margin: nil ) .view.maxHeight_(buttonHeight) + .asView.name_(control) ; } @@ -473,7 +517,8 @@ BowelyzerGUI{ numberWidth: 70, layout: \line2, margin: nil - ); + ) + ; } setupEZRanger{ @@ -494,7 +539,8 @@ BowelyzerGUI{ }, labelWidth: 120, unitWidth:30 - ); + ) + ; } setupEZKnob{ @@ -515,7 +561,32 @@ BowelyzerGUI{ }, labelWidth: 120, unitWidth:30 - ); + ) + ; } + + // set LevelIndicator values for given channel + setLevel{ + arg name, level, peak; + channels.do({|channel| + if(channel.name.asSymbol == name,{ + channel.children.do({|channelChild| + if(channelChild.name.asSymbol == \meterAndControls,{ + channelChild.children.do({|meterAndControls| + if(meterAndControls.name.asSymbol == \meterView, { + meterAndControls.children.do({|meterView| + if(meterView.isKindOf(LevelIndicator), { + meterView.value = level; + meterView.peakLevel = peak; + }); + }); + }); + }); + }); + }); + }); + }); + } + } |