andrew@0
|
1 /*
|
andrew@0
|
2 * LoadedAudioHolder.cpp
|
andrew@0
|
3 * fileLoaderAndOnsetDetection
|
andrew@0
|
4 *
|
andrew@0
|
5 * Created by Andrew on 28/01/2012.
|
andrew@0
|
6 * Copyright 2012 QMUL. All rights reserved.
|
andrew@0
|
7 *
|
andrew@0
|
8 */
|
andrew@0
|
9
|
andrew@0
|
10 #include "LoadedAudioHolder.h"
|
andrew@0
|
11
|
andrew@0
|
12 LoadedAudioHolder::LoadedAudioHolder(){
|
andrew@0
|
13 audioPaused = true;
|
andrew@0
|
14 audioPlaying = false;
|
andrew@0
|
15 trackType = 0;
|
andrew@0
|
16 }
|
andrew@0
|
17
|
andrew@0
|
18 void LoadedAudioHolder::updateToPlayPosition(){
|
andrew@0
|
19 fileLoader.updateToAudioPosition(loadedAudio.getPosition());
|
andrew@0
|
20 }
|
andrew@0
|
21
|
andrew@0
|
22 void LoadedAudioHolder::updateToMillisPosition(const double& millis){
|
andrew@0
|
23 fileLoader.updateToMillisPosition(millis);
|
andrew@0
|
24 }
|
andrew@0
|
25
|
andrew@0
|
26 void LoadedAudioHolder::updatePlaybackPositionToMillis(const double& millis){
|
andrew@0
|
27 printf("updatePlay %f", millis * 44.1 / (double) fileLoader.totalNumberOfSamples );
|
andrew@0
|
28
|
andrew@0
|
29 loadedAudio.setPosition(millis * 44.1 / (double) fileLoader.totalNumberOfSamples );
|
andrew@0
|
30 }
|
andrew@0
|
31
|
andrew@0
|
32 void LoadedAudioHolder::draw(){
|
andrew@0
|
33 fileLoader.drawFile();
|
andrew@0
|
34 }
|
andrew@0
|
35
|
andrew@0
|
36 void LoadedAudioHolder::loadAudioFile(string soundFileName){
|
andrew@0
|
37 loadedAudio.loadSound(soundFileName);
|
andrew@0
|
38 fileLoader.loadNewAudio(soundFileName);
|
andrew@0
|
39 audioPlaying = false;
|
andrew@0
|
40 loadedFileName = soundFileName;
|
andrew@0
|
41 copyOnsetTimes();
|
andrew@0
|
42
|
andrew@0
|
43 }
|
andrew@0
|
44
|
andrew@0
|
45 void LoadedAudioHolder::copyOnsetTimes(){
|
andrew@0
|
46
|
andrew@0
|
47 onsetTimesMillis.clear();
|
andrew@0
|
48
|
andrew@0
|
49 for (int i = 0;i < fileLoader.onsetDetect.chromaOnsets.size();i++)
|
andrew@0
|
50 onsetTimesMillis.push_back(fileLoader.onsetDetect.chromaOnsets[i].millisTime);
|
andrew@0
|
51
|
andrew@0
|
52 }
|
andrew@0
|
53
|
andrew@0
|
54 void LoadedAudioHolder::setTrackType(const int& i){
|
andrew@0
|
55 fileLoader.onsetDetect.trackType = i;
|
andrew@0
|
56 trackType = i;
|
andrew@0
|
57 }
|
andrew@0
|
58
|
andrew@0
|
59 void LoadedAudioHolder::togglePlay(){
|
andrew@0
|
60 if (!audioPlaying) {
|
andrew@0
|
61 loadedAudio.play();
|
andrew@0
|
62 loadedAudio.setPaused(false);
|
andrew@0
|
63 audioPlaying = true;
|
andrew@0
|
64 audioPaused = false;
|
andrew@0
|
65 printf("playing %s\n", loadedFileName.c_str());
|
andrew@0
|
66 }
|
andrew@0
|
67 else{
|
andrew@0
|
68 audioPaused = !audioPaused;
|
andrew@0
|
69 loadedAudio.setPaused(audioPaused);
|
andrew@0
|
70 }
|
andrew@0
|
71 }
|
andrew@0
|
72
|
andrew@0
|
73 void LoadedAudioHolder::stop(){
|
andrew@0
|
74 audioPlaying = false;
|
andrew@0
|
75 loadedAudio.setPaused(true);
|
andrew@0
|
76 loadedAudio.setPosition(0.0);
|
andrew@0
|
77 }
|
andrew@0
|
78
|
andrew@0
|
79 void LoadedAudioHolder::switchScreens(){
|
andrew@0
|
80 fileLoader.screenToDraw = 1 - fileLoader.screenToDraw;
|
andrew@0
|
81 }
|
andrew@0
|
82
|
andrew@0
|
83 void LoadedAudioHolder::windowResized(const int& w, const int& h){
|
andrew@0
|
84 fileLoader.onsetDetect.windowResized(w, h);
|
andrew@0
|
85 }
|
andrew@0
|
86
|
andrew@0
|
87
|
andrew@0
|
88 void LoadedAudioHolder::printEvents(){
|
andrew@0
|
89 for (int i = 0;i < fileLoader.onsetDetect.chromaOnsets.size();i++){
|
andrew@0
|
90 printf("Event time %f millis %i frames pitch %f\n", fileLoader.onsetDetect.chromaOnsets[i].millisTime,
|
andrew@0
|
91 fileLoader.onsetDetect.chromaOnsets[i].frameTime, fileLoader.onsetDetect.chromaOnsets[i].aubioPitch);
|
andrew@0
|
92 }
|
andrew@0
|
93 }
|