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
1111
1212 #include "AudioScriptingInterface.h"
1313
14+AudioScriptingInterface& AudioScriptingInterface::getInstance() {
15+ static AudioScriptingInterface staticInstance;
16+ return staticInstance;
17+}
18+
19+void AudioScriptingInterface::stopAllInjectors() {
20+
21+}
22+
1423 AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
1524
1625 if (sound->isStereo()) {
@@ -23,15 +32,18 @@ AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjec · 6 unmodified lines
2332 injector->moveToThread(injectorThread);
2433
2534 // start injecting when the injector thread starts
26− connect(injectorThread, SIGNAL(started()), injector, SLOT(injectAudio()));
35+ connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio);
2736
2837 // 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()));
30− connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit()));
31− connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater()));
38+ connect(injector, &AudioInjector::finished, injector, &AudioInjector::deleteLater);
39+ connect(injector, &AudioInjector::finished, injectorThread, &QThread::quit);
40+ connect(injector, &AudioInjector::finished, this, &AudioScriptingInterface::injectorStopped);
41+ connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);
3242
3343 injectorThread->start();
3444
45+ _activeInjectors.insert(injector);
46+
3547 return injector;
3648 }
3749
@@ -45,24 +57,9 @@ bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) { · 7 unmodified lines
4557 return (injector != NULL);
4658 }
4759
48−void AudioScriptingInterface::startDrumSound(float volume, float frequency, float duration, float decay,
49− const AudioInjectorOptions* injectorOptions) {
50−
51− Sound* sound = new Sound(volume, frequency, duration, decay);
52− AudioInjector* injector = new AudioInjector(sound, *injectorOptions);
53− sound->setParent(injector);
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−}
60+void AudioScriptingInterface::injectorStopped() {
61+ qDebug() << "Removing" << sender() << "from active injectors";
62+ qDebug() << _activeInjectors.size();
63+ _activeInjectors.remove(static_cast<AudioInjector*>(sender()));
64+ qDebug() << _activeInjectors.size();
65+}