andrew@2
|
1 #include "testApp.h"
|
andrew@2
|
2
|
andrew@2
|
3 //possible to just omit the drawing (uses ofxWindowRegion for the screen and ofxPlotFunction to plot beat times)
|
andrew@2
|
4
|
andrew@2
|
5 //--------------------------------------------------------------
|
andrew@2
|
6 void testApp::setup(){
|
andrew@2
|
7 pov.window.setToRelativeSize(0.1, 0.1, 0.8, 0.3);
|
andrew@2
|
8 pov.pod = &preciseOnsetDetect;
|
andrew@2
|
9
|
andrew@2
|
10 // preciseOnsetDetect.load("/Users/andrew/Documents/work/programming/MadMax/AudioFiles/AdamBetts/AdamBetss_1_Swing_Kick.wav");
|
andrew@2
|
11 // preciseOnsetDetect.load("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Bouncing/Snare_Sontronics#08edit.aif");
|
andrew@2
|
12 loadNewFile("/Users/andrew/Music/Logic/GreenOnionsChichester/GreenOnionsChichester/Audio Files/Ride_SM58#08.aif");
|
andrew@2
|
13
|
andrew@2
|
14 }
|
andrew@2
|
15
|
andrew@2
|
16
|
andrew@2
|
17 void testApp::loadNewFile(std::string filename){
|
andrew@2
|
18 preciseOnsetDetect.load(filename);
|
andrew@2
|
19 preciseOnsetDetect.printOnsetLocations();
|
andrew@2
|
20
|
andrew@2
|
21 //windowStart = 0;
|
andrew@2
|
22 //windowEnd = preciseOnsetDetect.samples/44100.;
|
andrew@2
|
23 //windowPress = 0;
|
andrew@2
|
24
|
andrew@2
|
25 pov.newFile();
|
andrew@2
|
26 }
|
andrew@2
|
27
|
andrew@2
|
28 //--------------------------------------------------------------
|
andrew@2
|
29 void testApp::update(){
|
andrew@2
|
30 preciseOnsetDetect.update();
|
andrew@2
|
31 pov.update();
|
andrew@2
|
32 }
|
andrew@2
|
33
|
andrew@2
|
34 //--------------------------------------------------------------
|
andrew@2
|
35 void testApp::draw(){
|
andrew@2
|
36
|
andrew@2
|
37 pov.draw();
|
andrew@2
|
38 /*
|
andrew@2
|
39 //if plotting use this, else comment out
|
andrew@2
|
40 ofSetColor(ofColor::white);
|
andrew@2
|
41 window.drawBackground();
|
andrew@2
|
42 ofSetColor(ofColor::black);
|
andrew@2
|
43 window.drawOutline();
|
andrew@2
|
44 ofSetColor(ofColor::blue);
|
andrew@2
|
45 plotter.drawBeatStripes(preciseOnsetDetect.onsetLocations, window, windowStart, windowEnd);
|
andrew@2
|
46 */
|
andrew@2
|
47
|
andrew@2
|
48 }
|
andrew@2
|
49
|
andrew@2
|
50 //--------------------------------------------------------------
|
andrew@2
|
51 void testApp::keyPressed(int key){
|
andrew@2
|
52 std::string loadName;
|
andrew@2
|
53 switch (key) {
|
andrew@2
|
54 case 'r':
|
andrew@2
|
55 pov.resetWindow();
|
andrew@2
|
56 break;
|
andrew@2
|
57 case 's':
|
andrew@2
|
58 pov.cropStart();
|
andrew@2
|
59 break;
|
andrew@2
|
60 case 'e':
|
andrew@2
|
61 pov.cropEnd();
|
andrew@2
|
62 break;
|
andrew@2
|
63 case 'o':
|
andrew@2
|
64 if (getFilenameFromDialogBox(&loadName)){
|
andrew@2
|
65 printf("loading %s\n", (loadName).c_str());
|
andrew@2
|
66 loadNewFile(loadName);
|
andrew@2
|
67 };
|
andrew@2
|
68
|
andrew@2
|
69 //delete testName;
|
andrew@2
|
70 break;
|
andrew@2
|
71 case ' ':
|
andrew@2
|
72 pov.togglePlay();
|
andrew@2
|
73 break;
|
andrew@2
|
74 case OF_KEY_RETURN:
|
andrew@2
|
75 pov.soundPlay.stop();
|
andrew@2
|
76 break;
|
andrew@2
|
77
|
andrew@2
|
78 default:
|
andrew@2
|
79 break;
|
andrew@2
|
80 }
|
andrew@2
|
81 }
|
andrew@2
|
82
|
andrew@2
|
83 //--------------------------------------------------------------
|
andrew@2
|
84 void testApp::keyReleased(int key){
|
andrew@2
|
85
|
andrew@2
|
86 }
|
andrew@2
|
87
|
andrew@2
|
88 //--------------------------------------------------------------
|
andrew@2
|
89 void testApp::mouseMoved(int x, int y){
|
andrew@2
|
90
|
andrew@2
|
91 }
|
andrew@2
|
92
|
andrew@2
|
93 //--------------------------------------------------------------
|
andrew@2
|
94 void testApp::mouseDragged(int x, int y, int button){
|
andrew@2
|
95
|
andrew@2
|
96 }
|
andrew@2
|
97
|
andrew@2
|
98 //--------------------------------------------------------------
|
andrew@2
|
99 void testApp::mousePressed(int x, int y, int button){
|
andrew@2
|
100 // if (window.tapped(x, y)){
|
andrew@2
|
101 // windowPress = windowStart + (windowEnd-windowStart)*(x - window.x)/window.width;
|
andrew@2
|
102 //
|
andrew@2
|
103 // printf("window position is %f\n", windowPress);
|
andrew@2
|
104 // }
|
andrew@2
|
105 pov.mousePressed(x, y);
|
andrew@2
|
106
|
andrew@2
|
107 }
|
andrew@2
|
108
|
andrew@2
|
109 //--------------------------------------------------------------
|
andrew@2
|
110 void testApp::mouseReleased(int x, int y, int button){
|
andrew@2
|
111
|
andrew@2
|
112 }
|
andrew@2
|
113
|
andrew@2
|
114 //--------------------------------------------------------------
|
andrew@2
|
115 void testApp::windowResized(int w, int h){
|
andrew@2
|
116
|
andrew@2
|
117 }
|
andrew@2
|
118
|
andrew@2
|
119 //--------------------------------------------------------------
|
andrew@2
|
120 void testApp::gotMessage(ofMessage msg){
|
andrew@2
|
121
|
andrew@2
|
122 }
|
andrew@2
|
123
|
andrew@2
|
124 //--------------------------------------------------------------
|
andrew@2
|
125 void testApp::dragEvent(ofDragInfo dragInfo){
|
andrew@2
|
126
|
andrew@2
|
127 }
|
andrew@2
|
128
|
andrew@2
|
129
|
andrew@2
|
130
|
andrew@2
|
131 bool testApp::getFilenameFromDialogBox(std::string* fileNameToSave){
|
andrew@2
|
132 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully
|
andrew@2
|
133 // first, create a string that will hold the URL
|
andrew@2
|
134 string URL;
|
andrew@2
|
135
|
andrew@2
|
136 // // openFile(string& URL) returns 1 if a file was picked
|
andrew@2
|
137 // // returns 0 when something went wrong or the user pressed 'cancel'
|
andrew@2
|
138 // int response = ofxFileDialogOSX::openFile(URL);
|
andrew@2
|
139 // if(response){
|
andrew@2
|
140 // // now you can use the URL
|
andrew@2
|
141 // *fileNameToSave = URL;
|
andrew@2
|
142 // //printf("\n filename is %s \n", soundFileName.c_str());
|
andrew@2
|
143 // return true;
|
andrew@2
|
144 // }
|
andrew@2
|
145 // else {
|
andrew@2
|
146 // // soundFileName = "OPEN canceled. ";
|
andrew@2
|
147 // printf("\n open file cancelled \n");
|
andrew@2
|
148 // return false;
|
andrew@2
|
149 // }
|
andrew@2
|
150
|
andrew@2
|
151 // openFile(string& URL) returns 1 if a file was picked
|
andrew@2
|
152 // returns 0 when something went wrong or the user pressed 'cancel'
|
andrew@2
|
153 ofFileDialogResult fileResult = ofSystemLoadDialog("Choose audio file to load");
|
andrew@2
|
154
|
andrew@2
|
155 if(fileResult.bSuccess){
|
andrew@2
|
156 // now you can use the URL
|
andrew@2
|
157 *fileNameToSave = fileResult.filePath;
|
andrew@2
|
158 //printf("\n filename is %s \n", soundFileName.c_str());
|
andrew@2
|
159 return true;
|
andrew@2
|
160 }
|
andrew@2
|
161 else {
|
andrew@2
|
162 // soundFileName = "OPEN canceled. ";
|
andrew@2
|
163 printf("\n open file cancelled \n");
|
andrew@2
|
164 return false;
|
andrew@2
|
165 }
|
andrew@2
|
166 }
|
andrew@2
|
167
|