rt300@1
|
1 //
|
rt300@1
|
2 // presetManager.h
|
rt300@1
|
3 // oscSenderExample
|
rt300@1
|
4 //
|
rt300@1
|
5 // Created by Robert Tubb on 07/11/2012.
|
rt300@1
|
6 //
|
rt300@1
|
7 //
|
rt300@1
|
8
|
rt300@1
|
9 // defines:
|
rt300@1
|
10 // PresetManager
|
rt300@1
|
11 // and Preset
|
rt300@1
|
12
|
rt300@1
|
13 #ifndef __oscSenderExample__presetManager__
|
rt300@1
|
14 #define __oscSenderExample__presetManager__
|
rt300@1
|
15
|
rt300@1
|
16 #define PRESET_FILENAME "presets.json"
|
rt300@1
|
17
|
rt300@1
|
18 #include <iostream>
|
rt300@1
|
19 #include <string>
|
rt300@1
|
20 #include "ofMain.h"
|
rt300@1
|
21 #include "ofxiPhone.h"
|
rt300@1
|
22 #include "ofxiPhoneExtras.h"
|
rt300@1
|
23 #include "eventLogger.h"
|
rt300@1
|
24 #include "json.h"
|
rt300@1
|
25 #include <ctime>
|
rt300@12
|
26 #include "PresetView.h"
|
rt300@1
|
27
|
rt300@1
|
28 //---------------------------------------------------------------------------
|
rt300@1
|
29 class Preset{
|
rt300@1
|
30 public:
|
rt300@1
|
31 // important details - these saved to file (uploaded?)
|
rt300@1
|
32 string creatorUserName;
|
rt300@1
|
33 unsigned int creatorDeviceID; // unique user device ID
|
rt300@1
|
34 string name; // name of preset
|
rt300@1
|
35 unsigned long long creationTime; // datetime that preset was created milliseconds
|
rt300@5
|
36 string imageFileName;
|
rt300@1
|
37 vector<int> CCValues; // the actual data
|
rt300@6
|
38 bool isFilled;
|
rt300@12
|
39 PresetIconView* iconView;
|
rt300@1
|
40 // from save button press
|
rt300@12
|
41 Preset(vector<int> aCCValues,
|
rt300@12
|
42 string aname,
|
rt300@12
|
43 int aID,
|
rt300@12
|
44 string un,
|
rt300@12
|
45 unsigned int uid,
|
rt300@12
|
46 string imageFile = ""){
|
rt300@1
|
47 CCValues = aCCValues;
|
rt300@6
|
48 if (CCValues.size()){
|
rt300@6
|
49 isFilled = true;
|
rt300@6
|
50
|
rt300@6
|
51 }else{
|
rt300@6
|
52 isFilled = false;
|
rt300@6
|
53 }
|
rt300@1
|
54
|
rt300@1
|
55 name = aname;
|
rt300@1
|
56 creatorUserName = un;
|
rt300@1
|
57 creatorDeviceID = uid;
|
rt300@1
|
58 double timemsd = [NSDate timeIntervalSinceReferenceDate];
|
rt300@1
|
59 creationTime = (unsigned long long)(timemsd*1000);
|
rt300@1
|
60
|
rt300@1
|
61 //TODO color / texture?
|
rt300@5
|
62 imageFileName = imageFile;
|
rt300@12
|
63 if (imageFileName != ""){
|
rt300@12
|
64 iconView = new PresetIconView(name, imageFileName);
|
rt300@5
|
65 }
|
rt300@6
|
66
|
rt300@1
|
67 };
|
rt300@1
|
68 // contruct from json value
|
rt300@1
|
69 Preset(Json::Value jval){
|
rt300@1
|
70
|
rt300@1
|
71 name = jval["name"].asString();
|
rt300@1
|
72 creatorUserName = jval["creatorUserName"].asString();
|
rt300@1
|
73 creatorDeviceID = jval["creatorDeviceID"].asUInt();
|
rt300@1
|
74
|
rt300@1
|
75
|
rt300@1
|
76 creationTime = jval["creationTime"].asLargestInt(); // dodgy?
|
rt300@5
|
77 imageFileName = jval["imageFileName"].asString();
|
rt300@1
|
78
|
rt300@1
|
79 Json::Value JArray = jval["CCValues"];
|
rt300@5
|
80
|
rt300@1
|
81 if(JArray.size() < 1){
|
rt300@1
|
82 cout << "No Presets";
|
rt300@1
|
83 }
|
rt300@1
|
84 for ( unsigned int i = 0; i < JArray.size(); i++ )
|
rt300@1
|
85 {
|
rt300@1
|
86 CCValues.push_back(JArray[i].asInt());
|
rt300@1
|
87 }
|
rt300@5
|
88
|
rt300@5
|
89 if (imageFileName != ""){
|
rt300@12
|
90 iconView = new PresetIconView(name, imageFileName);
|
rt300@5
|
91 }
|
rt300@1
|
92
|
rt300@12
|
93
|
rt300@1
|
94 }
|
rt300@12
|
95
|
rt300@12
|
96 ofImage* getImage(){
|
rt300@12
|
97 return iconView->getImage();
|
rt300@12
|
98 }
|
rt300@1
|
99 Json::Value presetToJson();
|
rt300@1
|
100
|
rt300@1
|
101 string displayTextDescription(){ // eg: for grid hover
|
rt300@1
|
102 // objC to C to C++ bleurgh
|
rt300@1
|
103 NSDate *ocdate = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)(creationTime/1000.0)];
|
rt300@1
|
104 NSString *dateText = [ocdate description];
|
rt300@1
|
105 const char *date_str = [dateText cStringUsingEncoding:NSASCIIStringEncoding];
|
rt300@1
|
106 stringstream ss;
|
rt300@1
|
107 ss << "Name: \t" << name << "\nCreation time: \t" << date_str << "\nCreator: \t" << creatorUserName << '\n';
|
rt300@1
|
108 return ss.str();
|
rt300@1
|
109
|
rt300@1
|
110 }
|
rt300@4
|
111
|
rt300@4
|
112 string getName(){
|
rt300@4
|
113 return name;
|
rt300@4
|
114 }
|
rt300@4
|
115 vector<int> getValues(){
|
rt300@4
|
116 return CCValues;
|
rt300@4
|
117 }
|
rt300@6
|
118 void setValues(vector<int> v){
|
rt300@6
|
119 CCValues = v;
|
rt300@6
|
120 double timemsd = [NSDate timeIntervalSinceReferenceDate];
|
rt300@6
|
121 creationTime = (unsigned long long)(timemsd*1000);
|
rt300@6
|
122 if (CCValues.size()){
|
rt300@6
|
123 isFilled = true;
|
rt300@6
|
124
|
rt300@6
|
125 }else{
|
rt300@6
|
126 isFilled = false;
|
rt300@6
|
127 }
|
rt300@6
|
128 }
|
rt300@6
|
129
|
rt300@1
|
130 };
|
rt300@1
|
131
|
rt300@1
|
132 //---------------------------------------------------------------------------
|
rt300@1
|
133 class PresetManager{
|
rt300@1
|
134 public:
|
rt300@5
|
135 PresetManager();
|
rt300@5
|
136 void savePreset(string name, vector<int> stuff);
|
rt300@6
|
137 void generatePresetSlot(const string name, const string imagefn);
|
rt300@5
|
138 vector<int> recallPreset(int presetID);
|
rt300@5
|
139 vector<int> recallPreset(string name);
|
rt300@5
|
140 void startLoadAll(); // load everything from the json file
|
rt300@5
|
141 void exitAndSaveAll(); // save stuff to the json file
|
rt300@5
|
142 void printAll();
|
rt300@5
|
143 void clearAll();
|
rt300@16
|
144
|
rt300@16
|
145 Preset* getPresetAtIndex(int index){
|
rt300@16
|
146
|
rt300@16
|
147 if (index >= thePresets.size()){
|
rt300@16
|
148 cout << "ERROR: index " << index << " exceeds number of presets " << thePresets.size() << endl;
|
rt300@16
|
149 return NULL;
|
rt300@16
|
150 }else{
|
rt300@16
|
151 return thePresets[index];
|
rt300@16
|
152
|
rt300@16
|
153 }
|
rt300@16
|
154 };
|
rt300@5
|
155 protected:
|
rt300@5
|
156 string presetFileName;
|
rt300@1
|
157 int nextID;
|
rt300@1
|
158 int timesOpened;
|
rt300@1
|
159 bool presetAlertShowing;
|
rt300@1
|
160
|
rt300@1
|
161 vector<Preset *> thePresets;
|
rt300@5
|
162
|
rt300@5
|
163 Json::Value allPresetsToJson();
|
rt300@5
|
164 void loadPresetsFromJsonFile(const string &jsonFile);
|
rt300@5
|
165 void updatePresetFile();
|
rt300@5
|
166 void showNameDialog();
|
rt300@1
|
167
|
rt300@1
|
168 };
|
rt300@1
|
169
|
rt300@1
|
170
|
rt300@1
|
171 #endif /* defined(__oscSenderExample__presetManager__) */
|