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