annotate ofxPreciseOnsetDetectorOffline/testApp.cpp @ 3:50f62c48b421

Small change
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 03 Jan 2014 17:43:02 +0000
parents 7ec1ed0b2eb0
children eb29c6b6dff8
rev   line source
andrew@2 1 #include "testApp.h"
andrew@2 2
andrew@2 3 //possible to just omit the drawing (uses ofxWindowRegion for the screen and ofxPlotFunction to plot beat times)
andrew@2 4
andrew@2 5 //--------------------------------------------------------------
andrew@2 6 void testApp::setup(){
andrew@2 7 pov.window.setToRelativeSize(0.1, 0.1, 0.8, 0.3);
andrew@3 8 pov.pod = &preciseOnsetDetect;//set up pointer if we want to visualise the onsets in a window
andrew@2 9
andrew@2 10 // preciseOnsetDetect.load("/Users/andrew/Documents/work/programming/MadMax/AudioFiles/AdamBetts/AdamBetss_1_Swing_Kick.wav");
andrew@2 11 // preciseOnsetDetect.load("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Bouncing/Snare_Sontronics#08edit.aif");
andrew@2 12 loadNewFile("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Audio Files/Ride_SM58#08.aif");
andrew@2 13
andrew@2 14 }
andrew@2 15
andrew@2 16
andrew@2 17 void testApp::loadNewFile(std::string filename){
andrew@2 18 preciseOnsetDetect.load(filename);
andrew@2 19 preciseOnsetDetect.printOnsetLocations();
andrew@2 20
andrew@2 21 pov.newFile();
andrew@2 22 }
andrew@2 23
andrew@2 24 //--------------------------------------------------------------
andrew@2 25 void testApp::update(){
andrew@2 26 preciseOnsetDetect.update();
andrew@2 27 pov.update();
andrew@2 28 }
andrew@2 29
andrew@2 30 //--------------------------------------------------------------
andrew@2 31 void testApp::draw(){
andrew@2 32
andrew@2 33 pov.draw();
andrew@3 34
andrew@2 35 }
andrew@2 36
andrew@3 37
andrew@2 38 //--------------------------------------------------------------
andrew@2 39 void testApp::keyPressed(int key){
andrew@2 40 std::string loadName;
andrew@2 41 switch (key) {
andrew@2 42 case 'r':
andrew@2 43 pov.resetWindow();
andrew@2 44 break;
andrew@2 45 case 's':
andrew@2 46 pov.cropStart();
andrew@2 47 break;
andrew@2 48 case 'e':
andrew@2 49 pov.cropEnd();
andrew@2 50 break;
andrew@3 51 case 'x':
andrew@3 52 printf("Exporting between %f and %f\n", pov.windowStart, pov.windowEnd);
andrew@3 53 preciseOnsetDetect.exportOnsetTimes(pov.windowStart, pov.windowEnd);
andrew@3 54 break;
andrew@2 55 case 'o':
andrew@2 56 if (getFilenameFromDialogBox(&loadName)){
andrew@2 57 printf("loading %s\n", (loadName).c_str());
andrew@2 58 loadNewFile(loadName);
andrew@2 59 };
andrew@2 60
andrew@2 61 //delete testName;
andrew@2 62 break;
andrew@2 63 case ' ':
andrew@2 64 pov.togglePlay();
andrew@2 65 break;
andrew@2 66 case OF_KEY_RETURN:
andrew@2 67 pov.soundPlay.stop();
andrew@2 68 break;
andrew@2 69
andrew@2 70 default:
andrew@2 71 break;
andrew@2 72 }
andrew@2 73 }
andrew@2 74
andrew@2 75 //--------------------------------------------------------------
andrew@2 76 void testApp::keyReleased(int key){
andrew@2 77
andrew@2 78 }
andrew@2 79
andrew@2 80 //--------------------------------------------------------------
andrew@2 81 void testApp::mouseMoved(int x, int y){
andrew@2 82
andrew@2 83 }
andrew@2 84
andrew@2 85 //--------------------------------------------------------------
andrew@2 86 void testApp::mouseDragged(int x, int y, int button){
andrew@2 87
andrew@2 88 }
andrew@2 89
andrew@2 90 //--------------------------------------------------------------
andrew@2 91 void testApp::mousePressed(int x, int y, int button){
andrew@2 92 // if (window.tapped(x, y)){
andrew@2 93 // windowPress = windowStart + (windowEnd-windowStart)*(x - window.x)/window.width;
andrew@2 94 //
andrew@2 95 // printf("window position is %f\n", windowPress);
andrew@2 96 // }
andrew@2 97 pov.mousePressed(x, y);
andrew@2 98
andrew@2 99 }
andrew@2 100
andrew@2 101 //--------------------------------------------------------------
andrew@2 102 void testApp::mouseReleased(int x, int y, int button){
andrew@2 103
andrew@2 104 }
andrew@2 105
andrew@2 106 //--------------------------------------------------------------
andrew@2 107 void testApp::windowResized(int w, int h){
andrew@2 108
andrew@2 109 }
andrew@2 110
andrew@2 111 //--------------------------------------------------------------
andrew@2 112 void testApp::gotMessage(ofMessage msg){
andrew@2 113
andrew@2 114 }
andrew@2 115
andrew@2 116 //--------------------------------------------------------------
andrew@2 117 void testApp::dragEvent(ofDragInfo dragInfo){
andrew@2 118
andrew@2 119 }
andrew@2 120
andrew@2 121
andrew@2 122
andrew@2 123 bool testApp::getFilenameFromDialogBox(std::string* fileNameToSave){
andrew@2 124 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully
andrew@2 125 // first, create a string that will hold the URL
andrew@2 126 string URL;
andrew@2 127
andrew@2 128 // // openFile(string& URL) returns 1 if a file was picked
andrew@2 129 // // returns 0 when something went wrong or the user pressed 'cancel'
andrew@2 130 // int response = ofxFileDialogOSX::openFile(URL);
andrew@2 131 // if(response){
andrew@2 132 // // now you can use the URL
andrew@2 133 // *fileNameToSave = URL;
andrew@2 134 // //printf("\n filename is %s \n", soundFileName.c_str());
andrew@2 135 // return true;
andrew@2 136 // }
andrew@2 137 // else {
andrew@2 138 // // soundFileName = "OPEN canceled. ";
andrew@2 139 // printf("\n open file cancelled \n");
andrew@2 140 // return false;
andrew@2 141 // }
andrew@2 142
andrew@2 143 // openFile(string& URL) returns 1 if a file was picked
andrew@2 144 // returns 0 when something went wrong or the user pressed 'cancel'
andrew@2 145 ofFileDialogResult fileResult = ofSystemLoadDialog("Choose audio file to load");
andrew@2 146
andrew@2 147 if(fileResult.bSuccess){
andrew@2 148 // now you can use the URL
andrew@2 149 *fileNameToSave = fileResult.filePath;
andrew@2 150 //printf("\n filename is %s \n", soundFileName.c_str());
andrew@2 151 return true;
andrew@2 152 }
andrew@2 153 else {
andrew@2 154 // soundFileName = "OPEN canceled. ";
andrew@2 155 printf("\n open file cancelled \n");
andrew@2 156 return false;
andrew@2 157 }
andrew@2 158 }
andrew@2 159