/* ==================================== JUCER_BINARY_RESOURCE ====================================

   This is an auto-generated file: Any edits you make may be overwritten!

*/

#include <cstring>

namespace BinaryData
{

//================== jucer_AudioPluginARAPlaybackRendererTemplate.cpp ==================
static const unsigned char temp_binary_data_26[] =
"/*\r\n"
"  ==============================================================================\r\n"
"\r\n"
"    This file was auto-generated!\r\n"
"\r\n"
"    It contains the basic framework code for an ARA playback renderer implementation.\r\n"
"\r\n"
"  ==============================================================================\r\n"
"*/\r\n"
"\r\n"
"%%araplaybackrenderer_headers%%\r\n"
"\r\n"
"//==============================================================================\r\n"
"void %%araplaybackrenderer_class_name%%::prepareToPlay (double sampleRateIn, int maximumSamplesPerBlockIn, int numChannelsIn, juce::AudioProcessor::ProcessingPrecision, AlwaysNonRealtime alwaysNonRealtime)\r\n"
"{\r\n"
"    numChannels = numChannelsIn;\r\n"
"    sampleRate = sampleRateIn;\r\n"
"    maximumSamplesPerBlock = maximumSamplesPerBlockIn;\r\n"
"    useBufferedAudioSourceReader = alwaysNonRealtime == AlwaysNonRealtime::no;\r\n"
"}\r\n"
"\r\n"
"void %%araplaybackrenderer_class_name%%::releaseResources()\r\n"
"{\r\n"
"}\r\n"
"\r\n"
"//==============================================================================\r\n"
"bool %%araplaybackrenderer_class_name%%::processBlock (juce::AudioBuffer<float>& buffer,\r\n"
"                                                       juce::AudioProcessor::Realtime realtime,\r\n"
"                                                       const juce::AudioPlayHead::PositionInfo& positionInfo) noexcept\r\n"
"{\r\n"
"    const auto numSamples = buffer.getNumSamples();\r\n"
"    jassert (numSamples <= maximumSamplesPerBlock);\r\n"
"    jassert (numChannels == buffer.getNumChannels());\r\n"
"    jassert (realtime == juce::AudioProcessor::Realtime::no || useBufferedAudioSourceReader);\r\n"
"    const auto timeInSamples = positionInfo.getTimeInSamples().orFallback (0);\r\n"
"    const auto isPlaying = positionInfo.getIsPlaying();\r\n"
"\r\n"
"    bool success = true;\r\n"
"    bool didRenderAnyRegion = false;\r\n"
"\r\n"
"    if (isPlaying)\r\n"
"    {\r\n"
"        const auto blockRange = juce::Range<juce::int64>::withStartAndLength (timeInSamples, numSamples);\r\n"
"\r\n"
"        for (const auto& playbackRegion : getPlaybackRegions())\r\n"
"        {\r\n"
"            // Evaluate region borders in song time, calculate sample range to render in song time.\r\n"
"            // Note that this example does not use head- or tailtime, so the includeHeadAndTail\r\n"
"            // parameter is set to false here - this might need to be adjusted in actual plug-ins.\r\n"
"            const auto playbackSampleRange = playbackRegion->getSampleRange (sampleRate,\r\n"
"                                                                             juce::ARAPlaybackRegion::IncludeHeadAndTail::no);\r\n"
"            auto renderRange = blockRange.getIntersectionWith (playbackSampleRange);\r\n"
"\r\n"
"            if (renderRange.isEmpty())\r\n"
"                continue;\r\n"
"\r\n"
"            // Evaluate region borders in modification/source time and calculate offset between\r\n"
"            // song and source samples, then clip song samples accordingly\r\n"
"            // (if an actual plug-in supports time stretching, this must be taken into account here).\r\n"
"            juce::Range<juce::int64> modificationSampleRange { playbackRegion->getStartInAudioModificationSamples(),\r\n"
"                                                               playbackRegion->getEndInAudioModificationSamples() };\r\n"
"            const auto modificationSampleOffset = modificationSampleRange.getStart() - playbackSampleRange.getStart();\r\n"
"\r\n"
"            renderRange = renderRange.getIntersectionWith (modificationSampleRange.movedToStartAt (playbackSampleRange.getStart()));\r\n"
"\r\n"
"            if (renderRange.isEmpty())\r\n"
"                continue;\r\n"
"\r\n"
"            // Now calculate the samples in renderRange for this PlaybackRegion based on the ARA model\r\n"
"            // graph. If didRenderAnyRegion is true, add the region's output samples in renderRange to\r\n"
"            // the buffer. Otherwise the buffer needs to be initialised so the sample value must be\r\n"
"            // overwritten.\r\n"
"            const int numSamplesToRead = (int) renderRange.getLength();\r\n"
"            const int startInBuffer = (int) (renderRange.getStart() - blockRange.getStart());\r\n"
"            const auto startInSource = renderRange.getStart() + modificationSampleOffset;\r\n"
"\r\n"
"            for (int c = 0; c < numChannels; ++c)\r\n"
"            {\r\n"
"                auto* channelData = buffer.getWritePointer (c);\r\n"
"\r\n"
"                for (int i = 0; i < numSamplesToRead; ++i)\r\n"
"                {\r\n"
"                    // Calculate region output sample at index startInSource + i ...\r\n"
"                    float sample = 0.0f;\r\n"
"\r\n"
"                    if (didRenderAnyRegion)\r\n"
"                        channelData[startInBuffer + i] += sample;\r\n"
"                    else\r\n"
"                        channelData[startInBuffer + i] = sample;\r\n"
"                }\r\n"
"            }\r\n"
"\r\n"
"            // If rendering first region, clear any excess at start or end of the region.\r\n"
"            if (! didRenderAnyRegion)\r\n"
"            {\r\n"
"                if (startInBuffer != 0)\r\n"
"                    buffer.clear (0, startInBuffer);\r\n"
"\r\n"
"                const int endInBuffer = startInBuffer + numSamples;\r\n"
"                const int remainingSamples = numSamples - endInBuffer;\r\n"
"\r\n"
"                if (remainingSamples != 0)\r\n"
"                    buffer.clear (endInBuffer, remainingSamples);\r\n"
"\r\n"
"                didRenderAnyRegion = true;\r\n"
"            }\r\n"
"        }\r\n"
"    }\r\n"
"\r\n"
"    if (! didRenderAnyRegion)\r\n"
"        buffer.clear();\r\n"
"\r\n"
"    return success;\r\n"
"}\r\n";

const char* jucer_AudioPluginARAPlaybackRendererTemplate_cpp = (const char*) temp_binary_data_26;
}
