From ba885b3716e6180d3ac1d81049f0a2ebccd042fa Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 10 Jul 2016 17:02:54 +0200 Subject: classes/BowelyzerGUI.sc: Implementing channel selector as EZPopUpMenu. Providing complete BowelyzerConfig instance on BowelyzerGUI init, to also get access to configFilePath for display. Refactoring action of 'save as' Button into separate function for easier access, when no configuration file is setup yet. classes/Bowelyzer.sc: Initializing BowelyzerGUI with complete BowelyzerConfig instance. Calling 'save as' if there is no configuration file setup yet. --- classes/Bowelyzer.sc | 10 +++- classes/BowelyzerGUI.sc | 132 +++++++++++++++++++++++++++++++----------------- 2 files changed, 93 insertions(+), 49 deletions(-) (limited to 'classes') diff --git a/classes/Bowelyzer.sc b/classes/Bowelyzer.sc index db6913d..3a61618 100644 --- a/classes/Bowelyzer.sc +++ b/classes/Bowelyzer.sc @@ -22,7 +22,7 @@ Bowelyzer{ server.waitForBoot({ hub = BowelyzerOSCHub.new(config.config); analyzer = BowelyzerAnalyzer.new(config.config); - gui = BowelyzerGUI.new(config.config); + gui = BowelyzerGUI.new(config); this.addGUIListeners; this.addServerListeners; }, @@ -179,7 +179,13 @@ Bowelyzer{ func: {|msg, time, addr, recvPort| var path = msg[1]; postln("Received: "++msg); - config.writeConfigurationFile; + if(config.configFilePath.isNil || config.configFilePath == "",{ + { + gui.saveAsAction(nil); + }.defer; + },{ + config.writeConfigurationFile; + }); }, path: "/save", srcID: hub.local diff --git a/classes/BowelyzerGUI.sc b/classes/BowelyzerGUI.sc index 02a621a..457abf7 100644 --- a/classes/BowelyzerGUI.sc +++ b/classes/BowelyzerGUI.sc @@ -21,7 +21,7 @@ BowelyzerGUI{ configViewSize, meterViewWidth = 54, meterViewHeight = 700, - headViewHeight = 24, + headViewHeight = 30, headViewWidth = 300, controlsViewWidth = 246, controlsViewHeight = 700 @@ -29,7 +29,7 @@ BowelyzerGUI{ *new{ arg config; - ^super.new.init(config) + ^super.new.init(config); } init{ @@ -40,16 +40,16 @@ BowelyzerGUI{ configViewSize = 64@64; controlMeterContainerViewSize = controlMeterContainerViewWidth@controlMeterContainerViewHeight; channelViewSize = channelViewWidth@channelViewHeight; - channels = Set.new(config.at(\inputs).size); - indicators = Dictionary.new(config.at(\inputs).size); - this.setupMainView(config); + channels = Set.new(config.config.at(\inputs).size); + indicators = Dictionary.new(config.config.at(\inputs).size); + this.setupMainView(config.config, config.configFilePath); this.setupChannelAddButton(channelContainerView); - this.setupChannelViews(config); + this.setupChannelViews(config.config); } //setup the main view, in which all other views reside setupMainView{ - arg config; + arg config, configFilePath; var channelScrollView, configView, layout; mainView = PageLayout.new("Bowelyzer"); mainView.asView.background = Color.fromHexString("#DBDBDB"); @@ -74,7 +74,7 @@ BowelyzerGUI{ configView.layout.margins = settingsSubViewMargins; configView.name = "config"; configView.maxSize_(configViewSize); - this.setupSaveButton(configView); + this.setupSaveButton(configView, configFilePath); this.setupSaveAsButton(configView); this.setupLoadButton(configView); @@ -211,19 +211,16 @@ BowelyzerGUI{ headView.asView.background = Color.fromHexString("#DDEFDD"); headView.name = \inputs; headView.layout = HLayout(); - headView.layout.spacing = 0; - headView.layout.margins = [2,0,2,0]; - headView.maxHeight_(buttonHeight); + headView.layout.spacing = 4; + headView.layout.margins = [4,0,4,0]; + headView.maxHeight_(headViewHeight); Routine{ 0.5.wait; this.setupEZText(headView, "name", name.asString).children.do({|item| if(item.isKindOf(StaticText),{item.align_(\left)}); if(item.isKindOf(TextField),{item.align_(\right)}); }); - this.setupEZNumber(headView, "input", config.at(\inputs).at(name)).children.do({|item| - if(item.isKindOf(StaticText),{item.align_(\left)}); - if(item.isKindOf(NumberBox),{item.align_(\right)}); - }); + this.setupEZPopUpMenu(headView, "input", Server.default.options.numInputBusChannels, config.at(\inputs).at(name)); this.setupChannelCloseButton(headView, name); }.play(AppClock); @@ -255,7 +252,6 @@ BowelyzerGUI{ controlsView = View(controlMeterContainerView.asView, Rect(0,0, controlsViewWidth, controlsViewHeight)); controlsView.asView.background = Color.fromHexString("#EEEFEE"); controlsView.name = \controls; - //controlsView.maxWidth = controlsViewWidth; controlsView.layout = VLayout(); controlsView.layout.spacing = 0; controlsView.layout.margins = [2,0,2,0]; @@ -368,23 +364,40 @@ BowelyzerGUI{ // create a save button, that launches a FileDialog on press setupSaveButton{ - arg parent; + arg parent, file, state = 1; ^Button(parent, Rect(0, 0, buttonWidth, buttonHeight)) .states_([ - //TODO: set Color depending on whether config file is not "" - ["save", Color.black, Color.fromHexString("#99FF99")], + ["save", Color.black, Color.fromHexString("#99FF99")] ]) .action_({ - arg controlUnit; - var address = NetAddr.new("127.0.0.1", NetAddr.langPort), - type = "/save"; - postln("Sending: ["++type++"]"); - address.sendMsg(type); - }) + arg controlUnit; + var address = NetAddr.new("127.0.0.1", NetAddr.langPort), + type = "/save"; + postln("Sending: ["++type++"]"); + address.sendMsg(type); + }) + .value_(1) .maxSize_(buttonWidth@buttonHeight) ; } + // open a FileDialog to send a path via OSC to save config to that file + saveAsAction{ + arg controlUnit; + var address = NetAddr.new("127.0.0.1", NetAddr.langPort), + type = "/saveas"; + FileDialog.new( + okFunc: {|path| + postln("Sending: ["++type++", "++path++"]"); + address.sendMsg(type, path.asString); + }, + cancelFunc: {}, + fileMode: 0, + acceptMode: 1, + stripResult: true + ); + } + // create a save button, that launches a FileDialog on press setupSaveAsButton{ arg parent; @@ -392,21 +405,7 @@ BowelyzerGUI{ .states_([ ["save as", Color.black, Color.fromHexString("#99FF99")], ]) - .action_({ - arg controlUnit; - var address = NetAddr.new("127.0.0.1", NetAddr.langPort), - type = "/saveas"; - FileDialog.new( - okFunc: {|path| - postln("Sending: ["++type++", "++path++"]"); - address.sendMsg(type, path.asString); - }, - cancelFunc: {}, - fileMode: 0, - acceptMode: 1, - stripResult: true - ); - }) + .action_({this.saveAsAction}) .maxSize_(buttonWidth@buttonHeight) ; } @@ -486,7 +485,8 @@ BowelyzerGUI{ }); if(control == "name", { bounds = 140@buttonHeight; - textWidth = 84; + labelWidth = 34; + textWidth = 106; }); ^EZText( parent: parent, @@ -520,6 +520,50 @@ BowelyzerGUI{ ; } + // setup a StaticText and a NumberBox + setupEZPopUpMenu{ + arg parent, control, inputs, value; + var bounds = 120@buttonHeight, + labelWidth = 34, + menu = EZPopUpMenu.new( + parentView: parent, + bounds: bounds, + label: control, + initVal:value, + labelWidth: labelWidth, + labelHeight: buttonHeight + ), + action = { + arg controlUnit; + var address = NetAddr.new("127.0.0.1", NetAddr.langPort), + type = "/"++controlUnit.view.parent.name.asString, + name = controlUnit.view.parent.parent.name.asSymbol, + controlName = controlUnit.labelView.string.asSymbol, + controlValue = controlUnit.value; + postln("Sending: "++"["++type++", "++name++", "++controlName++", "++controlValue++"]"); + address.sendMsg(type, name, controlName, controlValue); + }; + + // create state for each input + inputs.do({|i| + menu.addItem(i.asSymbol, action); + }); + // set bounds properly + menu.view.bounds_(bounds); + // set alignment and bounds for StaticText + menu.view.children.do({|item| + if(item.isKindOf(StaticText),{ + item.align_(\left); + item.bounds_(labelWidth@buttonHeight); + }); + }); + ^menu + .value_(value) + .view.maxSize_(bounds).bounds_(bounds) + .asView.name_(control) + ; + } + // setup a StaticText and a NumberBox setupEZNumber{ arg parent, control, value; @@ -532,12 +576,6 @@ BowelyzerGUI{ labelWidth = 70; numberWidth = 70; }); - //TODO: use EZPopupMenu - if(control == "input", { - bounds = 124@buttonHeight; - labelWidth = 48; - numberWidth = 76; - }); ^EZNumber( parent: parent, bounds: bounds, -- cgit v1.2.3-70-g09d2