annotate ofxPreciseOnsetDetectorOffline/PointerOnsetVisualiser.cpp @ 8:184a7c232049 tip

changed files since updating computer
author Venetian
date Thu, 14 Aug 2014 17:53:57 +0100
parents b1c13e8bec26
children
rev   line source
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;
Venetian@7 30 printf("loading sound %s\n", pod->loadedFilename.c_str());
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);
Venetian@7 79 plotter.drawBeatStripes(pod->onsetList, window, (*windowStart), (*windowEnd));
Venetian@7 80 //replaced above line with a plotter that can do our onset list
andrew@6 81
andrew@6 82 //play position
andrew@6 83 ofSetColor(ofColor::red);
andrew@6 84 plotter.drawStripe(positionSeconds(), window, (*windowStart), (*windowEnd));
andrew@6 85
andrew@6 86 ofSetColor(ofColor::black);
andrew@6 87 ofDrawBitmapString(ofToString((*windowStart), 1), window.x, window.y+window.height+10);
andrew@6 88 ofDrawBitmapString(ofToString((*windowEnd), 1), window.x+window.width, window.y+window.height+10);
andrew@6 89
andrew@6 90 }
andrew@6 91
andrew@6 92 double PointerOnsetVisualiser::positionSeconds(){
andrew@6 93 return soundPlay.getPosition()*pod->samples/44100.;
andrew@6 94 }
andrew@6 95
andrew@6 96 //void PointerOnsetVisualiser::drawOnsets(DoubleVector& onsetTimesSeconds, ofxWindowregion& window, double startTime, double endTime){
andrew@6 97 //}
andrew@6 98
andrew@6 99 void PointerOnsetVisualiser::resetWindow(){
andrew@6 100 (*windowStart) = 0;
andrew@6 101 (*windowEnd) = 8;
andrew@6 102 // while ((*windowEnd) < pod->samples/44100.)
andrew@6 103 // (*windowEnd) *= 2;
andrew@6 104
Venetian@7 105 // (*windowEnd) = pod->samples/44100.;
andrew@6 106
andrew@6 107 printf("reset: start %.1f end %.1f\n", (*windowStart), (*windowEnd));
andrew@6 108 }
andrew@6 109
andrew@6 110 void PointerOnsetVisualiser::cropStart(){
andrew@6 111 if (soundPlay.getPositionMS()/1000. < (*windowEnd)){
andrew@6 112 (*windowStart) = soundPlay.getPositionMS()/1000.;
andrew@6 113 printf("s: start %.1f end %.1f\n", (*windowStart), (*windowEnd));
andrew@6 114 }
andrew@6 115 }
andrew@6 116
andrew@6 117 void PointerOnsetVisualiser::cropStartSeconds(double& val){
andrew@6 118 if (val < (*windowEnd))
andrew@6 119 (*windowStart) = val;
andrew@6 120 }
andrew@6 121
andrew@6 122 void PointerOnsetVisualiser::cropEnd(){//crops to play position
andrew@6 123
andrew@6 124 if (soundPlay.getPositionMS()/1000. > (*windowStart)){
andrew@6 125 (*windowEnd) = soundPlay.getPositionMS()/1000.;
andrew@6 126 printf("crop end: start %.1f end %.1f\n", (*windowStart), (*windowEnd));
andrew@6 127 }
andrew@6 128 }
andrew@6 129
andrew@6 130
andrew@6 131 void PointerOnsetVisualiser::cropEndSeconds(double& val){
andrew@6 132 if (val > (*windowStart))
andrew@6 133 (*windowEnd) = val;
andrew@6 134
andrew@6 135 printf("crop end: start %.1f end %.1f\n", (*windowStart), (*windowEnd));
andrew@6 136 }
andrew@6 137
andrew@6 138
andrew@6 139 void PointerOnsetVisualiser::mousePressed(int& x, int& y){
andrew@6 140 /*
andrew@6 141 if (window.tapped(x, y)){
andrew@6 142 windowPress = (*windowStart) + ((*windowEnd)-(*windowStart))*(x - window.x)/window.width;
andrew@6 143 double newPos = windowPress/(double)(pod->samples/44100.);
andrew@6 144 printf("window position is %.1f new pos %f\n", windowPress, newPos);
andrew@6 145 soundPlay.setPositionMS(windowPress*1000.0);
andrew@6 146 }
andrew@6 147 */
andrew@6 148 }
andrew@6 149
andrew@6 150 void PointerOnsetVisualiser::setSoundPositionSeconds(double position){
andrew@6 151 printf("set position, was %i, new pos %f\n", soundPlay.getPositionMS(), position);
andrew@6 152 soundPlay.setPositionMS(position*1000.0);
andrew@6 153 printf("new position %i\n", soundPlay.getPositionMS());
andrew@6 154 }
andrew@6 155
andrew@6 156 void PointerOnsetVisualiser::togglePlay(){
andrew@6 157 if (!paused ){
andrew@6 158 soundPlay.setPaused(true);
andrew@6 159 paused = true;
andrew@6 160 printf("was playing\n");
andrew@6 161 }
andrew@6 162 else {
andrew@6 163 soundPlay.setPaused(false);//
andrew@6 164 paused = false;
andrew@6 165 printf("was not playing\n");
andrew@6 166 }
andrew@6 167 }
andrew@6 168
andrew@6 169 void PointerOnsetVisualiser::stop(){
andrew@6 170 soundPlay.stop();
andrew@6 171 //then get set to be played
andrew@6 172 soundPlay.play();
andrew@6 173 soundPlay.setPaused(true);
andrew@6 174 soundPlay.setPositionMS((*windowStart)*1000.0);
andrew@6 175 paused = true;
andrew@6 176 }
andrew@6 177
andrew@6 178 void PointerOnsetVisualiser::zoomIn(){
andrew@6 179 double positionNow = positionSeconds();
andrew@6 180 if (positionNow > (*windowEnd)){
andrew@6 181 double tmp = windowWidth();
andrew@6 182 (*windowEnd) += windowWidth();
andrew@6 183 (*windowStart) += tmp;
andrew@6 184 }
andrew@6 185
andrew@6 186 (*windowStart) = positionNow - ((*windowEnd)-(*windowStart))/4;
andrew@6 187 if ((*windowStart) < 0)
andrew@6 188 (*windowStart) = 0;
andrew@6 189 (*windowEnd) = positionNow + ((*windowEnd)-(*windowStart))/4;
andrew@6 190 }
andrew@6 191
andrew@6 192
andrew@6 193 void PointerOnsetVisualiser::zoomOut(){
andrew@6 194 double positionNow = positionSeconds();
andrew@6 195 if (positionNow > (*windowEnd)){
andrew@6 196 double tmp = windowWidth();
andrew@6 197 (*windowEnd) += tmp;
andrew@6 198 (*windowStart) += tmp;
andrew@6 199 }
andrew@6 200
andrew@6 201 (*windowStart) = positionNow - ((*windowEnd)-(*windowStart));
andrew@6 202 (*windowEnd) = positionNow + ((*windowEnd)-(*windowStart));
andrew@6 203 if ((*windowStart) < 0)
andrew@6 204 (*windowStart) = 0;
andrew@6 205 }
andrew@6 206
andrew@6 207 void PointerOnsetVisualiser::scrollLeft(){
andrew@6 208 double tmp = windowWidth();
andrew@6 209 (*windowStart) = max(0., (*windowStart) - windowWidth()/2.);
andrew@6 210 (*windowEnd) = (*windowStart) + tmp;
andrew@6 211 checkPosition();
andrew@6 212 }
andrew@6 213
andrew@6 214
andrew@6 215 void PointerOnsetVisualiser::scrollRight(){
andrew@6 216 double tmp = windowWidth();
andrew@6 217 (*windowStart) = min( (*windowStart)+tmp/2., pod->samples/44100.);
andrew@6 218 (*windowEnd) = (*windowStart) + tmp;
andrew@6 219 checkPosition();
andrew@6 220 }
andrew@6 221
andrew@6 222 void PointerOnsetVisualiser::checkPosition(){
andrew@6 223 double positionNow = positionSeconds();
andrew@6 224 if (positionNow < (*windowStart) || positionNow > (*windowEnd))
andrew@6 225 soundPlay.setPositionMS((*windowStart)*1000);
andrew@6 226 }