changeset 19:bd23c1b922be

Explore preset saving slot stuff kind of works.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 22 Oct 2014 16:29:31 +0100
parents 36cdb73691da
children 1e6d4ece1572
files ExpMessageOrganiser.h ExpMessageOrganiser.mm ExplorePresetManager.h ExplorePresetManager.mm TrainingMessageOrganiser.h UI code/IconPanel.h UI code/IconPanel.mm eventLogger.h presetManager.h presetManager.mm testApp.mm
diffstat 11 files changed, 93 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ExpMessageOrganiser.h	Wed Oct 22 15:00:14 2014 +0100
+++ b/ExpMessageOrganiser.h	Wed Oct 22 16:29:31 2014 +0100
@@ -25,11 +25,9 @@
     vector<int> getMappingIDsFromSynths();
     void showCurrentSlot();
     void loadPreset(string pname);
-    //-----------------------------------------------------------------------------
-    
     void buttonPressCallback(int mappingID, int value);
 private:
-    Preset* currentPresetSlot;
+    void loadDefaultSound();
     int numParamsToUse;
 };
 
--- a/ExpMessageOrganiser.mm	Wed Oct 22 15:00:14 2014 +0100
+++ b/ExpMessageOrganiser.mm	Wed Oct 22 16:29:31 2014 +0100
@@ -19,8 +19,7 @@
     setupDefaultMapping();
     expPresetManager.goToFirstEmptySlot();
     showCurrentSlot();
-    
-    
+  
 }
 
 
@@ -51,8 +50,20 @@
 }
 
 void ExpMessageOrganiser::showCurrentSlot(){
-    currentPresetSlot =  expPresetManager.getCurrentPresetSlot();
-    presetIconPanel->setTextAndImage(currentPresetSlot->name, currentPresetSlot->getImage());
+
+    if(expPresetManager.getCurrentPresetSlot() == NULL){
+        // hide next button
+        return;
+    }
+    presetIconPanel->setTextAndImage(expPresetManager.getCurrentPresetSlot()->name, expPresetManager.getCurrentPresetSlot()->getImage(),expPresetManager.getCurrentPresetSlot()->isFilled);
+    if(expPresetManager.getCurrentPresetSlot()->isFilled){
+        // show this preset on sliders
+        loadPreset(expPresetManager.getCurrentPresetSlot()->name);
+    }else{
+        // show default slidervals
+        loadDefaultSound();
+        
+    }
 }
 
 void ExpMessageOrganiser::loadPreset(string pname){
@@ -65,7 +76,16 @@
         cout << "ERROR, no preset found" << endl;
     }
 }
+void ExpMessageOrganiser::loadDefaultSound(){
+    vector<int> values;
+    for(int i = 0; i < TOTAL_NUM_PARAMS; i++){
+        values.push_back(0);
+    }
 
+    candidateSynth.setAllParams(values);
+    setAllSlidersToValues(values);
+
+}
 
 
 //-----------------------------------------------------------------------------
@@ -80,8 +100,12 @@
     }
     if(mappingID == SAVE_PRESET_HIT){
         
-        expPresetManager.writeValuesToSlot(candidateSynth.getAllParamValues());
-        showCurrentSlot();
+        bool finished = expPresetManager.writeValuesToSlot(candidateSynth.getAllParamValues());
+        if(finished){
+            instructionPanel->setLabel("ALL PRESETS MADE");
+        }else{
+            showCurrentSlot();
+        }
         
         return;
     }
--- a/ExplorePresetManager.h	Wed Oct 22 15:00:14 2014 +0100
+++ b/ExplorePresetManager.h	Wed Oct 22 16:29:31 2014 +0100
@@ -89,7 +89,7 @@
     void onAppLoad();
     void goToFirstEmptySlot();
     bool writeValuesToSlot(vector<int> values);
-    Preset* getCurrentPresetSlot();
+    PresetSlot* getCurrentPresetSlot();
     PresetSlot* getPresetSlotAtIndex(int index);
 
 protected:
