Showing the changes to libraries/audio/src/AudioScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -11,6 +11,15 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | #include "AudioScriptingInterface.h" |
| 13 | 13 | |
| 14 | +AudioScriptingInterface& AudioScriptingInterface::getInstance() { | |
| 15 | + static AudioScriptingInterface staticInstance; | |
| 16 | + return staticInstance; | |
| 17 | +} | |
| 18 | + | |
| 19 | +void AudioScriptingInterface::stopAllInjectors() { | |
| 20 | + | |
| 21 | +} | |
| 22 | + | |
| 14 | 23 | AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) { |
| 15 | 24 | |
| 16 | 25 | if (sound->isStereo()) { |
| @@ -23,15 +32,18 @@ AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjec · 6 unmodified lines | ||
| 23 | 32 | injector->moveToThread(injectorThread); |
| 24 | 33 | |
| 25 | 34 | // 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 | 37 | // 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); | |
| 32 | 42 | |
| 33 | 43 | injectorThread->start(); |
| 34 | 44 | |
| 45 | + _activeInjectors.insert(injector); | |
| 46 | + | |
| 35 | 47 | return injector; |
| 36 | 48 | } |
| 37 | 49 | |
| @@ -45,24 +57,9 @@ bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) { · 7 unmodified lines | ||
| 45 | 57 | return (injector != NULL); |
| 46 | 58 | } |
| 47 | 59 | |
| 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 | +} | |