Skip to content

Commit

Permalink
Clarify assigning playback region(s) for playback renderers in AAX (w…
Browse files Browse the repository at this point in the history
…hich does not communicate render-active-state)
  • Loading branch information
sgretscher committed Jun 13, 2024
1 parent 3b930ac commit 171c5e5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
14 changes: 11 additions & 3 deletions TestPlugIn/ARATestPlaybackRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void ARATestPlaybackRenderer::renderPlaybackRegions (float* const* ppOutput, ARA
}
}

void ARATestPlaybackRenderer::enableRendering (ARA::ARASampleRate sampleRate, ARA::ARAChannelCount channelCount, ARA::ARASampleCount maxSamplesToRender) noexcept
void ARATestPlaybackRenderer::enableRendering (ARA::ARASampleRate sampleRate, ARA::ARAChannelCount channelCount, ARA::ARASampleCount maxSamplesToRender, bool apiSupportsToggleRendering) noexcept
{
// proper plug-ins would use this call to manage the resources which they need for rendering,
// but our test plug-in caches everything it needs in-memory anyways, so this method is near-empty
Expand All @@ -122,6 +122,7 @@ void ARATestPlaybackRenderer::enableRendering (ARA::ARASampleRate sampleRate, AR
_maxSamplesToRender = maxSamplesToRender;
#if ARA_VALIDATE_API_CALLS
_isRenderingEnabled = true;
_apiSupportsToggleRendering = apiSupportsToggleRendering;
#endif
}

Expand All @@ -135,11 +136,18 @@ void ARATestPlaybackRenderer::disableRendering () noexcept
#if ARA_VALIDATE_API_CALLS
void ARATestPlaybackRenderer::willAddPlaybackRegion (ARA::PlugIn::PlaybackRegion* /*playbackRegion*/) noexcept
{
ARA_VALIDATE_API_STATE (!_isRenderingEnabled);
if (_apiSupportsToggleRendering)
ARA_VALIDATE_API_STATE (!_isRenderingEnabled);
// else
// proper plug-ins would check _isRenderingEnabled here and toggle it off on demand, toggling it back on in didAddPlaybackRegion()
// this works because hosts using such APIs implicitly guarantee that they do not concurrently render the plug-in while making this call
}

void ARATestPlaybackRenderer::willRemovePlaybackRegion (ARA::PlugIn::PlaybackRegion* /*playbackRegion*/) noexcept
{
ARA_VALIDATE_API_STATE (!_isRenderingEnabled);
if (_apiSupportsToggleRendering)
ARA_VALIDATE_API_STATE (!_isRenderingEnabled);
// else
// see willAddPlaybackRegion(), same pattern applies here
}
#endif
3 changes: 2 additions & 1 deletion TestPlugIn/ARATestPlaybackRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ARATestPlaybackRenderer : public ARA::PlugIn::PlaybackRenderer

void renderPlaybackRegions (float* const* ppOutput, ARA::ARASamplePosition samplePosition, ARA::ARASampleCount samplesToRender, bool isPlayingBack);

void enableRendering (ARA::ARASampleRate sampleRate, ARA::ARAChannelCount channelCount, ARA::ARASampleCount maxSamplesToRender) noexcept;
void enableRendering (ARA::ARASampleRate sampleRate, ARA::ARAChannelCount channelCount, ARA::ARASampleCount maxSamplesToRender, bool apiSupportsToggleRendering) noexcept;
void disableRendering () noexcept;

protected:
Expand All @@ -44,5 +44,6 @@ class ARATestPlaybackRenderer : public ARA::PlugIn::PlaybackRenderer
ARA::ARAChannelCount _channelCount { 1 };
#if ARA_VALIDATE_API_CALLS
bool _isRenderingEnabled { false };
bool _apiSupportsToggleRendering { true }; // AAX enables rendering only once upon init, but does not allow to toggle it later like VST3, AU, CLAP etc.
#endif
};
2 changes: 1 addition & 1 deletion TestPlugIn/AudioUnit/TestAudioUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ OSStatus TestAudioUnit::Initialize()
OSStatus result = AUEffectBase::Initialize();

if (ARATestPlaybackRenderer* playbackRenderer = _araPlugInExtension.getPlaybackRenderer<ARATestPlaybackRenderer>())
playbackRenderer->enableRendering(GetSampleRate(), GetNumberOfChannels(), GetMaxFramesPerSlice());
playbackRenderer->enableRendering(GetSampleRate(), GetNumberOfChannels(), GetMaxFramesPerSlice(), true);

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion TestPlugIn/CLAP/TestCLAPPlugIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static bool my_plug_activate(const struct clap_plugin *plugin,
plug->max_frames_count = max_frames_count;

if (auto *playbackRenderer = plug->ara_extension.getPlaybackRenderer<ARATestPlaybackRenderer>())
playbackRenderer->enableRendering(sample_rate, (ARA::ARAChannelCount)plug->channel_count, max_frames_count);
playbackRenderer->enableRendering(sample_rate, (ARA::ARAChannelCount)plug->channel_count, max_frames_count, true);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion TestPlugIn/VST3/TestVST3Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ tresult PLUGIN_API TestVST3Processor::setActive (TBool state)
if (ARATestPlaybackRenderer* playbackRenderer = _araPlugInExtension.getPlaybackRenderer<ARATestPlaybackRenderer> ())
{
if (state)
playbackRenderer->enableRendering (processSetup.sampleRate, getAudioBusChannelCount (audioOutputs[0]), processSetup.maxSamplesPerBlock);
playbackRenderer->enableRendering (processSetup.sampleRate, getAudioBusChannelCount (audioOutputs[0]), processSetup.maxSamplesPerBlock, true);
else
playbackRenderer->disableRendering ();
}
Expand Down

0 comments on commit 171c5e5

Please sign in to comment.