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