annotate DrumTimingLoader_OF/PerformanceAnalyserSrc/TimingAnalyser.h @ 3:303edbbcf1bd tip

updated ofxAubioOnsetDetection file
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Sun, 24 Nov 2013 08:15:17 +0000
parents 50ba55abea8c
children
rev   line source
andrew@1 1 /*
andrew@1 2 * TimingAnalyser.h
andrew@1 3 * performanceTimingAnalyser
andrew@1 4 *
andrew@1 5 * Created by Andrew on 17/12/2011.
andrew@1 6 * Copyright 2011 QMUL. All rights reserved.
andrew@1 7 *
andrew@1 8 */
andrew@1 9 #ifndef TIMING_ANALYSER
andrew@1 10 #define TIMING_ANALYSER
andrew@1 11
andrew@1 12 #include "ofMain.h"
andrew@1 13
andrew@1 14 #include <vector>
andrew@1 15 #include <cstdlib>
andrew@1 16 using namespace std;
andrew@1 17
andrew@1 18 //big matrix stores cost
andrew@1 19
andrew@1 20
andrew@1 21 struct Route {
andrew@1 22 int tempoIndex, phaseIndex;
andrew@1 23 double addedCost, totalCost;
andrew@1 24 int previousTempoIndex;
andrew@1 25 int previousPhaseIndex;
andrew@1 26 int phaseHop, tempoHop;
andrew@1 27 double previousCost;
andrew@1 28 double preHopCost;
andrew@1 29 double phaseHopCost, tempoHopCost;
andrew@1 30
andrew@1 31 // int currentTempoIndex, currentPhaseIndex;
andrew@1 32 // int globalPhaseOffset;
andrew@1 33 // int tempoMinimumOffset;
andrew@1 34 };
andrew@1 35
andrew@1 36 typedef std::vector<Route> RouteVector;
andrew@1 37 typedef std::vector<RouteVector> RouteMatrix;
andrew@1 38 typedef std::vector<RouteMatrix> RouteHistory;
andrew@1 39
andrew@1 40 typedef std::vector<double> DoubleVector;
andrew@1 41 typedef std::vector<DoubleVector> DoubleMatrix;
andrew@1 42
andrew@1 43 struct Path{
andrew@1 44 RouteMatrix currentRoute;
andrew@1 45 int bestTempo, bestPhase;
andrew@1 46 // int globalPhaseOffset;
andrew@1 47 int tempoOffset, phaseOffset;
andrew@1 48 int phaseShiftApplied;
andrew@1 49 int tempoShiftApplied;
andrew@1 50 int eventTimeObserved;
andrew@1 51 DoubleMatrix costMatrix;
andrew@1 52 };
andrew@1 53 typedef std::vector<Path> PathVector;
andrew@1 54
andrew@1 55 class TimingAnalyser{
andrew@1 56 public:
andrew@1 57 TimingAnalyser();
andrew@1 58 //size of matrix and mean tempo determined here
andrew@1 59 static const int tempoRange = 47;
andrew@1 60 static const int phaseRange = 57;
andrew@1 61 int meanGlobalTempo ;
andrew@1 62
andrew@1 63 std::string timingDataFilepath;
andrew@1 64 std::string processedBeatTimesFilepath;
andrew@1 65
andrew@1 66 void setTempoLimits(const int& newGlobalTempo);
andrew@1 67
andrew@1 68 DoubleMatrix previousLogMatrix;
andrew@1 69
andrew@1 70 typedef std::vector<int> IntVector;
andrew@1 71 typedef std::vector<IntVector> IntMatrix;
andrew@1 72 IntMatrix timingData;
andrew@1 73 IntVector basicInterOnsetInterval;
andrew@1 74
andrew@2 75 void updatePlayIndex(const double& seconds);
andrew@2 76 double getNoteTime(const int& index);
andrew@1 77
andrew@1 78 void printCostMatrix(const RouteMatrix& m);
andrew@1 79 //NEW COST METHODS:
andrew@1 80 void updateCostToPoint(const int& eventTime, const int& eventBeatLocation);
andrew@1 81 double getBestMinimumCost(const int& newTempoInUnits, const int& newPhaseInUnits, Route& r);
andrew@1 82
andrew@1 83 double getPhaseIndexFromEventTime(const double& eventTime);
andrew@1 84 double getTempoInUnits(const double& tempoInMs);
andrew@1 85
andrew@1 86
andrew@1 87
andrew@1 88 PathVector pathHistory;
andrew@1 89 void setBestTempoAndPhase(Path& newPath);
andrew@1 90 void printPathHistory();
andrew@1 91 void printIOIdata();
andrew@1 92 void processPathHistory();
andrew@1 93
andrew@1 94 // RouteMatrix routes;
andrew@1 95 // RouteHistory history;
andrew@1 96
andrew@1 97 int playingIndex;
andrew@1 98
andrew@1 99 // void printHistory();
andrew@1 100 //void printBestPath();
andrew@1 101
andrew@1 102 int phaseMinimumOffset;
andrew@1 103 int globalTimeOffset;
andrew@1 104 int tempoMinimumOffset;
andrew@1 105 double maximumTempo, minimumTempo;
andrew@1 106 double screenHeight, screenWidth ;
andrew@1 107
andrew@1 108 void drawTempoCurve();
andrew@1 109 int getHeightPoint(float f);
andrew@1 110
andrew@1 111 int numberOfPointsPerPage;
andrew@1 112 bool printHistory;
andrew@1 113
andrew@1 114 double tempoCost, phaseCost;
andrew@1 115
andrew@1 116 DoubleMatrix logProbabilityMatrix;
andrew@1 117 double lastBeatPosition;
andrew@1 118
andrew@1 119 int minimumPhaseHop, maximumPhaseHop ;
andrew@1 120
andrew@1 121 // double getCost(const int& eventTime, const int& interval, const int& tempoIndex, const int& phaseIndex);
andrew@1 122 void updateCost(const int& eventTime, const int& eventBeatLocation);
andrew@1 123 void updateMatrixOffsets(const int& eventTime);
andrew@1 124
andrew@1 125 void checkShiftMatrix();
andrew@1 126 void shiftMatrixToMatchBestPhase(const int& bestPhaseIndex);
andrew@1 127 void shiftMatrixToMatchBestTempo(const int& bestTempoIndex);
andrew@1 128 int recentPhaseShift, recentTempoShift;
andrew@1 129 bool moveMatrixToOptimalCostPosition;
andrew@1 130
andrew@1 131 int startPoint;//for drawing
andrew@1 132
andrew@1 133
andrew@1 134 float movementFactor;
andrew@1 135 // static const double tempoMinimumOffset = meanGlobalTempo - (tempoRange-1)/2;
andrew@1 136
andrew@1 137 bool checkPhaseRange(const int& phaseToCheck);
andrew@1 138 bool checkTempoRange(const int& tempoToCheck);
andrew@1 139
andrew@1 140 double phaseHopCost(const int& phaseHop);
andrew@1 141 double tempoHopCost(const int& tempoHop);
andrew@1 142
andrew@1 143 double tempoScalar, phaseScalar;
andrew@1 144 int meanTempo;
andrew@1 145 int meanTempoIndex, meanPhaseIndex;
andrew@1 146
andrew@1 147 int currentBestTempo, currentBestPhase;
andrew@1 148
andrew@1 149 double getPhase(const int& phaseIndex);
andrew@1 150 double getTempo(const int& tempoIndex);
andrew@1 151 double getTempo(const int& tempoIndex, const int& tempoOffset);
andrew@1 152 double getPhase(const int& phaseIndex, const int& phaseOffset);
andrew@1 153
andrew@1 154 int getTempoIndex(const double& tempo);
andrew@1 155 int getPhaseIndex(const double& location);
andrew@1 156
andrew@1 157 double getBestPreviousCost(const int& tempoIndex, const int& phaseIndex, Route& r);
andrew@1 158 //double getlocation(const int& tempoIndex, const int& phaseIndex);
andrew@1 159 void getLocation(const int& tempoIndex, const int& phaseIndex, const int& interval);
andrew@1 160 void drawCostMatrix();
andrew@1 161 double getMaximum();
andrew@1 162
andrew@1 163 double getMinimumTransitionCost(const int& interval, const int& tempoIndex, const int& phaseIndex);
andrew@1 164 //int getBeatLocation(const int& phaseIndex);
andrew@1 165 //int getProjectedBeatLocation(const int& tempoIndex, const int& phaseIndex, const int& interval);
andrew@1 166
andrew@1 167 void initialiseRoutes();
andrew@1 168 void printLogMatrix();
andrew@1 169 void printMatrix(DoubleMatrix& logMatrix);
andrew@1 170
andrew@1 171 void exportTimingData();
andrew@1 172 void importTimingData(std::string importFileName);
andrew@1 173 void exportProcessedBeatTimes(const double& firstBeatTime);
andrew@1 174
andrew@2 175
andrew@2 176
andrew@1 177 bool drawIOIintervals;
andrew@1 178
andrew@1 179 void calculateTempoLimits();
andrew@1 180 void clearData();
andrew@1 181
andrew@1 182 int getIndexAtMouseXposition(const int& Xpos);
andrew@1 183
andrew@1 184 int minDrawTempo, maxDrawTempo;
andrew@1 185 bool drawBPM;
andrew@1 186 double msToBpm(const double& ms);
andrew@1 187
andrew@1 188 void moveDrawWindowUp();
andrew@1 189 void moveDrawWindowDown();
andrew@1 190 void widenDrawWindow();
andrew@1 191 void narrowDrawWindow();
andrew@1 192
andrew@1 193 bool blackAndWhite;
andrew@1 194 DoubleVector beatPosition;
andrew@1 195
andrew@1 196 IntMatrix timingHistogram;
andrew@1 197 void clearHistogram();
andrew@1 198 void getHistogramResults();
andrew@1 199
andrew@1 200 bool drawExpressiveTimingData;
andrew@1 201 bool mozartTriplets;
andrew@1 202
andrew@1 203 int tempoVariationStartIndex;
andrew@1 204 int tempoVariationEndIndex;
andrew@1 205 double calculateTempoVariation();
andrew@1 206
andrew@1 207 ofTrueTypeFont timesFont;//FONT
andrew@1 208
andrew@1 209 //vars added since new project on Drum Timing
andrew@1 210 double offsetToFirstPoint;//this set at beginning - when we load in beat times that do not start at zero;
andrew@1 211
andrew@1 212 void zoomIn();
andrew@1 213 void zoomOut();
andrew@1 214 };
andrew@1 215
andrew@1 216 #endif