andrew@24: /* andrew@24: * midiEventHolder.h andrew@24: * midiCannamReader3 andrew@24: * andrew@24: * Created by Andrew on 19/07/2011. andrew@24: * Copyright 2011 QMUL. All rights reserved. andrew@24: * andrew@24: */ andrew@24: #ifndef MIDI_EVENT_HOLDER andrew@24: #define MIDI_EVENT_HOLDER andrew@24: andrew@24: #include "ofMain.h" andrew@24: #include "BayesianArrayStructure.h" andrew@24: andrew@24: class midiEventHolder{ andrew@24: andrew@24: public: andrew@24: andrew@24: midiEventHolder(); andrew@24: void printNotes(); andrew@24: andrew@24: typedef std::vector IntVector; andrew@24: typedef std::vector IntMatrix; andrew@24: andrew@24: typedef std::vector BoolVector; andrew@24: andrew@24: typedef std::vector DoubleVector; andrew@24: typedef std::vector DoubleMatrix; andrew@24: andrew@24: //the rehearsal version andrew@24: IntMatrix recordedNoteOnMatrix;//note, velocity, duration andrew@24: DoubleVector recordedEventTimes; andrew@24: andrew@24: IntVector matchesFound; andrew@24: BoolVector noteOnMatches; andrew@24: andrew@24: void drawMidiFile(IntMatrix& midiFileToDraw); andrew@24: andrew@24: // int recordedNoteOnIndex; andrew@24: andrew@24: andrew@24: IntMatrix playedNoteOnMatrix; andrew@24: DoubleVector playedEventTimes; andrew@24: int playedNoteIndex; andrew@24: IntMatrix matchMatrix; andrew@24: IntVector bestMatchFound; andrew@25: IntVector measureVector; andrew@24: andrew@26: IntVector recordedTotalNoteCounterByPitch; andrew@26: int totalNoteCounterIndex; andrew@26: andrew@24: DoubleMatrix matchConfidence; andrew@24: double totalConfidence; andrew@24: andrew@24: double mouseX; andrew@24: andrew@24: void clearAllEvents(); andrew@24: bool drawTempoMode, drawPhaseMode; andrew@24: andrew@24: double minimumMatchSpeed , maximumMatchSpeed; andrew@24: andrew@24: double period, pulsesPerQuarternote; andrew@24: double getEventTimeMillis(double ticks); andrew@24: double getEventTimeTicks(double millis); andrew@24: andrew@24: int getLocationFromTicks(double tickPosition); andrew@24: int getLocationFromMillis(double millisPosition); andrew@24: andrew@24: double getTimeNow(double eventTime); andrew@24: bool runningInRealTime; andrew@24: andrew@24: double windowStartTime; andrew@24: andrew@24: //functions for finding match to incoming note andrew@24: void newNoteOnEvent(int pitch, int velocity, double timePlayed); andrew@24: int findLocalMatches(int notePitch); andrew@24: bool checkIfMatchedNote(const int& tmpIndex); andrew@24: int findMatch(const int& notePitch, const int& startTime, const int& endTime); andrew@24: andrew@29: void updateTempo(); andrew@24: void findLocalTempoPairs(); andrew@24: void findLocalTempoPairsWeightedForConfidence(); andrew@29: void findOptimumTempoPairsToCurrentBestMatch(); andrew@29: double getBestSpeedEstimate(const int& currentPlayedIndex, const int& equivalentRecordedIndex); andrew@24: andrew@30: andrew@30: void calcuateNewInterNoteIntervals(); andrew@30: andrew@24: double likelihoodWidth; andrew@24: double likelihoodToNoiseRatio; andrew@24: andrew@24: void printMatchMatrix(); andrew@24: void printRecordedEvents(); andrew@26: void printNoteCounter(); andrew@26: void updateNoteCounter(); andrew@24: andrew@24: void setMatchLikelihoods(int numberOfMatches); andrew@24: andrew@24: void setStartPlayingTimes(); andrew@24: void setSpeedPrior(double speedPriorValue); andrew@24: andrew@24: int width, height; andrew@24: ///// andrew@24: string matchString; andrew@24: void updatePlayPosition(); andrew@24: andrew@24: DoubleMatrix beatPeriodMatrix; andrew@24: andrew@24: void drawFile(); andrew@24: void drawMidiFile(); andrew@24: void reset(); andrew@24: void setMatchedNotesBackToFalse(); andrew@24: andrew@24: int ticksPerScreen; andrew@24: int tickLocation; andrew@24: int numberOfScreensIn; andrew@24: int noteArrayIndex; andrew@24: andrew@24: int matchWindowWidth; andrew@24: andrew@24: int noteMinimum, noteMaximum; andrew@24: int* screenWidth; andrew@24: int* screenHeight; andrew@24: float noteHeight; andrew@24: float tempo; andrew@24: double lastPeriodUpdateTime; andrew@25: int lastPlayedPitch; andrew@24: andrew@24: double playPositionInMillis; andrew@24: andrew@24: double timeOffsetForScreen; andrew@24: andrew@24: double recentNoteOnTime; andrew@24: andrew@24: void exampleCrossUpdate(); andrew@24: BayesianArrayStructure bayesStruct; andrew@24: andrew@24: double speedPriorValue; andrew@24: int bestMatchIndex; andrew@24: string timeString; andrew@24: double startTime; andrew@24: int speedWindowWidthMillis; andrew@24: andrew@24: bool confidenceWeightingUsed; andrew@24: andrew@24: double minimumMatchError;//recent best error between observed note and aligned midi file andrew@24: andrew@24: void reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix); andrew@24: int getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix); andrew@24: void correctTiming(IntMatrix& noteOnMatrix); andrew@24: void doublecheckOrder(IntMatrix& noteOnMatrix); andrew@24: int getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix); andrew@24: bool useTempoPrior; andrew@24: string tempoSpeedString; andrew@24: int minimumTimeIntervalForTempoUpdate; andrew@24: andrew@24: double ticksFactor; andrew@29: andrew@30: bool newOptimalMethod; andrew@30: DoubleMatrix interNoteIntervals; andrew@30: IntVector intervalsToCheck; andrew@30: void checkForCorrectInterval(const double& playedTimeDifference, DoubleVector* v); andrew@30: void drawInterNoteIntervals(); andrew@30: void printInterNoteIntervals(); andrew@30: int interNoteRange; andrew@31: DoubleMatrix periodValues; andrew@31: andrew@24: }; andrew@24: #endif