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@18
|
38 //bool isFilled;
|
rt300@12
|
39 PresetIconView* iconView;
|
rt300@1
|
40 // from save button press
|
rt300@27
|
41 Preset(){};
|
rt300@27
|
42
|
rt300@12
|
43 Preset(vector<int> aCCValues,
|
rt300@12
|
44 string aname,
|
rt300@12
|
45 int aID,
|
rt300@12
|
46 string un,
|
rt300@12
|
47 unsigned int uid,
|
rt300@12
|
48 string imageFile = ""){
|
rt300@1
|
49 CCValues = aCCValues;
|
rt300@18
|
50 // if (CCValues.size()){
|
rt300@18
|
51 // isFilled = true;
|
rt300@18
|
52 //
|
rt300@18
|
53 // }else{
|
rt300@18
|
54 // isFilled = false;
|
rt300@18
|
55 // }
|
rt300@1
|
56
|
rt300@1
|
57 name = aname;
|
rt300@1
|
58 creatorUserName = un;
|
rt300@1
|
59 creatorDeviceID = uid;
|
rt300@1
|
60 double timemsd = [NSDate timeIntervalSinceReferenceDate];
|
rt300@1
|
61 creationTime = (unsigned long long)(timemsd*1000);
|
rt300@1
|
62
|
rt300@1
|
63 //TODO color / texture?
|
rt300@5
|
64 imageFileName = imageFile;
|
rt300@12
|
65 if (imageFileName != ""){
|
rt300@12
|
66 iconView = new PresetIconView(name, imageFileName);
|
rt300@5
|
67 }
|
rt300@6
|
68
|
rt300@1
|
69 };
|
rt300@1
|
70 // contruct from json value
|
rt300@1
|
71 Preset(Json::Value jval){
|
rt300@1
|
72
|
rt300@1
|
73 name = jval["name"].asString();
|
rt300@1
|
74 creatorUserName = jval["creatorUserName"].asString();
|
rt300@1
|
75 creatorDeviceID = jval["creatorDeviceID"].asUInt();
|
rt300@1
|
76
|
rt300@1
|
77
|
rt300@1
|
78 creationTime = jval["creationTime"].asLargestInt(); // dodgy?
|
rt300@5
|
79 imageFileName = jval["imageFileName"].asString();
|
rt300@1
|
80
|
rt300@1
|
81 Json::Value JArray = jval["CCValues"];
|
rt300@5
|
82
|
rt300@1
|
83 if(JArray.size() < 1){
|
rt300@1
|
84 cout << "No Presets";
|
rt300@1
|
85 }
|
rt300@1
|
86 for ( unsigned int i = 0; i < JArray.size(); i++ )
|
rt300@1
|
87 {
|
rt300@1
|
88 CCValues.push_back(JArray[i].asInt());
|
rt300@1
|
89 }
|
rt300@5
|
90
|
rt300@5
|
91 if (imageFileName != ""){
|
rt300@12
|
92 iconView = new PresetIconView(name, imageFileName);
|
rt300@5
|
93 }
|
rt300@1
|
94
|
rt300@12
|
95
|
rt300@1
|
96 }
|
rt300@12
|
97
|
rt300@12
|
98 ofImage* getImage(){
|
rt300@12
|
99 return iconView->getImage();
|
rt300@12
|
100 }
|
rt300@1
|
101 Json::Value presetToJson();
|
rt300@1
|
102
|
rt300@1
|
103 string displayTextDescription(){ // eg: for grid hover
|
rt300@1
|
104 // objC to C to C++ bleurgh
|
rt300@1
|
105 NSDate *ocdate = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)(creationTime/1000.0)];
|
rt300@1
|
106 NSString *dateText = [ocdate description];
|
rt300@1
|
107 const char *date_str = [dateText cStringUsingEncoding:NSASCIIStringEncoding];
|
rt300@1
|
108 stringstream ss;
|
rt300@1
|
109 ss << "Name: \t" << name << "\nCreation time: \t" << date_str << "\nCreator: \t" << creatorUserName << '\n';
|
rt300@1
|
110 return ss.str();
|
rt300@1
|
111
|
rt300@1
|
112 }
|
rt300@4
|
113
|
rt300@4
|
114 string getName(){
|
rt300@4
|
115 return name;
|
rt300@4
|
116 }
|
rt300@4
|
117 vector<int> getValues(){
|
rt300@4
|
118 return CCValues;
|
rt300@4
|
119 }
|
rt300@18
|
120
|
rt300@18
|
121 void overwriteValues(vector<int> v){
|
rt300@18
|
122 if (v.size() != CCValues.size()){
|
rt300@18
|
123 cout << "ERROR: wrong size for vector of CCValues" << endl;
|
rt300@18
|
124 }
|
rt300@6
|
125 CCValues = v;
|
rt300@6
|
126 double timemsd = [NSDate timeIntervalSinceReferenceDate];
|
rt300@6
|
127 creationTime = (unsigned long long)(timemsd*1000);
|
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@18
|
136 void savePreset(Preset * aPreset);
|
rt300@5
|
137 void savePreset(string name, vector<int> stuff);
|
rt300@6
|
138 void generatePresetSlot(const string name, const string imagefn);
|
rt300@18
|
139 vector<int> getPresetValuesForID(int presetID);
|
rt300@18
|
140 vector<int> getPresetValuesForName(string name);
|
rt300@5
|
141 void startLoadAll(); // load everything from the json file
|
rt300@5
|
142 void exitAndSaveAll(); // save stuff to the json file
|
rt300@5
|
143 void printAll();
|
rt300@5
|
144 void clearAll();
|
rt300@27
|
145 Preset* getNeutralPreset();
|
rt300@16
|
146
|
rt300@18
|
147 Preset* getPresetAtIndex(int index);
|
rt300@18
|
148 int getNumberOfPresets(){return thePresets.size();};
|
rt300@5
|
149 protected:
|
rt300@5
|
150 string presetFileName;
|
rt300@1
|
151 int nextID;
|
rt300@1
|
152 int timesOpened;
|
rt300@1
|
153 bool presetAlertShowing;
|
rt300@19
|
154 void showOverwriteDialog();
|
rt300@27
|
155 vector<Preset *> thePresets;
|
rt300@27
|
156
|
rt300@5
|
157
|
rt300@5
|
158 Json::Value allPresetsToJson();
|
rt300@5
|
159 void loadPresetsFromJsonFile(const string &jsonFile);
|
rt300@5
|
160 void updatePresetFile();
|
rt300@5
|
161 void showNameDialog();
|
rt300@31
|
162 void makeNeutralPreset();
|
rt300@27
|
163 Preset neutralPreset;
|
rt300@1
|
164 };
|
rt300@1
|
165
|
rt300@1
|
166
|
rt300@1
|
167 #endif /* defined(__oscSenderExample__presetManager__) */
|