# HG changeset patch # User Robert Tubb # Date 1413986414 -3600 # Node ID 36cdb73691dae3be3929ee2a627592a083e91c37 # Parent 2a7320a8cbed00a000c0e150a347bd05f3a63ef1 PIMPL speed compile? eventlogger now just saves as it goes more refactoring diff -r 2a7320a8cbed -r 36cdb73691da ExpMessageOrganiser.h --- a/ExpMessageOrganiser.h Tue Oct 21 18:58:25 2014 +0100 +++ b/ExpMessageOrganiser.h Wed Oct 22 15:00:14 2014 +0100 @@ -19,87 +19,15 @@ class ExpMessageOrganiser : public MessageOrganiser { public: - void init( PDSynthWrapper& cs, PDSynthWrapper& ts){ - numParamsToUse = TOTAL_NUM_PARAMS; - MessageOrganiser::init(cs,ts); - - - } - void setup(){ - // do stuff like load first slot - setupDefaultMapping(); - expPresetManager.goToFirstEmptySlot(); - showCurrentSlot(); - - - } - - - void setupDefaultMapping(){ - vector mappingIDsForChangeableParams = getMappingIDsFromSynths(); - - controlPanelType cpt = REVISITABLE; - vector elemList; - for(int i = 0; i < numParamsToUse; i++){ - elemList.push_back(SLIDER); - } - - vector UIElemHandles = panel->generateControls(elemList, cpt); - - mapSlidersToParams(UIElemHandles, mappingIDsForChangeableParams); - - bottomPanel->show(); - } - - vector getMappingIDsFromSynths(){ - vector index; - for(int i = 0; i < numParamsToUse; i++){ - index.push_back(i); - } - vector mids = candidateSynth.getMappingIDForIndices(index); - - return mids; - } - - void showCurrentSlot(){ - currentPresetSlot = expPresetManager.getCurrentPresetSlot(); - presetIconPanel->setTextAndImage(currentPresetSlot->name, currentPresetSlot->getImage()); - } - - void loadPreset(string pname){ - - vector values = expPresetManager.recallPreset(pname); - if (values.size()){ - candidateSynth.setAllParams(values); - setAllSlidersToValues(values); - }else{ - cout << "ERROR, no preset found" << endl; - } - } - - - + void init( PDSynthWrapper& cs, PDSynthWrapper& ts); + void setup(); + void setupDefaultMapping(); + vector getMappingIDsFromSynths(); + void showCurrentSlot(); + void loadPreset(string pname); //----------------------------------------------------------------------------- - void buttonPressCallback(int mappingID, int value){ - - - if (mappingID == TRIGGER_CANDIDATE_ID){ - triggerCandidateSound(); - - return; - } - if(mappingID == SAVE_PRESET_HIT){ - - expPresetManager.writeValuesToSlot(candidateSynth.getAllParamValues()); - showCurrentSlot(); - - return; - } - - } - - + void buttonPressCallback(int mappingID, int value); private: Preset* currentPresetSlot; int numParamsToUse; diff -r 2a7320a8cbed -r 36cdb73691da ExpMessageOrganiser.mm --- a/ExpMessageOrganiser.mm Tue Oct 21 18:58:25 2014 +0100 +++ b/ExpMessageOrganiser.mm Wed Oct 22 15:00:14 2014 +0100 @@ -7,3 +7,83 @@ // #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(); + + +} + + +void ExpMessageOrganiser::setupDefaultMapping(){ + vector mappingIDsForChangeableParams = getMappingIDsFromSynths(); + + controlPanelType cpt = REVISITABLE; + vector elemList; + for(int i = 0; i < numParamsToUse; i++){ + elemList.push_back(SLIDER); + } + + vector UIElemHandles = panel->generateControls(elemList, cpt); + + mapSlidersToParams(UIElemHandles, mappingIDsForChangeableParams); + + bottomPanel->show(); +} + +vector ExpMessageOrganiser::getMappingIDsFromSynths(){ + vector index; + for(int i = 0; i < numParamsToUse; i++){ + index.push_back(i); + } + vector mids = candidateSynth.getMappingIDForIndices(index); + + return mids; +} + +void ExpMessageOrganiser::showCurrentSlot(){ + currentPresetSlot = expPresetManager.getCurrentPresetSlot(); + presetIconPanel->setTextAndImage(currentPresetSlot->name, currentPresetSlot->getImage()); +} + +void ExpMessageOrganiser::loadPreset(string pname){ + + vector values = expPresetManager.getPresetValuesForName(pname); + if (values.size()){ + candidateSynth.setAllParams(values); + setAllSlidersToValues(values); + }else{ + cout << "ERROR, no preset found" << endl; + } +} + + + +//----------------------------------------------------------------------------- + +void ExpMessageOrganiser::buttonPressCallback(int mappingID, int value){ + + + if (mappingID == TRIGGER_CANDIDATE_ID){ + triggerCandidateSound(); + + return; + } + if(mappingID == SAVE_PRESET_HIT){ + + expPresetManager.writeValuesToSlot(candidateSynth.getAllParamValues()); + showCurrentSlot(); + + return; + } + +} \ No newline at end of file diff -r 2a7320a8cbed -r 36cdb73691da ExplorePresetManager.h --- a/ExplorePresetManager.h Tue Oct 21 18:58:25 2014 +0100 +++ b/ExplorePresetManager.h Wed Oct 22 15:00:14 2014 +0100 @@ -15,100 +15,95 @@ #include #include "presetManager.h" +#include "eventLogger.h" +#define MAX_PRESETS 8 -#define MAX_PRESETS 8 +extern EventLogger eventLogger; + + +template +vector makeVector8(T a1, T a2,T a3,T a4,T a5,T a6, T a7, T a8){ + + vector vec; + vec.push_back(a1); + vec.push_back(a2); + vec.push_back(a3); + vec.push_back(a4); + vec.push_back(a5); + vec.push_back(a6); + vec.push_back(a7); + vec.push_back(a8); + return vec; +} +// preset slot is a preset with no values, waiting to become a real preset + +class PresetSlot : public Preset{ +public: + bool isFilled; + + + PresetSlot(vector defaults, + string aname, + int aID, + string un, + unsigned int uid, + string imageFile = "") + : Preset(defaults, aname, aID, un, uid, imageFile) + + { + isFilled = false; + + name = aname; + creatorUserName = un; + creatorDeviceID = uid; + double timemsd = [NSDate timeIntervalSinceReferenceDate]; + creationTime = (unsigned long long)(timemsd*1000); + + //TODO color / texture? + imageFileName = imageFile; + if (imageFileName != ""){ + iconView = new PresetIconView(name, imageFileName); + } + + }; + + void setValues(vector v){ + CCValues = v; + double timemsd = [NSDate timeIntervalSinceReferenceDate]; + creationTime = (unsigned long long)(timemsd*1000); + if (CCValues.size()){ + isFilled = true; + + }else{ + isFilled = false; + } + } + +}; +//===================================================================================== +//===================================================================================== class ExplorePresetManager : public PresetManager { public: - void onAppLoad(){ - // check for already saved stuff - startLoadAll(); - - if (thePresets.size() != MAX_PRESETS){ - - initPresetSlots(); - } - - } - void initPresetSlots(){ - - presetSlotFilename = ofFilePath::getAbsolutePath(ofToDataPath("presetSlots.json")); - - // set up preset slots with names and images - Json::Value root; - Json::Reader reader; - - - ifstream theFile(presetSlotFilename.c_str()); - stringstream fileText; - string line; - if(!theFile){ - cout<<"can't find presetSlot file \n"; - return; - }else{ - - while(theFile){ - theFile >> line; - // cout << line << "\n"; // lots? - fileText << line; - - } - - theFile.close(); - } - - bool parsingSuccessful = reader.parse( fileText.str(), root ); - - if ( !parsingSuccessful ) - { - // report to the user the failure and their locations in the document. - std::cout << "Failed to parse preset slot JSON: \n" - << reader.getFormattedErrorMessages(); - return; - } - - // now put into variables - const Json::Value jv = root["presetSlots"]; - - for ( int index = 0; index < jv.size(); ++index ){ - string name = jv[index]["name"].asString(); - string imageFileName = jv[index]["imageFileName"].asString(); - vector empty; - generatePresetSlot(name, imageFileName); - } - - printAll(); - - filledSlots = 0; - } - -//---------------------------------------------------------------------------- - void goToFirstEmptySlot(){ - currentPresetSlot = filledSlots + 1; - } - bool writeValuesToSlot(vector values){ - getPresetAtIndex(currentPresetSlot)->setValues(values); - getPresetAtIndex(currentPresetSlot)->isFilled = true; - - filledSlots++; - currentPresetSlot++; - if(filledSlots == MAX_PRESETS){ - cout << "FINISHED EXP STAGE!" << endl; - return true; - } - return false; - } - Preset* getCurrentPresetSlot(){ - - return getPresetAtIndex(currentPresetSlot); - } - + void onAppLoad(); + void goToFirstEmptySlot(); + bool writeValuesToSlot(vector values); + Preset* getCurrentPresetSlot(); + PresetSlot* getPresetSlotAtIndex(int index); protected: + + void initPresetSlots(); + + void fillSlotsWithLoadedPresets(); + void fillSlotFromLoadedPreset(vector::iterator psi, vector::iterator pi); + void generatePresetSlot(const string name, const string imagefn); + int filledSlots; - int currentPresetSlot; + int currentPresetSlotIndex; string presetSlotFilename; + vector thePresetSlots; vector categories; vector names; diff -r 2a7320a8cbed -r 36cdb73691da ExplorePresetManager.mm --- a/ExplorePresetManager.mm Tue Oct 21 18:58:25 2014 +0100 +++ b/ExplorePresetManager.mm Wed Oct 22 15:00:14 2014 +0100 @@ -8,3 +8,133 @@ #include "ExplorePresetManager.h" ExplorePresetManager expPresetManager; + +//----------------------------------------------------------------------------- + +void ExplorePresetManager::onAppLoad(){ + // check for already saved stuff + startLoadAll(); + + if (thePresets.size() != MAX_PRESETS){ + + initPresetSlots(); + } + +} + +//---------------------------------------------------------------------------- +void ExplorePresetManager::goToFirstEmptySlot(){ + currentPresetSlotIndex = 0; + + // loop thru slots, find first empty slot +} +//---------------------------------------------------------------------------- +bool ExplorePresetManager::writeValuesToSlot(vector values){ + getPresetSlotAtIndex(currentPresetSlotIndex)->setValues(values); + + // now put it into a real preset, so it will be saved to file + savePreset(getPresetSlotAtIndex(currentPresetSlotIndex)); + + filledSlots++; + currentPresetSlotIndex++; + if(filledSlots == MAX_PRESETS){ + cout << "FINISHED EXP STAGE!" << endl; + return true; + } + return false; +} +//-------------------------------------------------------------------------------- +Preset* ExplorePresetManager::getCurrentPresetSlot(){ + + return getPresetSlotAtIndex(currentPresetSlotIndex); +} +//---------------------------------------------------------------------------- + +PresetSlot* ExplorePresetManager::getPresetSlotAtIndex(int index){ + + if (index >= thePresetSlots.size()){ + cout << "ERROR: index " << index << " exceeds number of presetslots " << thePresets.size() << endl; + return NULL; + }else{ + return thePresetSlots[index]; + + } +}; +//--------------------------------------------------------------------------- +void ExplorePresetManager::initPresetSlots(){ + + presetSlotFilename = ofFilePath::getAbsolutePath(ofToDataPath("presetSlots.json")); + + // set up preset slots with names and images + Json::Value root; + Json::Reader reader; + + + ifstream theFile(presetSlotFilename.c_str()); + stringstream fileText; + string line; + if(!theFile){ + cout<<"can't find presetSlot file \n"; + return; + }else{ + + while(theFile){ + theFile >> line; + // cout << line << "\n"; // lots? + fileText << line; + + } + + theFile.close(); + } + + bool parsingSuccessful = reader.parse( fileText.str(), root ); + + if ( !parsingSuccessful ) + { + // report to the user the failure and their locations in the document. + std::cout << "Failed to parse preset slot JSON: \n" + << reader.getFormattedErrorMessages(); + return; + } + + // now put into variables + const Json::Value jv = root["presetSlots"]; + + for ( int index = 0; index < jv.size(); ++index ){ + string name = jv[index]["name"].asString(); + string imageFileName = jv[index]["imageFileName"].asString(); + vector empty; + generatePresetSlot(name, imageFileName); + } + + // now look at existing presets to see if slots are filled + fillSlotsWithLoadedPresets(); + + filledSlots = 0; +} +//----------------------------------------------------------------------------- + +void ExplorePresetManager::fillSlotsWithLoadedPresets(){ + for(auto pi = thePresets.begin(); pi < thePresets.end(); pi++){ + string presetName = (*pi)->name; + + for(auto psi = thePresetSlots.begin(); psi < thePresetSlots.end(); psi++){ + string slotName = (*psi)->name; + if (slotName == presetName){ + fillSlotFromLoadedPreset(psi, pi); + } + } + } +} +//----------------------------------------------------------------------------- + +void ExplorePresetManager::fillSlotFromLoadedPreset(vector::iterator psi, vector::iterator pi){ + (*pi) = (*psi); // dodgy? +} +//----------------------------------------------------------------------------- +void ExplorePresetManager::generatePresetSlot(const string name, const string imagefn){ + vector values = makeVector8(int(rand() % 128),int(rand() % 128),int(rand() % 128),int(rand() % 128),int(rand() % 128),0,0,0); // empty + thePresetSlots.push_back(new PresetSlot(values, name, nextID, eventLogger.userName, eventLogger.deviceID, imagefn)); + +} diff -r 2a7320a8cbed -r 36cdb73691da MessageOrganiser.h --- a/MessageOrganiser.h Tue Oct 21 18:58:25 2014 +0100 +++ b/MessageOrganiser.h Wed Oct 22 15:00:14 2014 +0100 @@ -60,52 +60,16 @@ class MessageOrganiser { public: - void init(PDSynthWrapper& cs, PDSynthWrapper& ts){ - candidateSynth = cs; - targetSynth = ts; - - onlyChangeCandidateOnTrigger = true; - } - // could template for ui element type?? - void mapButtonToAction(UIElement* control, int mappingID){ - UICallbackFunction callbackF; - callbackF = boost::bind(&MessageOrganiser::buttonPressCallback, this, _1,_2); - control->addHandler(callbackF, mappingID); - currentMapping.insert(std::pair(mappingID,control)); - } + void init(PDSynthWrapper& cs, PDSynthWrapper& ts); // could template for ui element type?? + void mapButtonToAction(UIElement* control, int mappingID); - - void setControlPanel(SliderPanel* p){ // a bit specific?? - panel = p; - - }; - void setBottomPanel(ButtonPanel * ntb){ - bottomPanel = ntb; - }; - - - void setIconPanel(IconPanel * ip){ - presetIconPanel = ip; - } - void setInstructionPanel(TextPanel * ip){ - instructionPanel = ip; - instructionPanel->show(); - } - - + void setControlPanel(SliderPanel* p); + void setBottomPanel(ButtonPanel * ntb); + void setIconPanel(IconPanel * ip); + void setInstructionPanel(TextPanel * ip); //----------------------------------------------------------------------------- - void hideMyPanels(){ - presetIconPanel->hide(); - instructionPanel->hide(); - bottomPanel->hide(); - panel->hide(); - } - void showMyPanels(){ - presetIconPanel->show(); - instructionPanel->show(); - bottomPanel->show(); - panel->show(); - } + void hideMyPanels(); + void showMyPanels(); protected: PDSynthWrapper candidateSynth; @@ -119,148 +83,24 @@ map currentMapping; // could get more sophisticated if not 1-1 ? - void triggerCandidateSound(){ - // log event - sendSynthValuesAgain(); - candidateSynth.trigger(); - eventLogger.logEvent(CANDIDATE_PLAYED); - // flash panel? - panel->flash(); - } + void triggerCandidateSound(); + void paramChangeCallback(int mappingID, int value); + void sendSynthValuesAgain(); + void setAllSlidersToValues(vector values); - void paramChangeCallback(int mappingID, int value){ - - if(onlyChangeCandidateOnTrigger){ - candidateSynth.paramChangeCallback(mappingID, value, false); - }else{ - candidateSynth.paramChangeCallback(mappingID, value, true); - } - - vector evtData; - evtData.push_back(mappingID); // or just index? - evtData.push_back(value); - - eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData); - }; - - void sendSynthValuesAgain(){ - candidateSynth.sendAllParams(); - targetSynth.sendAllParams(); - }; - - - void setAllSlidersToValues(vector values){ - for(int i = 0; i < values.size(); i++){ - setUIToParam(i, values[i]); - } - } // we want to set UI object - void 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 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(mappingID,control)); - cout << " Mapped control to ID: " << mappingID << "Name: " << candidateSynth.getNameForMappingID(mappingID) << endl; - control->setLabel(candidateSynth.getNameForMappingID(mappingID)); - }; - + void setUIToParam(int index, int value); + void mapControlToParam(UIElement* control, int mappingID); //----------------------------------------------------------------------------- - void mapSlidersToParams(vector elems, vector mids){ - - vector::iterator elit; - vector typeListLog; - int i = 0; - for(elit=elems.begin(); elitgetType() == 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 mapSlidersToParams(vector elems, vector mids); + void mapXYToParams(ButtronXY* control, int mappingIDX, int mappingIDY); - void 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(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 mapControlToParam(UIElement* control, string paramName); + virtual void buttonPressCallback(int mappingID, int value); - void mapControlToParam(UIElement* control, string paramName){ - // get mapping ID from synth - int mappingID = candidateSynth.getMappingIDForName(paramName); - mapControlToParam(control, mappingID); - control->setLabel(paramName); - }; - - virtual void buttonPressCallback(int mappingID, int value){ - - }; - - - void setSlidersToTarget(){ - // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh - // get target values - // set ui - vector vals = targetSynth.getAllParamValues(); - for(int i=1; i < vals.size(); i++){ - setUIToParam(i, vals[i]); - } - } - void setSlidersToDefault(){ - for(int i=1; i < targetSynth.getNumParams(); i++){ - setUIToParam(i, 0); - } - } - + void setSlidersToTarget(); + void setSlidersToDefault(); bool onlyChangeCandidateOnTrigger; }; diff -r 2a7320a8cbed -r 36cdb73691da MessageOrganiser.mm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MessageOrganiser.mm Wed Oct 22 15:00:14 2014 +0100 @@ -0,0 +1,191 @@ + +#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(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::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 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 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(mappingID,control)); + cout << " Mapped control to ID: " << mappingID << "Name: " << candidateSynth.getNameForMappingID(mappingID) << endl; + control->setLabel(candidateSynth.getNameForMappingID(mappingID)); +}; + +//----------------------------------------------------------------------------- + +void MessageOrganiser::mapSlidersToParams(vector elems, vector mids){ + + vector::iterator elit; + vector typeListLog; + int i = 0; + for(elit=elems.begin(); elitgetType() == 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(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 vals = targetSynth.getAllParamValues(); + for(int i=1; i < vals.size(); i++){ + setUIToParam(i, vals[i]); + } +} +void MessageOrganiser::setSlidersToDefault(){ + for(int i=1; i < targetSynth.getNumParams(); i++){ + setUIToParam(i, 0); + } +} \ No newline at end of file diff -r 2a7320a8cbed -r 36cdb73691da UI code/UIElement.h --- a/UI code/UIElement.h Tue Oct 21 18:58:25 2014 +0100 +++ b/UI code/UIElement.h Wed Oct 22 15:00:14 2014 +0100 @@ -64,7 +64,7 @@ virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual? { - cout << "handler added to UIElement " << endl; + //cout << "handler added to UIElement " << endl; callback = handlerFunction; myParamID = paramID; }; diff -r 2a7320a8cbed -r 36cdb73691da UI code/buttonPanel.mm --- a/UI code/buttonPanel.mm Tue Oct 21 18:58:25 2014 +0100 +++ b/UI code/buttonPanel.mm Wed Oct 22 15:00:14 2014 +0100 @@ -15,7 +15,7 @@ vector elemList) : UIElementContainer(ax,ay,awidth,aheight,aprops) { - cout << "ButtonPanel auto layout contructor\n"; + //cout << "ButtonPanel auto layout contructor\n"; generateControls(elemList); autoArrangeRow(); @@ -28,7 +28,7 @@ const UIProps& aprops) : UIElementContainer(ax,ay,awidth,aheight,aprops) { - cout << "ButtonPanel - ctrls added later constructor\n"; + //cout << "ButtonPanel - ctrls added later constructor\n"; } //--------------------------------------------------- diff -r 2a7320a8cbed -r 36cdb73691da eventLogger.h --- a/eventLogger.h Tue Oct 21 18:58:25 2014 +0100 +++ b/eventLogger.h Wed Oct 22 15:00:14 2014 +0100 @@ -31,9 +31,10 @@ #define EVENT_THIN_FACTOR 30 #define EVENT_LOG_FILENAME "log.json" #define UPLOAD_CHUNK_SIZE 1000 +#define SAVE_CHUNK_SIZE 5000 #define APP_CREATION_TIME 0 // ignore this, pointless -#define PROGRAM_NAME "TWEAKATHLON" -#define PROGRAM_VERSION 0.2 +#define PROGRAM_NAME "RIFTATHON" +#define PROGRAM_VERSION 0.1 #define SUPERVISED // this def will save files @@ -165,6 +166,7 @@ EventLogger(); // public methods: + void onUsernameEntered(); void startLoadAll(); void exitAndSave(); void setUsername(const char *u); @@ -194,6 +196,8 @@ vector questionnaireAnswers; + string nextLogFileIndexString(); + void loadUserDetailsFromLastLogFile(int numExistingLogs); // private methods void testConnection(); void checkLogFile(); @@ -212,7 +216,7 @@ bool matchID2(); // ServerComms *serverComms; - + int nextLogFileIndex; }; diff -r 2a7320a8cbed -r 36cdb73691da eventLogger.mm --- a/eventLogger.mm Tue Oct 21 18:58:25 2014 +0100 +++ b/eventLogger.mm Wed Oct 22 15:00:14 2014 +0100 @@ -25,6 +25,39 @@ serverComms = [[ServerComms alloc] init]; } +// for RIFTATHON this replaces startLoadAll +// because we can't look at logs or presets until we know user + +void EventLogger::onUsernameEntered(){ + sessionStartTime = ofGetSystemTime(); + // userName = name; done already by dialog + // check for eventlog with this name + + + string path = ofxiPhoneGetDocumentsDirectory(); + ofDirectory dir(path); + //only show png files + dir.allowExt("json"); + //populate the directory object + dir.listDir(); + + //chek for username's logs + bool userHasLogs = false; + int numExistingLogs = 0; + for(int i = 0; i < dir.numFiles(); i++){ + string fname = dir.getName(i); + if( 0 == fname.compare(0, userName.length() + 10, userName + "_eventlog_" )){ + numExistingLogs++; + userHasLogs = true; + } + + } + // if found, load other details such as device id + loadUserDetailsFromLastLogFile(numExistingLogs); + nextLogFileIndex = numExistingLogs+1; + +} + //--------------------------------------------------------------------------- void EventLogger::startLoadAll(){ @@ -70,6 +103,14 @@ } //--------------------------------------------------------------------------- + +void EventLogger::loadUserDetailsFromLastLogFile(int numExistingLogs){ + + +} +//--------------------------------------------------------------------------- + + // this reads the persistent log file , checks if we've used the app before and // if we've answered questionnaire or not @@ -316,11 +357,12 @@ break; } - if(theEvents.size() > nextUploadQty && !logUploadInProgress){ - //try to upload asynchronously - // TODO pilot doesn't upload - //uploadEventLog(true); + // new riftathon save as we go + if (theEvents.size() > SAVE_CHUNK_SIZE){ + saveSessionToFile(); + theEvents.clear(); } + //TODO thiswrong? totalInteractionTime = savedInteractionTime + (ofGetSystemTime() - sessionStartTime); // milliseconds @@ -348,6 +390,12 @@ // TODO pilot doesn't upload //uploadEventLog(true); } + + // new riftathon save as we go + if (theEvents.size() > SAVE_CHUNK_SIZE){ + saveSessionToFile(); + } + //TODO thiswrong? totalInteractionTime = savedInteractionTime + (ofGetSystemTime() - sessionStartTime); // milliseconds @@ -421,6 +469,7 @@ //-------------------------------------------------------------------- // called from newUser void EventLogger::deleteLogs(){ + return; // the theEvents.clear(); string fname = ofxiPhoneGetDocumentsDirectory() + EVENT_LOG_FILENAME; @@ -432,6 +481,9 @@ void EventLogger::exitAndSave(){ + saveSessionToFile(); + return; + if(!consentGiven){ Json::Value jlogs = logsToJson(); // try to upload TODO (no - might hang and prevent exit???) @@ -526,16 +578,27 @@ void EventLogger::saveSessionToFile(){ stringstream fn; - fn << ofxiPhoneGetDocumentsDirectory() << userName << '_' << sessionStartTime << "_BACKUP.json"; + fn << ofxiPhoneGetDocumentsDirectory() << userName << "_eventlog_" << nextLogFileIndexString() << ".json"; string fname = fn.str(); //ofxiPhoneGetDocumentsDirectory() + userName + '_' + "TESTSAVE.json"; // write to file - // json without the logs that were uploaded! + Json::Value jlogs = logsToJson(); ofFile logFile(fname,ofFile::WriteOnly); logFile << jlogs; logFile.close(); + nextLogFileIndex++; +} + +string EventLogger::nextLogFileIndexString(){ + string num = ofToString(nextLogFileIndex); + string zero = ofToString(0); + int numzeros = 4 - num.length(); + for (int i=0; i< numzeros;i++){ + num = zero + num; + } + return num; } //---------------------------------------------------------------------------- diff -r 2a7320a8cbed -r 36cdb73691da presetManager.h --- a/presetManager.h Tue Oct 21 18:58:25 2014 +0100 +++ b/presetManager.h Wed Oct 22 15:00:14 2014 +0100 @@ -35,7 +35,7 @@ unsigned long long creationTime; // datetime that preset was created milliseconds string imageFileName; vector CCValues; // the actual data - bool isFilled; + //bool isFilled; PresetIconView* iconView; // from save button press Preset(vector aCCValues, @@ -45,12 +45,12 @@ unsigned int uid, string imageFile = ""){ CCValues = aCCValues; - if (CCValues.size()){ - isFilled = true; - - }else{ - isFilled = false; - } +// if (CCValues.size()){ +// isFilled = true; +// +// }else{ +// isFilled = false; +// } name = aname; creatorUserName = un; @@ -115,16 +115,14 @@ vector getValues(){ return CCValues; } - void setValues(vector v){ + + void overwriteValues(vector v){ + if (v.size() != CCValues.size()){ + cout << "ERROR: wrong size for vector of CCValues" << endl; + } CCValues = v; double timemsd = [NSDate timeIntervalSinceReferenceDate]; creationTime = (unsigned long long)(timemsd*1000); - if (CCValues.size()){ - isFilled = true; - - }else{ - isFilled = false; - } } }; @@ -133,26 +131,19 @@ class PresetManager{ public: PresetManager(); + void savePreset(Preset * aPreset); void savePreset(string name, vector stuff); void generatePresetSlot(const string name, const string imagefn); void saveFilledSlotToFile(); - vector recallPreset(int presetID); - vector recallPreset(string name); + vector getPresetValuesForID(int presetID); + vector getPresetValuesForName(string name); void startLoadAll(); // load everything from the json file void exitAndSaveAll(); // save stuff to the json file void printAll(); void clearAll(); - Preset* getPresetAtIndex(int index){ - - if (index >= thePresets.size()){ - cout << "ERROR: index " << index << " exceeds number of presets " << thePresets.size() << endl; - return NULL; - }else{ - return thePresets[index]; - - } - }; + Preset* getPresetAtIndex(int index); + int getNumberOfPresets(){return thePresets.size();}; protected: string presetFileName; int nextID; diff -r 2a7320a8cbed -r 36cdb73691da presetManager.mm --- a/presetManager.mm Tue Oct 21 18:58:25 2014 +0100 +++ b/presetManager.mm Wed Oct 22 15:00:14 2014 +0100 @@ -12,20 +12,7 @@ extern EventLogger eventLogger; -template -vector makeVector8(T a1, T a2,T a3,T a4,T a5,T a6, T a7, T a8){ - - vector vec; - vec.push_back(a1); - vec.push_back(a2); - vec.push_back(a3); - vec.push_back(a4); - vec.push_back(a5); - vec.push_back(a6); - vec.push_back(a7); - vec.push_back(a8); - return vec; -} + //--------------------------------------------------------------------------- Json::Value Preset::presetToJson(){ @@ -110,7 +97,14 @@ // now put into variables const Json::Value jpresets = root["presets"]; - for ( int index = 0; index < jpresets.size(); ++index ) thePresets.push_back(new Preset(jpresets[index])); + for ( int index = 0; index < jpresets.size(); ++index ){ + + // check that it is our user ID + if (jpresets[index]["creatorUserName"].asString() == eventLogger.userName){ + thePresets.push_back(new Preset(jpresets[index])); + } + + } } @@ -128,6 +122,32 @@ // } } +//------------------------------------------------ +// when preset slot becomes a real preset to save +void PresetManager::savePreset(Preset * aPreset){ + + vector::iterator iter; + + for(iter = thePresets.begin(); iter < thePresets.end(); iter++){ + if ((*iter)->name == aPreset->name){ + cout << "WARNING Preset by that name exists, overwriting\n"; + // overwrite it + (*iter)->overwriteValues(aPreset->CCValues); + updatePresetFile(); + eventLogger.logEvent(SAVE_PRESET); // TODO need to log details? + return; + } + } + + if(aPreset->name == ""){ + cout << "Please name preset\n"; + + } + + thePresets.push_back(new Preset(aPreset->CCValues, aPreset->name, nextID, eventLogger.userName, eventLogger.deviceID, aPreset->imageFileName)); + eventLogger.logEvent(SAVE_PRESET); // TODO need to log details? + updatePresetFile(); +} //--------------------------------------------------------------------------- // when save button pressed void PresetManager::savePreset(const string name, vector values){ @@ -140,7 +160,7 @@ if ((*iter)->name == name){ cout << "WARNING Preset by that name exists, overwriting\n"; // overwrite it - (*iter)->setValues(values); + (*iter)->overwriteValues(values); updatePresetFile(); eventLogger.logEvent(SAVE_PRESET); // TODO need to log details? return; @@ -157,18 +177,9 @@ updatePresetFile(); } -//----------------------------------------------------------------------------- -void PresetManager::generatePresetSlot(const string name, const string imagefn){ - vector values = makeVector8(int(rand() % 128),int(rand() % 128),int(rand() % 128),int(rand() % 128),int(rand() % 128),0,0,0); // empty - thePresets.push_back(new Preset(values, name, nextID, eventLogger.userName, eventLogger.deviceID, imagefn)); - -} + //----------------------------------------------cu----------------------------- -void PresetManager::saveFilledSlotToFile(){ - // uuuhhhh -} -//----------------------------------------------cu----------------------------- -vector PresetManager::recallPreset(string name){ +vector PresetManager::getPresetValuesForName(string name){ vector::iterator p; for(p = thePresets.begin(); p < thePresets.end(); p++){ if ( (*p)->getName() == name){ @@ -178,7 +189,18 @@ vector empty; return empty; } -//----------------------------------------------cu----------------------------- +//--------------------------------------------------------------------------- +Preset* PresetManager::getPresetAtIndex(int index){ + + if (index >= thePresets.size()){ + cout << "ERROR: index " << index << " exceeds number of presets " << thePresets.size() << endl; + return NULL; + }else{ + return thePresets[index]; + + } +}; +//--------------------------------------------------------------------------- void PresetManager::startLoadAll(){ presetFileName = ofxiPhoneGetDocumentsDirectory() + PRESET_FILENAME; diff -r 2a7320a8cbed -r 36cdb73691da testApp.mm --- a/testApp.mm Tue Oct 21 18:58:25 2014 +0100 +++ b/testApp.mm Wed Oct 22 15:00:14 2014 +0100 @@ -17,7 +17,7 @@ initialiseVariables(); - expPresetManager.onAppLoad(); + //presetManager.startLoadAll(); @@ -33,25 +33,12 @@ initialiseMIDI(); setupUIElements(); - - -// -// light.setSpotlight(45. , 1.); -// light.enable(); -// ofEnableSeparateSpecularLight(); ofEnableDepthTest(); ofEnableAlphaBlending(); - // in setup: + //-------------------------------------- - eventLogger.startLoadAll(); - //-------------------------------------- - - // now do things that will affect the start up state of the app - - // initialise PD - int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512 core.setup(2, 2, 44100, ticksPerBuffer); @@ -61,7 +48,7 @@ ofSoundStreamSetup(2, 2, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3); - if(true){ // force start + if(false){ // force start startTheExpTests(); }else{ @@ -422,7 +409,10 @@ void testApp::usernameEntered(){ // display a thing that gives us an option as to which stage to start // EXPLORE, PERFORMANCE TRAINING, SEARCH + eventLogger.onUsernameEntered(); + expPresetManager.onAppLoad(); + startTheExpTests(); } //--------------------------------------------------------------