annotate presetManager.h @ 49:178642d134a7 tip

xtra files
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 01 May 2013 17:34:33 +0100
parents 1e266647840d
children
rev   line source
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@35 17 #define PILOT_PRESET_FILENAME "pilot_presets.json"
rt300@46 18 #define FACTORY_PRESET_FILENAME "factory_presets.json"
rt300@8 19
rt300@0 20 #include <iostream>
rt300@8 21 #include <string>
rt300@0 22 #include "ofMain.h"
rt300@0 23 #include "ofxiPhone.h"
rt300@0 24 #include "ofxiPhoneExtras.h"
rt300@0 25 #include "2dvector.h"
rt300@3 26 #include "grid.h"
rt300@8 27 #include "eventLogger.h"
rt300@8 28 #include "json.h"
rt300@9 29 #include <ctime>
rt300@8 30
rt300@16 31 #import "presetAlertViewController.h"
rt300@8 32
rt300@0 33 //---------------------------------------------------------------------------
rt300@0 34 class Preset{
rt300@3 35 public:
rt300@8 36 // important details - these saved to file (uploaded?)
rt300@8 37 string creatorUserName;
rt300@8 38 unsigned int creatorDeviceID; // unique user device ID
rt300@8 39 string name; // name of preset
rt300@9 40 unsigned long long creationTime; // datetime that preset was created milliseconds
rt300@8 41 vector<ofColor> pixVals; // hmmm
rt300@8 42 TwoVector coordinates; // position on grid
rt300@38 43 vector<int> params; // actual parameters???
rt300@46 44 unsigned int whichSequence; // the sequence number that this preset was saved with.
rt300@46 45
rt300@3 46
rt300@5 47 // from save button press
rt300@46 48 Preset(TwoVector acoord, string aname,int aID, string un, unsigned int uid, unsigned int sequence){
rt300@0 49 coordinates = acoord;
rt300@0 50 name = aname;
rt300@8 51 creatorUserName = un;
rt300@8 52 creatorDeviceID = uid;
rt300@8 53 double timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@9 54 creationTime = (unsigned long long)(timemsd*1000);
rt300@9 55
rt300@9 56 cout << "Create preset sys time: " << creationTime << "\n";
rt300@8 57 pixVals = makePresetPicture(coordinates);
rt300@46 58 whichSequence = sequence;
rt300@9 59
rt300@4 60 };
rt300@8 61 // from json value
rt300@8 62 Preset(Json::Value jval){
rt300@9 63
rt300@8 64 name = jval["name"].asString();
rt300@8 65 creatorUserName = jval["creatorUserName"].asString();
rt300@8 66 creatorDeviceID = jval["creatorDeviceID"].asUInt();
rt300@8 67 coordinates.x = jval["coordinates"].get("x", 0.0).asFloat();
rt300@8 68 coordinates.y = jval["coordinates"].get("y", 0.0).asFloat();
rt300@9 69 creationTime = jval["creationTime"].asLargestInt(); // dodgy?
rt300@46 70 whichSequence = jval["whichSequence"].asUInt();
rt300@8 71 pixVals = makePresetPicture(coordinates);
rt300@4 72
rt300@46 73 };
rt300@8 74 // from preset file load
rt300@46 75 Preset(TwoVector acoord, string aname,int aID, long long stime, unsigned int seq){
rt300@4 76 coordinates = acoord;
rt300@4 77 name = aname;
rt300@8 78 creationTime = stime;
rt300@8 79 pixVals = makePresetPicture(coordinates);
rt300@46 80 whichSequence = seq;
rt300@0 81 };
rt300@5 82
rt300@8 83 // from download request??
rt300@8 84
rt300@5 85 void draw();
rt300@8 86 Json::Value presetToJson();
rt300@8 87 vector<ofColor> makePresetPicture(TwoVector coord);
rt300@8 88
rt300@9 89 string displayTextDescription(){ // eg: for grid hover
rt300@9 90 // objC to C to C++ bleurgh
rt300@9 91 NSDate *ocdate = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)(creationTime/1000.0)];
rt300@9 92 NSString *dateText = [ocdate description];
rt300@9 93 const char *date_str = [dateText cStringUsingEncoding:NSASCIIStringEncoding];
rt300@8 94 stringstream ss;
rt300@46 95 ss << "Name: \t" << name << "\nCreation time: \t" << date_str << "\nCreator: \t" << creatorUserName << '\n' << "\nSequence: \t" << whichSequence << '\n';
rt300@8 96 return ss.str();
rt300@8 97
rt300@8 98 }
rt300@0 99 };
rt300@3 100
rt300@3 101 //---------------------------------------------------------------------------
rt300@0 102 class PresetManager{
rt300@0 103 public:
rt300@0 104 int nextID;
rt300@3 105 int timesOpened;
rt300@22 106 bool presetAlertShowing;
rt300@22 107
rt300@0 108 // names values
rt300@0 109 // check if already there
rt300@0 110 // find and return all(?) presets within a certain coordinate range
rt300@44 111 vector<Preset> thePresets;
rt300@0 112
rt300@38 113 int addPreset(string name);
rt300@46 114
rt300@0 115 TwoVector recallPreset(int presetID); // by name ? id?
rt300@0 116 TwoVector recallPreset(string name); // by name ? id?
rt300@5 117 vector<Preset *> getPresetsInRange(TwoVector min, TwoVector max);
rt300@5 118 void drawPresetsInRange(const TwoVector min, const TwoVector max);
rt300@4 119 void printAll();
rt300@0 120
rt300@30 121 void startLoadAll(); // get stuff from XML
rt300@0 122 void exitAndSaveAll(); // save to XML, delete presets array (?)
rt300@5 123 void clearAll();
rt300@8 124 Json::Value allPresetsToJson();
rt300@8 125 void readJsonToPresets(const string &jsonFile);
rt300@9 126 void showNameDialog();
rt300@0 127 PresetManager();
rt300@32 128 void saveSessionToFile(string userName);
rt300@0 129 };
rt300@0 130
rt300@4 131
rt300@0 132 #endif /* defined(__oscSenderExample__presetManager__) */