Mercurial > hg > tweakathon2ios
view MessageOrganiser.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 | 8124f46eda65 |
children | 8eb530e0601b |
line wrap: on
line source
#include "MessageOrganiser.h" void MessageOrganiser::init(PDSynthWrapper& cs, PDSynthWrapper& ts){ candidateSynth = cs; targetSynth = ts; onlyChangeCandidateOnTrigger = true; } // could template for ui element type?? void MessageOrganiser::mapButtonToAction(UIElement* control, int mappingID){ UICallbackFunction callbackF; callbackF = boost::bind(&MessageOrganiser::buttonPressCallback, this, _1,_2); control->addHandler(callbackF, mappingID); currentMapping.insert(std::pair<int,UIElement*>(mappingID,control)); } void MessageOrganiser::setControlPanel(SliderPanel* p){ // a bit specific?? panel = p; }; void MessageOrganiser::setBottomPanel(ButtonPanel * ntb){ bottomPanel = ntb; }; void MessageOrganiser::setIconPanel(IconPanel * ip){ presetIconPanel = ip; } void MessageOrganiser::setBox(Leap6DBox * box){ box6D = box; } void MessageOrganiser::setInstructionPanel(TextPanel * ip){ instructionPanel = ip; instructionPanel->show(); } //----------------------------------------------------------------------------- void MessageOrganiser::hideMyPanels(){ presetIconPanel->hide(); instructionPanel->hide(); bottomPanel->hide(); panel->hide(); } void MessageOrganiser::showMyPanels(){ presetIconPanel->show(); instructionPanel->show(); bottomPanel->show(); panel->show(); } void MessageOrganiser::triggerCandidateSound(){ // log event sendSynthValuesAgain(); candidateSynth.trigger(); eventLogger.logEvent(CANDIDATE_PLAYED); // flash panel? panel->flash(); } void MessageOrganiser::paramChangeCallback(int mappingID, int value){ if(onlyChangeCandidateOnTrigger){ candidateSynth.paramChangeCallback(mappingID, value, false); }else{ candidateSynth.paramChangeCallback(mappingID, value, true); } vector<int> evtData; evtData.push_back(mappingID); // or just index? evtData.push_back(value); eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData); }; void MessageOrganiser::sendSynthValuesAgain(){ candidateSynth.sendAllParams(); targetSynth.sendAllParams(); }; void MessageOrganiser::setAllSlidersToValues(vector<int> values){ for(int i = 0; i < values.size(); i++){ setUIToParam(i, values[i]); } } // we want to set UI object void MessageOrganiser::setUIToParam(int index, int value){ // e.g. from MIDI incoming, will handle both box and sliders... // theXY->setValueAndScale(candidateSynth.getParamValueForID(mids[i]), candidateSynth.getParamValueForID(mids[i+1])); UIElement* elem; // get the element if(panel->subElements.size() <= index){ cout << "ERROR: index out of range for num sliders" << endl; return; } elem = panel->subElements[index]; if ( elem->getType() == SLIDER){ ButtronSlider* theSlider = (ButtronSlider*)elem; theSlider->setValueAndScale(value); }else{ cout << "ERROR ERROR: ui type not handled by setUIToParam!" << endl; } }; void MessageOrganiser::mapControlToParam(UIElement* control, int mappingID){ UICallbackFunction callbackF; callbackF = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2); control->addHandler(callbackF, mappingID); // put in our map so we can send param values to gui currentMapping.insert(std::pair<int,UIElement*>(mappingID,control)); cout << " Mapped control to ID: " << mappingID << "Name: " << candidateSynth.getNameForMappingID(mappingID) << endl; control->setLabel(candidateSynth.getNameForMappingID(mappingID)); }; //----------------------------------------------------------------------------- void MessageOrganiser::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 MessageOrganiser::mapXYToParams(ButtronXY* control, int mappingIDX, int mappingIDY){ UICallbackFunction callback; callback = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2); control->addHandler(callback, mappingIDX, mappingIDY); // put in our map so we can send param values to gui //currentMapping.insert(std::pair<int,UIElement*>(mappingID,control)); cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl; cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl; control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY)); }; void MessageOrganiser::mapControlToParam(UIElement* control, string paramName){ // get mapping ID from synth int mappingID = candidateSynth.getMappingIDForName(paramName); mapControlToParam(control, mappingID); control->setLabel(paramName); }; void MessageOrganiser::buttonPressCallback(int mappingID, int value){ }; void MessageOrganiser::setSlidersToTarget(){ // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh // get target values // set ui vector<int> vals = targetSynth.getAllParamValues(); for(int i=1; i < vals.size(); i++){ setUIToParam(i, vals[i]); } } void MessageOrganiser::showTargetAsHints(){ // int i = 0; // vector<int> vals = targetSynth.getAllParamValues(); // for(auto elit=elems.begin(); elit<elems.end();elit++){ // ButtronSlider* theSlider = (ButtronSlider*)(*elit); // theSlider->setHintValue(vals[i]); // i++; // } } void MessageOrganiser::setSlidersToDefault(){ for(int i=1; i < candidateSynth.getNumParams(); i++){ setUIToParam(i, 0); } } void MessageOrganiser::setCandidateAndSlidersToRandom(){ vector<int> rands; for(int i = 0; i < candidateSynth.getNumParams(); i++){ rands.push_back(rand() % 127); } setAllSlidersToValues(rands); candidateSynth.setAllParams(rands); }