Mercurial > hg > soniczoomios
view presetManager.h @ 49:178642d134a7 tip
xtra files
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 01 May 2013 17:34:33 +0100 |
parents | 1e266647840d |
children |
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" #define PILOT_PRESET_FILENAME "pilot_presets.json" #define FACTORY_PRESET_FILENAME "factory_presets.json" #include <iostream> #include <string> #include "ofMain.h" #include "ofxiPhone.h" #include "ofxiPhoneExtras.h" #include "2dvector.h" #include "grid.h" #include "eventLogger.h" #include "json.h" #include <ctime> #import "presetAlertViewController.h" //--------------------------------------------------------------------------- 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<ofColor> pixVals; // hmmm TwoVector coordinates; // position on grid vector<int> params; // actual parameters??? unsigned int whichSequence; // the sequence number that this preset was saved with. // from save button press Preset(TwoVector acoord, string aname,int aID, string un, unsigned int uid, unsigned int sequence){ coordinates = acoord; name = aname; creatorUserName = un; creatorDeviceID = uid; double timemsd = [NSDate timeIntervalSinceReferenceDate]; creationTime = (unsigned long long)(timemsd*1000); cout << "Create preset sys time: " << creationTime << "\n"; pixVals = makePresetPicture(coordinates); whichSequence = sequence; }; // from json value Preset(Json::Value jval){ name = jval["name"].asString(); creatorUserName = jval["creatorUserName"].asString(); creatorDeviceID = jval["creatorDeviceID"].asUInt(); coordinates.x = jval["coordinates"].get("x", 0.0).asFloat(); coordinates.y = jval["coordinates"].get("y", 0.0).asFloat(); creationTime = jval["creationTime"].asLargestInt(); // dodgy? whichSequence = jval["whichSequence"].asUInt(); pixVals = makePresetPicture(coordinates); }; // from preset file load Preset(TwoVector acoord, string aname,int aID, long long stime, unsigned int seq){ coordinates = acoord; name = aname; creationTime = stime; pixVals = makePresetPicture(coordinates); whichSequence = seq; }; // from download request?? void draw(); Json::Value presetToJson(); vector<ofColor> makePresetPicture(TwoVector coord); 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' << "\nSequence: \t" << whichSequence << '\n'; return ss.str(); } }; //--------------------------------------------------------------------------- class PresetManager{ public: int nextID; int timesOpened; bool presetAlertShowing; // names values // check if already there // find and return all(?) presets within a certain coordinate range vector<Preset> thePresets; int addPreset(string name); TwoVector recallPreset(int presetID); // by name ? id? TwoVector recallPreset(string name); // by name ? id? vector<Preset *> getPresetsInRange(TwoVector min, TwoVector max); void drawPresetsInRange(const TwoVector min, const TwoVector max); void printAll(); void startLoadAll(); // get stuff from XML void exitAndSaveAll(); // save to XML, delete presets array (?) void clearAll(); Json::Value allPresetsToJson(); void readJsonToPresets(const string &jsonFile); void showNameDialog(); PresetManager(); void saveSessionToFile(string userName); }; #endif /* defined(__oscSenderExample__presetManager__) */