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