Mercurial > hg > precise-onset-detection
comparison ofxPreciseOnsetDetectorOffline/testApp.cpp @ 7:b1c13e8bec26
adding new files
author | Venetian |
---|---|
date | Thu, 14 Aug 2014 16:27:52 +0100 |
parents | eb29c6b6dff8 |
children |
comparison
equal
deleted
inserted
replaced
6:eb29c6b6dff8 | 7:b1c13e8bec26 |
---|---|
1 #include "testApp.h" | 1 #include "testApp.h" |
2 | 2 |
3 //possible to just omit the drawing (uses ofxWindowRegion for the screen and ofxPlotFunction to plot beat times) | 3 //possible to just omit the drawing (uses ofxWindowRegion for the screen and ofxPlotFunction to plot beat times) |
4 | 4 |
5 //w: export window | |
6 //x:export whole file | |
7 //o: open file | |
8 | |
5 //-------------------------------------------------------------- | 9 //-------------------------------------------------------------- |
6 void testApp::setup(){ | 10 void testApp::setup(){ |
7 pov.window.setToRelativeSize(0.1, 0.1, 0.8, 0.3); | 11 |
8 pov.pod = &preciseOnsetDetect;//set up pointer if we want to visualise the onsets in a window | |
9 | |
10 // preciseOnsetDetect.load("/Users/andrew/Documents/work/programming/MadMax/AudioFiles/AdamBetts/AdamBetss_1_Swing_Kick.wav"); | |
11 // preciseOnsetDetect.load("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Bouncing/Snare_Sontronics#08edit.aif"); | |
12 | |
13 std::string fileName = "/Users/andrew/Music/Logic/GreenOnionsEvaluation/GreenOnionsEvaluationPlain/Audio Files/SongClickTrack#09.aif"; | |
14 // fileName = "/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Audio Files/Ride_SM58#08.aif"; | |
15 loadNewFile(fileName); | |
16 | 12 |
17 } | 13 } |
18 | 14 |
19 | 15 |
20 void testApp::loadNewFile(std::string filename){ | |
21 preciseOnsetDetect.load(filename); | |
22 preciseOnsetDetect.printOnsetLocations(); | |
23 | |
24 pov.newFile(); | |
25 } | |
26 | |
27 //-------------------------------------------------------------- | 16 //-------------------------------------------------------------- |
28 void testApp::update(){ | 17 void testApp::update(){ |
29 preciseOnsetDetect.update(); | 18 |
30 pov.update(); | 19 onsetDetector.update(); |
31 } | 20 } |
32 | 21 |
33 //-------------------------------------------------------------- | 22 //-------------------------------------------------------------- |
34 void testApp::draw(){ | 23 void testApp::draw(){ |
35 | 24 |
36 pov.draw(); | 25 onsetDetector.draw(); |
37 | 26 |
38 } | 27 } |
39 | 28 |
40 | 29 |
41 //-------------------------------------------------------------- | 30 //-------------------------------------------------------------- |
42 void testApp::keyPressed(int key){ | 31 void testApp::keyPressed(int key){ |
43 std::string loadName; | 32 onsetDetector.keyPressed(key); |
44 switch (key) { | |
45 case 'r': | |
46 pov.resetWindow(); | |
47 break; | |
48 case 's': | |
49 pov.cropStart(); | |
50 break; | |
51 case 'e': | |
52 pov.cropEnd(); | |
53 break; | |
54 case 'w': | |
55 printf("Exporting between %f and %f\n", pov.windowStart, pov.windowEnd); | |
56 preciseOnsetDetect.exportOnsetTimes(pov.windowStart, pov.windowEnd); | |
57 break; | |
58 case 'x': | |
59 printf("Exporting between %f and %f\n", 0., pov.lengthSeconds()); | |
60 preciseOnsetDetect.exportOnsetTimes(0, pov.lengthSeconds()); | |
61 break; | |
62 | |
63 case 'o': | |
64 if (getFilenameFromDialogBox(&loadName)){ | |
65 printf("loading %s\n", (loadName).c_str()); | |
66 loadNewFile(loadName); | |
67 }; | |
68 | |
69 //delete testName; | |
70 break; | |
71 case ' ': | |
72 pov.togglePlay(); | |
73 break; | |
74 case OF_KEY_RETURN: | |
75 pov.soundPlay.stop(); | |
76 break; | |
77 | |
78 case OF_KEY_UP: | |
79 pov.zoomIn(); | |
80 break; | |
81 case OF_KEY_DOWN: | |
82 pov.zoomOut(); | |
83 break; | |
84 case OF_KEY_RIGHT: | |
85 pov.scrollRight(); | |
86 break; | |
87 case OF_KEY_LEFT: | |
88 pov.scrollLeft(); | |
89 break; | |
90 | |
91 default: | |
92 break; | |
93 } | |
94 } | 33 } |
95 | 34 |
96 //-------------------------------------------------------------- | 35 //-------------------------------------------------------------- |
97 void testApp::keyReleased(int key){ | 36 void testApp::keyReleased(int key){ |
98 | 37 |
108 | 47 |
109 } | 48 } |
110 | 49 |
111 //-------------------------------------------------------------- | 50 //-------------------------------------------------------------- |
112 void testApp::mousePressed(int x, int y, int button){ | 51 void testApp::mousePressed(int x, int y, int button){ |
113 // if (window.tapped(x, y)){ | |
114 // windowPress = windowStart + (windowEnd-windowStart)*(x - window.x)/window.width; | |
115 // | |
116 // printf("window position is %f\n", windowPress); | |
117 // } | |
118 pov.mousePressed(x, y); | |
119 | 52 |
53 onsetDetector.mousePressed(x,y,button); | |
120 } | 54 } |
121 | 55 |
122 //-------------------------------------------------------------- | 56 //-------------------------------------------------------------- |
123 void testApp::mouseReleased(int x, int y, int button){ | 57 void testApp::mouseReleased(int x, int y, int button){ |
124 | 58 |
139 | 73 |
140 } | 74 } |
141 | 75 |
142 | 76 |
143 | 77 |
144 bool testApp::getFilenameFromDialogBox(std::string* fileNameToSave){ | |
145 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully | |
146 // first, create a string that will hold the URL | |
147 string URL; | |
148 | |
149 // // openFile(string& URL) returns 1 if a file was picked | |
150 // // returns 0 when something went wrong or the user pressed 'cancel' | |
151 // int response = ofxFileDialogOSX::openFile(URL); | |
152 // if(response){ | |
153 // // now you can use the URL | |
154 // *fileNameToSave = URL; | |
155 // //printf("\n filename is %s \n", soundFileName.c_str()); | |
156 // return true; | |
157 // } | |
158 // else { | |
159 // // soundFileName = "OPEN canceled. "; | |
160 // printf("\n open file cancelled \n"); | |
161 // return false; | |
162 // } | |
163 | |
164 // openFile(string& URL) returns 1 if a file was picked | |
165 // returns 0 when something went wrong or the user pressed 'cancel' | |
166 ofFileDialogResult fileResult = ofSystemLoadDialog("Choose audio file to load"); | |
167 | |
168 if(fileResult.bSuccess){ | |
169 // now you can use the URL | |
170 *fileNameToSave = fileResult.filePath; | |
171 //printf("\n filename is %s \n", soundFileName.c_str()); | |
172 return true; | |
173 } | |
174 else { | |
175 // soundFileName = "OPEN canceled. "; | |
176 printf("\n open file cancelled \n"); | |
177 return false; | |
178 } | |
179 } | |
180 | 78 |