diff TrainingMessageOrganiser.h @ 14:f83635861187

rewrote sequence controller. ticks show relevant UI modes. images show for preset textures (but greenish?)
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 21 Oct 2014 16:39:39 +0100
parents ab3e0e980c82
children 2da0350a4aa2
line wrap: on
line diff
--- a/TrainingMessageOrganiser.h	Mon Oct 20 19:36:39 2014 +0100
+++ b/TrainingMessageOrganiser.h	Tue Oct 21 16:39:39 2014 +0100
@@ -19,6 +19,7 @@
 
 class TrainingMessageOrganiser : public MessageOrganiser {
 public:
+    int numParamsToUse;
     void init( PDSynthWrapper& cs, PDSynthWrapper& ts){
         
         MessageOrganiser::init(cs,ts);
@@ -27,15 +28,16 @@
         callback = boost::bind(&TrainingMessageOrganiser::onNextTick, this, _1);
         candidateSynth.registerForTicks(callback);
         
-        sequencePreview = true;
+        numParamsToUse = 3;
+        
     }
-
+    
     void setupDefaultMapping(){
         vector<int> mappingIDsForChangeableParams = getMappingIDsFromSynths();
         
         controlPanelType cpt = REVISITABLE;
         vector<controllerType> elemList;
-        for(int i = 0; i < TOTAL_NUM_PARAMS; i++){
+        for(int i = 0; i < numParamsToUse; i++){
             elemList.push_back(SLIDER);
         }
         
@@ -48,7 +50,7 @@
     
     vector<int> getMappingIDsFromSynths(){
         vector<int> index;
-        for(int i = 0; i < TOTAL_NUM_PARAMS; i++){
+        for(int i = 0; i < numParamsToUse; i++){
             index.push_back(i);
         }
         vector<int> mids = candidateSynth.getMappingIDForIndices(index);
@@ -57,73 +59,123 @@
     }
     
     void setupNewTest(){
-
+        
         
     };
     
     void setIconPanel(IconPanel * ip){
         presetIconPanel = ip;
     }
+    void setInstructionPanel(TextPanel * ip){
+        instructionPanel = ip;
+        instructionPanel->show();
+    }
+//-----------------------------------------------------------------------
+    void displayInstructions(Step s){
+        
+
+        if (s.type == Step::COUNT_IN){
+            instructionPanel->setText("GET READY");
+        }
+        if (s.type == Step::PREVIEW_DISPLAY){
+            instructionPanel->setText("MEMORISE");
+            panel->setColor(ofColor(0,0,0));
+        }
+        if (s.type == Step::PREVIEW_PLAY){
+            instructionPanel->setText("MEMORISE");
+            panel->setColor(ofColor(0,0,0));
+        }
+        if (s.type == Step::MATCHING_INTERACTION){
+            instructionPanel->setText("MATCH:");
+            panel->setColor(ofColor(100,0,0));
+        }
+        if (s.type == Step::MATCHING_RESULT){
+            instructionPanel->setText("RESULT");
+            panel->setColor(ofColor(0,100,0));
+        }
+    }
+//-----------------------------------------------------------------------
     void onNextTick(int tickNumber){
         cout << "TICK " << tickNumber << endl;
+
+        // only first beat in bar is active one
+        if ( tickNumber % 4  != 0){
+            return;
+        }
+        // load next target preset
         
-        if ( !(tickNumber % 2)){
-            // load next target preset
-            
-            int i = sequenceController.getCurrentPresetIndex();
-            
-            currentTargetPreset =  expPresetManager.getPreset(i);
-            
-            if (sequencePreview){
-                // show next target preset
-                // presetIconPanel->setTextAndImage(currentTargetPreset->name, currentTargetPreset->getImage());
-             
-                // show image
-                // show name
-                // show controllersettings
-                
-                
-            }else{ // the user is matching it
-                // show image
-                // show name
-                
-                // if guided
-                    // show controller guide
-            }
-            
-            
-        }else{ // we're plying the sound
-         
-            //
-            if (sequencePreview){
-                // send target values again
-                targetSynth.setAllParams(currentTargetPreset->getValues());
-                setSlidersToTarget();
-                targetSynth.trigger();
-                
-                // flash the interface?
-            }else{
-                // has this been done? yes. candidateSynth.setAllParams(ui stuff);
-                candidateSynth.trigger();
-                showUserHowTheyDid();
-                
-            }
+        Step newStep = sequenceController.getNextStep();
+        displayInstructions(newStep);
+        
+        if(newStep.isLastOfAll){
+            // do finished run stuff, show summary
+            candidateSynth.stopMetronome();
+            cout << "FINISHED BLOCK" << endl;
         }
-        
-        int run = sequenceController.stepForward();
-        if (run == -2){
+        if(newStep.isLastOfRun){
             // do finished run stuff, show summary
             candidateSynth.stopMetronome();
             cout << "FINISHED RUN" << endl;
         }
-        if (run == -1){
-            // finished whole block
-            candidateSynth.stopMetronome();
-            cout << "FINISHED BLOCK" << endl;
+        
+        float t = newStep.getTimeBetweenTicks();
+        candidateSynth.setMetroTime(t);
+        
+        if(newStep.type == Step::COUNT_IN){
+            // count in
+            return;
         }
+        
+        if(newStep.presetIndex >= 0 && newStep.presetIndex <= 8){
+            currentTargetPreset =  expPresetManager.getPreset(newStep.presetIndex);
+        }
+        
+        if(newStep.showsTargetIcon){
+            presetIconPanel->setTextAndImage(currentTargetPreset->name, currentTargetPreset->getImage());
+            presetIconPanel->show();
+        }else{
+            presetIconPanel->hide();
+        }
+        
+        if(newStep.showsControlSettings){
+            targetSynth.setAllParams(currentTargetPreset->getValues());
+            setSlidersToTarget();
+            
+        }else{
+            //setSlidersToDefault();
+            
+        }
+        
+        if(newStep.playsTarget){
+            targetSynth.setAllParams(currentTargetPreset->getValues());
+            targetSynth.trigger();
+        }
+        
+        if(newStep.playsCandidate){
+            triggerCandidateSound();
+        }
+        
+        if(newStep.allowsCandidateControl){
+            panel->setActive(true);
+        }else{
+            panel->setActive(false);
+        }
+        
+        if(newStep.showsMatchResults){
+            // do something
+        }
+        
+        if(newStep.showsControlGuides){
+            
+            panel->setHintValues(currentTargetPreset->getValues());
+            panel->showHint(true);
+        }else{
+            panel->showHint(false);
+        }
+        
     }
-
-   
+    
+    //-----------------------------------------------------------------------
 protected:
     void showUserHowTheyDid(){
         // colour flash
@@ -143,6 +195,7 @@
     }
     
     
+    //-----------------------------------------------------------------------
     void showATargetPresetWithGuide(Preset * p){ // this is when demoing the sequence to the user
         // p.show icon
         vector<int> values = p->getValues();
@@ -153,6 +206,7 @@
             cout << "WARNING, preset to show had no values" << endl;
         }
     }
+    //-----------------------------------------------------------------------------
     
     void mapSlidersToParams(vector<UIElement*> elems, vector<int> mids){
         
@@ -181,6 +235,7 @@
         
         eventLogger.logEvent(CONTROL_LIST,typeListLog);
     };
+//-----------------------------------------------------------------------------
     
     void buttonPressCallback(int mappingID, int value){
         if(mappingID == VOLUME_CHANGE_ID){
@@ -188,10 +243,11 @@
             candidateSynth.sendVolume(value);
             return;
         }
-
+        
         if (mappingID == TRIGGER_CANDIDATE_ID){
-            triggerCandidateSound();
+            //triggerCandidateSound();
             // compare to target
+            candidateSynth.setMetroTime(sequenceController.getStartTickTime());
             candidateSynth.startMetronome();
             return;
         }
@@ -205,9 +261,12 @@
             return;
         }
     }
+    //-----------------------------------------------------------------------------
+    
     SequenceController sequenceController;
     bool sequencePreview;
     Preset * currentTargetPreset;
     IconPanel* presetIconPanel;
+    TextPanel* instructionPanel;
 };
 #endif /* defined(__riftathon__TrainingMessageOrganiser__) */