Mercurial > hg > tweakathon2ios
view presetManager.h @ 4:60b54ba87f6a
Preset save and recall works.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Thu, 16 Oct 2014 14:34:14 +0100 |
parents | 7e0a19a538d4 |
children | 213df0baed47 |
line wrap: on
line source
// // presetManager.h // oscSenderExample // // Created by Robert Tubb on 07/11/2012. // // // defines: // PresetManager // and Preset #ifndef __oscSenderExample__presetManager__ #define __oscSenderExample__presetManager__ #define PRESET_FILENAME "presets.json" #include <iostream> #include <string> #include "ofMain.h" #include "ofxiPhone.h" #include "ofxiPhoneExtras.h" #include "eventLogger.h" #include "json.h" #include <ctime> //--------------------------------------------------------------------------- class Preset{ public: // important details - these saved to file (uploaded?) string creatorUserName; unsigned int creatorDeviceID; // unique user device ID string name; // name of preset unsigned long long creationTime; // datetime that preset was created milliseconds vector<int> CCValues; // the actual data // from save button press Preset(vector<int> aCCValues, string aname, int aID, string un, unsigned int uid){ CCValues = aCCValues; name = aname; creatorUserName = un; creatorDeviceID = uid; double timemsd = [NSDate timeIntervalSinceReferenceDate]; creationTime = (unsigned long long)(timemsd*1000); cout << "Create preset sys time: " << creationTime << "\n"; //TODO color / texture? }; // contruct from json value Preset(Json::Value jval){ name = jval["name"].asString(); creatorUserName = jval["creatorUserName"].asString(); creatorDeviceID = jval["creatorDeviceID"].asUInt(); creationTime = jval["creationTime"].asLargestInt(); // dodgy? Json::Value JArray = jval["CCValues"]; if(JArray.size() < 1){ cout << "No Presets"; } for ( unsigned int i = 0; i < JArray.size(); i++ ) { CCValues.push_back(JArray[i].asInt()); } } void draw(); Json::Value presetToJson(); string displayTextDescription(){ // eg: for grid hover // objC to C to C++ bleurgh NSDate *ocdate = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)(creationTime/1000.0)]; NSString *dateText = [ocdate description]; const char *date_str = [dateText cStringUsingEncoding:NSASCIIStringEncoding]; stringstream ss; ss << "Name: \t" << name << "\nCreation time: \t" << date_str << "\nCreator: \t" << creatorUserName << '\n'; return ss.str(); } string getName(){ return name; } vector<int> getValues(){ return CCValues; } }; //--------------------------------------------------------------------------- class PresetManager{ public: int nextID; int timesOpened; bool presetAlertShowing; vector<Preset *> thePresets; int savePreset(string name, vector<int> stuff); vector<int> recallPreset(int presetID); // by name ? id? vector<int> recallPreset(string name); // by name ? id? void printAll(); void startLoadAll(); // load everything from the json file void exitAndSaveAll(); // save stuff to the json file void clearAll(); Json::Value allPresetsToJson(); void readJsonToPresets(const string &jsonFile); void showNameDialog(); PresetManager(); }; #endif /* defined(__oscSenderExample__presetManager__) */