annotate grid.h @ 44:a1e75b94c505

Snap to eval points. Double tap to go to preset (doesn't quite work yet). Coloured locks. Changed Question 2. Fixed some leaks.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 22 Apr 2013 18:32:34 +0100
parents b91a1859829a
children 1e266647840d
rev   line source
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@0 22 class Grid {
rt300@24 23
rt300@24 24 public:
rt300@24 25 bool snapped;
rt300@44 26 bool automatedMovement;
rt300@44 27 bool presetWasTapped;
rt300@43 28 Hilbert hilbert;
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@44 36 void tap(TwoVector pixel); // user has tapped a point
rt300@44 37
rt300@37 38 typedef enum{NO_INTERPOLATION, INTERPOLATE_GRID, INTERPOLATE_PRESET} interpolateModeType;
rt300@37 39 interpolateModeType interpolateMode;
rt300@24 40 void snapCheck();
rt300@24 41 void shiftCentreToSnapped();
rt300@37 42 void draw();
rt300@43 43
rt300@24 44 void update(); // change according to zoom
rt300@38 45 double interpLevel;
rt300@37 46 int smallestGridSpacing; // number of pixels when small grid dissappears from view
rt300@24 47 vector<int> getParams();
rt300@24 48 TwoVector getCoord();
rt300@39 49 double getScale(){return scale;};
rt300@24 50 void setMinZoom();
rt300@24 51 void setMaxZoom();
rt300@38 52 void setInterpolation(interpolateModeType mode);
rt300@44 53
rt300@44 54 Preset * getClosestPresetOf(vector<Preset *> closePresets);
rt300@44 55 void interpolateTo(TwoVector coord);
rt300@35 56 // HILBERT now does each coord for this
rt300@37 57 vector<int> calculateParamsFromCoord(TwoVector coord);
rt300@37 58 TwoVector calculateCoordFromParams(vector<int> params);
rt300@37 59 vector<int> calculateInterpolatedParamsFromCoord(TwoVector coord);
rt300@24 60 TwoVector coordToPixel(TwoVector coord);
rt300@44 61 TwoVector pixelToCoord(TwoVector pixel);
rt300@44 62
rt300@39 63 void setScale(double scaleLevel);
rt300@24 64 // the inverse stuff
rt300@24 65 void setParams(vector<int>);
rt300@39 66 TwoVector getCoordForPresetSave();
rt300@43 67
rt300@43 68 // experimental
rt300@43 69 void changeNumberOfParamsPerDim();
rt300@0 70 private:
rt300@43 71 void drawGridLines();
rt300@24 72 double scale; // surface units per pixel GUI
rt300@0 73
rt300@43 74 double maxValue; // width of entire space
rt300@3 75 const double minValue; // smallest zoom
rt300@35 76 int paramsPerDim; // no of parameters per dimension (
rt300@35 77 int paramBitDepth; // number of bits for the parameter control data - i.e. always 7 for midi CC
rt300@38 78
rt300@5 79
rt300@5 80
rt300@24 81 TwoVector topLeft; // top left corner of view, surface coords GUI
rt300@0 82 TwoVector bottomRight;
rt300@0 83 TwoVector size; // size of view, surface coords
rt300@0 84 TwoVector pixSize; // size of view pixels (ie screen size!)
rt300@24 85
rt300@0 86 TwoVector centre;
rt300@5 87 TwoVector snapCentre;
rt300@24 88 TwoVector snapDist; // number of pixels to snap to GUI
rt300@7 89 Preset * closestPreset; // pointer to the currently selected (snapped to ) preset.. NULL if none.
rt300@44 90 Preset * tappedPreset; // pointer to currently highlighted (tapped)
rt300@0 91 bool maxZoom, minZoom;
rt300@3 92
rt300@43 93 vector<int> midiCC; // the actual params
rt300@0 94
rt300@0 95 // private functions
rt300@0 96
rt300@38 97
rt300@0 98 void checkLimits();
rt300@0 99 void viewWasChanged();
rt300@0 100 void checkConsistencies();
rt300@0 101
rt300@38 102
rt300@0 103
rt300@0 104 vector<int> walkDiff(vector<bool> left, vector<bool> right); // not used... not worth it!
rt300@0 105
rt300@0 106 void displayInfo();
rt300@3 107 void drawPresets();
rt300@0 108
rt300@0 109 void setCoord(TwoVector coord);
rt300@5 110 void drawCrossHairs();
rt300@9 111
rt300@44 112
rt300@38 113 double calculateInterpolateLevel();
rt300@37 114 vector<int> interpVector(vector<int> upper, vector<int> lower, float frac);
rt300@38 115 vector<int> interpHilbert(int bitlevel, TwoVector coord);
rt300@3 116
rt300@38 117 // the old stuff!!!!!!!!!!
rt300@38 118
rt300@38 119 int codeLength; // the 1d size of the code, determines max extent of single tile, related to params per dim
rt300@38 120
rt300@38 121 void makeCode();
rt300@38 122 vector< vector<bool> > vcode; //
rt300@38 123 vector<int> icode;
rt300@38 124 vector<int> transSeq;
rt300@38 125
rt300@38 126 TwoVector calculateCoordFromParamsOld(vector<int> params) const;
rt300@38 127 vector<int> calculateParamsFromCoordOld(TwoVector coord) const;
rt300@38 128 vector<bool> intToGray(int num, int dimToTravel=3) const;
rt300@38 129 vector<int> coordTobase32(double coord) const;
rt300@38 130 vector<int> grayToMidi(vector<vector <bool> > grayCodes) const;
rt300@38 131
rt300@38 132 // the inverse stuff
rt300@38 133 int grayToInt(vector<bool>) const;
rt300@38 134 double base32toCoord(vector<int>) const;
rt300@38 135 vector<vector <bool> > midiToGray(vector<int>) const;
rt300@38 136 vector<int> codesToBase32(vector<vector<bool> >) const;
rt300@0 137
rt300@0 138
rt300@0 139 };
rt300@0 140
rt300@0 141 #endif /* defined(__oscSenderExample__grid__) */