view TrainingMessageOrganiser.h @ 19:bd23c1b922be

Explore preset saving slot stuff kind of works.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 22 Oct 2014 16:29:31 +0100
parents 2a7320a8cbed
children 5cf2b80909fc
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:
    int numParamsToUse;
    void init( PDSynthWrapper& cs, PDSynthWrapper& ts){
        
        MessageOrganiser::init(cs,ts);
        
        TickListenerFunction callback;
        callback = boost::bind(&TrainingMessageOrganiser::onNextTick, this, _1);
        candidateSynth.registerForTicks(callback);
        
        numParamsToUse = TOTAL_NUM_PARAMS;
        
    }
    
    void setupDefaultMapping(){
        vector<int> mappingIDsForChangeableParams = getMappingIDsFromSynths();
        
        controlPanelType cpt = REVISITABLE;
        vector<controllerType> elemList;
        for(int i = 0; i < numParamsToUse; 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 < numParamsToUse; i++){
            index.push_back(i);
        }
        vector<int> mids = candidateSynth.getMappingIDForIndices(index);
        
        return mids;
    }


//-----------------------------------------------------------------------
    void displayInstructions(Step s){
        

        if (s.type == Step::COUNT_IN){
            instructionPanel->setText("GET READY");
        }
        if (s.type == Step::PREVIEW_DISPLAY){
            instructionPanel->setText("MEMORISE");
            panel->setColor(ofColor(0,0,0));
        }
        if (s.type == Step::PREVIEW_PLAY){
            instructionPanel->setText("MEMORISE");
            panel->setColor(ofColor(0,0,0));
        }
        if (s.type == Step::MATCHING_INTERACTION){
            instructionPanel->setText("MATCH:");
            panel->setColor(ofColor(100,0,0));
        }
        if (s.type == Step::MATCHING_RESULT){
            instructionPanel->setText("RESULT");
            panel->setColor(ofColor(0,100,0));
        }
    }
//-----------------------------------------------------------------------
    void onNextTick(int tickNumber){
        cout << "TICK " << tickNumber << endl;

        // only first beat in bar is active one
        if ( tickNumber % 4  != 0){
            return;
        }
        // load next target preset
        
        Step newStep = sequenceController.getNextStep();
        displayInstructions(newStep);
        
        if(newStep.isLastOfAll){
            // do finished run stuff, show summary
            candidateSynth.stopMetronome();
            cout << "FINISHED BLOCK" << endl;
        }
        if(newStep.isLastOfRun){
            // do finished run stuff, show summary
            candidateSynth.stopMetronome();
            cout << "FINISHED RUN" << endl;
        }
        
        float t = newStep.getTimeBetweenTicks();
        candidateSynth.setMetroTime(t);
        
        if(newStep.type == Step::COUNT_IN){
            // count in
            return;
        }
        
        if(newStep.presetIndex >= 0 && newStep.presetIndex <= 8){
            currentTargetPreset =  expPresetManager.getPresetAtIndex(newStep.presetIndex);
        }
        
        if(newStep.showsTargetIcon){
            bool showTick = true;
            presetIconPanel->setTextAndImage(currentTargetPreset->name, currentTargetPreset->getImage(), showTick);
            presetIconPanel->show();
        }else{
            presetIconPanel->hide();
        }
        
        if(newStep.showsControlSettings){
            targetSynth.setAllParams(currentTargetPreset->getValues());
            setSlidersToTarget();
            
        }else{
            //setSlidersToDefault();
            
        }
        
        if(newStep.playsTarget){
            targetSynth.setAllParams(currentTargetPreset->getValues());
            targetSynth.trigger();
        }
        
        if(newStep.playsCandidate){
            triggerCandidateSound();
        }
        
        if(newStep.allowsCandidateControl){
            panel->setActive(true);
        }else{
            panel->setActive(false);
        }
        
        if(newStep.showsMatchResults){
            // do something
        }
        
        if(newStep.showsControlGuides){
            
            panel->setHintValues(currentTargetPreset->getValues());
            panel->showHint(true);
        }else{
            panel->showHint(false);
        }
        
    }

    //-----------------------------------------------------------------------
protected:
    void showUserHowTheyDid(){
        // colour flash
        // distance ?
        // score
        
    }

    
    
    //-----------------------------------------------------------------------
    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 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.setMetroTime(sequenceController.getStartTickTime());
            candidateSynth.startMetronome();
            return;
        }

    }
    //-----------------------------------------------------------------------------
    
    SequenceController sequenceController;

    Preset * currentTargetPreset;

};
#endif /* defined(__riftathon__TrainingMessageOrganiser__) */