--- a/ExplorePresetManager.mm	Wed Oct 22 15:00:14 2014 +0100
+++ b/ExplorePresetManager.mm	Wed Oct 22 16:29:31 2014 +0100
@@ -14,11 +14,8 @@
 void ExplorePresetManager::onAppLoad(){
     // check for already saved stuff
     startLoadAll();
-    
-    if (thePresets.size() != MAX_PRESETS){
-        
-        initPresetSlots();
-    }
+    initPresetSlots();
+
     
 }
 
@@ -39,12 +36,13 @@
     currentPresetSlotIndex++;
     if(filledSlots == MAX_PRESETS){
         cout << "FINISHED EXP STAGE!" << endl;
+        currentPresetSlotIndex = 0;
         return true;
     }
     return false;
 }
 //--------------------------------------------------------------------------------
-Preset* ExplorePresetManager::getCurrentPresetSlot(){
+PresetSlot* ExplorePresetManager::getCurrentPresetSlot(){
     
     return getPresetSlotAtIndex(currentPresetSlotIndex);
 }
@@ -129,8 +127,16 @@
 }
 //-----------------------------------------------------------------------------
 
-void ExplorePresetManager::fillSlotFromLoadedPreset(vector<PresetSlot*>::iterator psi, vector<Preset*>::iterator pi){
-    (*pi) = (*psi); // dodgy?
+void ExplorePresetManager::fillSlotFromLoadedPreset(vector<PresetSlot*>::iterator slotToFill, vector<Preset*>::iterator preset){
+    (*slotToFill)->setValues((*preset)->CCValues);
+    (*slotToFill)->isFilled = true;
+    filledSlots++;
+
+    if(filledSlots == MAX_PRESETS){
+        cout << "ALL SLOTS ARE FILLED!" << endl;
+    }
+    
+    
 }
 //-----------------------------------------------------------------------------
 void ExplorePresetManager::generatePresetSlot(const string name, const string imagefn){
--- a/TrainingMessageOrganiser.h	Wed Oct 22 15:00:14 2014 +0100
+++ b/TrainingMessageOrganiser.h	Wed Oct 22 16:29:31 2014 +0100
@@ -120,7 +120,8 @@
         }
         
         if(newStep.showsTargetIcon){
-            presetIconPanel->setTextAndImage(currentTargetPreset->name, currentTargetPreset->getImage());
+            bool showTick = true;
+            presetIconPanel->setTextAndImage(currentTargetPreset->name, currentTargetPreset->getImage(), showTick);
             presetIconPanel->show();
         }else{
             presetIconPanel->hide();
--- a/UI code/IconPanel.h	Wed Oct 22 15:00:14 2014 +0100
+++ b/UI code/IconPanel.h	Wed Oct 22 16:29:31 2014 +0100
@@ -45,11 +45,13 @@
     void drawOutline();
     void drawTextLabel();
     void drawTexture();
-    
-    void setTextAndImage(string text, ofImage* image){
+    void drawTick();
+    void drawCross();
+    void setTextAndImage(string text, ofImage* image, bool isFilled){
         setLabel(text);
         textureImage = image;
         hasBeenSet = true;
+        showTick = isFilled;
     }
     
     virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID);
@@ -58,6 +60,7 @@
 
     ofImage* textureImage;
     bool hasBeenSet;
+    bool showTick;
 };
 
 
--- a/UI code/IconPanel.mm	Wed Oct 22 15:00:14 2014 +0100
+++ b/UI code/IconPanel.mm	Wed Oct 22 16:29:31 2014 +0100
@@ -30,6 +30,7 @@
     on = false;
     hasBeenSet = false;
     textureImage = NULL;
+    showTick = false;
 }
 //------------------------------------------------------------------
 void IconPanel::draw(){
@@ -43,9 +44,32 @@
         drawTextLabel();
         
     }
+    if(showTick){
+        drawTick();
+    }else{
+        drawCross();
+    }
     
     
 }
