changeset 13:ab3e0e980c82

Sequence conrtollrer FINALLY works.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 20 Oct 2014 19:36:39 +0100
parents af71bf84660f
children f83635861187
files PDSynthWrapper.h PresetView.h SequenceController.h TrainingMessageOrganiser.h globalVariables.h presetManager.h presetManager.mm trainingTestController.h trainingTestController.mm
diffstat 9 files changed, 194 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/PDSynthWrapper.h	Mon Oct 20 14:12:23 2014 +0100
+++ b/PDSynthWrapper.h	Mon Oct 20 19:36:39 2014 +0100
@@ -37,8 +37,8 @@
         timbreParams.push_back(SynthParam(64,aCore,"FiltTyp",sp));
         timbreParams.push_back(SynthParam(64,aCore,"FiltFrq",sp));
         
-        //timbreParams.push_back(SynthParam(64,aCore,"SPAM",sp));
-        //timbreParams.push_back(SynthParam(64,aCore,"FILTH",sp));
+        timbreParams.push_back(SynthParam(64,aCore,"SPAM",sp));
+        timbreParams.push_back(SynthParam(64,aCore,"FILTH",sp));
         //timbreParams.push_back(SynthParam(64,aCore,"reson",sp));
         
         if (timbreParams.size() != TOTAL_NUM_PARAMS){
--- a/PresetView.h	Mon Oct 20 14:12:23 2014 +0100
+++ b/PresetView.h	Mon Oct 20 19:36:39 2014 +0100
@@ -21,20 +21,10 @@
         if (imageFileName != ""){
             // these are NOT put in images/ directory for some reason...
             string fname = ofFilePath::getAbsolutePath(ofToDataPath(imageFileName));
-
             ofFile f = ofFile(fname);
-            
-            
-            cout << fname << endl;
-            cout << f.exists() <<  endl;
-            
             image.loadImage(fname);
         }
-        
-
         name = aName;
-
-        
         
     };
 
--- a/SequenceController.h	Mon Oct 20 14:12:23 2014 +0100
+++ b/SequenceController.h	Mon Oct 20 19:36:39 2014 +0100
@@ -12,59 +12,190 @@
 #include <iostream>
 #include "presetManager.h"
 
-#define MAX_TARGETS_IN_SEQUENCE 8
+#define MAX_TARGETS_IN_SEQUENCE 2
 #define MIN_TEMPO   80
 #define MAX_TEMPO   200
-#define NUM_TEMPO_STEPS 8
+#define NUM_TEMPO_STEPS 3
 #define NUM_PRESETS 16
 
+//===============================================================================
+
 
 class Sequence{
-    int tempo;
-    vector<Preset *> presetSequence;
+public:
+    Sequence(vector<int> si, int t, bool pv){
+        tempo = t;
+        presetSequence =  si;
+        isSequencePreview = pv;
+        curStep = 0;
+    };
+    bool moveToNextStep(){
+        curStep++;
+        
+        if (curStep >= presetSequence.size()){
+            return false;
+        }else{
+            return true;
+        }
+    };
+    int getCurrentPresetIndex(){
+        cout << "step : " << curStep << endl;
+        if (curStep >= presetSequence.size()){
+            cout << "ERROR: off end of seq" << endl;
+            return 0;
+        }
+        int i = presetSequence[curStep];
+        if(i < 0){
+            cout << "ERROR: negative index" << endl;
+        }
+        return i;
+
+    };
+    int getStepNo(){
+        return curStep;
+    }
+    float tempo;
     
+    bool isSequencePreview; // true if demoing the seq to the user, false if user is matching a seq
+    vector<int> presetSequence;
+    int curStep;
     
 };
 
