annotate jnmr/drawMidiNotes.cpp @ 52:13194a9dca77 tip

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