annotate hackday/midiEventHolder.h @ 29:69083ce48b83

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