From 59ebf8a05dff40657e2b6a8fa221c1fc98794952 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 7 Mar 2012 12:09:17 +0000 Subject: [PATCH] Fixed a bug in MixerAudioSource::removeAllInputs(), and simplified the implementation of removeInputSource(). --- .../sources/juce_MixerAudioSource.cpp | 31 ++++++++++--------- .../sources/juce_MixerAudioSource.h | 27 +++++----------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/modules/juce_audio_basics/sources/juce_MixerAudioSource.cpp b/modules/juce_audio_basics/sources/juce_MixerAudioSource.cpp index 337fd47dc1..b5b211bd32 100644 --- a/modules/juce_audio_basics/sources/juce_MixerAudioSource.cpp +++ b/modules/juce_audio_basics/sources/juce_MixerAudioSource.cpp @@ -60,31 +60,27 @@ void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhen } } -void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput) +void MixerAudioSource::removeInputSource (AudioSource* const input) { if (input != nullptr) { - int index; + ScopedPointer toDelete; { const ScopedLock sl (lock); + const int index = inputs.indexOf (input); - index = inputs.indexOf (input); + if (index < 0) + return; - if (index >= 0) - { - inputsToDelete.shiftBits (index, 1); - inputs.remove (index); - } + if (inputsToDelete [index]) + toDelete = input; + + inputsToDelete.shiftBits (index, 1); + inputs.remove (index); } - if (index >= 0) - { - input->releaseResources(); - - if (deleteInput) - delete input; - } + input->releaseResources(); } } @@ -98,7 +94,12 @@ void MixerAudioSource::removeAllInputs() for (int i = inputs.size(); --i >= 0;) if (inputsToDelete[i]) toDelete.add (inputs.getUnchecked(i)); + + inputs.clear(); } + + for (int i = toDelete.size(); --i >= 0;) + toDelete.getUnchecked(i)->releaseResources(); } void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate) diff --git a/modules/juce_audio_basics/sources/juce_MixerAudioSource.h b/modules/juce_audio_basics/sources/juce_MixerAudioSource.h index 42c4c55b9b..cafdf01295 100644 --- a/modules/juce_audio_basics/sources/juce_MixerAudioSource.h +++ b/modules/juce_audio_basics/sources/juce_MixerAudioSource.h @@ -41,8 +41,7 @@ class JUCE_API MixerAudioSource : public AudioSource { public: //============================================================================== - /** Creates a MixerAudioSource. - */ + /** Creates a MixerAudioSource. */ MixerAudioSource(); /** Destructor. */ @@ -58,41 +57,29 @@ public: @param newInput the source to add to the mixer @param deleteWhenRemoved if true, then this source will be deleted when - the mixer is deleted or when removeAllInputs() is - called (unless the source is previously removed - with the removeInputSource method) + no longer needed by the mixer. */ void addInputSource (AudioSource* newInput, bool deleteWhenRemoved); /** Removes an input source. - - If the mixer is running, this will remove the source but not call its - releaseResources() method, so the caller might want to do this manually. - - @param input the source to remove - @param deleteSource whether to delete this source after it's been removed + If the source was added by calling addInputSource() with the deleteWhenRemoved + flag set, it will be deleted by this method. */ - void removeInputSource (AudioSource* input, bool deleteSource); + void removeInputSource (AudioSource* input); /** Removes all the input sources. - - If the mixer is running, this will remove the sources but not call their - releaseResources() method, so the caller might want to do this manually. - - Any sources which were added with the deleteWhenRemoved flag set will be - deleted by this method. + Any sources which were added by calling addInputSource() with the deleteWhenRemoved + flag set will be deleted by this method. */ void removeAllInputs(); //============================================================================== /** Implementation of the AudioSource method. - This will call prepareToPlay() on all its input sources. */ void prepareToPlay (int samplesPerBlockExpected, double sampleRate); /** Implementation of the AudioSource method. - This will call releaseResources() on all its input sources. */ void releaseResources();