gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit a82f18389090386b2307e27b6e643d91b70418eb
parent 0f9cce5aa84545fd86e82eedbbeabe3106340b8c
Author: Tal Aviram <me@talaviram.com>
Date:   Fri, 30 Jul 2021 08:38:56 +0300

controller - moved actual work to timer (messageThread) but can be easily refactor to use a thread of its own through the controller.

Diffstat:
Msource/jucePlugin/VirusController.cpp | 15+++++++++++++--
Msource/jucePlugin/VirusController.h | 5++++-
2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/source/jucePlugin/VirusController.cpp b/source/jucePlugin/VirusController.cpp @@ -15,6 +15,7 @@ namespace Virus { registerParams(); sendSysEx(constructMessage({MessageType::REQUEST_TOTAL})); + startTimer(5); } void Controller::registerParams() @@ -618,9 +619,9 @@ namespace Virus return msg; } - void Controller::dispatchVirusOut(const std::vector<synthLib::SMidiEvent> &newData) + void Controller::timerCallback() { - m_virusOut = newData; + const juce::ScopedLock sl(m_eventQueueLock); for (auto msg : m_virusOut) { if (msg.sysex.size() == 0) @@ -632,5 +633,15 @@ namespace Virus else parseMessage(msg.sysex); } + m_virusOut.clear(); + } + + void Controller::dispatchVirusOut(const std::vector<synthLib::SMidiEvent> &newData) + { + const juce::ScopedTryLock sl(m_eventQueueLock); + if (!sl.isLocked()) + return; + + m_virusOut.insert(m_virusOut.end(), newData.begin(), newData.end()); } }; // namespace Virus diff --git a/source/jucePlugin/VirusController.h b/source/jucePlugin/VirusController.h @@ -9,7 +9,7 @@ class AudioPluginAudioProcessor; namespace Virus { using SysEx = std::vector<uint8_t>; - class Controller + class Controller : private juce::Timer { public: friend Parameter; @@ -33,6 +33,8 @@ namespace Virus juce::StringArray getMultiPresetsName() const; private: + void timerCallback() override; + static constexpr size_t kDataSizeInBytes = 256; // same for multi and single struct MultiPatch @@ -87,6 +89,7 @@ namespace Virus std::vector<uint8_t> constructMessage(SysEx msg); AudioPluginAudioProcessor &m_processor; + juce::CriticalSection m_eventQueueLock; std::vector<synthLib::SMidiEvent> m_virusOut; unsigned char m_deviceId; };