annotate src/drawMidiNotes.cpp @ 5:195907bb8bb7

added purple where notes have been seen - lets you see what updates have been used. Also the chopping of midi files to the beginning was introduced recently, so when they load, you chop any white space at the beginning, then use first note to launch.
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 19 Aug 2011 16:38:30 +0100
parents b299a65a3ad0
children
rev   line source
andrew@0 1 /*
andrew@0 2 * drawMidiNotes.cpp
andrew@0 3 * midiCannamReader
andrew@0 4 *
andrew@0 5 * Created by Andrew on 17/07/2011.
andrew@0 6 * Copyright 2011 QMUL. All rights reserved.
andrew@0 7 *
andrew@0 8 */
andrew@0 9
andrew@0 10 #include "drawMidiNotes.h"
andrew@0 11
andrew@0 12 drawMidiNotes::drawMidiNotes(){
andrew@0 13
andrew@0 14
andrew@0 15 ticksPerScreen = 8000;
andrew@0 16 tickLocation = 0;
andrew@0 17 pulsesPerQuarternote = 240;
andrew@0 18 noteArrayIndex = 0;
andrew@0 19 noteMinimum = 30;
andrew@0 20 noteMaximum = 96;
andrew@0 21 screenWidth = ofGetWidth();
andrew@0 22 screenHeight = ofGetHeight();
andrew@0 23 noteHeight = screenHeight / (float)(noteMaximum - noteMinimum);
andrew@0 24 }
andrew@0 25
andrew@0 26 void drawMidiNotes::reset(){
andrew@0 27 noteArrayIndex = 0;
andrew@0 28 tickLocation = 0;
andrew@0 29 lastPeriodUpdateTime = ofGetElapsedTimeMillis();
andrew@0 30
andrew@0 31 }
andrew@0 32
andrew@0 33 void drawMidiNotes::updatePlayPosition(){
andrew@0 34 double timeDifference = ofGetElapsedTimeMillis() - lastPeriodUpdateTime;
andrew@0 35 //this is time diff in milliseconds
andrew@0 36 //then we have
andrew@0 37 double quarterNoteIntervals = (timeDifference / period);
andrew@0 38 tickLocation = quarterNoteIntervals * pulsesPerQuarternote;
andrew@0 39
andrew@0 40 }
andrew@0 41
andrew@0 42 void drawMidiNotes::drawFile(const IntMatrix& noteOnMatrix){
andrew@0 43 int size = noteOnMatrix.size();
andrew@0 44 if (size > 0){
andrew@0 45
andrew@0 46 int numberOfScreensIn = tickLocation / ticksPerScreen;
andrew@0 47
andrew@0 48 while (noteArrayIndex < noteOnMatrix.size() && tickLocation > noteOnMatrix[noteArrayIndex][0] )
andrew@0 49 noteArrayIndex++;
andrew@0 50
andrew@0 51 while (noteArrayIndex > 0 && noteArrayIndex < size && tickLocation < noteOnMatrix[noteArrayIndex][0])
andrew@0 52 noteArrayIndex--;
andrew@0 53
andrew@0 54 //need to start where we currently are in file
andrew@0 55 int maxNoteIndexToPrint = noteArrayIndex;
andrew@0 56 int minNoteIndexToPrint = noteArrayIndex;
andrew@0 57
andrew@0 58
andrew@0 59 while (maxNoteIndexToPrint < noteOnMatrix.size() && noteOnMatrix[maxNoteIndexToPrint][0] < (numberOfScreensIn+1)*ticksPerScreen )
andrew@0 60 maxNoteIndexToPrint++;
andrew@0 61
andrew@0 62 while (minNoteIndexToPrint > 0 && minNoteIndexToPrint < size && noteOnMatrix[minNoteIndexToPrint][0] > numberOfScreensIn*ticksPerScreen)
andrew@0 63 minNoteIndexToPrint--;
andrew@0 64
andrew@0 65
andrew@0 66 for (int tmpIndex = minNoteIndexToPrint;tmpIndex < maxNoteIndexToPrint;tmpIndex++){
andrew@0 67 int xLocation = (float)(noteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*screenWidth/(float)ticksPerScreen;
andrew@0 68 int duration = (float)(noteOnMatrix[tmpIndex][3]*screenWidth)/(float)ticksPerScreen;
andrew@0 69
andrew@0 70
andrew@0 71 int yLocation = screenHeight - ((noteOnMatrix[tmpIndex][1] - noteMinimum )*screenHeight/ (float)(noteMaximum - noteMinimum));
andrew@0 72 ofRect(xLocation,yLocation, duration, noteHeight);
andrew@0 73
andrew@0 74 }
andrew@0 75
andrew@0 76 int xLocation = (float)(tickLocation - numberOfScreensIn*ticksPerScreen)*screenWidth/(float)ticksPerScreen;
andrew@0 77 ofLine(xLocation, 0, xLocation, screenHeight);
andrew@0 78
andrew@0 79 // if (noteArrayIndex < size )
andrew@0 80 // printf("tick %i :: note array :%i: %i\n", tickLocation, noteArrayIndex, noteOnMatrix[noteArrayIndex][0]);
andrew@0 81 // else
andrew@0 82 // printf("end of file\n");
andrew@0 83
andrew@0 84
andrew@0 85 }
andrew@0 86
andrew@0 87 }