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