Mercurial > hg > tweakathon2ios
comparison 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 |
comparison
equal
deleted
inserted
replaced
12:af71bf84660f | 13:ab3e0e980c82 |
---|---|
10 #define __riftathon__SequenceController__ | 10 #define __riftathon__SequenceController__ |
11 | 11 |
12 #include <iostream> | 12 #include <iostream> |
13 #include "presetManager.h" | 13 #include "presetManager.h" |
14 | 14 |
15 #define MAX_TARGETS_IN_SEQUENCE 8 | 15 #define MAX_TARGETS_IN_SEQUENCE 2 |
16 #define MIN_TEMPO 80 | 16 #define MIN_TEMPO 80 |
17 #define MAX_TEMPO 200 | 17 #define MAX_TEMPO 200 |
18 #define NUM_TEMPO_STEPS 8 | 18 #define NUM_TEMPO_STEPS 3 |
19 #define NUM_PRESETS 16 | 19 #define NUM_PRESETS 16 |
20 | 20 |
21 //=============================================================================== | |
22 | |
21 | 23 |
22 class Sequence{ | 24 class Sequence{ |
23 int tempo; | 25 public: |
24 vector<Preset *> presetSequence; | 26 Sequence(vector<int> si, int t, bool pv){ |
25 | 27 tempo = t; |
28 presetSequence = si; | |
29 isSequencePreview = pv; | |
30 curStep = 0; | |
31 }; | |
32 bool moveToNextStep(){ | |
33 curStep++; | |
34 | |
35 if (curStep >= presetSequence.size()){ | |
36 return false; | |
37 }else{ | |
38 return true; | |
39 } | |
40 }; | |
41 int getCurrentPresetIndex(){ | |
42 cout << "step : " << curStep << endl; | |
43 if (curStep >= presetSequence.size()){ | |
44 cout << "ERROR: off end of seq" << endl; | |
45 return 0; | |
46 } | |
47 int i = presetSequence[curStep]; | |
48 if(i < 0){ | |
49 cout << "ERROR: negative index" << endl; | |
50 } | |
51 return i; | |
52 | |
53 }; | |
54 int getStepNo(){ | |
55 return curStep; | |
56 } | |
57 float tempo; | |
58 | |
59 bool isSequencePreview; // true if demoing the seq to the user, false if user is matching a seq | |
60 vector<int> presetSequence; | |
61 int curStep; | |
26 | 62 |
27 }; | 63 }; |
64 | |
65 //=============================================================================== | |
66 | |
67 class Run{ | |
68 public: | |
69 Run(vector<Sequence> vs, int sl){ | |
70 theSequences = vs; | |
71 sequenceLength = sl; | |
72 curSeq = 0; | |
73 }; | |
74 bool moveToNextStep(){ | |
75 if (curSeq >= theSequences.size()){ | |
76 return false; | |
77 } | |
78 | |
79 bool stepFound = theSequences[curSeq].moveToNextStep(); | |
80 if (stepFound){ | |
81 return true; | |
82 }else{ | |
83 curSeq++; | |
84 if (curSeq >= theSequences.size()){ | |
85 return false; | |
86 | |
87 }else{ | |
88 return true; | |
89 } | |
90 } | |
91 | |
92 return false; | |
93 }; | |
94 int getCurrentPresetIndex(){ | |
95 cout << "seq : " << curSeq << endl; | |
96 if (curSeq >= theSequences.size()){ | |
97 cout << "ERROR: get preset" << endl; | |
98 return 0; | |
99 } | |
100 return theSequences[curSeq].getCurrentPresetIndex(); | |
101 | |
102 }; | |
103 int getSequenceNo(){ | |
104 return curSeq; | |
105 } | |
106 | |
107 vector<Sequence> theSequences; | |
108 int curSeq; | |
109 int sequenceLength; | |
110 | |
111 }; | |
112 //=============================================================================== | |
28 | 113 |
29 class SequenceController{ | 114 class SequenceController{ |
30 public: | 115 public: |
116 | |
31 SequenceController(){ | 117 SequenceController(){ |
32 makeSequences(); | 118 makeSequences(); |
33 }; | 119 tempoInc = float(MAX_TEMPO - MIN_TEMPO) / float(NUM_TEMPO_STEPS); |
34 SequenceController(const vector<Preset>& presets) | 120 curRun = 0; |
35 : thePresets(presets) | 121 }; |
36 | 122 |
37 { | 123 int stepForward(){ |
38 | 124 cout << "run : " << curRun << endl; |
39 makeSequences(); | 125 if (curRun >= theRuns.size()){ |
40 }; | 126 return -1; |
41 Sequence getNextSequence(); | 127 } |
42 int getNextPresetIndex(){ | 128 |
129 bool stepFound = theRuns[curRun].moveToNextStep(); | |
130 if (stepFound){ | |
131 return curRun; | |
132 }else{ | |
133 curRun++; | |
134 if (curRun >= theRuns.size()){ | |
135 cout << " END OF RUNS " << endl; | |
136 return -1; | |
137 | |
138 }else{ | |
139 return -2; // in order to stop the metro, next tick will just start thjings agaaain | |
140 } | |
141 } | |
142 | |
143 return false; | |
144 | |
145 } | |
146 | |
147 int getCurrentPresetIndex(){ | |
43 | 148 |
44 // if end of sequence return something else so we can do something | 149 // if end of sequence return something else so we can do something |
45 // if end of tempo ramp return something else | 150 // if end of tempo ramp return something else |
46 uint randomInt = rand() % 8; | 151 if (curRun >= theRuns.size()){ |
47 return randomInt; | 152 cout << "DAAAAHHH" << endl; |
48 | 153 return -1; |
49 }; | 154 } |
155 int nextIndex = theRuns[curRun].getCurrentPresetIndex(); | |
156 | |
157 return nextIndex; | |
158 }; | |
159 vector<int> getCurrentRunSeqAndStep(){ | |
160 vector<int> rss; | |
161 // int r = curRun - theRuns.begin(); | |
162 // int sq = (*curRun).getSequenceNo(); | |
163 // int s = 4534534; | |
164 // rss.push_back(r); | |
165 // rss.push_back(sq); | |
166 // rss.push_back(s); | |
167 return rss; | |
168 | |
169 } | |
50 protected: | 170 protected: |
51 void makeSequences(){ | 171 void makeSequences(){ |
52 | 172 srand (time(NULL)); |
53 | 173 |
54 for(int numInSequence = 1; numInSequence < MAX_TARGETS_IN_SEQUENCE; numInSequence++){ | 174 |
175 for(int numInSequence = 1; numInSequence <= MAX_TARGETS_IN_SEQUENCE; numInSequence++){ | |
176 float curTempo = MIN_TEMPO; | |
177 vector<Sequence> seqsForRun; | |
178 | |
55 for(int tempoLevel = 0; tempoLevel < NUM_TEMPO_STEPS; tempoLevel++){ | 179 for(int tempoLevel = 0; tempoLevel < NUM_TEMPO_STEPS; tempoLevel++){ |
56 | 180 |
57 vector<int> indexSequence; | 181 vector<int> stepsForSequence; |
58 | 182 |
59 // repeat the same tests for xtra practice? | 183 // repeat the same tests for xtra practice? |
60 for(int n=0; n < numInSequence; n++){ | 184 for(int n=0; n < numInSequence; n++){ |
61 int next = getRandomButNot(NUM_PRESETS,indexSequence); | 185 int next = getRandomButNot(NUM_PRESETS,stepsForSequence); |
62 indexSequence.push_back(next); | 186 stepsForSequence.push_back(next); |
63 | 187 |
64 cout << next << ","; | 188 cout << next << ","; |
65 } | 189 } |
190 seqsForRun.push_back(Sequence(stepsForSequence, curTempo, true)); | |
191 seqsForRun.push_back(Sequence(stepsForSequence, curTempo, false)); | |
192 curTempo += tempoInc; | |
66 cout << endl; | 193 cout << endl; |
194 | |
67 } | 195 } |
196 | |
197 theRuns.push_back( Run(seqsForRun,numInSequence) ); | |
198 | |
68 cout << "---" << endl; | 199 cout << "---" << endl; |
69 } | 200 } |
70 }; | 201 }; |
71 | 202 |
72 int getRandomButNot(int max, vector<int> notThese){ | 203 int getRandomButNot(int max, vector<int> notThese){ |
73 | 204 |
74 bool there = true; | 205 bool there = true; |
75 uint randomInt = rand() % max; | 206 int randomInt = rand() % max; |
76 | 207 |
77 if (notThese.size()){ | 208 if (notThese.size()){ |
78 while(there){ | 209 while(there){ |
79 randomInt = rand() % max; | 210 randomInt = rand() % max; |
80 vector<int>::iterator result = std::find(notThese.begin(), notThese.end(), randomInt); | 211 vector<int>::iterator result = std::find(notThese.begin(), notThese.end(), randomInt); |
82 } | 213 } |
83 } | 214 } |
84 return randomInt; | 215 return randomInt; |
85 | 216 |
86 }; | 217 }; |
87 | 218 |
88 | 219 |
89 private: | 220 private: |
90 const vector<Preset> thePresets; | 221 |
91 vector<Sequence> theSequences; | 222 vector<Run> theRuns; |
223 int curRun; | |
224 | |
225 float tempoInc; | |
92 }; | 226 }; |
227 //=============================================================================== | |
93 | 228 |
94 #endif /* defined(__riftathon__SequenceController__) */ | 229 #endif /* defined(__riftathon__SequenceController__) */ |