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