andrew@0: /* andrew@0: * drawMidiNotes.cpp andrew@0: * midiCannamReader andrew@0: * andrew@0: * Created by Andrew on 17/07/2011. andrew@0: * Copyright 2011 QMUL. All rights reserved. andrew@0: * andrew@0: */ andrew@0: andrew@0: #include "drawMidiNotes.h" andrew@0: andrew@0: drawMidiNotes::drawMidiNotes(){ andrew@0: andrew@0: andrew@0: ticksPerScreen = 8000; andrew@0: tickLocation = 0; andrew@0: pulsesPerQuarternote = 240; andrew@0: noteArrayIndex = 0; andrew@0: noteMinimum = 30; andrew@0: noteMaximum = 96; andrew@0: screenWidth = ofGetWidth(); andrew@0: screenHeight = ofGetHeight(); andrew@0: noteHeight = screenHeight / (float)(noteMaximum - noteMinimum); andrew@0: } andrew@0: andrew@0: void drawMidiNotes::reset(){ andrew@0: noteArrayIndex = 0; andrew@0: tickLocation = 0; andrew@0: lastPeriodUpdateTime = ofGetElapsedTimeMillis(); andrew@0: andrew@0: } andrew@0: andrew@0: void drawMidiNotes::updatePlayPosition(){ andrew@0: double timeDifference = ofGetElapsedTimeMillis() - lastPeriodUpdateTime; andrew@0: //this is time diff in milliseconds andrew@0: //then we have andrew@0: double quarterNoteIntervals = (timeDifference / period); andrew@0: tickLocation = quarterNoteIntervals * pulsesPerQuarternote; andrew@0: andrew@0: } andrew@0: andrew@0: void drawMidiNotes::drawFile(const IntMatrix& noteOnMatrix){ andrew@0: int size = noteOnMatrix.size(); andrew@0: if (size > 0){ andrew@0: andrew@0: int numberOfScreensIn = tickLocation / ticksPerScreen; andrew@0: andrew@0: while (noteArrayIndex < noteOnMatrix.size() && tickLocation > noteOnMatrix[noteArrayIndex][0] ) andrew@0: noteArrayIndex++; andrew@0: andrew@0: while (noteArrayIndex > 0 && noteArrayIndex < size && tickLocation < noteOnMatrix[noteArrayIndex][0]) andrew@0: noteArrayIndex--; andrew@0: andrew@0: //need to start where we currently are in file andrew@0: int maxNoteIndexToPrint = noteArrayIndex; andrew@0: int minNoteIndexToPrint = noteArrayIndex; andrew@0: andrew@0: andrew@0: while (maxNoteIndexToPrint < noteOnMatrix.size() && noteOnMatrix[maxNoteIndexToPrint][0] < (numberOfScreensIn+1)*ticksPerScreen ) andrew@0: maxNoteIndexToPrint++; andrew@0: andrew@0: while (minNoteIndexToPrint > 0 && minNoteIndexToPrint < size && noteOnMatrix[minNoteIndexToPrint][0] > numberOfScreensIn*ticksPerScreen) andrew@0: minNoteIndexToPrint--; andrew@0: andrew@0: andrew@0: for (int tmpIndex = minNoteIndexToPrint;tmpIndex < maxNoteIndexToPrint;tmpIndex++){ andrew@0: int xLocation = (float)(noteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*screenWidth/(float)ticksPerScreen; andrew@0: int duration = (float)(noteOnMatrix[tmpIndex][3]*screenWidth)/(float)ticksPerScreen; andrew@0: andrew@0: andrew@0: int yLocation = screenHeight - ((noteOnMatrix[tmpIndex][1] - noteMinimum )*screenHeight/ (float)(noteMaximum - noteMinimum)); andrew@0: ofRect(xLocation,yLocation, duration, noteHeight); andrew@0: andrew@0: } andrew@0: andrew@0: int xLocation = (float)(tickLocation - numberOfScreensIn*ticksPerScreen)*screenWidth/(float)ticksPerScreen; andrew@0: ofLine(xLocation, 0, xLocation, screenHeight); andrew@0: andrew@0: // if (noteArrayIndex < size ) andrew@0: // printf("tick %i :: note array :%i: %i\n", tickLocation, noteArrayIndex, noteOnMatrix[noteArrayIndex][0]); andrew@0: // else andrew@0: // printf("end of file\n"); andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: }