andrew@0
|
1 /*
|
andrew@0
|
2 * midiEventHolder.h
|
andrew@0
|
3 * midiCannamReader3
|
andrew@0
|
4 *
|
andrew@0
|
5 * Created by Andrew on 19/07/2011.
|
andrew@0
|
6 * Copyright 2011 QMUL. All rights reserved.
|
andrew@0
|
7 *
|
andrew@0
|
8 */
|
andrew@0
|
9 #ifndef MIDI_EVENT_HOLDER
|
andrew@0
|
10 #define MIDI_EVENT_HOLDER
|
andrew@0
|
11
|
andrew@0
|
12 #include "ofMain.h"
|
andrew@0
|
13 #include "BayesianArrayStructure.h"
|
andrew@0
|
14
|
andrew@0
|
15
|
andrew@0
|
16 class midiEventHolder{
|
andrew@0
|
17
|
andrew@0
|
18 public:
|
andrew@0
|
19
|
andrew@0
|
20 midiEventHolder();
|
andrew@0
|
21 void printNotes();
|
andrew@0
|
22
|
andrew@0
|
23 typedef std::vector<int> IntVector;
|
andrew@0
|
24 typedef std::vector<IntVector> IntMatrix;
|
andrew@0
|
25
|
andrew@0
|
26 typedef std::vector<bool> BoolVector;
|
andrew@0
|
27
|
andrew@0
|
28 typedef std::vector<double> DoubleVector;
|
andrew@0
|
29 typedef std::vector<DoubleVector> DoubleMatrix;
|
andrew@0
|
30
|
andrew@0
|
31 //the rehearsal version
|
andrew@0
|
32 IntMatrix recordedNoteOnMatrix;//note, velocity, duration
|
andrew@0
|
33 DoubleVector recordedEventTimes;
|
andrew@0
|
34
|
andrew@0
|
35 IntVector matchesFound;
|
andrew@0
|
36 BoolVector noteOnMatches;
|
andrew@0
|
37
|
andrew@0
|
38 void drawMidiFile(IntMatrix& midiFileToDraw);
|
andrew@0
|
39
|
andrew@0
|
40 // int recordedNoteOnIndex;
|
andrew@0
|
41
|
andrew@0
|
42
|
andrew@0
|
43 IntMatrix playedNoteOnMatrix;
|
andrew@0
|
44 DoubleVector playedEventTimes;
|
andrew@0
|
45 int playedNoteIndex;
|
andrew@0
|
46 IntMatrix matchMatrix;
|
andrew@0
|
47 IntVector bestMatchFound;
|
andrew@0
|
48 IntVector measureVector;
|
andrew@0
|
49
|
andrew@0
|
50 IntVector recordedTotalNoteCounterByPitch;
|
andrew@0
|
51 int totalNoteCounterIndex;
|
andrew@0
|
52
|
andrew@0
|
53 DoubleMatrix matchConfidence;
|
andrew@0
|
54 double totalConfidence;
|
andrew@0
|
55
|
andrew@0
|
56 double mouseX;
|
andrew@0
|
57
|
andrew@0
|
58 void clearAllEvents();
|
andrew@0
|
59 bool drawTempoMode, drawPhaseMode;
|
andrew@0
|
60
|
andrew@0
|
61 double minimumMatchSpeed , maximumMatchSpeed;
|
andrew@0
|
62
|
andrew@0
|
63 double period, pulsesPerQuarternote;
|
andrew@0
|
64 double getEventTimeMillis(double ticks);
|
andrew@0
|
65 double getEventTimeTicks(double millis);
|
andrew@0
|
66
|
andrew@0
|
67 int getLocationFromTicks(double tickPosition);
|
andrew@0
|
68 int getLocationFromMillis(double millisPosition);
|
andrew@0
|
69
|
andrew@0
|
70 double getTimeNow(double eventTime);
|
andrew@0
|
71 bool runningInRealTime;
|
andrew@0
|
72
|
andrew@0
|
73 double windowStartTime;
|
andrew@0
|
74
|
andrew@0
|
75 //functions for finding match to incoming note
|
andrew@0
|
76 void newNoteOnEvent(int pitch, int velocity, double timePlayed);
|
andrew@0
|
77 int findLocalMatches(int notePitch);
|
andrew@0
|
78 bool checkIfMatchedNote(const int& tmpIndex);
|
andrew@0
|
79 int findMatch(const int& notePitch, const int& startTime, const int& endTime);
|
andrew@0
|
80
|
andrew@0
|
81 void updateTempo();
|
andrew@0
|
82 void findLocalTempoPairs();
|
andrew@0
|
83 void findLocalTempoPairsWeightedForConfidence();
|
andrew@0
|
84 void findOptimumTempoPairsToCurrentBestMatch();
|
andrew@0
|
85 double getBestSpeedEstimate(const int& currentPlayedIndex, const int& equivalentRecordedIndex);
|
andrew@0
|
86
|
andrew@0
|
87
|
andrew@0
|
88 void calcuateNewInterNoteIntervals();
|
andrew@0
|
89
|
andrew@0
|
90 double likelihoodWidth;
|
andrew@0
|
91 double likelihoodToNoiseRatio;
|
andrew@0
|
92
|
andrew@0
|
93 void printMatchMatrix();
|
andrew@0
|
94 void printRecordedEvents();
|
andrew@0
|
95 void printNoteCounter();
|
andrew@0
|
96 void updateNoteCounter();
|
andrew@0
|
97
|
andrew@0
|
98 void setMatchLikelihoods(int numberOfMatches);
|
andrew@0
|
99
|
andrew@0
|
100 void setStartPlayingTimes();
|
andrew@0
|
101 void setSpeedPrior(double speedPriorValue);
|
andrew@0
|
102
|
andrew@0
|
103 int width, height;
|
andrew@0
|
104 /////
|
andrew@0
|
105 string matchString;
|
andrew@0
|
106 void updatePlayPosition();
|
andrew@0
|
107
|
andrew@0
|
108 DoubleMatrix beatPeriodMatrix;
|
andrew@0
|
109
|
andrew@0
|
110 void drawFile();
|
andrew@0
|
111 void drawMidiFile();
|
andrew@0
|
112 void reset();
|
andrew@0
|
113 void setMatchedNotesBackToFalse();
|
andrew@0
|
114
|
andrew@0
|
115 int ticksPerScreen;
|
andrew@0
|
116 int tickLocation;
|
andrew@0
|
117 int numberOfScreensIn;
|
andrew@0
|
118 int noteArrayIndex;
|
andrew@0
|
119
|
andrew@0
|
120 int matchWindowWidth;
|
andrew@0
|
121
|
andrew@0
|
122 int noteMinimum, noteMaximum;
|
andrew@0
|
123 int* screenWidth;
|
andrew@0
|
124 int* screenHeight;
|
andrew@0
|
125 float noteHeight;
|
andrew@0
|
126 float tempo;
|
andrew@0
|
127 double startPlayingTime;
|
andrew@0
|
128 int lastPlayedPitch;
|
andrew@0
|
129
|
andrew@0
|
130 //double playPositionInMillis;
|
andrew@0
|
131
|
andrew@0
|
132 double timeOffsetForScreen;
|
andrew@0
|
133
|
andrew@0
|
134 double recentNoteOnTime;
|
andrew@0
|
135
|
andrew@0
|
136 void exampleCrossUpdate();
|
andrew@0
|
137 BayesianArrayStructure bayesStruct;
|
andrew@0
|
138
|
andrew@0
|
139 double speedPriorValue;
|
andrew@0
|
140 int bestMatchIndex;
|
andrew@0
|
141 string timeString;
|
andrew@0
|
142 //double startTime;
|
andrew@0
|
143 int speedWindowWidthMillis;
|
andrew@0
|
144
|
andrew@0
|
145 bool confidenceWeightingUsed;
|
andrew@0
|
146
|
andrew@0
|
147 double minimumMatchError;//recent best error between observed note and aligned midi file
|
andrew@0
|
148
|
andrew@0
|
149 void reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix);
|
andrew@0
|
150 int getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix);
|
andrew@0
|
151 void correctTiming(IntMatrix& noteOnMatrix);
|
andrew@0
|
152 void doublecheckOrder(IntMatrix& noteOnMatrix);
|
andrew@0
|
153 int getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix);
|
andrew@0
|
154 bool useTempoPrior;
|
andrew@0
|
155 string tempoSpeedString;
|
andrew@0
|
156 int minimumTimeIntervalForTempoUpdate;
|
andrew@0
|
157
|
andrew@0
|
158 double ticksFactor;
|
andrew@0
|
159
|
andrew@0
|
160 bool newOptimalMethod;
|
andrew@0
|
161 DoubleMatrix interNoteIntervals;
|
andrew@0
|
162 IntVector intervalsToCheck;
|
andrew@0
|
163 void checkForCorrectInterval(const double& playedTimeDifference, DoubleVector* v);
|
andrew@0
|
164 void drawInterNoteIntervals();
|
andrew@0
|
165 void printInterNoteIntervals();
|
andrew@0
|
166 int interNoteRange;
|
andrew@0
|
167 DoubleMatrix periodValues;
|
andrew@0
|
168 int periodCounter;
|
andrew@0
|
169 void updatePeriodValue(const double& miupdatesllis);
|
andrew@0
|
170
|
andrew@0
|
171 double smoothPlayPosition;
|
andrew@0
|
172 // double storedSmoothPlayPosition;
|
andrew@0
|
173 // double lastSmoothUpdateTime;
|
andrew@0
|
174 // double relativeSpeedForSmooth;
|
andrew@0
|
175 // void updateSmoothPlaySpeed();;
|
andrew@0
|
176 //best alignment
|
andrew@0
|
177 double alignmentPosition;
|
andrew@0
|
178 double firstEventOffsetTimeMillis;
|
andrew@0
|
179
|
andrew@0
|
180 void updateSmoothPositionTo(const double& newPosition);
|
andrew@0
|
181 int smoothIndex;
|
andrew@0
|
182 DoubleVector beatPositions;
|
andrew@0
|
183
|
andrew@0
|
184 };
|
andrew@0
|
185 #endif |