+//------------------------------------------------------------------
+void IconPanel::drawTick(){
+    ofPoint pos(x + width - 25, y + height - 25);
+    ofSetColor(0, 200, 20);
+    ofSetLineWidth(2);
+    ofLine(pos.x, pos.y, pos.x+8, pos.y+10);
+    ofLine(pos.x+8, pos.y+10, pos.x+10, pos.y+8);
+}
+//------------------------------------------------------------------
+void IconPanel::drawCross(){
+    ofPoint pos(x + width - 25, y + height - 25);
+    ofSetColor(230, 0, 20);
+    ofSetLineWidth(2);
+    ofLine(pos.x, pos.y, pos.x+10, pos.y+10);
+    ofLine(pos.x+10, pos.y, pos.x, pos.y+10);
+}
+//------------------------------------------------------------------
+
 void IconPanel::drawTexture(){
     float z = 10;
     textureImage->draw(x+10,y+10,z,width-20,height-20);
--- a/eventLogger.h	Wed Oct 22 15:00:14 2014 +0100
+++ b/eventLogger.h	Wed Oct 22 16:29:31 2014 +0100
@@ -31,7 +31,7 @@
 #define EVENT_THIN_FACTOR 30
 #define EVENT_LOG_FILENAME "log.json"
 #define UPLOAD_CHUNK_SIZE 1000
-#define SAVE_CHUNK_SIZE 5000
+#define SAVE_CHUNK_SIZE 200
 #define APP_CREATION_TIME 0   // ignore this, pointless
 #define PROGRAM_NAME "RIFTATHON"
 #define PROGRAM_VERSION 0.1
--- a/presetManager.h	Wed Oct 22 15:00:14 2014 +0100
+++ b/presetManager.h	Wed Oct 22 16:29:31 2014 +0100
@@ -149,7 +149,7 @@
     int nextID;
     int timesOpened;
     bool presetAlertShowing;
-
+    void showOverwriteDialog();
     vector<Preset *> thePresets; 
 
     Json::Value  allPresetsToJson();
--- a/presetManager.mm	Wed Oct 22 15:00:14 2014 +0100
+++ b/presetManager.mm	Wed Oct 22 16:29:31 2014 +0100
@@ -122,6 +122,15 @@
 //    }
     
 }
+//---------------------------------------------------------------------------
+void PresetManager::showOverwriteDialog(){
+    //    if(!presetAlertViewController.alertShowing){ // this is to stop wierd infinite loop in ios5 (simulator)
+    //        presetAlertShowing = true;
+    //        [presetAlertViewController showPresetNamePrompt];
+    //
+    //    }
+    
+}
 //------------------------------------------------
 // when preset slot becomes a real preset to save
 void PresetManager::savePreset(Preset * aPreset){
@@ -131,7 +140,9 @@
     for(iter = thePresets.begin(); iter < thePresets.end(); iter++){
         if ((*iter)->name == aPreset->name){
             cout << "WARNING Preset by that name exists, overwriting\n";
-            // overwrite it
+            // TODO throw up a dialog?
+            showOverwriteDialog();
+            
             (*iter)->overwriteValues(aPreset->CCValues);
             updatePresetFile();
             eventLogger.logEvent(SAVE_PRESET); // TODO need to log details?
@@ -203,7 +214,7 @@
 //---------------------------------------------------------------------------
 void PresetManager::startLoadAll(){
 
-    presetFileName = ofxiPhoneGetDocumentsDirectory() + PRESET_FILENAME;
+    presetFileName = ofxiPhoneGetDocumentsDirectory() + eventLogger.userName + '_' + PRESET_FILENAME;
     
     loadPresetsFromJsonFile(presetFileName);
     
--- a/testApp.mm	Wed Oct 22 15:00:14 2014 +0100
+++ b/testApp.mm	Wed Oct 22 16:29:31 2014 +0100
@@ -110,7 +110,7 @@
     bottomButtonPanel->addButton(playCandidateButton);
 
     Buttron * savePresetButton = new Buttron(props->buttonWidth*1.4,680, *props);
-    savePresetButton->setLabel("SAVE");
+    savePresetButton->setLabel("SAVE/NEXT");
     expMessageOrganiser.mapButtonToAction(savePresetButton, SAVE_PRESET_HIT);
     bottomButtonPanel->addButton(savePresetButton);