andrew@33: /* andrew@33: * midiEventHolder.h andrew@33: * midiCannamReader3 andrew@33: * andrew@33: * Created by Andrew on 19/07/2011. andrew@33: * Copyright 2011 QMUL. All rights reserved. andrew@33: * andrew@33: */ andrew@33: #ifndef MIDI_EVENT_HOLDER andrew@33: #define MIDI_EVENT_HOLDER andrew@33: andrew@33: #include "ofMain.h" andrew@33: #include "BayesianArrayStructure.h" andrew@36: #include "Annotations.h" andrew@52: #include "OutputDataWriter.h" andrew@52: andrew@33: andrew@33: class midiEventHolder{ andrew@33: andrew@33: public: andrew@33: andrew@33: midiEventHolder(); andrew@33: void printNotes(); andrew@33: andrew@33: typedef std::vector IntVector; andrew@33: typedef std::vector IntMatrix; andrew@33: andrew@33: typedef std::vector BoolVector; andrew@33: andrew@33: typedef std::vector DoubleVector; andrew@33: typedef std::vector DoubleMatrix; andrew@33: andrew@33: //the rehearsal version andrew@33: IntMatrix recordedNoteOnMatrix;//note, velocity, duration andrew@33: DoubleVector recordedEventTimes; andrew@33: andrew@33: IntVector matchesFound; andrew@33: BoolVector noteOnMatches; andrew@33: andrew@33: void drawMidiFile(IntMatrix& midiFileToDraw); andrew@33: andrew@33: // int recordedNoteOnIndex; andrew@33: andrew@33: andrew@33: IntMatrix playedNoteOnMatrix; andrew@33: DoubleVector playedEventTimes; andrew@33: int playedNoteIndex; andrew@33: IntMatrix matchMatrix; andrew@33: IntVector bestMatchFound; andrew@33: IntVector measureVector; andrew@33: andrew@33: IntVector recordedTotalNoteCounterByPitch; andrew@33: int totalNoteCounterIndex; andrew@33: andrew@33: DoubleMatrix matchConfidence; andrew@33: double totalConfidence; andrew@33: andrew@33: double mouseX; andrew@33: andrew@33: void clearAllEvents(); andrew@33: bool drawTempoMode, drawPhaseMode; andrew@33: andrew@33: double minimumMatchSpeed , maximumMatchSpeed; andrew@33: andrew@33: double period, pulsesPerQuarternote; andrew@33: double getEventTimeMillis(double ticks); andrew@33: double getEventTimeTicks(double millis); andrew@33: andrew@46: // int getLocationFromTicks(double tickPosition); andrew@33: int getLocationFromMillis(double millisPosition); andrew@33: andrew@33: double getTimeNow(double eventTime); andrew@33: bool runningInRealTime; andrew@33: andrew@33: double windowStartTime; andrew@33: andrew@33: //functions for finding match to incoming note andrew@33: void newNoteOnEvent(int pitch, int velocity, double timePlayed); andrew@33: int findLocalMatches(int notePitch); andrew@33: bool checkIfMatchedNote(const int& tmpIndex); andrew@33: int findMatch(const int& notePitch, const int& startTime, const int& endTime); andrew@33: andrew@33: void updateTempo(); andrew@33: void findLocalTempoPairs(); andrew@33: void findLocalTempoPairsWeightedForConfidence(); andrew@33: void findOptimumTempoPairsToCurrentBestMatch(); andrew@33: double getBestSpeedEstimate(const int& currentPlayedIndex, const int& equivalentRecordedIndex); andrew@33: andrew@33: andrew@33: void calcuateNewInterNoteIntervals(); andrew@33: andrew@33: double likelihoodWidth; andrew@33: double likelihoodToNoiseRatio; andrew@33: andrew@33: void printMatchMatrix(); andrew@33: void printRecordedEvents(); andrew@33: void printNoteCounter(); andrew@33: void updateNoteCounter(); andrew@33: andrew@33: void setMatchLikelihoods(int numberOfMatches); andrew@33: andrew@33: void setStartPlayingTimes(); andrew@33: void setSpeedPrior(double speedPriorValue); andrew@33: andrew@33: int width, height; andrew@33: ///// andrew@33: string matchString; andrew@33: void updatePlayPosition(); andrew@33: andrew@33: DoubleMatrix beatPeriodMatrix; andrew@33: andrew@33: void drawFile(); andrew@33: void drawMidiFile(); andrew@33: void reset(); andrew@33: void setMatchedNotesBackToFalse(); andrew@33: andrew@33: int ticksPerScreen; andrew@33: int tickLocation; andrew@33: int numberOfScreensIn; andrew@33: int noteArrayIndex; andrew@33: andrew@33: int matchWindowWidth; andrew@33: andrew@33: int noteMinimum, noteMaximum; andrew@33: int* screenWidth; andrew@33: int* screenHeight; andrew@33: float noteHeight; andrew@33: float tempo; andrew@34: double startPlayingTime; andrew@33: int lastPlayedPitch; andrew@33: andrew@34: //double playPositionInMillis; andrew@33: andrew@33: double timeOffsetForScreen; andrew@33: andrew@33: double recentNoteOnTime; andrew@33: andrew@46: // void exampleCrossUpdate(); andrew@46: andrew@33: BayesianArrayStructure bayesStruct; andrew@33: andrew@33: double speedPriorValue; andrew@33: int bestMatchIndex; andrew@33: string timeString; andrew@34: //double startTime; andrew@33: int speedWindowWidthMillis; andrew@33: andrew@33: bool confidenceWeightingUsed; andrew@33: andrew@33: double minimumMatchError;//recent best error between observed note and aligned midi file andrew@33: andrew@33: void reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix); andrew@33: int getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix); andrew@33: void correctTiming(IntMatrix& noteOnMatrix); andrew@33: void doublecheckOrder(IntMatrix& noteOnMatrix); andrew@33: int getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix); andrew@33: bool useTempoPrior; andrew@33: string tempoSpeedString; andrew@33: int minimumTimeIntervalForTempoUpdate; andrew@33: andrew@33: double ticksFactor; andrew@33: andrew@33: bool newOptimalMethod; andrew@33: DoubleMatrix interNoteIntervals; andrew@33: IntVector intervalsToCheck; andrew@33: void checkForCorrectInterval(const double& playedTimeDifference, DoubleVector* v); andrew@33: void drawInterNoteIntervals(); andrew@33: void printInterNoteIntervals(); andrew@33: int interNoteRange; andrew@33: DoubleMatrix periodValues; andrew@46: // int periodCounter; andrew@46: // void updatePeriodValue(const double& miupdatesllis); andrew@33: andrew@34: double smoothPlayPosition; andrew@34: // double storedSmoothPlayPosition; andrew@34: // double lastSmoothUpdateTime; andrew@34: // double relativeSpeedForSmooth; andrew@34: // void updateSmoothPlaySpeed();; andrew@34: //best alignment andrew@34: double alignmentPosition; andrew@34: double firstEventOffsetTimeMillis; andrew@35: andrew@48: double causalPlayPosition; andrew@48: void updateCausalPlayPosition(const double& timeNow); andrew@50: void updateCausalSpeed(); andrew@48: double lastCausalUpdateTime ; andrew@48: double causalSpeed; andrew@48: andrew@50: void updateOutputPositionTo(const double& newPosition); andrew@50: int outputIndex; andrew@35: DoubleVector beatPositions; andrew@35: andrew@35: ofstream *fileOutput; andrew@36: Annotations myNotation; andrew@37: ofstream *differenceOutput; andrew@49: double timeProjectionToMeet;///ms in future they will intersect andrew@49: andrew@49: double smoothDifference; andrew@50: double lastUpdatePosition, lastUpdatePlayingTime; andrew@50: double outputPosition;//debug variable andrew@50: andrew@50: void testSpeedPriorSetting(); andrew@52: andrew@52: bool printInfo; andrew@52: OutputDataWriter dataWriter; andrew@52: void writeAllDistributions(); andrew@52: void writeDistribution(DynamicVector& distribution, std::string file); andrew@52: ofImage img; andrew@52: void saveImageFile(std::string file); andrew@52: bool saveImage; andrew@52: andrew@33: }; andrew@33: #endif