view SequenceController.h @ 14:f83635861187

rewrote sequence controller. ticks show relevant UI modes. images show for preset textures (but greenish?)
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 21 Oct 2014 16:39:39 +0100
parents ab3e0e980c82
children 5cf2b80909fc
line wrap: on
line source
//
//  SequenceGenerator.h
//  riftathon
//
//  Created by Robert Tubb on 21/10/2014.
//
//

#ifndef __riftathon__SequenceGenerator__
#define __riftathon__SequenceGenerator__

#include <iostream>
#include "ofMain.h"

#define MIN_TARGETS_IN_SEQUENCE 3
#define MAX_TARGETS_IN_SEQUENCE 5
#define MIN_TEMPO   80
#define MAX_TEMPO   150
#define NUM_TEMPO_STEPS 16
#define NUM_PRESETS 8

class Step{
public:
    typedef enum {COUNT_IN, PREVIEW_DISPLAY, PREVIEW_PLAY, MATCHING_INTERACTION, MATCHING_RESULT} stepTypes;
// gui display
    bool showsTargetIcon;
    bool showsControlSettings;
    bool showsControlGuides;
    bool showsMatchResults;
// gui input
    bool allowsCandidateControl;
// sound
    bool playsTarget;
    bool playsCandidate;
// control flow
    stepTypes type;
    bool isPreview;
    
    int seqNumber;
    int runNumber;
    bool isLastOfSeq;
    bool isLastOfRun;
    bool playsMetroClick;
    int tempo;
// preset info
    int presetIndex;
    int numInSequence;
    bool isLastOfAll;
    
    Step(){
        type = COUNT_IN;
        
        showsTargetIcon = false;
        showsControlSettings = false;
        showsControlGuides = false;
        showsMatchResults = false;
        isPreview = false;
        
        allowsCandidateControl = false;
        playsTarget = false;
        playsCandidate = false;
        
        playsMetroClick = true;
        
        isLastOfSeq = false;
        isLastOfRun = false;
        isLastOfAll = false;
        presetIndex = -1;
        seqNumber = -1;
        runNumber = -1;
        
        tempo = MIN_TEMPO;
    }
    void setAsPreviewShower(){
        type = PREVIEW_DISPLAY;
        showsTargetIcon = true;
        showsControlSettings = true;
        showsMatchResults = false;
        isPreview = true;
        
        allowsCandidateControl = false;
        playsTarget = true;
        playsCandidate = false;
        playsMetroClick = false;
    }
    void setAsPreviewPlayer(){
        type = PREVIEW_PLAY;
        showsTargetIcon = true;
        showsControlSettings = false;
        showsMatchResults = false;
        isPreview = true;
        
        allowsCandidateControl = false;
        playsTarget = true;
        playsCandidate = false;
        
        playsMetroClick = false;
    }
    void setAsMatchingPreparer(){
        type = MATCHING_INTERACTION;
        showsTargetIcon = true;
        showsControlSettings = false;
        showsControlGuides = true;
        showsMatchResults = false;
        isPreview = false;
        
        allowsCandidateControl = true;
        playsTarget = false;
        playsCandidate = false;
        
        playsMetroClick = false;
    }
    void setAsMatchingReckoner(){
        type = MATCHING_RESULT;
        showsTargetIcon = true;
        showsControlSettings = false;
        showsControlGuides = true;
        showsMatchResults = true; // shows how far off you were?
        isPreview = false;
        
        allowsCandidateControl = false;
        playsTarget = false;
        playsCandidate = true;
        
        playsMetroClick = false;
    }
    
    float getTimeBetweenTicks(){
        return 1000. * (60.0/tempo);
    }
};

class SequenceController{
public:
    SequenceController(){
        tempoInc = float(MAX_TEMPO - MIN_TEMPO) / float(NUM_TEMPO_STEPS);
        generateSteps();
        setToStart();
    };
    Step getNextStep(){

        currentStep++;
        if ((*currentStep).isLastOfRun){
            // uh
        }
        if ((*currentStep).isLastOfSeq){
            
        }
        return (*currentStep);
        
    };
    void setToStart(){
        currentStep = steps.begin();
    }
    void stepForward(){
        currentStep++;
    };
    float getStartTickTime(){
        return 1000. * (60.0/MIN_TEMPO);
    }
private:
    void generateSteps(){
        srand (time(NULL));
        
        int run = 0;
        
        
        
        for(int numInSequence = MIN_TARGETS_IN_SEQUENCE; numInSequence <= MAX_TARGETS_IN_SEQUENCE; numInSequence++){
            generateCountIn(2);
            generateARun(run, numInSequence);

            steps.back().isLastOfRun = true;
            run++;
            cout << "-generate run finished-" << endl;
        }
        steps.back().isLastOfAll = true;
    };
    void generateCountIn(int countInLength){
        Step countStep;
        for (int i = 0; i < countInLength; i++){
            countStep.numInSequence = countInLength - i + 1;
            steps.push_back(countStep);
            
        }
    };
    void generateARun(int run, int numInSequence){
        float curTempo = MIN_TEMPO;
        int seqNo = 0;
        
        for(int tempoLevel = 0; tempoLevel < NUM_TEMPO_STEPS; tempoLevel++){
            
            vector<int> stepPreset;
            
            // get some random ints
            for(int n=0; n < numInSequence; n++){
                int nextPreset = getRandomButNot(NUM_PRESETS,stepPreset);
                stepPreset.push_back(nextPreset);
                cout << nextPreset << ",";
            }
            // put preview
            Step nextStep;
            
            int n = 0;
            for(auto si = stepPreset.begin(); si < stepPreset.end(); si++){
                // put loader
                
                nextStep.presetIndex = *si;
                nextStep.runNumber = run;
                nextStep.seqNumber = seqNo;
                nextStep.numInSequence = n;
                nextStep.tempo = curTempo;
                nextStep.setAsPreviewShower();
                steps.push_back(nextStep);
                
                // put player
//
//                nextStep.setAsPreviewPlayer();
//                steps.push_back(nextStep);
                n++;
            }
            // last one in sequence allows control ?
            steps.back().allowsCandidateControl = true;
            // put in matching sequence
            n = 0;
            for(auto si = stepPreset.begin(); si < stepPreset.end(); si++){
                // put loader
                
                nextStep.presetIndex = *si;
                nextStep.numInSequence = n;
                nextStep.setAsMatchingPreparer();
                steps.push_back(nextStep);
                
                // put player
                
                nextStep.setAsMatchingReckoner();
                steps.push_back(nextStep);
                n++;
            }
            
            steps.back().isLastOfSeq = true;
            curTempo += tempoInc;
            seqNo++;
            cout << endl;
            
        }
        
    }
    
    
    int getRandomButNot(int max, vector<int> notThese){
        
        bool there = true;
        int 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;
        
    };
    
    vector<Step> steps;
    vector<Step>::iterator currentStep;
    float tempoInc;
};

#endif /* defined(__riftathon__SequenceGenerator__) */