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