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