1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-17 00:44:19 +00:00

Fixed a bug in MixerAudioSource::removeAllInputs(), and simplified the implementation of removeInputSource().

This commit is contained in:
jules 2012-03-07 12:09:17 +00:00
parent 83b35eba25
commit 59ebf8a05d
2 changed files with 23 additions and 35 deletions

View file

@ -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<AudioSource> 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)

View file

@ -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();