view grid.h @ 47:0d3a993405e4

trying rto stop duplictae symbols
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 01 May 2013 16:47:11 +0100
parents 1e266647840d
children
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"
#include "hilbert.h"

#define PRESET_INTERP_TIME 90 // frames
using namespace std;
class Preset;

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

    void animateTo(TwoVector point);
    
    void tap(TwoVector pixel); // user has tapped a point
    
    typedef enum{NO_INTERPOLATION, INTERPOLATE_GRID, INTERPOLATE_PRESET} interpolateModeType;
    interpolateModeType interpolateMode;
    void snapCheck();
    void shiftCentreToSnapped();
    void draw();  

    void update(); // only called if animating
    double interpLevel;
    int smallestGridSpacing; // number of pixels when small grid dissappears from view
    vector<int> getParams();
    TwoVector getCoord();
    double getScale(){return scale;};
    void setMinZoom();
    void setMaxZoom();
    void setInterpolation(interpolateModeType mode);
    
    void startInterpolatedAnimation(TwoVector endCoordinate);


    
    Preset * getClosestPresetOf(vector<Preset *> closePresets);
    void interpolateTo(TwoVector coord);
    // HILBERT now does each coord for this
    vector<int> calculateParamsFromCoord(TwoVector coord);
    TwoVector calculateCoordFromParams(vector<int> params);
    vector<int> calculateInterpolatedParamsFromCoord(TwoVector coord);
    TwoVector coordToPixel(TwoVector coord);
    TwoVector pixelToCoord(TwoVector pixel);
    
    void setScale(double scaleLevel);
    // the inverse stuff
    void setParams(vector<int>);
    TwoVector getCoordForPresetSave();
    
    // experimental
    void changeNumberOfParamsPerDim();
private:
    int framesRemaining;
    
    vector<int> startInterpParams;
    vector<int> endInterpParams;
    TwoVector endInterpCoord;
    
    void drawGridLines();
    double scale;        // surface units per pixel GUI

    double maxValue;    // width of entire space
    const double minValue;    // smallest zoom
    int paramsPerDim; // no of parameters per dimension (
    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.
    Preset * tappedPreset; // pointer to currently highlighted (tapped)
    
    
    bool maxZoom, minZoom;

    vector<int> midiCC; // the actual params
    
// private functions
    
    
    void checkLimits();
    void viewWasChanged();
    void checkConsistencies();
    

    
    vector<int> walkDiff(vector<bool> left, vector<bool> right); // not used... not worth it!
    
    void displayInfo();
    void drawPresets();
    
    void setCoord(TwoVector coord);
    void drawCrossHairs();
    void continueInterpolatedAnimation();
    
    double calculateInterpolateLevel();
    vector<int> interpVector(vector<int> upper, vector<int> lower, float frac);
    vector<int> interpHilbert(int bitlevel, TwoVector coord);

    // the old stuff!!!!!!!!!!

     int codeLength; // the 1d size of the code, determines max extent of single tile, related to params per dim

    void makeCode();
    vector< vector<bool> > vcode; //
    vector<int> icode;
    vector<int> transSeq;
    
    TwoVector calculateCoordFromParamsOld(vector<int> params) const;
    vector<int> calculateParamsFromCoordOld(TwoVector coord) const;
    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;

    
};

#endif /* defined(__oscSenderExample__grid__) */