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@0: #ifndef MIDI_EVENT_HOLDER andrew@0: #define MIDI_EVENT_HOLDER andrew@0: andrew@0: #include "ofMain.h" andrew@0: #include "BayesianArrayStructure.h" andrew@0: 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@0: DoubleVector recordedEventTimes; andrew@0: andrew@0: IntVector matchesFound; andrew@0: BoolVector noteOnMatches; andrew@0: andrew@0: void drawMidiFile(IntMatrix& midiFileToDraw); andrew@0: andrew@0: // int recordedNoteOnIndex; andrew@0: andrew@0: andrew@0: IntMatrix playedNoteOnMatrix; andrew@0: DoubleVector playedEventTimes; andrew@0: int playedNoteIndex; andrew@0: IntMatrix matchMatrix; andrew@0: IntVector bestMatchFound; andrew@0: IntVector measureVector; andrew@0: andrew@0: IntVector recordedTotalNoteCounterByPitch; andrew@0: int totalNoteCounterIndex; andrew@0: andrew@0: DoubleMatrix matchConfidence; andrew@0: double totalConfidence; andrew@0: andrew@0: double mouseX; andrew@0: andrew@0: void clearAllEvents(); andrew@0: 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@0: double getTimeNow(double eventTime); andrew@0: bool runningInRealTime; andrew@0: 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: void updateTempo(); andrew@0: void findLocalTempoPairs(); andrew@0: void findLocalTempoPairsWeightedForConfidence(); andrew@0: void findOptimumTempoPairsToCurrentBestMatch(); andrew@0: double getBestSpeedEstimate(const int& currentPlayedIndex, const int& equivalentRecordedIndex); andrew@0: andrew@0: andrew@0: void calcuateNewInterNoteIntervals(); andrew@0: andrew@0: double likelihoodWidth; andrew@0: double likelihoodToNoiseRatio; andrew@0: andrew@0: void printMatchMatrix(); andrew@0: void printRecordedEvents(); andrew@0: void printNoteCounter(); andrew@0: void updateNoteCounter(); andrew@0: andrew@0: void setMatchLikelihoods(int numberOfMatches); andrew@0: andrew@0: void setStartPlayingTimes(); andrew@0: 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@0: void drawMidiFile(); andrew@0: void reset(); andrew@0: 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 startPlayingTime; andrew@0: int lastPlayedPitch; 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@0: double speedPriorValue; andrew@0: int bestMatchIndex; andrew@0: string timeString; andrew@0: //double startTime; andrew@0: int speedWindowWidthMillis; andrew@0: andrew@0: bool confidenceWeightingUsed; andrew@0: andrew@0: double minimumMatchError;//recent best error between observed note and aligned midi file andrew@0: andrew@0: void reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix); andrew@0: int getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix); andrew@0: void correctTiming(IntMatrix& noteOnMatrix); andrew@0: void doublecheckOrder(IntMatrix& noteOnMatrix); andrew@0: int getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix); andrew@0: bool useTempoPrior; andrew@0: string tempoSpeedString; andrew@0: int minimumTimeIntervalForTempoUpdate; andrew@0: andrew@0: double ticksFactor; andrew@0: andrew@0: bool newOptimalMethod; andrew@0: DoubleMatrix interNoteIntervals; andrew@0: IntVector intervalsToCheck; andrew@0: void checkForCorrectInterval(const double& playedTimeDifference, DoubleVector* v); andrew@0: void drawInterNoteIntervals(); andrew@0: void printInterNoteIntervals(); andrew@0: int interNoteRange; andrew@0: DoubleMatrix periodValues; andrew@0: int periodCounter; andrew@0: void updatePeriodValue(const double& miupdatesllis); andrew@0: andrew@0: double smoothPlayPosition; andrew@0: // double storedSmoothPlayPosition; andrew@0: // double lastSmoothUpdateTime; andrew@0: // double relativeSpeedForSmooth; andrew@0: // void updateSmoothPlaySpeed();; andrew@0: //best alignment andrew@0: double alignmentPosition; andrew@0: double firstEventOffsetTimeMillis; andrew@0: andrew@0: void updateSmoothPositionTo(const double& newPosition); andrew@0: int smoothIndex; andrew@0: DoubleVector beatPositions; andrew@0: andrew@0: }; andrew@0: #endif