diff --git a/src/detail/vst3/os/osutil.h b/src/detail/vst3/os/osutil.h index c1d2572b..495f1ce1 100644 --- a/src/detail/vst3/os/osutil.h +++ b/src/detail/vst3/os/osutil.h @@ -7,12 +7,27 @@ #include #include +#include #define FMT_HEADER_ONLY 1 #include "fmt/format.h" #include "fmt/ranges.h" namespace os { + +class State { +public: + State(std::function on, std::function off) + : _on(on) + , _off(off) + {} + void on() { if ( !_state ) { _on(); } _state = true; } + void off() { if ( _state ) { _off();} _state = false; } +private: + bool _state = false; + std::function _on,_off; +}; + class IPlugObject { public: @@ -90,4 +105,4 @@ class fixedqueue std::atomic_uint32_t _head = 0u; std::atomic_uint32_t _tail = 0u; }; -}; // namespace util \ No newline at end of file +}; // namespace util diff --git a/src/wrapasvst3.cpp b/src/wrapasvst3.cpp index 2e081662..48091ab6 100644 --- a/src/wrapasvst3.cpp +++ b/src/wrapasvst3.cpp @@ -60,6 +60,7 @@ tresult PLUGIN_API ClapAsVst3::terminate() { if (_plugin) { + _os_attached.off(); // ensure we are detached (countermeasure to Bug in Renoise) _plugin->terminate(); _plugin.reset(); } @@ -87,11 +88,12 @@ tresult PLUGIN_API ClapAsVst3::setActive(TBool state) _expressionmap & clap_supported_note_expressions::AS_VST3_NOTE_EXPRESSION_TUNING); updateAudioBusses(); - os::attach(this); + _os_attached.on(); } if (!state) { - os::detach(this); + _os_attached.off(); + if (_active) { _plugin->deactivate(); diff --git a/src/wrapasvst3.h b/src/wrapasvst3.h index 579bbf33..8b8a1ecd 100644 --- a/src/wrapasvst3.h +++ b/src/wrapasvst3.h @@ -108,6 +108,7 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect, , _library(lib) , _libraryIndex(number) , _creationcontext(context) + , _os_attached( [this]{os::attach(this);},[this]{os::detach(this);}) { } @@ -253,6 +254,7 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect, // plugin state bool _active = false; + os::State _os_attached; bool _processing = false; std::mutex _processingLock; std::atomic_bool _requestedFlush = false;