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@1
|
75
|
andrew@1
|
76 void printCostMatrix(const RouteMatrix& m);
|
andrew@1
|
77 //NEW COST METHODS:
|
andrew@1
|
78 void updateCostToPoint(const int& eventTime, const int& eventBeatLocation);
|
andrew@1
|
79 double getBestMinimumCost(const int& newTempoInUnits, const int& newPhaseInUnits, Route& r);
|
andrew@1
|
80
|
andrew@1
|
81 double getPhaseIndexFromEventTime(const double& eventTime);
|
andrew@1
|
82 double getTempoInUnits(const double& tempoInMs);
|
andrew@1
|
83
|
andrew@1
|
84
|
andrew@1
|
85
|
andrew@1
|
86 PathVector pathHistory;
|
andrew@1
|
87 void setBestTempoAndPhase(Path& newPath);
|
andrew@1
|
88 void printPathHistory();
|
andrew@1
|
89 void printIOIdata();
|
andrew@1
|
90 void processPathHistory();
|
andrew@1
|
91
|
andrew@1
|
92 // RouteMatrix routes;
|
andrew@1
|
93 // RouteHistory history;
|
andrew@1
|
94
|
andrew@1
|
95 int playingIndex;
|
andrew@1
|
96
|
andrew@1
|
97 // void printHistory();
|
andrew@1
|
98 //void printBestPath();
|
andrew@1
|
99
|
andrew@1
|
100 int phaseMinimumOffset;
|
andrew@1
|
101 int globalTimeOffset;
|
andrew@1
|
102 int tempoMinimumOffset;
|
andrew@1
|
103 double maximumTempo, minimumTempo;
|
andrew@1
|
104 double screenHeight, screenWidth ;
|
andrew@1
|
105
|
andrew@1
|
106 void drawTempoCurve();
|
andrew@1
|
107 int getHeightPoint(float f);
|
andrew@1
|
108
|
andrew@1
|
109 int numberOfPointsPerPage;
|
andrew@1
|
110 bool printHistory;
|
andrew@1
|
111
|
andrew@1
|
112 double tempoCost, phaseCost;
|
andrew@1
|
113
|
andrew@1
|
114 DoubleMatrix logProbabilityMatrix;
|
andrew@1
|
115 double lastBeatPosition;
|
andrew@1
|
116
|
andrew@1
|
117 int minimumPhaseHop, maximumPhaseHop ;
|
andrew@1
|
118
|
andrew@1
|
119 // double getCost(const int& eventTime, const int& interval, const int& tempoIndex, const int& phaseIndex);
|
andrew@1
|
120 void updateCost(const int& eventTime, const int& eventBeatLocation);
|
andrew@1
|
121 void updateMatrixOffsets(const int& eventTime);
|
andrew@1
|
122
|
andrew@1
|
123 void checkShiftMatrix();
|
andrew@1
|
124 void shiftMatrixToMatchBestPhase(const int& bestPhaseIndex);
|
andrew@1
|
125 void shiftMatrixToMatchBestTempo(const int& bestTempoIndex);
|
andrew@1
|
126 int recentPhaseShift, recentTempoShift;
|
andrew@1
|
127 bool moveMatrixToOptimalCostPosition;
|
andrew@1
|
128
|
andrew@1
|
129 int startPoint;//for drawing
|
andrew@1
|
130
|
andrew@1
|
131
|
andrew@1
|
132 float movementFactor;
|
andrew@1
|
133 // static const double tempoMinimumOffset = meanGlobalTempo - (tempoRange-1)/2;
|
andrew@1
|
134
|
andrew@1
|
135 bool checkPhaseRange(const int& phaseToCheck);
|
andrew@1
|
136 bool checkTempoRange(const int& tempoToCheck);
|
andrew@1
|
137
|
andrew@1
|
138 double phaseHopCost(const int& phaseHop);
|
andrew@1
|
139 double tempoHopCost(const int& tempoHop);
|
andrew@1
|
140
|
andrew@1
|
141 double tempoScalar, phaseScalar;
|
andrew@1
|
142 int meanTempo;
|
andrew@1
|
143 int meanTempoIndex, meanPhaseIndex;
|
andrew@1
|
144
|
andrew@1
|
145 int currentBestTempo, currentBestPhase;
|
andrew@1
|
146
|
andrew@1
|
147 double getPhase(const int& phaseIndex);
|
andrew@1
|
148 double getTempo(const int& tempoIndex);
|
andrew@1
|
149 double getTempo(const int& tempoIndex, const int& tempoOffset);
|
andrew@1
|
150 double getPhase(const int& phaseIndex, const int& phaseOffset);
|
andrew@1
|
151
|
andrew@1
|
152 int getTempoIndex(const double& tempo);
|
andrew@1
|
153 int getPhaseIndex(const double& location);
|
andrew@1
|
154
|
andrew@1
|
155 double getBestPreviousCost(const int& tempoIndex, const int& phaseIndex, Route& r);
|
andrew@1
|
156 //double getlocation(const int& tempoIndex, const int& phaseIndex);
|
andrew@1
|
157 void getLocation(const int& tempoIndex, const int& phaseIndex, const int& interval);
|
andrew@1
|
158 void drawCostMatrix();
|
andrew@1
|
159 double getMaximum();
|
andrew@1
|
160
|
andrew@1
|
161 double getMinimumTransitionCost(const int& interval, const int& tempoIndex, const int& phaseIndex);
|
andrew@1
|
162 //int getBeatLocation(const int& phaseIndex);
|
andrew@1
|
163 //int getProjectedBeatLocation(const int& tempoIndex, const int& phaseIndex, const int& interval);
|
andrew@1
|
164
|
andrew@1
|
165 void initialiseRoutes();
|
andrew@1
|
166 void printLogMatrix();
|
andrew@1
|
167 void printMatrix(DoubleMatrix& logMatrix);
|
andrew@1
|
168
|
andrew@1
|
169 void exportTimingData();
|
andrew@1
|
170 void importTimingData(std::string importFileName);
|
andrew@1
|
171 void exportProcessedBeatTimes(const double& firstBeatTime);
|
andrew@1
|
172
|
andrew@1
|
173 bool drawIOIintervals;
|
andrew@1
|
174
|
andrew@1
|
175 void calculateTempoLimits();
|
andrew@1
|
176 void clearData();
|
andrew@1
|
177
|
andrew@1
|
178 int getIndexAtMouseXposition(const int& Xpos);
|
andrew@1
|
179
|
andrew@1
|
180 int minDrawTempo, maxDrawTempo;
|
andrew@1
|
181 bool drawBPM;
|
andrew@1
|
182 double msToBpm(const double& ms);
|
andrew@1
|
183
|
andrew@1
|
184 void moveDrawWindowUp();
|
andrew@1
|
185 void moveDrawWindowDown();
|
andrew@1
|
186 void widenDrawWindow();
|
andrew@1
|
187 void narrowDrawWindow();
|
andrew@1
|
188
|
andrew@1
|
189 bool blackAndWhite;
|
andrew@1
|
190 DoubleVector beatPosition;
|
andrew@1
|
191
|
andrew@1
|
192 IntMatrix timingHistogram;
|
andrew@1
|
193 void clearHistogram();
|
andrew@1
|
194 void getHistogramResults();
|
andrew@1
|
195
|
andrew@1
|
196 bool drawExpressiveTimingData;
|
andrew@1
|
197 bool mozartTriplets;
|
andrew@1
|
198
|
andrew@1
|
199 int tempoVariationStartIndex;
|
andrew@1
|
200 int tempoVariationEndIndex;
|
andrew@1
|
201 double calculateTempoVariation();
|
andrew@1
|
202
|
andrew@1
|
203 ofTrueTypeFont timesFont;//FONT
|
andrew@1
|
204
|
andrew@1
|
205 //vars added since new project on Drum Timing
|
andrew@1
|
206 double offsetToFirstPoint;//this set at beginning - when we load in beat times that do not start at zero;
|
andrew@1
|
207
|
andrew@1
|
208 void zoomIn();
|
andrew@1
|
209 void zoomOut();
|
andrew@1
|
210 };
|
andrew@1
|
211
|
andrew@1
|
212 #endif |