rt300@0
|
1 //
|
rt300@0
|
2 // grid.h
|
rt300@0
|
3 // oscSenderExample
|
rt300@0
|
4 //
|
rt300@0
|
5 // Created by Robert Tubb on 03/10/2012.
|
rt300@0
|
6 //
|
rt300@0
|
7 // This is the view onto the zoomable movable grid
|
rt300@0
|
8
|
rt300@0
|
9 #ifndef __oscSenderExample__grid__
|
rt300@0
|
10 #define __oscSenderExample__grid__
|
rt300@0
|
11
|
rt300@0
|
12 #include <iostream>
|
rt300@0
|
13 #include "2dvector.h"
|
rt300@3
|
14 #include "ofMain.h"
|
rt300@3
|
15 #include "eventLogger.h"
|
rt300@3
|
16 #include "presetManager.h"
|
rt300@0
|
17 using namespace std;
|
rt300@7
|
18 class Preset;
|
rt300@0
|
19
|
rt300@0
|
20 class Grid {
|
rt300@0
|
21 private:
|
rt300@0
|
22 double scale; // surface units per pixel
|
rt300@0
|
23
|
rt300@3
|
24 const double maxValue; // width of entire space
|
rt300@3
|
25 const double minValue; // smallest zoom
|
rt300@3
|
26 const int paramsPerDim; // no of parameters per dimension (
|
rt300@3
|
27 int codeLength; // the 1d size of the code, determines max extent of single tile, related to params per dim
|
rt300@3
|
28 const int paramBitDepth; // number of bits for the parameter control data - i.e. always 7 for midi CC
|
rt300@3
|
29
|
rt300@5
|
30
|
rt300@5
|
31
|
rt300@0
|
32 TwoVector topLeft; // top left corner of view, surface coords
|
rt300@0
|
33 TwoVector bottomRight;
|
rt300@0
|
34 TwoVector size; // size of view, surface coords
|
rt300@0
|
35 TwoVector pixSize; // size of view pixels (ie screen size!)
|
rt300@0
|
36 TwoVector centre;
|
rt300@5
|
37
|
rt300@5
|
38
|
rt300@5
|
39 TwoVector snapCentre;
|
rt300@5
|
40 TwoVector snapDist; // number of pixels to snap to
|
rt300@7
|
41 Preset * closestPreset; // pointer to the currently selected (snapped to ) preset.. NULL if none.
|
rt300@5
|
42
|
rt300@0
|
43 bool maxZoom, minZoom;
|
rt300@0
|
44 int cubeWidth; // side of hypercube. 2 for binary coding.
|
rt300@3
|
45
|
rt300@0
|
46 vector< vector<bool> > vcode; //
|
rt300@0
|
47 vector<int> icode;
|
rt300@0
|
48 vector<int> transSeq;
|
rt300@0
|
49 int midiCC[10]; // the actual params SHOULD BE INITED FROM 2*paramsPerDim
|
rt300@0
|
50
|
rt300@0
|
51 // private functions
|
rt300@0
|
52
|
rt300@0
|
53 void makeCode();
|
rt300@0
|
54 void checkLimits();
|
rt300@0
|
55 void viewWasChanged();
|
rt300@0
|
56 void checkConsistencies();
|
rt300@0
|
57
|
rt300@3
|
58 vector<bool> intToGray(int num, int dimToTravel=3) const;
|
rt300@3
|
59 vector<int> coordTobase32(double coord) const;
|
rt300@3
|
60 vector<int> grayToMidi(vector<vector <bool> > grayCodes) const;
|
rt300@0
|
61
|
rt300@0
|
62 // the inverse stuff
|
rt300@3
|
63 int grayToInt(vector<bool>) const;
|
rt300@3
|
64 double base32toCoord(vector<int>) const;
|
rt300@3
|
65 vector<vector <bool> > midiToGray(vector<int>) const;
|
rt300@3
|
66 vector<int> codesToBase32(vector<vector<bool> >) const;
|
rt300@0
|
67
|
rt300@0
|
68 vector<int> walkDiff(vector<bool> left, vector<bool> right); // not used... not worth it!
|
rt300@0
|
69
|
rt300@0
|
70 void displayInfo();
|
rt300@3
|
71 void drawPresets();
|
rt300@0
|
72
|
rt300@0
|
73 void setCoord(TwoVector coord);
|
rt300@5
|
74 void drawCrossHairs();
|
rt300@5
|
75 void snapCheck();
|
rt300@0
|
76 public:
|
rt300@5
|
77
|
rt300@0
|
78 Grid();
|
rt300@0
|
79 ~Grid();
|
rt300@0
|
80 void init();
|
rt300@3
|
81 void move(TwoVector moveP); // shift view by pixels
|
rt300@0
|
82 void zoom(float factor);
|
rt300@5
|
83 bool snapped;
|
rt300@0
|
84 void draw(); // draw lines
|
rt300@3
|
85
|
rt300@0
|
86 void update(); // change according to zoom
|
rt300@0
|
87
|
rt300@3
|
88 vector<int> calculateParamsFromCoord(TwoVector coord) const;
|
rt300@3
|
89 TwoVector calculateCoordFromParams(vector<int> params) const;
|
rt300@5
|
90 TwoVector coordToPixel(TwoVector coord);
|
rt300@0
|
91 vector<int> getParams();
|
rt300@0
|
92 TwoVector getCoord();
|
rt300@5
|
93 void setMinZoom();
|
rt300@5
|
94 void setMaxZoom();
|
rt300@5
|
95
|
rt300@0
|
96 // the inverse stuff
|
rt300@0
|
97 void setParams(vector<int>);
|
rt300@3
|
98
|
rt300@3
|
99
|
rt300@0
|
100
|
rt300@0
|
101
|
rt300@0
|
102 };
|
rt300@0
|
103
|
rt300@0
|
104 #endif /* defined(__oscSenderExample__grid__) */
|