Mercurial > hg > precise-onset-detection
comparison ofxPreciseOnsetDetectorOffline/PointerOnsetVisualiser.cpp @ 6:eb29c6b6dff8
added pointer version of visualiser
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sun, 19 Jan 2014 23:07:13 +0000 |
parents | |
children | b1c13e8bec26 |
comparison
equal
deleted
inserted
replaced
5:1e636a3511fb | 6:eb29c6b6dff8 |
---|---|
1 /* | |
2 * PointerOnsetVisualiser.cpp | |
3 * GreenOnionsMidiBeatApp | |
4 * | |
5 * Created by Andrew on 14/01/2014. | |
6 * Copyright 2014 QMUL. All rights reserved. | |
7 * | |
8 */ | |
9 | |
10 #include "PointerOnsetVisualiser.h" | |
11 | |
12 | |
13 PointerOnsetVisualiser::PointerOnsetVisualiser(){ | |
14 | |
15 } | |
16 | |
17 PointerOnsetVisualiser::~PointerOnsetVisualiser(){ | |
18 printf("deleting pointer in visualiser\n"); | |
19 pod = NULL; | |
20 delete pod; | |
21 | |
22 // delete windowStart; | |
23 // delete windowEnd; | |
24 // delete windowPress; | |
25 } | |
26 | |
27 void PointerOnsetVisualiser::newFile(){ | |
28 resetWindow(); | |
29 // windowPress = 0; | |
30 | |
31 soundPlay.loadSound(pod->loadedFilename, false); | |
32 paused = true; | |
33 soundPlay.play(); | |
34 soundPlay.setPaused(true); | |
35 } | |
36 | |
37 double PointerOnsetVisualiser::windowWidth(){ | |
38 return (*windowEnd) - (*windowStart); | |
39 } | |
40 | |
41 void PointerOnsetVisualiser::update(){ | |
42 double positionNow = positionSeconds(); | |
43 if (positionNow > (*windowEnd)){ | |
44 double tmp = windowWidth(); | |
45 (*windowEnd) += tmp; | |
46 (*windowStart) += tmp; | |
47 //printf("Scrolling\n"); | |
48 } | |
49 | |
50 } | |
51 | |
52 | |
53 void PointerOnsetVisualiser::draw(){ | |
54 //if plotting use this, else comment out | |
55 | |
56 ofSetColor(ofColor::white); | |
57 window.drawBackground(); | |
58 ofSetColor(ofColor::black); | |
59 window.drawOutline(); | |
60 | |
61 //draw df function | |
62 /* | |
63 int startIndex = 0; | |
64 while (startIndex < (int)pod->dfValues.size() && pod->frameIndexToSeconds(startIndex) < (*windowStart)) | |
65 startIndex++; | |
66 | |
67 int endIndex = 0; | |
68 while (endIndex < (int)pod->dfValues.size()-1 && pod->frameIndexToSeconds(endIndex) < (*windowEnd)) | |
69 endIndex++; | |
70 */ | |
71 ofSetColor(ofColor::tan); | |
72 // plotter.drawVector(pod->dfValues, startIndex, endIndex, window); | |
73 plotter.drawVector(pod->dfValues, round(pod->secondsToFrameIndex((*windowStart))), round(pod->secondsToFrameIndex((*windowEnd))), window); | |
74 ofSetColor(ofColor::black); | |
75 ofDrawBitmapString(ofToString(round(pod->secondsToFrameIndex((*windowStart))), 1), window.x, window.y-10); | |
76 ofDrawBitmapString(ofToString(round(pod->secondsToFrameIndex((*windowEnd))), 1), window.x+window.width, window.y-10); | |
77 | |
78 ofSetColor(ofColor::blue); | |
79 plotter.drawBeatStripes(pod->onsetLocations, window, (*windowStart), (*windowEnd)); | |
80 | |
81 //play position | |
82 ofSetColor(ofColor::red); | |
83 plotter.drawStripe(positionSeconds(), window, (*windowStart), (*windowEnd)); | |
84 | |
85 ofSetColor(ofColor::black); | |
86 ofDrawBitmapString(ofToString((*windowStart), 1), window.x, window.y+window.height+10); | |
87 ofDrawBitmapString(ofToString((*windowEnd), 1), window.x+window.width, window.y+window.height+10); | |
88 | |
89 } | |
90 | |
91 double PointerOnsetVisualiser::positionSeconds(){ | |
92 return soundPlay.getPosition()*pod->samples/44100.; | |
93 } | |
94 | |
95 //void PointerOnsetVisualiser::drawOnsets(DoubleVector& onsetTimesSeconds, ofxWindowregion& window, double startTime, double endTime){ | |
96 //} | |
97 | |
98 void PointerOnsetVisualiser::resetWindow(){ | |
99 (*windowStart) = 0; | |
100 (*windowEnd) = 8; | |
101 // while ((*windowEnd) < pod->samples/44100.) | |
102 // (*windowEnd) *= 2; | |
103 | |
104 (*windowEnd) = pod->samples/44100.; | |
105 | |
106 printf("reset: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); | |
107 } | |
108 | |
109 void PointerOnsetVisualiser::cropStart(){ | |
110 if (soundPlay.getPositionMS()/1000. < (*windowEnd)){ | |
111 (*windowStart) = soundPlay.getPositionMS()/1000.; | |
112 printf("s: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); | |
113 } | |
114 } | |
115 | |
116 void PointerOnsetVisualiser::cropStartSeconds(double& val){ | |
117 if (val < (*windowEnd)) | |
118 (*windowStart) = val; | |
119 } | |
120 | |
121 void PointerOnsetVisualiser::cropEnd(){//crops to play position | |
122 | |
123 if (soundPlay.getPositionMS()/1000. > (*windowStart)){ | |
124 (*windowEnd) = soundPlay.getPositionMS()/1000.; | |
125 printf("crop end: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); | |
126 } | |
127 } | |
128 | |
129 | |
130 void PointerOnsetVisualiser::cropEndSeconds(double& val){ | |
131 if (val > (*windowStart)) | |
132 (*windowEnd) = val; | |
133 | |
134 printf("crop end: start %.1f end %.1f\n", (*windowStart), (*windowEnd)); | |
135 } | |
136 | |
137 | |
138 void PointerOnsetVisualiser::mousePressed(int& x, int& y){ | |
139 /* | |
140 if (window.tapped(x, y)){ | |
141 windowPress = (*windowStart) + ((*windowEnd)-(*windowStart))*(x - window.x)/window.width; | |
142 double newPos = windowPress/(double)(pod->samples/44100.); | |
143 printf("window position is %.1f new pos %f\n", windowPress, newPos); | |
144 soundPlay.setPositionMS(windowPress*1000.0); | |
145 } | |
146 */ | |
147 } | |
148 | |
149 void PointerOnsetVisualiser::setSoundPositionSeconds(double position){ | |
150 printf("set position, was %i, new pos %f\n", soundPlay.getPositionMS(), position); | |
151 soundPlay.setPositionMS(position*1000.0); | |
152 printf("new position %i\n", soundPlay.getPositionMS()); | |
153 } | |
154 | |
155 void PointerOnsetVisualiser::togglePlay(){ | |
156 if (!paused ){ | |
157 soundPlay.setPaused(true); | |
158 paused = true; | |
159 printf("was playing\n"); | |
160 } | |
161 else { | |
162 soundPlay.setPaused(false);// | |
163 paused = false; | |
164 printf("was not playing\n"); | |
165 } | |
166 } | |
167 | |
168 void PointerOnsetVisualiser::stop(){ | |
169 soundPlay.stop(); | |
170 //then get set to be played | |
171 soundPlay.play(); | |
172 soundPlay.setPaused(true); | |
173 soundPlay.setPositionMS((*windowStart)*1000.0); | |
174 paused = true; | |
175 } | |
176 | |
177 void PointerOnsetVisualiser::zoomIn(){ | |
178 double positionNow = positionSeconds(); | |
179 if (positionNow > (*windowEnd)){ | |
180 double tmp = windowWidth(); | |
181 (*windowEnd) += windowWidth(); | |
182 (*windowStart) += tmp; | |
183 } | |
184 | |
185 (*windowStart) = positionNow - ((*windowEnd)-(*windowStart))/4; | |
186 if ((*windowStart) < 0) | |
187 (*windowStart) = 0; | |
188 (*windowEnd) = positionNow + ((*windowEnd)-(*windowStart))/4; | |
189 } | |
190 | |
191 | |
192 void PointerOnsetVisualiser::zoomOut(){ | |
193 double positionNow = positionSeconds(); | |
194 if (positionNow > (*windowEnd)){ | |
195 double tmp = windowWidth(); | |
196 (*windowEnd) += tmp; | |
197 (*windowStart) += tmp; | |
198 } | |
199 | |
200 (*windowStart) = positionNow - ((*windowEnd)-(*windowStart)); | |
201 (*windowEnd) = positionNow + ((*windowEnd)-(*windowStart)); | |
202 if ((*windowStart) < 0) | |
203 (*windowStart) = 0; | |
204 } | |
205 | |
206 void PointerOnsetVisualiser::scrollLeft(){ | |
207 double tmp = windowWidth(); | |
208 (*windowStart) = max(0., (*windowStart) - windowWidth()/2.); | |
209 (*windowEnd) = (*windowStart) + tmp; | |
210 checkPosition(); | |
211 } | |
212 | |
213 | |
214 void PointerOnsetVisualiser::scrollRight(){ | |
215 double tmp = windowWidth(); | |
216 (*windowStart) = min( (*windowStart)+tmp/2., pod->samples/44100.); | |
217 (*windowEnd) = (*windowStart) + tmp; | |
218 checkPosition(); | |
219 } | |
220 | |
221 void PointerOnsetVisualiser::checkPosition(){ | |
222 double positionNow = positionSeconds(); | |
223 if (positionNow < (*windowStart) || positionNow > (*windowEnd)) | |
224 soundPlay.setPositionMS((*windowStart)*1000); | |
225 } |