view ofxPreciseOnsetDetectorOffline/PreciseBassOnsetDetector.cpp @ 7:b1c13e8bec26

adding new files
author Venetian
date Thu, 14 Aug 2014 16:27:52 +0100
parents
children
line wrap: on
line source
/*
 *  PreciseBassOnsetDetector.cpp
 *  BasslinePrediction
 *
 *  Created by Andrew N Robertson on 13/04/2014.
 *  Copyright 2014 QMUL. All rights reserved.
 *
 */

#include "PreciseBassOnsetDetector.h"


PreciseBassOnsetDetector::PreciseBassOnsetDetector(){
	pov.window.setToRelativeSize(0.1, 0.1, 0.8, 0.3);
	pov.pod = &pod;//set up pointer if we want to visualise the onsets in a window
	
	//	std::string fileName;
	//	fileName = "/Users/andrewrobertson/Music/audiowavs/Islamey/BachBWV846-2.wav";
	//	loadNewFile(fileName);
}

PreciseBassOnsetDetector::~PreciseBassOnsetDetector(){
	
}

void PreciseBassOnsetDetector::loadNewFile(std::string filename){
	
	pod.initialise();
	pod.load(filename);	
	pod.printOnsetLocations();
	pov.newFile();//resets info in visualiser - could use pointer??
}

void PreciseBassOnsetDetector::update(){
	pod.update();
	pov.update();
}

void PreciseBassOnsetDetector::draw(){
	pov.draw();
}

bool PreciseBassOnsetDetector::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;
	
	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;
	}
}

void PreciseBassOnsetDetector::keyPressed(int key){
	std::string loadName;
	switch (key) {
		case 'r':
			pov.resetWindow();
			break;
		case 's':
			pov.cropStart();
			pod.cropStartTo(pov.windowStart);
			break;
		case 'e':
			pov.cropEnd();
			break;
		case 'w':
			printf("Exporting between %f and %f\n", pov.windowStart, pov.windowEnd);
			pod.exportOnsetTimes(pov.windowStart, pov.windowEnd);
			break;
		case 'x':
			printf("Exporting between %f and %f\n", 0., pov.lengthSeconds());
			pod.exportOnsetTimes(0, pov.lengthSeconds());
			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.stop();
			
			break;
			
		case OF_KEY_UP: case 'u':
			pov.zoomIn();
			break;
		case OF_KEY_DOWN:
			pov.zoomOut();
			break;
		case OF_KEY_RIGHT:
			pov.scrollRight();
			break;
		case OF_KEY_LEFT:
			pov.scrollLeft();
			break;	
			
		default:
			break;
	}
}

void PreciseBassOnsetDetector::mousePressed(int x, int y, int button){
	
	pov.mousePressed(x, y);
	
}