AudioTransportSource::endOfStream flag

Hello Julian.

While playing with JUCE audio framework, I noticed that sometimes it’s worth to know from AudioTransportSource (PositionableSource) that it’s stopped playing not because the stop() method was called but because a stream has reached its end.

I solved this by modifying the source code of AudioTransportSource this way:

  1. I’ve added a public data member called ‘endOfStream’ and initialized it to false;

  2. In ‘getNextAudioBlock’ I’ve added two lines of code:

void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
{
    const ScopedLock sl (callbackLock);

    endOfStream = false; // always initialized to false

    if (masterSource != 0 && ! stopped)
    {
        masterSource->getNextAudioBlock (info);

        if (! playing)
        {
            // just stopped playing, so fade out the last block..
            for (int i = info.buffer->getNumChannels(); --i >= 0;)
                info.buffer->applyGainRamp (i, 0, jmin (256, info.numSamples), 1.0f, 0.0f);
        }

        if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
             && ! positionableSource->isLooping())
        {
            playing = false;

            endOfStream = true; // the end of a stream has been reached!!!

            sendChangeMessage (this);
        }

        stopped = ! playing;

        for (int i = info.buffer->getNumChannels(); --i >= 0;)
        {
            info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
                                        lastGain, gain);
        }
    }
    else
    {
        info.clearActiveBufferRegion();
        stopped = true;
    }

    lastGain = gain;
}

So, when I’m informed the transport source has stopped, I look into the endOfStream data member to know what exactly caused that.

So, Julian, can you add some functionality to the AudioTransportSource class to “officially” inform listeners of a stream reached its end?

sounds sensible, I’ll add something along those lines. Thanks!