Mercurial > hg > tweakathon2ios
changeset 4:60b54ba87f6a
Preset save and recall works.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Thu, 16 Oct 2014 14:34:14 +0100 |
parents | c50de2d84732 |
children | 213df0baed47 |
files | MessageOrganiser.h globalVariables.h presetManager.h presetManager.mm testApp.mm |
diffstat | 5 files changed, 62 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/MessageOrganiser.h Fri Oct 10 18:22:14 2014 +0100 +++ b/MessageOrganiser.h Thu Oct 16 14:34:14 2014 +0100 @@ -32,6 +32,7 @@ #include "TextPanel.h" #include "CountdownText.h" #include "buttonPanel.h" +#include "presetManager.h" // event logger needs to know // which controls were showing in what mode @@ -51,6 +52,8 @@ extern EventLogger eventLogger; +extern PresetManager presetManager; + typedef boost::function<void(void)> AppModeChangeFunction; class MessageOrganiser { @@ -376,12 +379,18 @@ panel->setHintColor(c); }; + void setAllSlidersToValues(vector<int> values){ + for(int i = 0; i < values.size(); i++){ + setUIToParam(i, values[i]); + } + } // we want to set UI object void setUIToParam(int index, int value){ // e.g. from MIDI incoming, will handle both box and sliders... // theXY->setValueAndScale(candidateSynth.getParamValueForID(mids[i]), candidateSynth.getParamValueForID(mids[i+1])); UIElement* elem; // get the element if(panel->subElements.size() <= index){ + cout << "ERROR: index out of range for num sliders" << endl; return; } elem = panel->subElements[index]; @@ -645,6 +654,22 @@ showingHint = true; } } + if(mappingID == SAVE_PRESET_HIT){ + presetManager.savePreset("blah", candidateSynth.getAllParamValues()); + + } + if(mappingID == RECALL_PRESET_HIT){ + + loadPreset("blah"); + + + } + } + void loadPreset(string pname){ + + vector<int> values = presetManager.recallPreset(pname); + candidateSynth.setAllParams(values); + setAllSlidersToValues(values); } // called from UI void paramChangeCallback(int mappingID, int value){
--- a/globalVariables.h Fri Oct 10 18:22:14 2014 +0100 +++ b/globalVariables.h Thu Oct 16 14:34:14 2014 +0100 @@ -23,6 +23,8 @@ #define RESTART_EXPERIMENT_ID 99658290 #define SPEED_CHANGE_ID 99573012 #define VOLUME_CHANGE_ID 99263748 +#define SAVE_PRESET_HIT 99245748 +#define RECALL_PRESET_HIT 99298750 #define ALTERNATION_SPEED 180 // ms that target / candidate sounds play // globles
--- a/presetManager.h Fri Oct 10 18:22:14 2014 +0100 +++ b/presetManager.h Thu Oct 16 14:34:14 2014 +0100 @@ -86,6 +86,13 @@ return ss.str(); } + + string getName(){ + return name; + } + vector<int> getValues(){ + return CCValues; + } }; //--------------------------------------------------------------------------- @@ -99,8 +106,8 @@ int savePreset(string name, vector<int> stuff); - TwoVector recallPreset(int presetID); // by name ? id? - TwoVector recallPreset(string name); // by name ? id? + vector<int> recallPreset(int presetID); // by name ? id? + vector<int> recallPreset(string name); // by name ? id? void printAll();
--- a/presetManager.mm Fri Oct 10 18:22:14 2014 +0100 +++ b/presetManager.mm Thu Oct 16 14:34:14 2014 +0100 @@ -119,35 +119,41 @@ } //--------------------------------------------------------------------------- // when save button pressed -int PresetManager::savePreset(const string name, vector<int> stuff){ +int PresetManager::savePreset(const string name, vector<int> values){ presetAlertShowing = false; // check for same name vector<Preset *>::iterator iter; - /* + for(iter = thePresets.begin(); iter < thePresets.end(); iter++){ if ((*iter)->name == name){ - cout << " Preset by that name exists\n"; - - // use exceptions! - return -1; + cout << "WARNING Preset by that name exists, overwriting\n"; + // overwrite it + (*iter)->CCValues = values; } } if(name == ""){ cout << "Please name preset\n"; - return -2; } - */ - thePresets.push_back(new Preset(stuff, name, nextID, eventLogger.userName, eventLogger.deviceID)); + + thePresets.push_back(new Preset(values, name, nextID, eventLogger.userName, eventLogger.deviceID)); eventLogger.logEvent(SAVE_PRESET); // TODO need to log details? return nextID++; } - +vector<int> PresetManager::recallPreset(string name){ + vector<Preset *>::iterator p; + for(p = thePresets.begin(); p < thePresets.end(); p++){ + if ( (*p)->getName() == name){ + return (*p)->getValues(); + } + } + +} //----------------------------------------------cu----------------------------- void PresetManager::startLoadAll(){ // get stuff from file
--- a/testApp.mm Fri Oct 10 18:22:14 2014 +0100 +++ b/testApp.mm Thu Oct 16 14:34:14 2014 +0100 @@ -140,17 +140,17 @@ bottomButtonPanel->addButton(submitButton); // button - just for spacing pruposes - Buttron * spacerButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); - spacerButton->setLabel("-"); - messageOrganiser.mapButtonToAction(spacerButton, TRIGGER_CANDIDATE_ID); - bottomButtonPanel->addButton(spacerButton); - spacerButton->hide(); + Buttron * saveButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); + saveButton->setLabel("SAVE"); + messageOrganiser.mapButtonToAction(saveButton, SAVE_PRESET_HIT); + bottomButtonPanel->addButton(saveButton); + saveButton->show(); - Buttron * spacerButton2 = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); - spacerButton2->setLabel("-"); - messageOrganiser.mapButtonToAction(spacerButton2, TRIGGER_CANDIDATE_ID); - bottomButtonPanel->addButton(spacerButton2); - spacerButton2->hide(); + Buttron * recallButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); + recallButton->setLabel("RECALL"); + messageOrganiser.mapButtonToAction(recallButton, RECALL_PRESET_HIT); + bottomButtonPanel->addButton(recallButton); + recallButton->show(); messageOrganiser.setBottomPanel(bottomButtonPanel); UIElements.push_back(bottomButtonPanel);