Mercurial > hg > tweakathon2ios
diff presetManager.h @ 1:7e0a19a538d4
added preset manager (untested)
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 10 Oct 2014 13:20:55 +0100 |
parents | |
children | 60b54ba87f6a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/presetManager.h Fri Oct 10 13:20:55 2014 +0100 @@ -0,0 +1,118 @@ +// +// 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(); + + } +}; + +//--------------------------------------------------------------------------- +class PresetManager{ +public: + int nextID; + int timesOpened; + bool presetAlertShowing; + + vector<Preset *> thePresets; + + int savePreset(string name, vector<int> stuff); + + TwoVector recallPreset(int presetID); // by name ? id? + TwoVector 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__) */