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