view ExpMessageOrganiser.mm @ 52:89944ab3e129 tip

fix oF linker errors ios8
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 03 Feb 2015 13:18:23 +0000
parents d0f6c5293d6a
children
line wrap: on
line source
//
//  expMessageOrganiser.cpp
//  riftathon
//
//  Created by Robert Tubb on 21/10/2014.
//
//

#include "ExpMessageOrganiser.h"

void ExpMessageOrganiser::init( PDSynthWrapper& cs, PDSynthWrapper& ts){
    numParamsToUse = TOTAL_NUM_PARAMS;
    MessageOrganiser::init(cs,ts);
    
}
void ExpMessageOrganiser::setup(controlPanelType whichInterfaceAreWeUsing){

    
    setupDefaultMapping(whichInterfaceAreWeUsing);
    expPresetManager.goToFirstEmptySlot();
    
    instructionPanel->setLabel("Find a sound\n that expresses:");
    instructionPanel->show();
    bottomPanel->show();
    bottomPanel->showAllElements();
    nextButt->hide();
    controlPanel->show();
    controlPanel->showValueIndicators(true);
    if (whichInterfaceAreWeUsing == LEAP6DOF){
        distanceSlider->show();
    }else{
        distanceSlider->hide();
    }
    
    okToGetMidi = true;
    controlPanel->setActive(true);
    showCurrentSlot();
}


vector<int> ExpMessageOrganiser::getMappingIDsFromSynths(){
    vector<int> index;
    for(int i = 0; i < numParamsToUse; i++){
        index.push_back(i);
    }
    vector<int> mids = candidateSynth.getMappingIDForIndices(index);
    
    return mids;
}

void ExpMessageOrganiser::showCurrentSlot(){

    if(expPresetManager.getCurrentPresetSlot() == NULL){
        // hide next button
        nextButt->hide();
        return;
    }
    presetIconPanel->setTextAndImage(expPresetManager.getCurrentPresetSlot()->name, expPresetManager.getCurrentPresetSlot()->getImage(),expPresetManager.getCurrentPresetSlot()->isFilled);
    
    //controlPanel->setIndicatorTexture(expPresetManager.getCurrentPresetSlot()->getImage());
    
    if(expPresetManager.getCurrentPresetSlot()->isFilled){
        // was already saved, show it
        loadPreset(expPresetManager.getCurrentPresetSlot()->name);
        controlPanel->setAndShowHint(expPresetManager.getCurrentPresetSlot()->getValues(), expPresetManager.getCurrentPresetSlot()->getImage());
        targetSynth.setAllParams(expPresetManager.getCurrentPresetSlot()->getValues());
        nextButt->show();
    }else{
        // nothing saved yet show default slidervals
        loadDefaultSound();
        nextButt->hide();
        controlPanel->showHint(false);
    }
}

void ExpMessageOrganiser::loadPreset(string pname){
    
    vector<int> values = expPresetManager.getPresetValuesForName(pname);
    if (values.size()){
        candidateSynth.setAllParams(values);
        setAllSlidersToValues(values);
    }else{
        cout << "ERROR, no preset found" << endl;
    }
}
void ExpMessageOrganiser::loadDefaultSound(){
    vector<int> values;
    for(int i = 0; i < TOTAL_NUM_PARAMS; i++){
        values.push_back(0);
    }

    candidateSynth.setAllParams(values);
    setAllSlidersToValues(values);

}


//-----------------------------------------------------------------------------

void ExpMessageOrganiser::buttonPressCallback(int mappingID, int value){
    
    
    if (mappingID == TRIGGER_CANDIDATE_ID){
        triggerCandidateSound();
        
        return;
    }
    if(mappingID == SAVE_PRESET_HIT){
        
        bool finished = expPresetManager.writeValuesToSlot(candidateSynth.getAllParamValues());
        if(finished){
            instructionPanel->setText("ALL PRESETS MADE\n Please go to menu and select TRAIN stage");
            instructionPanel->show();
            bottomPanel->show();
            bottomPanel->showOnlyElementNamed("MENU");
            okToGetMidi = false;
            controlPanel->hide();
            
        }else{
            showCurrentSlot();
        }
        nextButt->show();
        return;
    }
    
    if(mappingID == NEXT_PRESET_HIT){
        
        expPresetManager.nextSlot();
        showCurrentSlot();

        
        return;
    }
    
}