+//===============================================================================
+
+class Run{
+public:
+    Run(vector<Sequence> vs, int sl){
+        theSequences = vs;
+        sequenceLength = sl;
+        curSeq = 0;
+    };
+    bool moveToNextStep(){
+        if (curSeq >= theSequences.size()){
+            return false;
+        }
+        
+        bool stepFound = theSequences[curSeq].moveToNextStep();
+        if (stepFound){
+            return true;
+        }else{
+            curSeq++;
+            if (curSeq >= theSequences.size()){
+                return false;
+                
+            }else{
+                return true;
+            }
+        }
+        
+        return false;
+    };
+    int getCurrentPresetIndex(){
+        cout << "seq : " << curSeq << endl;
+        if (curSeq >= theSequences.size()){
+            cout << "ERROR: get preset" << endl;
+            return 0;
+        }
+        return theSequences[curSeq].getCurrentPresetIndex();
+        
+    };
+    int getSequenceNo(){
+        return curSeq;
+    }
+    
+    vector<Sequence> theSequences;
+    int curSeq;
+    int sequenceLength;
+    
+};
+//===============================================================================
+
 class SequenceController{
 public:
+  
     SequenceController(){
         makeSequences();
+        tempoInc = float(MAX_TEMPO - MIN_TEMPO) / float(NUM_TEMPO_STEPS);
+        curRun = 0;
     };
-    SequenceController(const vector<Preset>& presets)
-    : thePresets(presets)
-    
-    {
+
+    int stepForward(){
+        cout << "run : " << curRun << endl;
+        if (curRun >= theRuns.size()){
+            return -1;
+        }
+            
+        bool stepFound = theRuns[curRun].moveToNextStep();
+        if (stepFound){
+            return curRun;
+        }else{
+            curRun++;
+            if (curRun >= theRuns.size()){
+                cout << " END OF RUNS " << endl;
+                return -1;
+                
+            }else{
+                return -2; // in order to stop the metro, next tick will just start thjings agaaain
+            }
+        }
         
-        makeSequences();
-    };
-    Sequence getNextSequence();
-    int getNextPresetIndex(){
+        return false;
+        
+    }
+
+    int getCurrentPresetIndex(){
         
         // if end of sequence return something else so we can do something
         // if end of tempo ramp return something else
-        uint randomInt = rand() % 8;
-        return randomInt;
+        if (curRun >= theRuns.size()){
+            cout << "DAAAAHHH" << endl;
+            return -1;
+        }
+        int nextIndex = theRuns[curRun].getCurrentPresetIndex();
+
+        return nextIndex;
+    };
+    vector<int> getCurrentRunSeqAndStep(){
+        vector<int> rss;
+//        int r = curRun - theRuns.begin();
+//        int sq = (*curRun).getSequenceNo();
+//        int s = 4534534;
+//        rss.push_back(r);
+//        rss.push_back(sq);
+//        rss.push_back(s);
+        return rss;
         
-    };
+    }
 protected:
     void makeSequences(){
+        srand (time(NULL));
         
-        
-        for(int numInSequence = 1; numInSequence < MAX_TARGETS_IN_SEQUENCE; numInSequence++){
+
+        for(int numInSequence = 1; numInSequence <= MAX_TARGETS_IN_SEQUENCE; numInSequence++){
+            float curTempo = MIN_TEMPO;
+            vector<Sequence> seqsForRun;
+            
             for(int tempoLevel = 0; tempoLevel < NUM_TEMPO_STEPS; tempoLevel++){
                 
-                vector<int> indexSequence;
+                vector<int> stepsForSequence;
                 
                 // repeat the same tests for xtra practice?
                 for(int n=0; n < numInSequence; n++){
-                    int next = getRandomButNot(NUM_PRESETS,indexSequence);
-                    indexSequence.push_back(next);
+                    int next = getRandomButNot(NUM_PRESETS,stepsForSequence);
+                    stepsForSequence.push_back(next);
                     
                     cout << next << ",";
                 }
+                seqsForRun.push_back(Sequence(stepsForSequence, curTempo, true));
+                seqsForRun.push_back(Sequence(stepsForSequence, curTempo, false));
+                curTempo += tempoInc;
                 cout << endl;
+                
             }
+            
+            theRuns.push_back( Run(seqsForRun,numInSequence) );
+            
             cout << "---" << endl;
         }
     };
@@ -72,7 +203,7 @@
     int getRandomButNot(int max, vector<int> notThese){
         
         bool there = true;
-        uint randomInt = rand() % max;
+        int randomInt = rand() % max;
         
         if (notThese.size()){
         while(there){
@@ -84,11 +215,15 @@
         return randomInt;
         
     };
-    
+
     
 private:
-    const vector<Preset> thePresets;
-    vector<Sequence> theSequences;
+   
+    vector<Run> theRuns;
+    int curRun;
+    
+    float tempoInc;
 };
+//===============================================================================
 
 #endif /* defined(__riftathon__SequenceController__) */
--- a/TrainingMessageOrganiser.h	Mon Oct 20 14:12:23 2014 +0100
+++ b/TrainingMessageOrganiser.h	Mon Oct 20 19:36:39 2014 +0100
@@ -10,7 +10,6 @@
 #define __riftathon__TrainingMessageOrganiser__
 
 #include <iostream>
-#include "trainingTestController.h"
 #include "MessageOrganiser.h"
 #include "SequenceController.h"
 #include "globalVariables.h"
@@ -22,8 +21,6 @@
 public:
     void init( PDSynthWrapper& cs, PDSynthWrapper& ts){
         
-        trainingTestController = new TrainingTestController;
-        
         MessageOrganiser::init(cs,ts);
         
         TickListenerFunction callback;
@@ -70,15 +67,16 @@
     void onNextTick(int tickNumber){
         cout << "TICK " << tickNumber << endl;
         
-        if ( tickNumber % 2){
+        if ( !(tickNumber % 2)){
             // load next target preset
-            int i = sequenceController.getNextPresetIndex();
+            
+            int i = sequenceController.getCurrentPresetIndex();
             
             currentTargetPreset =  expPresetManager.getPreset(i);
             
             if (sequencePreview){
                 // show next target preset
-                presetIconPanel->setTextAndImage(currentTargetPreset->name, currentTargetPreset->getImage());
+                // presetIconPanel->setTextAndImage(currentTargetPreset->name, currentTargetPreset->getImage());
              
                 // show image
                 // show name
@@ -100,6 +98,7 @@
             if (sequencePreview){
                 // send target values again
                 targetSynth.setAllParams(currentTargetPreset->getValues());
+                setSlidersToTarget();
                 targetSynth.trigger();
                 
                 // flash the interface?
@@ -110,6 +109,18 @@
                 
             }
         }
+        
+        int run = sequenceController.stepForward();
+        if (run == -2){
+            // do finished run stuff, show summary
+            candidateSynth.stopMetronome();
+            cout << "FINISHED RUN" << endl;
+        }
+        if (run == -1){
+            // finished whole block
+            candidateSynth.stopMetronome();
+            cout << "FINISHED BLOCK" << endl;
+        }
     }
 
    
@@ -195,7 +206,6 @@
         }
     }
     SequenceController sequenceController;
-    TrainingTestController* trainingTestController;
     bool sequencePreview;
     Preset * currentTargetPreset;
     IconPanel* presetIconPanel;
--- a/globalVariables.h	Mon Oct 20 14:12:23 2014 +0100
+++ b/globalVariables.h	Mon Oct 20 19:36:39 2014 +0100
@@ -29,7 +29,7 @@
 #define ALTERNATION_SPEED 180 // ms that target / candidate sounds play
 // globles
 
-#define TOTAL_NUM_PARAMS 6
+#define TOTAL_NUM_PARAMS 8
 #define TARGET_SCORE_CC_BAND 6 // number of cc vals per target band in dartboard
 typedef enum {TOUCH_DOWN, TOUCH_MOVED, TOUCH_UP} touchType;
 typedef enum {INTRO,QUESTIONNAIRE, HELP, TEST_IN_PROGRESS, SCORE_AND_HINT, COUNT_DOWN, READY_FOR_NEXT} interfaceType;
--- a/presetManager.h	Mon Oct 20 14:12:23 2014 +0100
+++ b/presetManager.h	Mon Oct 20 19:36:39 2014 +0100
@@ -58,8 +58,6 @@
         double timemsd = [NSDate timeIntervalSinceReferenceDate];
         creationTime = (unsigned long long)(timemsd*1000);
 
-        cout << "Create preset sys time: " << creationTime << "\n";
-        
         //TODO color / texture?
         imageFileName = imageFile;
         if (imageFileName != ""){
--- a/presetManager.mm	Mon Oct 20 14:12:23 2014 +0100
+++ b/presetManager.mm	Mon Oct 20 19:36:39 2014 +0100
@@ -12,6 +12,20 @@
 
 extern EventLogger eventLogger;
 
+template <typename T>
+vector<T> makeVector8(T a1, T a2,T a3,T a4,T a5,T a6, T a7, T a8){
+    
+    vector<T> vec;
+    vec.push_back(a1);
+    vec.push_back(a2);
+    vec.push_back(a3);
+    vec.push_back(a4);
+    vec.push_back(a5);
+    vec.push_back(a6);
+    vec.push_back(a7);
+    vec.push_back(a8);
+    return vec;
+}
 
 //---------------------------------------------------------------------------
 Json::Value Preset::presetToJson(){
@@ -145,7 +159,7 @@
 }
 //-----------------------------------------------------------------------------
 void PresetManager::generatePresetSlot(const string name, const string imagefn){
-    vector<int> values; // empty
+    vector<int> values = makeVector8(0,0,0,0,45,0,0,0); // empty
     thePresets.push_back(new Preset(values, name, nextID, eventLogger.userName, eventLogger.deviceID, imagefn));
     
 }
--- a/trainingTestController.h	Mon Oct 20 14:12:23 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-//
-//  trainingController.h
-//  riftathon
-//
-//  Created by Robert Tubb on 10/10/2014.
-//
-// this controls the sequence fo events, for both the slider UI and the VR one
-// it sends and recieves messages from a wrapper, it doesn't care which interface you're using
-// it only cares about the sequence of events
-
-
-#ifndef __riftathon__trainingController__
-#define __riftathon__trainingController__
-#include "presetManager.h"
-#include <iostream>
-
-// include message types ( or use defines? ) these message type should be sendable by osc / midi
-class TrainingTestController {
-public:
-    int numParams;
-    vector<Preset> presetSequence;
-    
-    // inputs
-    void soundSubmitted();
-    void readyForNextSequence();
-    
-    // outputs
-    void presentTheSequence();
-    void showCountdown();
-    void startSearch();
-    
-    //
-    void makePresetSequence(int sequenceLength);
-    
-    Preset getRandomPreset();
-    
-    
-    
-};
-#endif /* defined(__riftathon__trainingController__) */
--- a/trainingTestController.mm	Mon Oct 20 14:12:23 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-//
-//  trainingController.mm
-//  riftathon
-//
-//  Created by Robert Tubb on 10/10/2014.
-//
-//
-
-#include "trainingTestController.h"