annotate jnmr/midiEventHolder.h @ 52:13194a9dca77 tip

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