view ofxPreciseOnsetDetectorOffline/testApp.cpp @ 2:7ec1ed0b2eb0

Added offline precise onset detection, outputting precise locations in seconds to text file
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Mon, 30 Dec 2013 14:08:42 +0000
parents
children 50f62c48b421
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;
	
//	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();
	
	//windowStart = 0;
	//windowEnd = preciseOnsetDetect.samples/44100.;
	//windowPress = 0;
	
	pov.newFile();
}

//--------------------------------------------------------------
void testApp::update(){
	preciseOnsetDetect.update();
	pov.update();
}

//--------------------------------------------------------------
void testApp::draw(){
	
	pov.draw();
	/*
	//if plotting use this, else comment out
	ofSetColor(ofColor::white);
	window.drawBackground();
	ofSetColor(ofColor::black);
	window.drawOutline();
	ofSetColor(ofColor::blue);
	plotter.drawBeatStripes(preciseOnsetDetect.onsetLocations, window, windowStart, windowEnd);
*/
	
}

//--------------------------------------------------------------
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 '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;
	}
}