Skip to content

Commit

Permalink
Check active state before querying latency. Fixes #229
Browse files Browse the repository at this point in the history
  • Loading branch information
defiantnerd committed Mar 10, 2024
1 parent 900f847 commit aee5cab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ tresult PLUGIN_API ClapAsVst3::terminate()
if (_plugin)
{
_os_attached.off(); // ensure we are detached
if (_active)
{
// HOST has misbehaved
_plugin->deactivate();
}
_plugin->terminate();
_plugin.reset();
}
Expand Down Expand Up @@ -87,6 +92,11 @@ tresult PLUGIN_API ClapAsVst3::setActive(TBool state)
_expressionmap & clap_supported_note_expressions::AS_VST3_NOTE_EXPRESSION_TUNING);
updateAudioBusses();

if (_missedLatencyRequest)
{
latency_changed();
}

_os_attached.on();
}
if (!state)
Expand Down Expand Up @@ -137,11 +147,18 @@ tresult PLUGIN_API ClapAsVst3::getState(IBStream* state)

uint32 PLUGIN_API ClapAsVst3::getLatencySamples()
{
if (_plugin->_ext._latency && _active)
if (!_plugin->_ext._latency)
{
return _plugin->_ext._latency->get(_plugin->_plugin);
return 0;
}
return 0;
if (!_active)
{
_missedLatencyRequest = true;
return 0;
}

_missedLatencyRequest = false;
return _plugin->_ext._latency->get(_plugin->_plugin);
}

uint32 PLUGIN_API ClapAsVst3::getTailSamples()
Expand Down Expand Up @@ -950,7 +967,7 @@ void ClapAsVst3::onIdle()
std::lock_guard lock(_processingLock);

_requestedFlush = false;
if (!_processing)
if (!_active)
{
// setup a ProcessAdapter just for flush with no audio
Clap::ProcessAdapter pa;
Expand Down
1 change: 1 addition & 0 deletions src/wrapasvst3.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect,
std::mutex _processingLock;
std::atomic_bool _requestedFlush = false;
std::atomic_bool _requestUICallback = false;
bool _missedLatencyRequest = false;

// the queue from audiothread to UI thread
ClapWrapper::detail::shared::fixedqueue<queueEvent, 8192> _queueToUI;
Expand Down

0 comments on commit aee5cab

Please sign in to comment.