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