comparison src/testApp.cpp @ 0:c4f9e49226eb

Initialising repository. Live osc input registered. Files analysed offline.
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 31 Jan 2012 13:54:17 +0000
parents
children 852173ca8365
comparison
equal deleted inserted replaced
-1:000000000000 0:c4f9e49226eb
1 #include "testApp.h"
2 #include "stdio.h"
3 //#include "aubio.h"
4 #include <iostream>
5 #include <cstring>
6 #include <string>
7 #include <cstdlib>
8
9
10 const double samplingFrequency = 44100.0;
11
12 //--------------------------------------------------------------
13 void testApp::setup(){
14
15 // 2 output channels,
16 // 0 input channels
17 // 22050 samples per second
18 // 256 samples per buffer
19 // 4 num buffers (latency)
20
21 //nb THIS CODE WOULD BE USEFUL IF WE EVER WANTED REAL-TIME INPUT - VIA ofSoundSteam
22
23 receiver.setup( PORT );
24
25 sampleRate = 44100;
26 ofSoundStreamSetup(2,0,this, sampleRate,256, 4);
27
28 ofSetFrameRate(30);
29
30 LoadedAudioHolder lah;
31 const char *infilename = "../../../data/sound/bach4_short1.wav";
32
33
34 // lah.loadAudioFile(infilename);
35 // loadedAudioFiles.push_back(lah);
36
37 //Take care here - we need a pointer to create new instance
38 //but not then delete the instance before the vector of all audio tracks has been used
39 //the above code using lah has problem that it deletes objects once out of the scope of testApp.setup()
40 //when lah is in theory no longer used - something like that possible? - at least pointers to onset detection seem deleted
41 loadedAudioPtr = new LoadedAudioHolder;
42 loadedAudioPtr->loadAudioFile(infilename);
43 // loadedAudioFiles.push_back(*loadedAudioPtr);
44 loadedAudioFiles[0] = *loadedAudioPtr;
45
46 loadedAudioFiles[0].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.0, 1, 0.25);
47
48 // printf("Loaded audio %i\n", (int)numberOfAudioTracks);
49 printf("loaded max val is %f\n", loadedAudioFiles[0].fileLoader.onsetDetect.onsetDetector.maximumDetectionValue);
50
51 printf("BEFORE LOADING 1\n");
52 keyPressed('p');
53
54 loadedAudioPtr = new LoadedAudioHolder;
55 loadedAudioPtr->loadAudioFile(infilename);
56 // loadedAudioFiles.push_back(*loadedAudioPtr);
57 loadedAudioFiles[1] = *loadedAudioPtr;
58 loadedAudioFiles[1].fileLoader.onsetDetect.window.setToRelativeSize(0, 0.3, 1, 0.25);
59
60 printf("AFTER LOADING 1\n");
61 keyPressed('p');
62
63 numberOfAudioTracks = 2;
64
65
66 //audioFilePlayer.loadAudioFile(infilename);
67 }
68
69
70
71 //--------------------------------------------------------------
72 void testApp::update(){
73
74 for (int i = 0;i < numberOfAudioTracks;i++)
75 loadedAudioFiles[i].updateToPlayPosition();
76 // audioFilePlayer.updateToPlayPosition();
77
78 checkForOSCmessages();
79
80 }
81
82 void testApp::checkForOSCmessages(){
83 // check for waiting messages
84 while( receiver.hasWaitingMessages() )
85 {
86 // get the next message
87 ofxOscMessage m;
88 receiver.getNextMessage( &m );
89
90 // check for mouse moved message
91 if ( m.getAddress() == "/aubioPitch" )
92 {
93 float pitchIn = m.getArgAsFloat(0);
94 int timeIn = m.getArgAsInt32(1);
95 printf("AUBIO PITCH RECEIVED %f at time %i\n", pitchIn, timeIn);
96 }
97 }
98 }
99
100 //--------------------------------------------------------------
101 void testApp::draw(){
102
103 for (int i = 0;i < numberOfAudioTracks;i++){
104 loadedAudioFiles[i].draw();
105 }
106
107
108 eventMatcher.draw();
109
110 // audioFilePlayer.draw();
111
112 }
113
114
115
116 //--------------------------------------------------------------
117 void testApp::keyPressed (int key){
118 if (key == '-'){
119 volume -= 0.05;
120 volume = MAX(volume, 0);
121 } else if (key == '+'){
122 volume += 0.05;
123 volume = MIN(volume, 1);
124 }
125
126 if (key == 'q'){
127 for (int i = 0;i < numberOfAudioTracks;i++)
128 loadedAudioFiles[i].switchScreens();
129 // audioFilePlayer.switchScreens();
130 }
131
132 if (key == OF_KEY_RIGHT){
133 // audioFilePlayer.loadedAudio.setPosition(min(1.0, audioFilePlayer.loadedAudio.getPosition() + (audioFilePlayer.fileLoader.audioHolder.audioScaleSamples/(4.0*audioFilePlayer.fileLoader.audioHolder.audioVector.size()))) );
134
135 }
136
137 if (key == OF_KEY_LEFT){
138 // audioFilePlayer.loadedAudio.setPosition(max(0.0, audioFilePlayer.loadedAudio.getPosition() - (audioFilePlayer.fileLoader.audioHolder.audioScaleSamples/(4.0*audioFilePlayer.fileLoader.audioHolder.audioVector.size()))));
139
140 }
141
142
143 if (key == ' '){
144 for (int i = 0;i < numberOfAudioTracks;i++)
145 loadedAudioFiles[i].togglePlay();
146 // audioFilePlayer.togglePlay();
147 }
148
149 if (key == OF_KEY_RETURN){
150 for (int i = 0;i < numberOfAudioTracks;i++)
151 loadedAudioFiles[i].stop();
152
153 // audioFilePlayer.stop();
154 }
155
156
157 if (key == 'o'){
158 openNewAudioFileWithdialogBox();
159
160 }
161
162 if (key == 'p'){
163 loadedAudioFiles[0].fileLoader.onsetDetect.printChromaInfo();
164 loadedAudioFiles[0].printEvents();
165 }
166
167
168 if (key == OF_KEY_UP){
169 for (int i = 0;i < numberOfAudioTracks;i++)
170 loadedAudioFiles[i].fileLoader.zoomOut();
171 // audioFilePlayer.fileLoader.zoomOut();
172 }
173
174 if (key == OF_KEY_DOWN){
175 for (int i = 0;i < numberOfAudioTracks;i++)
176 loadedAudioFiles[i].fileLoader.zoomIn();
177
178 // audioFilePlayer.fileLoader.zoomIn();
179
180 }
181
182 }
183
184 //--------------------------------------------------------------
185 void testApp::keyReleased (int key){
186
187 }
188
189
190 //--------------------------------------------------------------
191 void testApp::mouseMoved(int x, int y ){
192
193
194 }
195
196 //--------------------------------------------------------------
197 void testApp::mouseDragged(int x, int y, int button){
198
199 }
200
201 //--------------------------------------------------------------
202 void testApp::mousePressed(int x, int y, int button){
203
204 }
205
206
207 //--------------------------------------------------------------
208 void testApp::mouseReleased(int x, int y, int button){
209
210 }
211
212 //--------------------------------------------------------------
213 void testApp::windowResized(int w, int h){
214 for (int i = 0;i < numberOfAudioTracks;i++)
215 loadedAudioFiles[i].windowResized(w, h);
216 //audioFilePlayer.windowResized(w, h);
217
218
219 }
220 //--------------------------------------------------------------
221 void testApp::audioRequested (float * output, int bufferSize, int nChannels){
222 //pan = 0.5f;
223 float leftScale = 1 - pan;
224 float rightScale = pan;
225
226 }
227
228
229
230 //--------------------------------------------------------------
231 void testApp::openNewAudioFileWithdialogBox(){
232 std::string filename;
233 getFilenameFromDialogBox(&filename);
234 loadNewAudio(filename);
235
236 }
237
238
239 void testApp::loadNewAudio(string soundFileName){
240
241 loadedAudioFiles[0].loadAudioFile(soundFileName);
242
243 // for (int i = 0;i < numberOfAudioTracks;i++)
244 // loadedAudioFiles[i].loadAudioFile(soundFileName);
245
246 // audioFilePlayer.loadAudioFile(soundFileName);
247
248 }
249
250
251 bool testApp::getFilenameFromDialogBox(std::string* fileNameToSave){
252 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully
253 // first, create a string that will hold the URL
254 string URL;
255
256 // openFile(string& URL) returns 1 if a file was picked
257 // returns 0 when something went wrong or the user pressed 'cancel'
258 int response = ofxFileDialogOSX::openFile(URL);
259 if(response){
260 // now you can use the URL
261 *fileNameToSave = URL;
262 //printf("\n filename is %s \n", soundFileName.c_str());
263 return true;
264 }
265 else {
266 // soundFileName = "OPEN canceled. ";
267 printf("\n open file cancelled \n");
268 return false;
269 }
270
271 }
272
273
274
275
276