Venetian@7
|
1 /*
|
Venetian@7
|
2 * PreciseBassOnsetDetector.cpp
|
Venetian@7
|
3 * BasslinePrediction
|
Venetian@7
|
4 *
|
Venetian@7
|
5 * Created by Andrew N Robertson on 13/04/2014.
|
Venetian@7
|
6 * Copyright 2014 QMUL. All rights reserved.
|
Venetian@7
|
7 *
|
Venetian@7
|
8 */
|
Venetian@7
|
9
|
Venetian@7
|
10 #include "PreciseBassOnsetDetector.h"
|
Venetian@7
|
11
|
Venetian@7
|
12
|
Venetian@7
|
13 PreciseBassOnsetDetector::PreciseBassOnsetDetector(){
|
Venetian@7
|
14 pov.window.setToRelativeSize(0.1, 0.1, 0.8, 0.3);
|
Venetian@7
|
15 pov.pod = &pod;//set up pointer if we want to visualise the onsets in a window
|
Venetian@7
|
16
|
Venetian@7
|
17 // std::string fileName;
|
Venetian@7
|
18 // fileName = "/Users/andrewrobertson/Music/audiowavs/Islamey/BachBWV846-2.wav";
|
Venetian@7
|
19 // loadNewFile(fileName);
|
Venetian@7
|
20 }
|
Venetian@7
|
21
|
Venetian@7
|
22 PreciseBassOnsetDetector::~PreciseBassOnsetDetector(){
|
Venetian@7
|
23
|
Venetian@7
|
24 }
|
Venetian@7
|
25
|
Venetian@7
|
26 void PreciseBassOnsetDetector::loadNewFile(std::string filename){
|
Venetian@7
|
27
|
Venetian@7
|
28 pod.initialise();
|
Venetian@7
|
29 pod.load(filename);
|
Venetian@7
|
30 pod.printOnsetLocations();
|
Venetian@7
|
31 pov.newFile();//resets info in visualiser - could use pointer??
|
Venetian@7
|
32 }
|
Venetian@7
|
33
|
Venetian@7
|
34 void PreciseBassOnsetDetector::update(){
|
Venetian@7
|
35 pod.update();
|
Venetian@7
|
36 pov.update();
|
Venetian@7
|
37 }
|
Venetian@7
|
38
|
Venetian@7
|
39 void PreciseBassOnsetDetector::draw(){
|
Venetian@7
|
40 pov.draw();
|
Venetian@7
|
41 }
|
Venetian@7
|
42
|
Venetian@7
|
43 bool PreciseBassOnsetDetector::getFilenameFromDialogBox(std::string* fileNameToSave){
|
Venetian@7
|
44 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully
|
Venetian@7
|
45 // first, create a string that will hold the URL
|
Venetian@7
|
46 string URL;
|
Venetian@7
|
47
|
Venetian@7
|
48 ofFileDialogResult fileResult = ofSystemLoadDialog("Choose audio file to load");
|
Venetian@7
|
49
|
Venetian@7
|
50 if(fileResult.bSuccess){
|
Venetian@7
|
51 // now you can use the URL
|
Venetian@7
|
52 *fileNameToSave = fileResult.filePath;
|
Venetian@7
|
53 //printf("\n filename is %s \n", soundFileName.c_str());
|
Venetian@7
|
54 return true;
|
Venetian@7
|
55 }
|
Venetian@7
|
56 else {
|
Venetian@7
|
57 // soundFileName = "OPEN canceled. ";
|
Venetian@7
|
58 printf("\n open file cancelled \n");
|
Venetian@7
|
59 return false;
|
Venetian@7
|
60 }
|
Venetian@7
|
61 }
|
Venetian@7
|
62
|
Venetian@7
|
63 void PreciseBassOnsetDetector::keyPressed(int key){
|
Venetian@7
|
64 std::string loadName;
|
Venetian@7
|
65 switch (key) {
|
Venetian@7
|
66 case 'r':
|
Venetian@7
|
67 pov.resetWindow();
|
Venetian@7
|
68 break;
|
Venetian@7
|
69 case 's':
|
Venetian@7
|
70 pov.cropStart();
|
Venetian@7
|
71 pod.cropStartTo(pov.windowStart);
|
Venetian@7
|
72 break;
|
Venetian@7
|
73 case 'e':
|
Venetian@7
|
74 pov.cropEnd();
|
Venetian@7
|
75 break;
|
Venetian@7
|
76 case 'w':
|
Venetian@7
|
77 printf("Exporting between %f and %f\n", pov.windowStart, pov.windowEnd);
|
Venetian@7
|
78 pod.exportOnsetTimes(pov.windowStart, pov.windowEnd);
|
Venetian@7
|
79 break;
|
Venetian@7
|
80 case 'x':
|
Venetian@7
|
81 printf("Exporting between %f and %f\n", 0., pov.lengthSeconds());
|
Venetian@7
|
82 pod.exportOnsetTimes(0, pov.lengthSeconds());
|
Venetian@7
|
83 break;
|
Venetian@7
|
84
|
Venetian@7
|
85 case 'o':
|
Venetian@7
|
86 if (getFilenameFromDialogBox(&loadName)){
|
Venetian@7
|
87 printf("loading %s\n", (loadName).c_str());
|
Venetian@7
|
88 loadNewFile(loadName);
|
Venetian@7
|
89 };
|
Venetian@7
|
90
|
Venetian@7
|
91 //delete testName;
|
Venetian@7
|
92 break;
|
Venetian@7
|
93 case ' ':
|
Venetian@7
|
94 pov.togglePlay();
|
Venetian@7
|
95 break;
|
Venetian@7
|
96 case OF_KEY_RETURN:
|
Venetian@7
|
97 pov.stop();
|
Venetian@7
|
98
|
Venetian@7
|
99 break;
|
Venetian@7
|
100
|
Venetian@7
|
101 case OF_KEY_UP: case 'u':
|
Venetian@7
|
102 pov.zoomIn();
|
Venetian@7
|
103 break;
|
Venetian@7
|
104 case OF_KEY_DOWN:
|
Venetian@7
|
105 pov.zoomOut();
|
Venetian@7
|
106 break;
|
Venetian@7
|
107 case OF_KEY_RIGHT:
|
Venetian@7
|
108 pov.scrollRight();
|
Venetian@7
|
109 break;
|
Venetian@7
|
110 case OF_KEY_LEFT:
|
Venetian@7
|
111 pov.scrollLeft();
|
Venetian@7
|
112 break;
|
Venetian@7
|
113
|
Venetian@7
|
114 default:
|
Venetian@7
|
115 break;
|
Venetian@7
|
116 }
|
Venetian@7
|
117 }
|
Venetian@7
|
118
|
Venetian@7
|
119 void PreciseBassOnsetDetector::mousePressed(int x, int y, int button){
|
Venetian@7
|
120
|
Venetian@7
|
121 pov.mousePressed(x, y);
|
Venetian@7
|
122
|
Venetian@7
|
123 } |