annotate presetManager.h @ 38:0dfe9e0c01aa

Evnt trails fit with uploads. Smooth button.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 10 Apr 2013 18:57:05 +0100
parents 790939017078
children a1e75b94c505
rev   line source
rt300@0 1 //
rt300@0 2 // presetManager.h
rt300@0 3 // oscSenderExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 07/11/2012.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@8 9 // defines:
rt300@8 10 // PresetManager
rt300@8 11 // and Preset
rt300@8 12
rt300@0 13 #ifndef __oscSenderExample__presetManager__
rt300@0 14 #define __oscSenderExample__presetManager__
rt300@0 15
rt300@8 16 #define PRESET_FILENAME "presets.json"
rt300@35 17 #define PILOT_PRESET_FILENAME "pilot_presets.json"
rt300@8 18
rt300@0 19 #include <iostream>
rt300@8 20 #include <string>
rt300@0 21 #include "ofMain.h"
rt300@0 22 #include "ofxiPhone.h"
rt300@0 23 #include "ofxiPhoneExtras.h"
rt300@0 24 #include "2dvector.h"
rt300@3 25 #include "grid.h"
rt300@8 26 #include "eventLogger.h"
rt300@8 27 #include "json.h"
rt300@9 28 #include <ctime>
rt300@8 29
rt300@16 30 #import "presetAlertViewController.h"
rt300@8 31
rt300@0 32 //---------------------------------------------------------------------------
rt300@0 33 class Preset{
rt300@3 34 public:
rt300@8 35 // important details - these saved to file (uploaded?)
rt300@8 36 string creatorUserName;
rt300@8 37 unsigned int creatorDeviceID; // unique user device ID
rt300@8 38 string name; // name of preset
rt300@9 39 unsigned long long creationTime; // datetime that preset was created milliseconds
rt300@8 40 vector<ofColor> pixVals; // hmmm
rt300@8 41 TwoVector coordinates; // position on grid
rt300@38 42 vector<int> params; // actual parameters???
rt300@38 43 // not so important - not uploaded
rt300@3 44
rt300@5 45 // from save button press
rt300@8 46 Preset(TwoVector acoord, string aname,int aID, string un, unsigned int uid){
rt300@0 47 coordinates = acoord;
rt300@0 48 name = aname;
rt300@8 49 creatorUserName = un;
rt300@8 50 creatorDeviceID = uid;
rt300@8 51 double timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@9 52 creationTime = (unsigned long long)(timemsd*1000);
rt300@9 53
rt300@9 54 cout << "Create preset sys time: " << creationTime << "\n";
rt300@8 55 pixVals = makePresetPicture(coordinates);
rt300@9 56
rt300@4 57 };
rt300@8 58 // from json value
rt300@8 59 Preset(Json::Value jval){
rt300@9 60
rt300@8 61 name = jval["name"].asString();
rt300@8 62 creatorUserName = jval["creatorUserName"].asString();
rt300@8 63 creatorDeviceID = jval["creatorDeviceID"].asUInt();
rt300@8 64 coordinates.x = jval["coordinates"].get("x", 0.0).asFloat();
rt300@8 65 coordinates.y = jval["coordinates"].get("y", 0.0).asFloat();
rt300@9 66 creationTime = jval["creationTime"].asLargestInt(); // dodgy?
rt300@8 67 pixVals = makePresetPicture(coordinates);
rt300@4 68
rt300@8 69 }
rt300@8 70 // from preset file load
rt300@8 71 Preset(TwoVector acoord, string aname,int aID, long long stime){
rt300@4 72 coordinates = acoord;
rt300@4 73 name = aname;
rt300@8 74 creationTime = stime;
rt300@8 75 pixVals = makePresetPicture(coordinates);
rt300@0 76
rt300@0 77 };
rt300@5 78
rt300@8 79 // from download request??
rt300@8 80
rt300@5 81 void draw();
rt300@8 82 Json::Value presetToJson();
rt300@8 83 vector<ofColor> makePresetPicture(TwoVector coord);
rt300@8 84
rt300@9 85 string displayTextDescription(){ // eg: for grid hover
rt300@9 86 // objC to C to C++ bleurgh
rt300@9 87 NSDate *ocdate = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)(creationTime/1000.0)];
rt300@9 88 NSString *dateText = [ocdate description];
rt300@9 89 const char *date_str = [dateText cStringUsingEncoding:NSASCIIStringEncoding];
rt300@8 90 stringstream ss;
rt300@26 91 ss << "Name: \t" << name << "\nCreation time: \t" << date_str << "\nCreator: \t" << creatorUserName << '\n';
rt300@8 92 return ss.str();
rt300@8 93
rt300@8 94 }
rt300@0 95 };
rt300@3 96
rt300@3 97 //---------------------------------------------------------------------------
rt300@0 98 class PresetManager{
rt300@0 99 public:
rt300@0 100 int nextID;
rt300@3 101 int timesOpened;
rt300@22 102 bool presetAlertShowing;
rt300@22 103
rt300@0 104 // names values
rt300@0 105 // check if already there
rt300@0 106 // find and return all(?) presets within a certain coordinate range
rt300@27 107 vector<Preset *> thePresets;
rt300@0 108
rt300@38 109 int addPreset(string name);
rt300@4 110 int loadPreset(const TwoVector coord, const string name, long long stime);
rt300@4 111
rt300@0 112 TwoVector recallPreset(int presetID); // by name ? id?
rt300@0 113 TwoVector recallPreset(string name); // by name ? id?
rt300@5 114 vector<Preset *> getPresetsInRange(TwoVector min, TwoVector max);
rt300@5 115 void drawPresetsInRange(const TwoVector min, const TwoVector max);
rt300@4 116 void printAll();
rt300@0 117
rt300@30 118 void startLoadAll(); // get stuff from XML
rt300@0 119 void exitAndSaveAll(); // save to XML, delete presets array (?)
rt300@5 120 void clearAll();
rt300@8 121 Json::Value allPresetsToJson();
rt300@8 122 void readJsonToPresets(const string &jsonFile);
rt300@9 123 void showNameDialog();
rt300@0 124 PresetManager();
rt300@32 125 void saveSessionToFile(string userName);
rt300@0 126 };
rt300@0 127
rt300@4 128
rt300@4 129 //---------------------------------------------------------------------------
rt300@8 130 // this is the function that 'saves' a single preset as formatted text
rt300@8 131 // replaced with presetToJson
rt300@4 132 inline ostream& operator<<(ostream & os, const Preset& p){
rt300@4 133 os.setf(ios_base::fixed,ios_base::floatfield);
rt300@4 134 os.precision(1);
rt300@4 135
rt300@8 136 // change this to JSON
rt300@8 137
rt300@8 138 os << p.creationTime << p.coordinates.x << ',' << p.coordinates.y << '\n';
rt300@4 139
rt300@4 140 return os;
rt300@4 141 }
rt300@4 142
rt300@8 143 //---------------------------------------------------------------------------
rt300@8 144 // this is the function that 'reads' all presets as formatted text
rt300@8 145 // replaced with jsonFromPreset or somesuch
rt300@4 146 inline istream& operator>>(istream & is, PresetManager& p)
rt300@4 147 {
rt300@4 148 //um
rt300@4 149 string pname = "BLANK";
rt300@4 150 char delim;
rt300@4 151 double px, py;
rt300@4 152 long long stime;
rt300@4 153
rt300@4 154
rt300@4 155 is.setf(ios_base::fixed,ios_base::floatfield);
rt300@4 156 is.precision(1);
rt300@4 157
rt300@4 158 is >> stime >> delim >> px >> delim >> py;
rt300@4 159 if(!is){
rt300@4 160 return(is);
rt300@4 161 }
rt300@4 162 TwoVector pcoord(px,py);
rt300@7 163 p.loadPreset(pcoord, pname, stime);
rt300@4 164 return(is);
rt300@4 165 }
rt300@4 166
rt300@0 167 #endif /* defined(__oscSenderExample__presetManager__) */