Mercurial > hg > tweakathon2ios
changeset 10:e25d2b1b185e
Sequence manager generates sequences of target sounds.
psudocode for onTick()
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 17 Oct 2014 19:23:30 +0100 |
parents | d5e928887f51 |
children | 91c3fba6e5b9 |
files | ExplorePresetManager.h SearchMessageOrganiser.h SequenceController.h TrainingMessageOrganiser.h |
diffstat | 4 files changed, 158 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/ExplorePresetManager.h Fri Oct 17 17:50:41 2014 +0100 +++ b/ExplorePresetManager.h Fri Oct 17 19:23:30 2014 +0100 @@ -87,6 +87,17 @@ void presentNextPreset(){ } + + Preset* getPreset(int index){ + + if (index >= thePresets.size()){ + cout << "ERROR: index exceeds number of presets" << endl; + return NULL; + }else{ + return thePresets[index]; + + } + }; protected: int filledSlots; string presetSlotFilename;
--- a/SearchMessageOrganiser.h Fri Oct 17 17:50:41 2014 +0100 +++ b/SearchMessageOrganiser.h Fri Oct 17 19:23:30 2014 +0100 @@ -219,28 +219,9 @@ showingHint = true; } } - if(mappingID == SAVE_PRESET_HIT){ - expPresetManager.savePreset("blah", candidateSynth.getAllParamValues()); - - } - if(mappingID == RECALL_PRESET_HIT){ - - loadPreset("blah"); - //candidateSynth.startMetronome(); - - } + } - //TODO move this - void loadPreset(string pname){ - - vector<int> values = expPresetManager.recallPreset(pname); - if (values.size()){ - candidateSynth.setAllParams(values); - setAllSlidersToValues(values); - }else{ - cout << "ERROR, no preset found" << endl; - } - } + // called from UI
--- a/SequenceController.h Fri Oct 17 17:50:41 2014 +0100 +++ b/SequenceController.h Fri Oct 17 19:23:30 2014 +0100 @@ -12,6 +12,13 @@ #include <iostream> #include "presetManager.h" +#define MAX_TARGETS_IN_SEQUENCE 8 +#define MIN_TEMPO 80 +#define MAX_TEMPO 200 +#define NUM_TEMPO_STEPS 8 +#define NUM_PRESETS 16 + + class Sequence{ int tempo; vector<Preset *> presetSequence; @@ -19,16 +26,66 @@ }; -class SequenceControler{ +class SequenceController{ +public: + SequenceController(){ + makeSequences(); + }; + SequenceController(const vector<Preset>& presets) + : thePresets(presets) - SequenceControler(const vector<Preset>& presets); + { + + makeSequences(); + }; + Sequence getNextSequence(); + int getNextPresetIndex(){ + + // if end of sequence return something else so we can do something + // if end of tempo ramp return something else + + }; +protected: + void makeSequences(){ + + + for(int numInSequence = 1; numInSequence < MAX_TARGETS_IN_SEQUENCE; numInSequence++){ + for(int tempoLevel = 0; tempoLevel < NUM_TEMPO_STEPS; tempoLevel++){ + + vector<int> indexSequence; + + // repeat the same tests for xtra practice? + for(int n=0; n < numInSequence; n++){ + int next = getRandomButNot(NUM_PRESETS,indexSequence); + indexSequence.push_back(next); + + cout << next << ","; + } + cout << endl; + } + cout << "---" << endl; + } + }; - void makeSequences(); + int getRandomButNot(int max, vector<int> notThese){ + + bool there = true; + uint randomInt = rand() % max; + + if (notThese.size()){ + while(there){ + randomInt = rand() % max; + vector<int>::iterator result = std::find(notThese.begin(), notThese.end(), randomInt); + there = (result != notThese.end()); + } + } + return randomInt; + + }; - Sequence getNextSequence(); private: - const vector<Preset>& thePresets; + const vector<Preset> thePresets; vector<Sequence> theSequences; };
--- a/TrainingMessageOrganiser.h Fri Oct 17 17:50:41 2014 +0100 +++ b/TrainingMessageOrganiser.h Fri Oct 17 19:23:30 2014 +0100 @@ -12,6 +12,10 @@ #include <iostream> #include "trainingTestController.h" #include "MessageOrganiser.h" +#include "SequenceController.h" + +extern ExplorePresetManager expPresetManager; + class TrainingMessageOrganiser : public MessageOrganiser { public: void init( PDSynthWrapper& cs, PDSynthWrapper& ts){ @@ -52,8 +56,73 @@ }; + + void onNextTick(int tickNumber){ + if ( tickNumber % 2){ + // load next target preset + int i = sequenceController.getNextPresetIndex(); + + currentTargetPreset = expPresetManager.getPreset(i); + + if (sequencePreview){ + // show next target preset + + // 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()); + targetSynth.trigger(); + + // flash the interface? + }else{ + // else the user should be hitting the play button + + } + } + } + protected: + + void loadPreset(string pname){ + + vector<int> values = expPresetManager.recallPreset(pname); + if (values.size()){ + candidateSynth.setAllParams(values); + setAllSlidersToValues(values); + }else{ + cout << "ERROR, no preset found" << endl; + } + } + + + void showATargetPresetWithGuide(Preset * p){ // this is when demoing the sequence to the user + // p.show icon + vector<int> values = p->getValues(); + if (values.size()){ + candidateSynth.setAllParams(values); + setAllSlidersToValues(values); + }else{ + cout << "WARNING, preset to show had no values" << endl; + } + } + void mapSlidersToParams(vector<UIElement*> elems, vector<int> mids){ vector<UIElement*>::iterator elit; @@ -86,15 +155,27 @@ if(mappingID == VOLUME_CHANGE_ID){ targetSynth.sendVolume(value); candidateSynth.sendVolume(value); - + return; } if (mappingID == TRIGGER_CANDIDATE_ID){ triggerCandidateSound(); + // compare to target + return; + } + if(mappingID == SAVE_PRESET_HIT){ + expPresetManager.savePreset("blah", candidateSynth.getAllParamValues()); + return; + } + if(mappingID == RECALL_PRESET_HIT){ + + loadPreset("blah"); return; } } - + SequenceController sequenceController; TrainingTestController* trainingTestController; + bool sequencePreview; + Preset * currentTargetPreset; }; #endif /* defined(__riftathon__TrainingMessageOrganiser__) */