Mercurial > hg > precise-onset-detection
view ofxPreciseOnsetDetectorOffline/testApp.cpp @ 4:93b9a9471011
Changes to precise onset
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Mon, 06 Jan 2014 18:10:01 +0000 |
parents | 50f62c48b421 |
children | eb29c6b6dff8 |
line wrap: on
line source
#include "testApp.h" //possible to just omit the drawing (uses ofxWindowRegion for the screen and ofxPlotFunction to plot beat times) //-------------------------------------------------------------- void testApp::setup(){ pov.window.setToRelativeSize(0.1, 0.1, 0.8, 0.3); pov.pod = &preciseOnsetDetect;//set up pointer if we want to visualise the onsets in a window // preciseOnsetDetect.load("/Users/andrew/Documents/work/programming/MadMax/AudioFiles/AdamBetts/AdamBetss_1_Swing_Kick.wav"); // preciseOnsetDetect.load("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Bouncing/Snare_Sontronics#08edit.aif"); loadNewFile("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Audio Files/Ride_SM58#08.aif"); } void testApp::loadNewFile(std::string filename){ preciseOnsetDetect.load(filename); preciseOnsetDetect.printOnsetLocations(); pov.newFile(); } //-------------------------------------------------------------- void testApp::update(){ preciseOnsetDetect.update(); pov.update(); } //-------------------------------------------------------------- void testApp::draw(){ pov.draw(); } //-------------------------------------------------------------- void testApp::keyPressed(int key){ std::string loadName; switch (key) { case 'r': pov.resetWindow(); break; case 's': pov.cropStart(); break; case 'e': pov.cropEnd(); break; case 'x': printf("Exporting between %f and %f\n", pov.windowStart, pov.windowEnd); preciseOnsetDetect.exportOnsetTimes(pov.windowStart, pov.windowEnd); break; case 'o': if (getFilenameFromDialogBox(&loadName)){ printf("loading %s\n", (loadName).c_str()); loadNewFile(loadName); }; //delete testName; break; case ' ': pov.togglePlay(); break; case OF_KEY_RETURN: pov.soundPlay.stop(); break; default: break; } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ // if (window.tapped(x, y)){ // windowPress = windowStart + (windowEnd-windowStart)*(x - window.x)/window.width; // // printf("window position is %f\n", windowPress); // } pov.mousePressed(x, y); } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ } bool testApp::getFilenameFromDialogBox(std::string* fileNameToSave){ //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully // first, create a string that will hold the URL string URL; // // openFile(string& URL) returns 1 if a file was picked // // returns 0 when something went wrong or the user pressed 'cancel' // int response = ofxFileDialogOSX::openFile(URL); // if(response){ // // now you can use the URL // *fileNameToSave = URL; // //printf("\n filename is %s \n", soundFileName.c_str()); // return true; // } // else { // // soundFileName = "OPEN canceled. "; // printf("\n open file cancelled \n"); // return false; // } // openFile(string& URL) returns 1 if a file was picked // returns 0 when something went wrong or the user pressed 'cancel' ofFileDialogResult fileResult = ofSystemLoadDialog("Choose audio file to load"); if(fileResult.bSuccess){ // now you can use the URL *fileNameToSave = fileResult.filePath; //printf("\n filename is %s \n", soundFileName.c_str()); return true; } else { // soundFileName = "OPEN canceled. "; printf("\n open file cancelled \n"); return false; } }