view grid.h @ 27:ae4d2c3ce5e0

Details. Zoom trailing finger move sorted. Qs rephrased.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 13 Feb 2013 17:03:56 +0000
parents a4908ad8c78e
children 94df2cd72d7b
line wrap: on
line source
//
//  grid.h
//  oscSenderExample
//
//  Created by Robert Tubb on 03/10/2012.
//
//  This is the view onto the zoomable movable grid

#ifndef __oscSenderExample__grid__
#define __oscSenderExample__grid__

#include <iostream>
#include "2dvector.h"
#include "ofMain.h"
#include "eventLogger.h"
#include "presetManager.h"
using namespace std;
class Preset;

class Grid {
    
public:
    bool snapped;
    
    
    Grid();
    ~Grid();
    void init();
    void move(TwoVector moveP); // shift view by pixels
    void zoom(float factor);

    
    void snapCheck();
    void shiftCentreToSnapped();
    void draw();    // draw lines
    
    void update(); // change according to zoom
    
    vector<int> getParams();
    TwoVector getCoord();
    void setMinZoom();
    void setMaxZoom();
    
    vector<int> calculateParamsFromCoord(TwoVector coord) const;
    TwoVector calculateCoordFromParams(vector<int> params) const;
    TwoVector coordToPixel(TwoVector coord);
 
    // the inverse stuff
    void setParams(vector<int>);
    
private:
    double scale;        // surface units per pixel GUI

    const double maxValue;    // width of entire space
    const double minValue;    // smallest zoom
    const int paramsPerDim; // no of parameters per dimension (
    int codeLength; // the 1d size of the code, determines max extent of single tile, related to params per dim
    const int paramBitDepth; // number of bits for the parameter control data - i.e. always 7 for midi CC
    

    
    TwoVector topLeft; // top left corner of view, surface coords GUI
    TwoVector bottomRight;
    TwoVector size;     // size of view, surface coords
    TwoVector pixSize; // size of view pixels (ie screen size!)
    
    TwoVector centre;
    TwoVector snapCentre;
    TwoVector snapDist; // number of pixels to snap to GUI
    Preset * closestPreset; // pointer to the currently selected (snapped to ) preset.. NULL if none.
    
    bool maxZoom, minZoom;
    int cubeWidth;    // side of hypercube. 2 for binary coding.

    vector< vector<bool> > vcode; //
    vector<int> icode;
    vector<int> transSeq;
    int midiCC[10]; // the actual params SHOULD BE INITED FROM 2*paramsPerDim
    
// private functions
    
    void makeCode();
    void checkLimits();
    void viewWasChanged();
    void checkConsistencies();
    
    vector<bool> intToGray(int num, int dimToTravel=3) const;
    vector<int> coordTobase32(double coord) const;
    vector<int> grayToMidi(vector<vector <bool> > grayCodes) const;
    
    // the inverse stuff
    int grayToInt(vector<bool>) const;
    double base32toCoord(vector<int>) const;
    vector<vector <bool> > midiToGray(vector<int>) const;
    vector<int> codesToBase32(vector<vector<bool> >) const;
    
    vector<int> walkDiff(vector<bool> left, vector<bool> right); // not used... not worth it!
    
    void displayInfo();
    void drawPresets();
    
    void setCoord(TwoVector coord);
    void drawCrossHairs();
    

    


    
};

#endif /* defined(__oscSenderExample__grid__) */