view ExpMessageOrganiser.mm @ 24:b339acf124df

new box - not really rendering properly
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 27 Oct 2014 17:40:05 +0000
parents 055e0c43afe5
children 27cdf475aa4b
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(){
    // do stuff like load first slot
    setupDefaultMapping();
    expPresetManager.goToFirstEmptySlot();
    showCurrentSlot();
    instructionPanel->setLabel("Find a sound\n that expresses:");
    instructionPanel->show();
    okToGetMidi = true;
}


void ExpMessageOrganiser::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> 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
        return;
    }
    presetIconPanel->setTextAndImage(expPresetManager.getCurrentPresetSlot()->name, expPresetManager.getCurrentPresetSlot()->getImage(),expPresetManager.getCurrentPresetSlot()->isFilled);
    if(expPresetManager.getCurrentPresetSlot()->isFilled){
        // show this preset on sliders
        loadPreset(expPresetManager.getCurrentPresetSlot()->name);
    }else{
        // show default slidervals
        loadDefaultSound();
        
    }
}

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->setLabel("ALL PRESETS MADE");
        }else{
            showCurrentSlot();
        }
        
        return;
    }
    
}

void ExpMessageOrganiser::midiFromLeap(int ctl_num, int ctl_val){


    if (!okToGetMidi){
        return;
    }
    vector<int> mids = candidateSynth.getAllMappingIDs();
    if (ctl_num >= mids.size() || ctl_num < 0) return;
    
    candidateSynth.paramChangeCallback(mids[ctl_num], ctl_val);
    
    setUIToParam(ctl_num, ctl_val);
    
    vector<int> evtData;
    evtData.push_back(mids[ctl_num]); // or just index?
    evtData.push_back(ctl_val);
    
    eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData);
    
}