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@1
|
26
|
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@5
|
38 ofImage presetImage;
|
rt300@1
|
39
|
rt300@1
|
40 // from save button press
|
rt300@5
|
41 Preset(vector<int> aCCValues, string aname, int aID, string un, unsigned int uid, string imageFile = ""){
|
rt300@1
|
42 CCValues = aCCValues;
|
rt300@1
|
43
|
rt300@1
|
44 name = aname;
|
rt300@1
|
45 creatorUserName = un;
|
rt300@1
|
46 creatorDeviceID = uid;
|
rt300@1
|
47 double timemsd = [NSDate timeIntervalSinceReferenceDate];
|
rt300@1
|
48 creationTime = (unsigned long long)(timemsd*1000);
|
rt300@1
|
49
|
rt300@1
|
50 cout << "Create preset sys time: " << creationTime << "\n";
|
rt300@1
|
51
|
rt300@1
|
52 //TODO color / texture?
|
rt300@5
|
53 imageFileName = imageFile;
|
rt300@5
|
54 if (imageFile != ""){
|
rt300@5
|
55 presetImage.loadImage(imageFile);
|
rt300@5
|
56 }
|
rt300@1
|
57 };
|
rt300@1
|
58 // contruct from json value
|
rt300@1
|
59 Preset(Json::Value jval){
|
rt300@1
|
60
|
rt300@1
|
61 name = jval["name"].asString();
|
rt300@1
|
62 creatorUserName = jval["creatorUserName"].asString();
|
rt300@1
|
63 creatorDeviceID = jval["creatorDeviceID"].asUInt();
|
rt300@1
|
64
|
rt300@1
|
65
|
rt300@1
|
66 creationTime = jval["creationTime"].asLargestInt(); // dodgy?
|
rt300@5
|
67 imageFileName = jval["imageFileName"].asString();
|
rt300@1
|
68
|
rt300@1
|
69 Json::Value JArray = jval["CCValues"];
|
rt300@5
|
70
|
rt300@1
|
71 if(JArray.size() < 1){
|
rt300@1
|
72 cout << "No Presets";
|
rt300@1
|
73 }
|
rt300@1
|
74 for ( unsigned int i = 0; i < JArray.size(); i++ )
|
rt300@1
|
75 {
|
rt300@1
|
76 CCValues.push_back(JArray[i].asInt());
|
rt300@1
|
77 }
|
rt300@5
|
78
|
rt300@5
|
79 if (imageFileName != ""){
|
rt300@5
|
80 presetImage.loadImage(imageFileName);
|
rt300@5
|
81 }
|
rt300@1
|
82
|
rt300@1
|
83 }
|
rt300@1
|
84
|
rt300@1
|
85 void draw();
|
rt300@1
|
86 Json::Value presetToJson();
|
rt300@1
|
87
|
rt300@1
|
88 string displayTextDescription(){ // eg: for grid hover
|
rt300@1
|
89 // objC to C to C++ bleurgh
|
rt300@1
|
90 NSDate *ocdate = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)(creationTime/1000.0)];
|
rt300@1
|
91 NSString *dateText = [ocdate description];
|
rt300@1
|
92 const char *date_str = [dateText cStringUsingEncoding:NSASCIIStringEncoding];
|
rt300@1
|
93 stringstream ss;
|
rt300@1
|
94 ss << "Name: \t" << name << "\nCreation time: \t" << date_str << "\nCreator: \t" << creatorUserName << '\n';
|
rt300@1
|
95 return ss.str();
|
rt300@1
|
96
|
rt300@1
|
97 }
|
rt300@4
|
98
|
rt300@4
|
99 string getName(){
|
rt300@4
|
100 return name;
|
rt300@4
|
101 }
|
rt300@4
|
102 vector<int> getValues(){
|
rt300@4
|
103 return CCValues;
|
rt300@4
|
104 }
|
rt300@1
|
105 };
|
rt300@1
|
106
|
rt300@1
|
107 //---------------------------------------------------------------------------
|
rt300@1
|
108 class PresetManager{
|
rt300@1
|
109 public:
|
rt300@5
|
110 PresetManager();
|
rt300@5
|
111 void savePreset(string name, vector<int> stuff);
|
rt300@5
|
112 vector<int> recallPreset(int presetID);
|
rt300@5
|
113 vector<int> recallPreset(string name);
|
rt300@5
|
114 void startLoadAll(); // load everything from the json file
|
rt300@5
|
115 void exitAndSaveAll(); // save stuff to the json file
|
rt300@5
|
116 void printAll();
|
rt300@5
|
117 void clearAll();
|
rt300@5
|
118 protected:
|
rt300@5
|
119 string presetFileName;
|
rt300@1
|
120 int nextID;
|
rt300@1
|
121 int timesOpened;
|
rt300@1
|
122 bool presetAlertShowing;
|
rt300@1
|
123
|
rt300@1
|
124 vector<Preset *> thePresets;
|
rt300@5
|
125
|
rt300@5
|
126 Json::Value allPresetsToJson();
|
rt300@5
|
127 void loadPresetsFromJsonFile(const string &jsonFile);
|
rt300@5
|
128 void updatePresetFile();
|
rt300@5
|
129 void showNameDialog();
|
rt300@1
|
130
|
rt300@1
|
131 };
|
rt300@1
|
132
|
rt300@1
|
133
|
rt300@1
|
134 #endif /* defined(__oscSenderExample__presetManager__) */
|