Skip to content

Commit

Permalink
defensive countermeasure to bug in Renoise
Browse files Browse the repository at this point in the history
  • Loading branch information
defiantnerd committed Sep 11, 2023
1 parent cefb565 commit daf849b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/detail/vst3/os/osutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@

#include <atomic>
#include <string>
#include <functional>
#define FMT_HEADER_ONLY 1
#include "fmt/format.h"
#include "fmt/ranges.h"

namespace os
{

class State {
public:
State(std::function<void()> on, std::function<void()> 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<void()> _on,_off;
};

class IPlugObject
{
public:
Expand Down Expand Up @@ -90,4 +105,4 @@ class fixedqueue
std::atomic_uint32_t _head = 0u;
std::atomic_uint32_t _tail = 0u;
};
}; // namespace util
}; // namespace util
6 changes: 4 additions & 2 deletions src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/wrapasvst3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);})
{
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit daf849b

Please sign in to comment.