Skip to content

Commit

Permalink
Implement offline processing for CLAPs (#250)
Browse files Browse the repository at this point in the history
adapting VST3 IAudioProcessor::setupProcessingand CLAP extension clap.render
see #12
  • Loading branch information
defiantnerd committed May 8, 2024
1 parent d747520 commit 4cc7f87
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/clap_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,6 @@ const void* Plugin::clapExtension(const clap_host* /*host*/, const char* extensi
{
return &HostExt::tail;
}
if (!strcmp(extension, CLAP_EXT_RENDER))
{
// TODO: implement CLAP_EXT_RENDER
}
if (!strcmp(extension, CLAP_EXT_STATE)) return &HostExt::state;
if (!strcmp(extension, CLAP_EXT_CONTEXT_MENU)) return &HostExt::context_menu;

Expand Down
49 changes: 49 additions & 0 deletions src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ tresult PLUGIN_API ClapAsVst3::setupProcessing(Vst::ProcessSetup& newSetup)
{
return kResultFalse;
}
if (_plugin->_ext._render)
{
if (_plugin->_ext._render->has_hard_realtime_requirement(_plugin->_plugin) &&
newSetup.processMode != Vst::kRealtime)
{
return kResultFalse;
}
clap_plugin_render_mode new_render_mode = CLAP_RENDER_REALTIME;
if (newSetup.processMode == Vst::kOffline)
{
new_render_mode = CLAP_RENDER_OFFLINE;
}
// handling Vst::kPrefetch as Vst::kRealTime

_plugin->_ext._render->set(_plugin->_plugin, new_render_mode);
}
_plugin->setSampleRate(newSetup.sampleRate);
_plugin->setBlockSizes(newSetup.maxSamplesPerBlock, newSetup.maxSamplesPerBlock);

Expand Down Expand Up @@ -330,6 +346,39 @@ tresult PLUGIN_API ClapAsVst3::activateBus(Vst::MediaType type, Vst::BusDirectio
return super::activateBus(type, dir, index, state);
}

tresult PLUGIN_API ClapAsVst3::setIoMode(Vst::IoMode mode)
{
#if 0 // disabled for now
// since there is always the override in setupProcessing, setting the mode here
// does not make much sense - even for a VST3
// so for now this stays kUnimplemented until we find a proper use case

auto rext = _plugin->_ext._render;

if (rext)
{
auto mainthread = _plugin->AlwaysMainThread();

bool realtime_only = rext->has_hard_realtime_requirement(_plugin->_plugin);
switch (mode)
{
case Vst::kOfflineProcessing:
if (realtime_only) return kResultFalse;
return (rext->set(_plugin->_plugin, CLAP_RENDER_OFFLINE)) ? kResultOk : kResultFalse;
break;
case Vst::kSimple:
case Vst::kAdvanced:
// both does not make any difference
return (rext->set(_plugin->_plugin, CLAP_RENDER_REALTIME)) ? kResultOk : kResultFalse;
break;
default:
return kNotImplemented;
}
}
#endif
return super::setIoMode(mode);
}

//-----------------------------------------------------------------------------

tresult PLUGIN_API ClapAsVst3::setComponentHandler(Vst::IComponentHandler* handler)
Expand Down
2 changes: 2 additions & 0 deletions src/wrapasvst3.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect,
tresult PLUGIN_API activateBus(Vst::MediaType type, Vst::BusDirection dir, int32 index,
TBool state) override;

tresult PLUGIN_API setIoMode(Vst::IoMode mode) override;

// from IEditController
tresult PLUGIN_API setComponentHandler(Vst::IComponentHandler* handler) override;

Expand Down

0 comments on commit 4cc7f87

Please sign in to comment.