Mercurial > hg > midi-score-follower
view hackday/drawMidiNotes.cpp @ 36:5a1b0c6fa1fb
Added class to read in the csv Annotation file, then write out the respective difference between the performed piece as followed here, and the annotation of RWC by Ewert and Muller
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Thu, 15 Dec 2011 02:28:49 +0000 |
parents | 49a5b023df1e |
children |
line wrap: on
line source
/* * drawMidiNotes.cpp * midiCannamReader * * Created by Andrew on 17/07/2011. * Copyright 2011 QMUL. All rights reserved. * */ #include "drawMidiNotes.h" drawMidiNotes::drawMidiNotes(){ ticksPerScreen = 8000; tickLocation = 0; pulsesPerQuarternote = 240; noteArrayIndex = 0; noteMinimum = 30; noteMaximum = 96; screenWidth = ofGetWidth(); screenHeight = ofGetHeight(); noteHeight = screenHeight / (float)(noteMaximum - noteMinimum); } void drawMidiNotes::reset(){ noteArrayIndex = 0; tickLocation = 0; lastPeriodUpdateTime = ofGetElapsedTimeMillis(); } void drawMidiNotes::updatePlayPosition(){ double timeDifference = ofGetElapsedTimeMillis() - lastPeriodUpdateTime; //this is time diff in milliseconds //then we have double quarterNoteIntervals = (timeDifference / period); tickLocation = quarterNoteIntervals * pulsesPerQuarternote; } void drawMidiNotes::drawFile(const IntMatrix& noteOnMatrix){ int size = noteOnMatrix.size(); if (size > 0){ int numberOfScreensIn = tickLocation / ticksPerScreen; while (noteArrayIndex < noteOnMatrix.size() && tickLocation > noteOnMatrix[noteArrayIndex][0] ) noteArrayIndex++; while (noteArrayIndex > 0 && noteArrayIndex < size && tickLocation < noteOnMatrix[noteArrayIndex][0]) noteArrayIndex--; //need to start where we currently are in file int maxNoteIndexToPrint = noteArrayIndex; int minNoteIndexToPrint = noteArrayIndex; while (maxNoteIndexToPrint < noteOnMatrix.size() && noteOnMatrix[maxNoteIndexToPrint][0] < (numberOfScreensIn+1)*ticksPerScreen ) maxNoteIndexToPrint++; while (minNoteIndexToPrint > 0 && minNoteIndexToPrint < size && noteOnMatrix[minNoteIndexToPrint][0] > numberOfScreensIn*ticksPerScreen) minNoteIndexToPrint--; for (int tmpIndex = minNoteIndexToPrint;tmpIndex < maxNoteIndexToPrint;tmpIndex++){ int xLocation = (float)(noteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*screenWidth/(float)ticksPerScreen; int duration = (float)(noteOnMatrix[tmpIndex][3]*screenWidth)/(float)ticksPerScreen; int yLocation = screenHeight - ((noteOnMatrix[tmpIndex][1] - noteMinimum )*screenHeight/ (float)(noteMaximum - noteMinimum)); ofRect(xLocation,yLocation, duration, noteHeight); } int xLocation = (float)(tickLocation - numberOfScreensIn*ticksPerScreen)*screenWidth/(float)ticksPerScreen; ofLine(xLocation, 0, xLocation, screenHeight); // if (noteArrayIndex < size ) // printf("tick %i :: note array :%i: %i\n", tickLocation, noteArrayIndex, noteOnMatrix[noteArrayIndex][0]); // else // printf("end of file\n"); } }