History

make the AudioInjectorScriptingInterface a singleton

Stephen Birarda committed 12 years ago

Commit 2c667d21 parent 7e36c515 files · +40 −34Browse files

Showing the changes to libraries/audio/src/AudioScriptingInterface.cpp (1 of 5 files). Show all

Unified · Split

libraries/audio/src/AudioScriptingInterface.cpp+22−25
@@ -11,6 +11,15 @@ · 10 unmodified lines
11 11
12#include "AudioScriptingInterface.h"12#include "AudioScriptingInterface.h"
13 13
14AudioScriptingInterface& AudioScriptingInterface::getInstance() {
15 static AudioScriptingInterface staticInstance;
16 return staticInstance;
17}
18
19void AudioScriptingInterface::stopAllInjectors() {
20
21}
22
14AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {23AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
15 24
16 if (sound->isStereo()) {25 if (sound->isStereo()) {
@@ -23,15 +32,18 @@ AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjec · 6 unmodified lines
23 injector->moveToThread(injectorThread);32 injector->moveToThread(injectorThread);
24 33
25 // start injecting when the injector thread starts34 // start injecting when the injector thread starts
26 connect(injectorThread, SIGNAL(started()), injector, SLOT(injectAudio()));35 connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio);
27 36
28 // connect the right slots and signals so that the AudioInjector is killed once the injection is complete37 // connect the right slots and signals so that the AudioInjector is killed once the injection is complete
29 connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater()));38 connect(injector, &AudioInjector::finished, injector, &AudioInjector::deleteLater);
30 connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit()));39 connect(injector, &AudioInjector::finished, injectorThread, &QThread::quit);
31 connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater()));40 connect(injector, &AudioInjector::finished, this, &AudioScriptingInterface::injectorStopped);
41 connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);
32 42
33 injectorThread->start();43 injectorThread->start();
34 44
45 _activeInjectors.insert(injector);
46
35 return injector;47 return injector;
36}48}
37 49
@@ -45,24 +57,9 @@ bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) { · 7 unmodified lines
45 return (injector != NULL);57 return (injector != NULL);
46}58}
47 59
48void AudioScriptingInterface::startDrumSound(float volume, float frequency, float duration, float decay, 60void AudioScriptingInterface::injectorStopped() {
49 const AudioInjectorOptions* injectorOptions) {61 qDebug() << "Removing" << sender() << "from active injectors";
50 62 qDebug() << _activeInjectors.size();
51 Sound* sound = new Sound(volume, frequency, duration, decay);63 _activeInjectors.remove(static_cast<AudioInjector*>(sender()));
52 AudioInjector* injector = new AudioInjector(sound, *injectorOptions);64 qDebug() << _activeInjectors.size();
53 sound->setParent(injector);65}
54
55 QThread* injectorThread = new QThread();
56
57 injector->moveToThread(injectorThread);
58
59 // start injecting when the injector thread starts
60 connect(injectorThread, SIGNAL(started()), injector, SLOT(injectAudio()));
61
62 // connect the right slots and signals so that the AudioInjector is killed once the injection is complete
63 connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater()));
64 connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit()));
65 connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater()));
66
67 injectorThread->start();
68}