andrew@0: /* andrew@0: * midiEventHolder.h andrew@0: * midiCannamReader3 andrew@0: * andrew@0: * Created by Andrew on 19/07/2011. andrew@0: * Copyright 2011 QMUL. All rights reserved. andrew@0: * andrew@0: */ andrew@2: #ifndef MIDI_EVENT_HOLDER andrew@2: #define MIDI_EVENT_HOLDER andrew@2: andrew@0: #include "ofMain.h" andrew@0: #include "BayesianArrayStructure.h" andrew@0: andrew@0: class midiEventHolder{ andrew@0: andrew@0: public: andrew@0: andrew@0: midiEventHolder(); andrew@0: void printNotes(); andrew@0: andrew@0: typedef std::vector IntVector; andrew@0: typedef std::vector IntMatrix; andrew@0: andrew@0: typedef std::vector BoolVector; andrew@0: andrew@0: typedef std::vector DoubleVector; andrew@0: typedef std::vector DoubleMatrix; andrew@0: andrew@0: //the rehearsal version andrew@0: IntMatrix recordedNoteOnMatrix;//note, velocity, duration andrew@2: DoubleVector recordedEventTimes; andrew@2: andrew@0: IntVector matchesFound; andrew@0: BoolVector noteOnMatches; andrew@1: andrew@0: // int recordedNoteOnIndex; andrew@2: andrew@0: andrew@0: IntMatrix playedNoteOnMatrix; andrew@0: DoubleVector playedEventTimes; andrew@0: int playedNoteIndex; andrew@0: IntMatrix matchMatrix; andrew@22: IntVector bestMatchFound; andrew@22: andrew@1: DoubleMatrix matchConfidence; andrew@1: double totalConfidence; andrew@0: andrew@1: double mouseX; andrew@1: andrew@1: void clearAllEvents(); andrew@9: bool drawTempoMode, drawPhaseMode; andrew@0: andrew@0: double minimumMatchSpeed , maximumMatchSpeed; andrew@0: andrew@0: double period, pulsesPerQuarternote; andrew@0: double getEventTimeMillis(double ticks); andrew@0: double getEventTimeTicks(double millis); andrew@0: andrew@0: int getLocationFromTicks(double tickPosition); andrew@0: int getLocationFromMillis(double millisPosition); andrew@0: andrew@14: double getTimeNow(double eventTime); andrew@14: bool runningInRealTime; andrew@14: andrew@0: double windowStartTime; andrew@0: andrew@0: //functions for finding match to incoming note andrew@0: void newNoteOnEvent(int pitch, int velocity, double timePlayed); andrew@0: int findLocalMatches(int notePitch); andrew@0: bool checkIfMatchedNote(const int& tmpIndex); andrew@0: int findMatch(const int& notePitch, const int& startTime, const int& endTime); andrew@0: andrew@0: andrew@0: void findLocalTempoPairs(); andrew@6: void findLocalTempoPairsWeightedForConfidence(); andrew@0: andrew@0: double likelihoodWidth; andrew@0: double likelihoodToNoiseRatio; andrew@0: andrew@0: void printMatchMatrix(); andrew@16: void printRecordedEvents(); andrew@0: andrew@0: void setMatchLikelihoods(int numberOfMatches); andrew@0: andrew@0: void setStartPlayingTimes(); andrew@3: void setSpeedPrior(double speedPriorValue); andrew@0: andrew@0: int width, height; andrew@0: ///// andrew@0: string matchString; andrew@0: void updatePlayPosition(); andrew@0: andrew@0: DoubleMatrix beatPeriodMatrix; andrew@0: andrew@0: void drawFile(); andrew@9: void drawMidiFile(); andrew@0: void reset(); andrew@5: void setMatchedNotesBackToFalse(); andrew@0: andrew@0: int ticksPerScreen; andrew@0: int tickLocation; andrew@0: int numberOfScreensIn; andrew@0: int noteArrayIndex; andrew@0: andrew@0: int matchWindowWidth; andrew@0: andrew@0: int noteMinimum, noteMaximum; andrew@0: int* screenWidth; andrew@0: int* screenHeight; andrew@0: float noteHeight; andrew@0: float tempo; andrew@0: double lastPeriodUpdateTime; andrew@0: andrew@0: double playPositionInMillis; andrew@0: andrew@0: double timeOffsetForScreen; andrew@0: andrew@0: double recentNoteOnTime; andrew@0: andrew@0: void exampleCrossUpdate(); andrew@0: BayesianArrayStructure bayesStruct; andrew@0: andrew@3: double speedPriorValue; andrew@5: int bestMatchIndex; andrew@0: string timeString; andrew@0: double startTime; andrew@6: int speedWindowWidthMillis; andrew@6: andrew@6: bool confidenceWeightingUsed; andrew@0: andrew@10: double minimumMatchError;//recent best error between observed note and aligned midi file andrew@14: andrew@16: void reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix); andrew@16: int getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix); andrew@16: void correctTiming(IntMatrix& noteOnMatrix); andrew@17: void doublecheckOrder(IntMatrix& noteOnMatrix); andrew@17: int getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix); andrew@21: bool useTempoPrior; andrew@22: string tempoSpeedString; andrew@22: int minimumTimeIntervalForTempoUpdate; andrew@2: }; andrew@2: #endif