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