annotate grid.h @ 46:1e266647840d

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