diff options
author | David Runge <dave@sleepmap.de> | 2016-07-14 02:55:00 +0200 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2016-07-14 02:55:00 +0200 |
commit | 5190b245ff3461b1fe1618ad61890b14f4843c36 (patch) | |
tree | e7b8ba15741985783577359ed55777bd1ed8e506 /classes | |
parent | fd532a95f547e752184dbfa5d9fed8f9b16f89fc (diff) | |
download | bowelyzer-0.8.tar.gz bowelyzer-0.8.tar.bz2 bowelyzer-0.8.tar.xz bowelyzer-0.8.zip |
classes/BowelyzerGUI.sc: Refactoring setupAddressesAndPorts into setupSynthServerView, setupHubView and setupForwardView. Dropping removeConfigView and removeAddressesandPorts in favor of the unifying removeSettingsView, that can remove a settingsView by name. Setting up all Buttons and EZViews by adding them to the layout of their parent. This is also true for the children of settingsView, which makes their distribution and resizing much easier (by additionally introducing a variable width stretching object). Factoring the sending of the /load message out of the load Button, to also be able to use it in the 'Current configuration' list, which is setup using setupConfigFilePathView and updated by setupCurrentConfigFilePath. The ScrollView holding the channelViews was added to lowerView, to make room for a higher level Button View on the left side of the screen. Removing useless additional colors and resetting some margins.0.8
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Bowelyzer.sc | 23 | ||||
-rw-r--r-- | classes/BowelyzerGUI.sc | 163 |
2 files changed, 129 insertions, 57 deletions
diff --git a/classes/Bowelyzer.sc b/classes/Bowelyzer.sc index e1fba76..35aa0c3 100644 --- a/classes/Bowelyzer.sc +++ b/classes/Bowelyzer.sc @@ -193,9 +193,19 @@ Bowelyzer{ key: \saveas, func: {|msg, time, addr, recvPort| var name = msg[0], - fileName = msg[1]; + fileName = msg[1], + dict; postln("Received: "++msg); - config.writeConfigurationFile(fileName); + if(config.writeConfigurationFile(fileName), { + if((gui.configFilePathView.items.size == 0), { + gui.setCurrentConfigFilePath(fileName); + },{ + dict = Dictionary.with(*gui.configFilePathView.items); + if(dict.includesKey(fileName.asSymbol).not,{ + gui.setCurrentConfigFilePath(fileName); + }); + }); + }); }, path: "/saveas", srcID: hub.local @@ -225,8 +235,13 @@ Bowelyzer{ hub.addSynthListener(name); }); // reload the addresses and ports Views - gui.removeAddressesAndPorts; - gui.setupAddressesAndPorts(config.config); + gui.removeSettingsView("synthServer"); + gui.removeSettingsView("hub"); + gui.removeSettingsView("forward"); + gui.setupSynthServerView(config.config); + gui.setupHubView(config.config); + gui.setupForwardView(config.config); + gui.setCurrentConfigFilePath(config.configFilePath); },{ ("Configuration could not be read: "++fileName).error; }); diff --git a/classes/BowelyzerGUI.sc b/classes/BowelyzerGUI.sc index 48b1688..31dea20 100644 --- a/classes/BowelyzerGUI.sc +++ b/classes/BowelyzerGUI.sc @@ -1,6 +1,6 @@ BowelyzerGUI{ - var mainView, <settingsView, <channelContainerView, + var mainView, <settingsView, <channelContainerView, lowerView, <configFilePathView, <channels, <indicators, fadeOutTime = 0.3, @@ -43,36 +43,54 @@ BowelyzerGUI{ 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.config); } //setup the main view, in which all other views reside setupMainView{ - arg config, configFilePath; + arg config, configFilePath, buttonView; var channelScrollView, layout; mainView = PageLayout.new("Bowelyzer"); mainView.asView.background = Color.fromHexString("#DBDBDB"); layout = mainView.asView.addFlowLayout(0@0, 0@0); mainView.onClose_({ |view| + //TODO: close everything depending on choice view.close; }); //settings - settingsView = View(mainView.asView, Rect(0, 0, settingsViewSize.x, settingsViewSize.y)); - settingsView.asView.background = Color.fromHexString("#99EF99"); + settingsView = View(mainView.asView, Rect(0, 0, mainView.bounds.width, settingsViewSize.y)); settingsView.layout = HLayout(); - settingsView.layout.spacing = 0; + settingsView.layout.spacing = 4; settingsView.layout.margins = [0,0,0,0]; + this.setupConfigView; - this.setupAddressesAndPorts(config); + this.setupConfigFilePathView(configFilePath); + this.setupSettingsSpacer; + this.setupSynthServerView(config); + this.setupHubView(config); + this.setupForwardView(config); // go to next line in layout layout.nextLine; + lowerView = View(mainView.asView, Rect(0 , 0, mainView.bounds.width, mainView.bounds.height-settingsView.bounds.height)); + lowerView.layout = HLayout(); + lowerView.layout.spacing = 0; + lowerView.layout.margins = [0,0,0,0]; + buttonView = View(bounds: Rect(0, 0, buttonWidth+8, mainView.bounds.height-settingsView.bounds.height)); + buttonView.layout = VLayout(); + buttonView.layout.spacing = 4; + buttonView.layout.margins = [4,4,4,4]; + buttonView.layout.insert(this.setupChannelAddButton, 0); + buttonView.layout.insert(nil, 1); + lowerView.layout.insert(buttonView, 0); + // scrollview for channels - channelScrollView = ScrollView(mainView.asView, Rect(0 , 0, mainView.bounds.width, mainView.bounds.height-settingsView.bounds.height)).autohidesScrollers_(false).hasBorder_(true); + channelScrollView = ScrollView(bounds: Rect(0 , 0, mainView.bounds.width-buttonWidth, mainView.bounds.height-settingsView.bounds.height)) + .autohidesScrollers_(false) + .hasBorder_(true); // container for channelViews channelContainerView = View(parent: channelScrollView, bounds: Rect(0, 0, (channelViewWidth*config.at(\inputs).size)+buttonWidth, channelViewHeight)); channelContainerView.asView.background = Color.fromHexString("#FEFEFE"); @@ -80,44 +98,68 @@ BowelyzerGUI{ channelContainerView.layout.spacing = 0; channelContainerView.layout.margins = [0,0,0,0]; channelContainerView.name = \channelContainerView; + lowerView.layout.insert(channelScrollView, 1); + } + + // setup View for displaying current configuration file + setupConfigFilePathView{ + arg configFilePath; + var listView; + { + listView = View(); + listView.minSize_((settingsSubViewSize.x*2)@settingsSubViewSize.y); + listView.addFlowLayout(0@0, 0@0); + listView.name = "configFilePath"; + configFilePathView = EZListView.new( + listView, + bounds: (settingsSubViewSize.x*2)@settingsSubViewSize.y, + label: "Current configuration:" + ); + if(configFilePath.notNil && (configFilePath != ""), { + configFilePathView.addItem(configFilePath, {|unit| this.sendLoadMessage(unit.item)}); + }); + settingsView.layout.insert(listView, 1); + }.defer; + } + + + // insert a new config file path at the top of the list and set it to current + setCurrentConfigFilePath{ + arg configFile; + { + configFilePathView.insertItem(0, configFile, {|unit| this.sendLoadMessage(unit.item)}); + configFilePathView.value(0); + }.defer; } // setup the config View with Buttons to save and load configurations setupConfigView{ + { var configView = View(); - configView.asView.background = Color.fromHexString("#DDDDEF"); configView.layout = VLayout(); - configView.layout.spacing = 0; - configView.layout.margins = settingsSubViewMargins; + configView.layout.spacing = 4; + configView.layout.margins = [4,4,4,4]; configView.name = "config"; configView.maxSize_(configViewSize); - this.setupSaveButton(configView); - this.setupSaveAsButton(configView); - this.setupLoadButton(configView); + configView.layout.insert(this.setupSaveButton, 0); + configView.layout.insert(this.setupSaveAsButton, 1); + configView.layout.insert(this.setupLoadButton, 2); + configView.layout.insert(nil, 2); settingsView.layout.insert(configView, 0); + }.defer; } - removeConfigView{ - settingsView.children.do({|setting, i| - if(setting.isKindOf(View) && (setting.name == "config"),{ - setting.remove; - }); - }); - } - - // setup Views for addresses and ports - setupAddressesAndPorts{ + // setup View for synthServer address and port + setupSynthServerView{ arg config; - var forwardView, hubView, synthServerView; + var synthServerView; { - //synthServer synthServerView = View(bounds: Rect(0, 0, settingsSubViewSize.x, settingsSubViewSize.y)); - synthServerView.asView.background = Color.fromHexString("#DDDDEF"); synthServerView.layout = VLayout(); synthServerView.layout.spacing = 0; synthServerView.layout.margins = settingsSubViewMargins; synthServerView.name = "synthServer"; - synthServerView.maxSize_(settingsSubViewSize); + synthServerView.minSize_(settingsSubViewSize); StaticText(synthServerView, Rect(0, 0, 140@buttonHeight)).string_("synthServer").align_(\center); this.setupEZText(synthServerView, "address", config.at(\synthServerAddress)).children.do({|item| if(item.isKindOf(StaticText),{ @@ -135,16 +177,21 @@ BowelyzerGUI{ item.align_(\right); }); }); - settingsView.layout.insert(synthServerView, 1); + settingsView.layout.insert(synthServerView, 3); + }.defer; + } - //hub + // setup View for hub address and port + setupHubView{ + arg config; + var hubView; + { hubView = View(bounds: Rect(0, 0, settingsSubViewSize.x, settingsSubViewSize.y)); - hubView.asView.background = Color.fromHexString("#DDDDEF"); hubView.layout = VLayout(); hubView.layout.spacing = 0; hubView.layout.margins = settingsSubViewMargins; hubView.name = "hub"; - hubView.maxSize_(settingsSubViewSize); + hubView.minSize_(settingsSubViewSize); StaticText(hubView, Rect(0, 0, 140@buttonHeight)).string_("hub").align_(\center); this.setupEZText(hubView, "address", config.at(\hubAddress)).children.do({|item| if(item.isKindOf(StaticText),{ @@ -162,16 +209,21 @@ BowelyzerGUI{ item.align_(\right); }); }); - settingsView.layout.insert(hubView, 2); + settingsView.layout.insert(hubView, 4); + }.defer; + } - //forward + // setup View for forward address and port + setupForwardView{ + arg config; + var forwardView; + { forwardView = View(bounds: Rect(0, 0, settingsSubViewSize.x, settingsSubViewSize.y)); - forwardView.asView.background = Color.fromHexString("#DDDDEF"); forwardView.layout = VLayout(); forwardView.layout.spacing = 0; forwardView.layout.margins = settingsSubViewMargins; forwardView.name = "forward"; - forwardView.maxSize_(settingsSubViewSize); + forwardView.minSize_(settingsSubViewSize); StaticText(forwardView, Rect(0, 0, 140@buttonHeight)).string_("forward").align_(\center); this.setupEZText(forwardView, "address", config.at(\forwardAddress)).children.do({|item| if(item.isKindOf(StaticText),{ @@ -189,15 +241,20 @@ BowelyzerGUI{ item.align_(\right); }); }); - settingsView.layout.insert(forwardView, 3); + settingsView.layout.insert(forwardView, 5); }.defer; + } + + setupSettingsSpacer{ + settingsView.layout.insert(nil, 5); } // remove Views for addresses and ports - removeAddressesAndPorts{ + removeSettingsView{ + arg name; { settingsView.children.do({|setting, i| - if(setting.isKindOf(View) && ((setting.name == "hub") || (setting.name == "synthServer") || (setting.name == "forward")),{ + if(setting.isKindOf(View) && (setting.name == name.asString), { setting.remove; }); }); @@ -433,20 +490,14 @@ BowelyzerGUI{ // create a load button, that launches a FileDialog on press setupLoadButton{ - arg parent; - ^Button(parent, Rect(0, 0, buttonWidth, buttonHeight)) + ^Button(bounds: Rect(0, 0, buttonWidth, buttonHeight)) .states_([ ["load", Color.black, Color.fromHexString("#99FF99")] ]) .action_({ arg controlUnit; - var address = NetAddr.new("127.0.0.1", NetAddr.langPort), - type = "/load"; FileDialog.new( - okFunc: {|path| - postln("Sending: ["++type++", "++path++"]"); - address.sendMsg(type, path.asString); - }, + okFunc: {|path| this.sendLoadMessage(path)}, cancelFunc: {}, fileMode: 1, acceptMode: 0, @@ -457,10 +508,17 @@ BowelyzerGUI{ ; } + // send a message via OSC to load a configuration file by name + sendLoadMessage{ + arg path; + var address = NetAddr.new("127.0.0.1", NetAddr.langPort), + postln("Sending: [/load, "++path++"]"); + address.sendMsg("/load", path.asString); + } + // create a save button, that launches a FileDialog on press setupSaveButton{ - arg parent; - ^Button(parent, Rect(0, 0, buttonWidth, buttonHeight)) + ^Button(bounds: Rect(0, 0, buttonWidth, buttonHeight)) .states_([ ["save", Color.black, Color.fromHexString("#99FF99")] ]) @@ -496,8 +554,7 @@ BowelyzerGUI{ // create a save button, that launches a FileDialog on press setupSaveAsButton{ - arg parent; - ^Button(parent, Rect(0, 0, buttonWidth, buttonHeight)) + ^Button(bounds: Rect(0, 0, buttonWidth, buttonHeight)) .states_([ ["save as", Color.black, Color.fromHexString("#99FF99")], ]) @@ -550,8 +607,7 @@ BowelyzerGUI{ // setup a button to add a channel setupChannelAddButton{ - arg parent; - ^Button(parent, Rect(0, 0, buttonWidth, buttonWidth)) + ^Button(bounds: Rect(0, 0, buttonWidth, buttonWidth)) .states_([ ["+", Color.black, Color.fromHexString("#99FF99")] ]) @@ -562,6 +618,7 @@ BowelyzerGUI{ postln("Sending: ["++type++"]"); address.sendMsg(type); }) + .minSize_(buttonWidth@buttonWidth) .maxSize_(buttonWidth@buttonWidth) .name_("add") ; |