diff SequenceController.h @ 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
line wrap: on
line diff
--- 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__) */