Mercurial > hg > drum-timing-analyser
diff DrumTimingLoader_OF/PerformanceAnalyserSrc/TimingAnalyser.h @ 1:106bc2d4f702
added timing analyser file
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sat, 23 Nov 2013 15:44:47 +0000 |
parents | |
children | 50ba55abea8c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DrumTimingLoader_OF/PerformanceAnalyserSrc/TimingAnalyser.h Sat Nov 23 15:44:47 2013 +0000 @@ -0,0 +1,212 @@ +/* + * TimingAnalyser.h + * performanceTimingAnalyser + * + * Created by Andrew on 17/12/2011. + * Copyright 2011 QMUL. All rights reserved. + * + */ +#ifndef TIMING_ANALYSER +#define TIMING_ANALYSER + +#include "ofMain.h" + +#include <vector> +#include <cstdlib> +using namespace std; + +//big matrix stores cost + + +struct Route { + int tempoIndex, phaseIndex; + double addedCost, totalCost; + int previousTempoIndex; + int previousPhaseIndex; + int phaseHop, tempoHop; + double previousCost; + double preHopCost; + double phaseHopCost, tempoHopCost; + + // int currentTempoIndex, currentPhaseIndex; + // int globalPhaseOffset; + // int tempoMinimumOffset; +}; + +typedef std::vector<Route> RouteVector; +typedef std::vector<RouteVector> RouteMatrix; +typedef std::vector<RouteMatrix> RouteHistory; + +typedef std::vector<double> DoubleVector; +typedef std::vector<DoubleVector> DoubleMatrix; + +struct Path{ + RouteMatrix currentRoute; + int bestTempo, bestPhase; +// int globalPhaseOffset; + int tempoOffset, phaseOffset; + int phaseShiftApplied; + int tempoShiftApplied; + int eventTimeObserved; + DoubleMatrix costMatrix; +}; +typedef std::vector<Path> PathVector; + +class TimingAnalyser{ + public: + TimingAnalyser(); + //size of matrix and mean tempo determined here + static const int tempoRange = 47; + static const int phaseRange = 57; + int meanGlobalTempo ; + + std::string timingDataFilepath; + std::string processedBeatTimesFilepath; + + void setTempoLimits(const int& newGlobalTempo); + + DoubleMatrix previousLogMatrix; + + typedef std::vector<int> IntVector; + typedef std::vector<IntVector> IntMatrix; + IntMatrix timingData; + IntVector basicInterOnsetInterval; + + + void printCostMatrix(const RouteMatrix& m); + //NEW COST METHODS: + void updateCostToPoint(const int& eventTime, const int& eventBeatLocation); + double getBestMinimumCost(const int& newTempoInUnits, const int& newPhaseInUnits, Route& r); + + double getPhaseIndexFromEventTime(const double& eventTime); + double getTempoInUnits(const double& tempoInMs); + + + + PathVector pathHistory; + void setBestTempoAndPhase(Path& newPath); + void printPathHistory(); + void printIOIdata(); + void processPathHistory(); + +// RouteMatrix routes; +// RouteHistory history; + + int playingIndex; + +// void printHistory(); + //void printBestPath(); + + int phaseMinimumOffset; + int globalTimeOffset; + int tempoMinimumOffset; + double maximumTempo, minimumTempo; + double screenHeight, screenWidth ; + + void drawTempoCurve(); + int getHeightPoint(float f); + + int numberOfPointsPerPage; + bool printHistory; + + double tempoCost, phaseCost; + + DoubleMatrix logProbabilityMatrix; + double lastBeatPosition; + + int minimumPhaseHop, maximumPhaseHop ; + +// double getCost(const int& eventTime, const int& interval, const int& tempoIndex, const int& phaseIndex); + void updateCost(const int& eventTime, const int& eventBeatLocation); + void updateMatrixOffsets(const int& eventTime); + + void checkShiftMatrix(); + void shiftMatrixToMatchBestPhase(const int& bestPhaseIndex); + void shiftMatrixToMatchBestTempo(const int& bestTempoIndex); + int recentPhaseShift, recentTempoShift; + bool moveMatrixToOptimalCostPosition; + + int startPoint;//for drawing + + + float movementFactor; +// static const double tempoMinimumOffset = meanGlobalTempo - (tempoRange-1)/2; + + bool checkPhaseRange(const int& phaseToCheck); + bool checkTempoRange(const int& tempoToCheck); + + double phaseHopCost(const int& phaseHop); + double tempoHopCost(const int& tempoHop); + + double tempoScalar, phaseScalar; + int meanTempo; + int meanTempoIndex, meanPhaseIndex; + + int currentBestTempo, currentBestPhase; + + double getPhase(const int& phaseIndex); + double getTempo(const int& tempoIndex); + double getTempo(const int& tempoIndex, const int& tempoOffset); + double getPhase(const int& phaseIndex, const int& phaseOffset); + + int getTempoIndex(const double& tempo); + int getPhaseIndex(const double& location); + + double getBestPreviousCost(const int& tempoIndex, const int& phaseIndex, Route& r); + //double getlocation(const int& tempoIndex, const int& phaseIndex); + void getLocation(const int& tempoIndex, const int& phaseIndex, const int& interval); + void drawCostMatrix(); + double getMaximum(); + + double getMinimumTransitionCost(const int& interval, const int& tempoIndex, const int& phaseIndex); + //int getBeatLocation(const int& phaseIndex); + //int getProjectedBeatLocation(const int& tempoIndex, const int& phaseIndex, const int& interval); + + void initialiseRoutes(); + void printLogMatrix(); + void printMatrix(DoubleMatrix& logMatrix); + + void exportTimingData(); + void importTimingData(std::string importFileName); + void exportProcessedBeatTimes(const double& firstBeatTime); + + bool drawIOIintervals; + + void calculateTempoLimits(); + void clearData(); + + int getIndexAtMouseXposition(const int& Xpos); + + int minDrawTempo, maxDrawTempo; + bool drawBPM; + double msToBpm(const double& ms); + + void moveDrawWindowUp(); + void moveDrawWindowDown(); + void widenDrawWindow(); + void narrowDrawWindow(); + + bool blackAndWhite; + DoubleVector beatPosition; + + IntMatrix timingHistogram; + void clearHistogram(); + void getHistogramResults(); + + bool drawExpressiveTimingData; + bool mozartTriplets; + + int tempoVariationStartIndex; + int tempoVariationEndIndex; + double calculateTempoVariation(); + + ofTrueTypeFont timesFont;//FONT + + //vars added since new project on Drum Timing + double offsetToFirstPoint;//this set at beginning - when we load in beat times that do not start at zero; + + void zoomIn(); + void zoomOut(); +}; + +#endif \ No newline at end of file