annotate presetManager.h @ 5:5ee5ef99e117

presets have "icons" and save OK. Snapping works. move velocity still frustrating.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 05 Dec 2012 18:42:02 +0000
parents 7541aeaebcdc
children 845ea04f8e33
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@0 9 #ifndef __oscSenderExample__presetManager__
rt300@0 10 #define __oscSenderExample__presetManager__
rt300@0 11
rt300@0 12 #include <iostream>
rt300@0 13 #include "ofMain.h"
rt300@0 14 #include "ofxiPhone.h"
rt300@0 15 #include "ofxiPhoneExtras.h"
rt300@0 16 #include "2dvector.h"
rt300@3 17 #include "grid.h"
rt300@3 18
rt300@0 19
rt300@0 20 //---------------------------------------------------------------------------
rt300@0 21 class Preset{
rt300@3 22 public:
rt300@0 23
rt300@0 24 int presetID;
rt300@0 25 string name;
rt300@4 26 long long savetime;
rt300@5 27 vector<ofColor> pixVals;
rt300@4 28 double timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@4 29
rt300@0 30 TwoVector coordinates;
rt300@3 31
rt300@5 32 // from save button press
rt300@5 33 Preset(TwoVector acoord, string aname,int aID, const vector<ofColor> & pixCols){
rt300@0 34 coordinates = acoord;
rt300@0 35 name = aname;
rt300@0 36 presetID = aID;
rt300@4 37
rt300@4 38 timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@4 39 savetime = (long long)(timemsd*1000);
rt300@5 40 pixVals = pixCols;
rt300@5 41
rt300@3 42
rt300@3 43 };
rt300@3 44 Preset(int aID){
rt300@3 45 coordinates.setCoord(0.0,0.0);
rt300@3 46 name = "Blank";
rt300@3 47 presetID = aID;
rt300@4 48 timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@4 49 savetime = (long long)(timemsd*1000);
rt300@4 50
rt300@4 51 };
rt300@4 52
rt300@5 53 // from file load
rt300@5 54 Preset(TwoVector acoord, string aname,int aID, long long stime, const vector<ofColor> & pixCols){
rt300@4 55 coordinates = acoord;
rt300@4 56 name = aname;
rt300@4 57 presetID = aID;
rt300@4 58 savetime = stime;
rt300@5 59 pixVals = pixCols;
rt300@0 60
rt300@0 61 };
rt300@5 62
rt300@5 63 void draw();
rt300@3 64
rt300@0 65 };
rt300@3 66
rt300@3 67
rt300@3 68 //---------------------------------------------------------------------------
rt300@0 69 class PresetManager{
rt300@0 70 public:
rt300@0 71 int nextID;
rt300@3 72 int timesOpened;
rt300@0 73 // names values
rt300@0 74 // check if already there
rt300@0 75 // find and return all(?) presets within a certain coordinate range
rt300@0 76 vector<Preset *> thePresets; // we want vector ? or list? pointers using new?
rt300@0 77
rt300@0 78 int addPreset(TwoVector coord, string name); // returns id or negative error number
rt300@4 79 int loadPreset(const TwoVector coord, const string name, long long stime);
rt300@4 80
rt300@0 81 TwoVector recallPreset(int presetID); // by name ? id?
rt300@0 82 TwoVector recallPreset(string name); // by name ? id?
rt300@5 83 vector<Preset *> getPresetsInRange(TwoVector min, TwoVector max);
rt300@5 84 void drawPresetsInRange(const TwoVector min, const TwoVector max);
rt300@5 85 vector<ofColor> makePresetPicture(TwoVector coord);
rt300@4 86 void printAll();
rt300@0 87
rt300@0 88 void startupLoadAll(); // get stuff from XML
rt300@0 89 void exitAndSaveAll(); // save to XML, delete presets array (?)
rt300@5 90 void clearAll();
rt300@0 91
rt300@0 92 PresetManager();
rt300@0 93 };
rt300@0 94
rt300@4 95
rt300@4 96 //---------------------------------------------------------------------------
rt300@4 97 inline ostream& operator<<(ostream & os, const Preset& p){
rt300@4 98 os.setf(ios_base::fixed,ios_base::floatfield);
rt300@4 99 os.precision(1);
rt300@4 100
rt300@4 101 os << p.savetime << ',' << p.coordinates.x << ',' << p.coordinates.y << '\n';
rt300@4 102
rt300@4 103 return os;
rt300@4 104 }
rt300@4 105
rt300@4 106 //---------------------------------------------------------------------------
rt300@4 107 inline istream& operator>>(istream & is, PresetManager& p)
rt300@4 108 {
rt300@4 109 //um
rt300@4 110 string pname = "BLANK";
rt300@4 111 char delim;
rt300@4 112 double px, py;
rt300@4 113 long long stime;
rt300@4 114
rt300@4 115
rt300@4 116 is.setf(ios_base::fixed,ios_base::floatfield);
rt300@4 117 is.precision(1);
rt300@4 118
rt300@4 119 is >> stime >> delim >> px >> delim >> py;
rt300@4 120 if(!is){
rt300@4 121 cout << "problem reading preset file";
rt300@4 122 return(is);
rt300@4 123 }
rt300@4 124 TwoVector pcoord(px,py);
rt300@4 125 int n = p.loadPreset(pcoord, pname, stime);
rt300@4 126 return(is);
rt300@4 127 }
rt300@4 128
rt300@0 129 #endif /* defined(__oscSenderExample__presetManager__) */