Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defensive countermeasure to bug in Renoise #126

Merged
merged 9 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/detail/vst3/os/osutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,42 @@

#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 +120,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)
defiantnerd marked this conversation as resolved.
Show resolved Hide resolved
_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