Mercurial > hg > tweakathon2ios
view TrainingMessageOrganiser.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 source
// // TrainingMessageOrganiser.h // riftathon // // Created by Robert Tubb on 17/10/2014. // // #ifndef __riftathon__TrainingMessageOrganiser__ #define __riftathon__TrainingMessageOrganiser__ #include <iostream> #include "MessageOrganiser.h" #include "SequenceController.h" #include "globalVariables.h" #include "IconPanel.h" extern ExplorePresetManager expPresetManager; class TrainingMessageOrganiser : public MessageOrganiser { public: void init( PDSynthWrapper& cs, PDSynthWrapper& ts){ MessageOrganiser::init(cs,ts); TickListenerFunction callback; callback = boost::bind(&TrainingMessageOrganiser::onNextTick, this, _1); candidateSynth.registerForTicks(callback); sequencePreview = true; } void setupDefaultMapping(){ vector<int> mappingIDsForChangeableParams = getMappingIDsFromSynths(); controlPanelType cpt = REVISITABLE; vector<controllerType> elemList; for(int i = 0; i < TOTAL_NUM_PARAMS; i++){ elemList.push_back(SLIDER); } vector<UIElement*> UIElemHandles = panel->generateControls(elemList, cpt); mapSlidersToParams(UIElemHandles, mappingIDsForChangeableParams); bottomPanel->show(); } vector<int> getMappingIDsFromSynths(){ vector<int> index; for(int i = 0; i < TOTAL_NUM_PARAMS; i++){ index.push_back(i); } vector<int> mids = candidateSynth.getMappingIDForIndices(index); return mids; } void setupNewTest(){ }; void setIconPanel(IconPanel * ip){ presetIconPanel = ip; } void onNextTick(int tickNumber){ cout << "TICK " << tickNumber << endl; 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(); } } 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; } } protected: void showUserHowTheyDid(){ // colour flash // distance ? // score } 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; vector<int> typeListLog; int i = 0; for(elit=elems.begin(); elit<elems.end();elit++){ if ( (*elit)->getType() == SLIDER){ if(i >= mids.size()){ cout << "ERROR ERROR: too many controls for mapping IDs: " << mids.size() << endl; } ButtronSlider* theSlider = (ButtronSlider*)(*elit); mapControlToParam((*elit), mids[i]); theSlider->setValueAndScale(candidateSynth.getParamValueForID(mids[i])); cout << "Hint Value " << targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])) << endl; theSlider->setHintValue(targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i]))); i++; typeListLog.push_back(int(SLIDER)); }else{ cout << "ERROR ERROR: ui type not handled my mapping function !" << endl; } } eventLogger.logEvent(CONTROL_LIST,typeListLog); }; void buttonPressCallback(int mappingID, int value){ if(mappingID == VOLUME_CHANGE_ID){ targetSynth.sendVolume(value); candidateSynth.sendVolume(value); return; } if (mappingID == TRIGGER_CANDIDATE_ID){ triggerCandidateSound(); // compare to target candidateSynth.startMetronome(); return; } if(mappingID == SAVE_PRESET_HIT){ expPresetManager.savePreset("blah", candidateSynth.getAllParamValues()); return; } if(mappingID == RECALL_PRESET_HIT){ loadPreset("blah"); return; } } SequenceController sequenceController; bool sequencePreview; Preset * currentTargetPreset; IconPanel* presetIconPanel; }; #endif /* defined(__riftathon__TrainingMessageOrganiser__) */