Mercurial > hg > tweakathon2ios
changeset 6:92850a2b099c
set up preset slots from init file.
PD synth has metronome, recieves ticks but doesn't do anything with them.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 17 Oct 2014 14:50:50 +0100 |
parents | 213df0baed47 |
children | 4e00f92567d9 |
files | AppCore.mm ExplorePresetManager.h ExplorePresetManager.mm MessageOrganiser.h PDSynthWrapper.h PresetView.h PresetView.mm presetManager.h presetManager.mm testApp.h testApp.mm |
diffstat | 11 files changed, 243 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/AppCore.mm Thu Oct 16 15:52:53 2014 +0100 +++ b/AppCore.mm Fri Oct 17 14:50:50 2014 +0100 @@ -14,8 +14,8 @@ void AppCore::setup(const int numOutChannels, const int numInChannels, const int sampleRate, const int ticksPerBuffer) { - ofSetFrameRate(60); - ofSetVerticalSync(true); +// ofSetFrameRate(60); +// ofSetVerticalSync(true); //ofSetLogLevel(OF_LOG_VERBOSE); // double check where we are ... @@ -29,11 +29,11 @@ // subscribe to receive source names pd.subscribe("toOF"); - pd.subscribe("env"); + pd.subscribe("onTickOF"); // add message receiver, disables polling (see processEvents) pd.addReceiver(*this); // automatically receives from all subscribed sources - pd.ignore(*this, "env"); // don't receive from "env" + //pd.ignore(*this); // ignore all sources //pd.receive(*this, "toOF"); // receive only from "toOF" @@ -51,7 +51,7 @@ // open patch //patchName = "targetSynth6.pd"; - patchName = "tweakathon_synth_pulse.pd"; + patchName = "riftathon_synth.pd"; Patch patch = pd.openPatch(patchName); cout << patch << endl; @@ -173,6 +173,10 @@ void AppCore::receiveFloat(const std::string& dest, float value) { cout << "OF: float " << dest << ": " << value << endl; + + if (dest == "onTickOF"){ + // call our on tick function + } } void AppCore::receiveSymbol(const std::string& dest, const std::string& symbol) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ExplorePresetManager.h Fri Oct 17 14:50:50 2014 +0100 @@ -0,0 +1,98 @@ +// +// ExplorePresetManager.h +// riftathon +// +// Created by Robert Tubb on 16/10/2014. +// +// when people explore and find presets save them +// record audio +// can display images and text + +// + +#ifndef __riftathon__ExplorePresetManager__ +#define __riftathon__ExplorePresetManager__ + +#include <iostream> +#include "presetManager.h" + + + +class ExplorePresetManager : public PresetManager { + +public: + void onAppLoad(){ + // check for already saved stuff + startLoadAll(); + + if (thePresets.size() != 16){ + // if numpresets != 16 + initPresets(); + } + + } + void initPresets(){ + + presetSlotFilename = ofFilePath::getAbsolutePath(ofToDataPath("presetSlots.json")); + + // set up 16 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<int> empty; + generatePresetSlot(name, imageFileName); + } + + printAll(); + + filledSlots = 0; + } + +//---------------------------------------------------------------------------- + void presentNextPreset(){ + + } +protected: + int filledSlots; + string presetSlotFilename; + + vector<string> categories; + vector<string> names; +}; + +#endif /* defined(__riftathon__ExplorePresetManager__) */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ExplorePresetManager.mm Fri Oct 17 14:50:50 2014 +0100 @@ -0,0 +1,10 @@ +// +// ExplorePresetManager.mm +// riftathon +// +// Created by Robert Tubb on 16/10/2014. +// +// + +#include "ExplorePresetManager.h" +ExplorePresetManager expPresetManager;
--- a/MessageOrganiser.h Thu Oct 16 15:52:53 2014 +0100 +++ b/MessageOrganiser.h Fri Oct 17 14:50:50 2014 +0100 @@ -32,7 +32,10 @@ #include "TextPanel.h" #include "CountdownText.h" #include "buttonPanel.h" -#include "presetManager.h" +#include "ExplorePresetManager.h" + + +// should be called TIMED TEST MESSAGE ORGANISER ? // event logger needs to know // which controls were showing in what mode @@ -52,7 +55,7 @@ extern EventLogger eventLogger; -extern PresetManager presetManager; +extern ExplorePresetManager expPresetManager; typedef boost::function<void(void)> AppModeChangeFunction; @@ -655,19 +658,19 @@ } } if(mappingID == SAVE_PRESET_HIT){ - presetManager.savePreset("blah", candidateSynth.getAllParamValues()); + expPresetManager.savePreset("blah", candidateSynth.getAllParamValues()); } if(mappingID == RECALL_PRESET_HIT){ loadPreset("blah"); - + //candidateSynth.startMetronome(); } } void loadPreset(string pname){ - vector<int> values = presetManager.recallPreset(pname); + vector<int> values = expPresetManager.recallPreset(pname); if (values.size()){ candidateSynth.setAllParams(values); setAllSlidersToValues(values);
--- a/PDSynthWrapper.h Thu Oct 16 15:52:53 2014 +0100 +++ b/PDSynthWrapper.h Fri Oct 17 14:50:50 2014 +0100 @@ -1,11 +1,13 @@ // // pdSynthWrapper.h -// tweakathlon +// RIFTATHON // // Created by Robert Tubb on 14/01/2014. // // + +// for riftathon, this is also a wrapper for the sequencer #pragma once #include "AppCore.h" @@ -225,9 +227,17 @@ return pl; } - void storeParamsAsPreset(string name){ + void storeParamsAsPreset(string name){ // ?? presetManager.savePreset(name, getAllParamValues()); } + + void startMetronome(){ + // play the noise + List toPD; + core->pd.sendMessage("fromOF", "startMetro", toPD); + + } + private: string synthPrefix; AppCore* core;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PresetView.h Fri Oct 17 14:50:50 2014 +0100 @@ -0,0 +1,30 @@ +// +// PresetView.h +// riftathon +// +// Created by Robert Tubb on 17/10/2014. +// +// + +#ifndef __riftathon__PresetView__ +#define __riftathon__PresetView__ + +#include <iostream> + +#include "presetManager.h" +#include "UIElement.h" + +class PresetIconView : public UIElement { + string imageFileName; + + ofImage image; + string name; + + + + void draw(); + + +}; + +#endif /* defined(__riftathon__PresetView__) */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PresetView.mm Fri Oct 17 14:50:50 2014 +0100 @@ -0,0 +1,9 @@ +// +// PresetView.mm +// riftathon +// +// Created by Robert Tubb on 17/10/2014. +// +// + +#include "PresetView.h"
--- a/presetManager.h Thu Oct 16 15:52:53 2014 +0100 +++ b/presetManager.h Fri Oct 17 14:50:50 2014 +0100 @@ -36,10 +36,17 @@ string imageFileName; vector<int> CCValues; // the actual data ofImage presetImage; + bool isFilled; // from save button press Preset(vector<int> aCCValues, string aname, int aID, string un, unsigned int uid, string imageFile = ""){ CCValues = aCCValues; + if (CCValues.size()){ + isFilled = true; + + }else{ + isFilled = false; + } name = aname; creatorUserName = un; @@ -52,8 +59,9 @@ //TODO color / texture? imageFileName = imageFile; if (imageFile != ""){ - presetImage.loadImage(imageFile); + presetImage.loadImage("Images/" + imageFile); } + }; // contruct from json value Preset(Json::Value jval){ @@ -102,6 +110,18 @@ vector<int> getValues(){ return CCValues; } + void setValues(vector<int> v){ + CCValues = v; + double timemsd = [NSDate timeIntervalSinceReferenceDate]; + creationTime = (unsigned long long)(timemsd*1000); + if (CCValues.size()){ + isFilled = true; + + }else{ + isFilled = false; + } + } + }; //--------------------------------------------------------------------------- @@ -109,6 +129,7 @@ public: PresetManager(); void savePreset(string name, vector<int> stuff); + void generatePresetSlot(const string name, const string imagefn); vector<int> recallPreset(int presetID); vector<int> recallPreset(string name); void startLoadAll(); // load everything from the json file
--- a/presetManager.mm Thu Oct 16 15:52:53 2014 +0100 +++ b/presetManager.mm Fri Oct 17 14:50:50 2014 +0100 @@ -10,7 +10,6 @@ //--------------------------------------------------------------------------- -PresetManager presetManager; extern EventLogger eventLogger; //--------------------------------------------------------------------------- @@ -101,8 +100,7 @@ const Json::Value jpresets = root["presets"]; for ( int index = 0; index < jpresets.size(); ++index ) thePresets.push_back(new Preset(jpresets[index])); - - printAll(); + } //--------------------------------------------------------------------------- @@ -131,7 +129,7 @@ if ((*iter)->name == name){ cout << "WARNING Preset by that name exists, overwriting\n"; // overwrite it - (*iter)->CCValues = values; + (*iter)->setValues(values); updatePresetFile(); eventLogger.logEvent(SAVE_PRESET); // TODO need to log details? return; @@ -148,6 +146,12 @@ updatePresetFile(); } +//----------------------------------------------------------------------------- +void PresetManager::generatePresetSlot(const string name, const string imagefn){ + vector<int> values; // empty + thePresets.push_back(new Preset(values, name, nextID, eventLogger.userName, eventLogger.deviceID, imagefn)); + +} //----------------------------------------------cu----------------------------- vector<int> PresetManager::recallPreset(string name){ vector<Preset *>::iterator p; @@ -177,8 +181,7 @@ // stick all the stuff in a json value Json::Value root = allPresetsToJson(); - - cout << root; + presetFile << root; } //---------------------------------------------------------------------------
--- a/testApp.h Thu Oct 16 15:52:53 2014 +0100 +++ b/testApp.h Fri Oct 17 14:50:50 2014 +0100 @@ -60,6 +60,9 @@ void initialiseVariables(); void initialiseMIDI(); void setupUIElements(); + void setupExpressViewPanels(); + void setupTrainingViewPanels(); + void setupSearchViewPanels(); void setup(); void update();
--- a/testApp.mm Thu Oct 16 15:52:53 2014 +0100 +++ b/testApp.mm Fri Oct 17 14:50:50 2014 +0100 @@ -1,9 +1,8 @@ #include "testApp.h" #include "ofAppiOSWindow.h" - +#include "ExplorePresetManager.h" extern EventLogger eventLogger; -extern PresetManager presetManager; - +extern ExplorePresetManager expPresetManager; // static members inited here. not my choice. int SynthParam::mappingUID = 88000; //-------------------------------------------------------------- @@ -21,7 +20,11 @@ testController = new TestController; - presetManager.startLoadAll(); + + expPresetManager.onAppLoad(); + + //presetManager.startLoadAll(); + messageOrganiser.init(&core, testController); timeController.init(); @@ -113,22 +116,28 @@ } //-------------------------------------------------------------- -void testApp::setupUIElements(){ - - // eventually: sliderpanel, topbuttonpanel, submitbuttonpanel, countdown panel, +// GUI for finding and saving presets to express concepts +void testApp::setupExpressViewPanels(){ - // --------------------- BUTTONS +} +//-------------------------------------------------------------- +// gui for the main training stage +void testApp::setupTrainingViewPanels(){ + +} +//-------------------------------------------------------------- +// gui for the old style tweakathlon stage +void testApp::setupSearchViewPanels(){ + UIProps p; - ofBackground(p.generalBackground); - ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+p.sliderPanelHeight,ofGetWidth(),250,p); - + Buttron* playTargetButton = new Buttron(p.buttonWidth*0.2,680, p); playTargetButton->setLabel("Target"); messageOrganiser.mapButtonToAction(playTargetButton, TRIGGER_TARGET_ID); bottomButtonPanel->addButton(playTargetButton); messageOrganiser.setTargetButton(playTargetButton); - + Buttron * playCandidateButton = new Buttron(p.buttonWidth*1.4,680, p); playCandidateButton->setLabel("Current"); messageOrganiser.mapButtonToAction(playCandidateButton, TRIGGER_CANDIDATE_ID); @@ -146,18 +155,28 @@ saveButton->setLabel("SAVE"); messageOrganiser.mapButtonToAction(saveButton, SAVE_PRESET_HIT); bottomButtonPanel->addButton(saveButton); - saveButton->show(); + saveButton->hide(); Buttron * recallButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); recallButton->setLabel("RECALL"); messageOrganiser.mapButtonToAction(recallButton, RECALL_PRESET_HIT); bottomButtonPanel->addButton(recallButton); - recallButton->show(); + recallButton->hide(); messageOrganiser.setBottomPanel(bottomButtonPanel); UIElements.push_back(bottomButtonPanel); bottomButtonPanel->showBorder(false); + +} +//-------------------------------------------------------------- +void testApp::setupUIElements(){ + + // eventually: sliderpanel, topbuttonpanel, submitbuttonpanel, countdown panel, + + // --------------------- BUTTONS + UIProps p; + ofBackground(p.generalBackground); // ------------------------------------ SLIDERS