annotate hackday/midiEventHolder.h @ 25:2a025ea7c793

hackday work to get live midi input, follow the notes, output measure, read measure in with midi file
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Sat, 03 Dec 2011 21:09:13 +0000
parents 5a11b19906c7
children 179365726f07
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@24 49 DoubleMatrix matchConfidence;
andrew@24 50 double totalConfidence;
andrew@24 51
andrew@24 52 double mouseX;
andrew@24 53
andrew@24 54 void clearAllEvents();
andrew@24 55 bool drawTempoMode, drawPhaseMode;
andrew@24 56
andrew@24 57 double minimumMatchSpeed , maximumMatchSpeed;
andrew@24 58
andrew@24 59 double period, pulsesPerQuarternote;
andrew@24 60 double getEventTimeMillis(double ticks);
andrew@24 61 double getEventTimeTicks(double millis);
andrew@24 62
andrew@24 63 int getLocationFromTicks(double tickPosition);
andrew@24 64 int getLocationFromMillis(double millisPosition);
andrew@24 65
andrew@24 66 double getTimeNow(double eventTime);
andrew@24 67 bool runningInRealTime;
andrew@24 68
andrew@24 69 double windowStartTime;
andrew@24 70
andrew@24 71 //functions for finding match to incoming note
andrew@24 72 void newNoteOnEvent(int pitch, int velocity, double timePlayed);
andrew@24 73 int findLocalMatches(int notePitch);
andrew@24 74 bool checkIfMatchedNote(const int& tmpIndex);
andrew@24 75 int findMatch(const int& notePitch, const int& startTime, const int& endTime);
andrew@24 76
andrew@24 77
andrew@24 78 void findLocalTempoPairs();
andrew@24 79 void findLocalTempoPairsWeightedForConfidence();
andrew@24 80
andrew@24 81 double likelihoodWidth;
andrew@24 82 double likelihoodToNoiseRatio;
andrew@24 83
andrew@24 84 void printMatchMatrix();
andrew@24 85 void printRecordedEvents();
andrew@24 86
andrew@24 87 void setMatchLikelihoods(int numberOfMatches);
andrew@24 88
andrew@24 89 void setStartPlayingTimes();
andrew@24 90 void setSpeedPrior(double speedPriorValue);
andrew@24 91
andrew@24 92 int width, height;
andrew@24 93 /////
andrew@24 94 string matchString;
andrew@24 95 void updatePlayPosition();
andrew@24 96
andrew@24 97 DoubleMatrix beatPeriodMatrix;
andrew@24 98
andrew@24 99 void drawFile();
andrew@24 100 void drawMidiFile();
andrew@24 101 void reset();
andrew@24 102 void setMatchedNotesBackToFalse();
andrew@24 103
andrew@24 104 int ticksPerScreen;
andrew@24 105 int tickLocation;
andrew@24 106 int numberOfScreensIn;
andrew@24 107 int noteArrayIndex;
andrew@24 108
andrew@24 109 int matchWindowWidth;
andrew@24 110
andrew@24 111 int noteMinimum, noteMaximum;
andrew@24 112 int* screenWidth;
andrew@24 113 int* screenHeight;
andrew@24 114 float noteHeight;
andrew@24 115 float tempo;
andrew@24 116 double lastPeriodUpdateTime;
andrew@25 117 int lastPlayedPitch;
andrew@24 118
andrew@24 119 double playPositionInMillis;
andrew@24 120
andrew@24 121 double timeOffsetForScreen;
andrew@24 122
andrew@24 123 double recentNoteOnTime;
andrew@24 124
andrew@24 125 void exampleCrossUpdate();
andrew@24 126 BayesianArrayStructure bayesStruct;
andrew@24 127
andrew@24 128 double speedPriorValue;
andrew@24 129 int bestMatchIndex;
andrew@24 130 string timeString;
andrew@24 131 double startTime;
andrew@24 132 int speedWindowWidthMillis;
andrew@24 133
andrew@24 134 bool confidenceWeightingUsed;
andrew@24 135
andrew@24 136 double minimumMatchError;//recent best error between observed note and aligned midi file
andrew@24 137
andrew@24 138 void reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix);
andrew@24 139 int getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix);
andrew@24 140 void correctTiming(IntMatrix& noteOnMatrix);
andrew@24 141 void doublecheckOrder(IntMatrix& noteOnMatrix);
andrew@24 142 int getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix);
andrew@24 143 bool useTempoPrior;
andrew@24 144 string tempoSpeedString;
andrew@24 145 int minimumTimeIntervalForTempoUpdate;
andrew@24 146
andrew@24 147 double ticksFactor;
andrew@24 148 };
andrew@24 149 #endif