From 41dae2fe24a590692c1df740fd199430e7eacf06 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 24 Nov 2020 08:24:39 +0100 Subject: [PATCH] Also process OSC in idle callback --- vst/SfizzVstEditor.cpp | 43 ++++++++++++++++++++++++++++++++++++++++-- vst/SfizzVstEditor.h | 5 +++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/vst/SfizzVstEditor.cpp b/vst/SfizzVstEditor.cpp index 5d27aeb0..21a0f862 100644 --- a/vst/SfizzVstEditor.cpp +++ b/vst/SfizzVstEditor.cpp @@ -18,12 +18,14 @@ static ViewRect sfizzUiViewRect { 0, 0, Editor::viewWidth, Editor::viewHeight }; enum { kOscTempSize = 8192, + kOscQueueSize = 65536, }; SfizzVstEditor::SfizzVstEditor(SfizzVstController* controller) : VSTGUIEditor(controller, &sfizzUiViewRect), oscTemp_(new uint8_t[kOscTempSize]) { + oscQueue_.reserve(kOscQueueSize); } SfizzVstEditor::~SfizzVstEditor() @@ -57,6 +59,8 @@ bool PLUGIN_API SfizzVstEditor::open(void* parent, const VSTGUI::PlatformType& p mustRedisplayState_ = true; mustRedisplayUiState_ = true; mustRedisplayPlayState_ = true; + flushOscQueue(); + updateStateDisplay(); if (!frame->open(parent, platformType, config)) { @@ -81,6 +85,8 @@ void PLUGIN_API SfizzVstEditor::close() frame->close(); this->frame = nullptr; } + + flushOscQueue(); } /// @@ -105,8 +111,10 @@ CMessageResult SfizzVstEditor::notify(CBaseObject* sender, const char* message) } #endif - if (message == CVSTGUITimer::kMsgTimer) + if (message == CVSTGUITimer::kMsgTimer) { + processOscQueue(); updateStateDisplay(); + } return result; } @@ -140,13 +148,44 @@ SfizzUiState SfizzVstEditor::getCurrentUiState() const void SfizzVstEditor::receiveMessage(const void* data, uint32_t size) { + if (!frame) { + // only accumulate if message processing is active + return; + } + + std::lock_guard lock(stateMutex_); + std::copy( + reinterpret_cast(data), + reinterpret_cast(data) + size, + std::back_inserter(oscQueue_)); +} + +void SfizzVstEditor::processOscQueue() +{ + std::lock_guard lock(stateMutex_); + + const uint8_t* oscData = oscQueue_.data(); + size_t oscSize = oscQueue_.size(); + const char* path; const char* sig; const sfizz_arg_t* args; uint8_t buffer[1024]; - if (sfizz_extract_message(data, size, buffer, sizeof(buffer), &path, &sig, &args) > 0) + uint32_t msgSize; + while ((msgSize = sfizz_extract_message(oscData, oscSize, buffer, sizeof(buffer), &path, &sig, &args)) > 0) { uiReceiveMessage(path, sig, args); + oscData += msgSize; + oscSize -= msgSize; + } + + oscQueue_.clear(); +} + +void SfizzVstEditor::flushOscQueue() +{ + std::lock_guard lock(stateMutex_); + oscQueue_.clear(); } /// diff --git a/vst/SfizzVstEditor.h b/vst/SfizzVstEditor.h index e3bb1126..e6b48478 100644 --- a/vst/SfizzVstEditor.h +++ b/vst/SfizzVstEditor.h @@ -41,6 +41,10 @@ public: SfizzUiState getCurrentUiState() const; void receiveMessage(const void* data, uint32_t size); +private: + void processOscQueue(); + void flushOscQueue(); + protected: // EditorController void uiSendValue(EditId id, const EditValue& v) override; @@ -75,4 +79,5 @@ private: volatile bool mustRedisplayState_ = false; volatile bool mustRedisplayUiState_ = false; volatile bool mustRedisplayPlayState_ = false; + std::vector oscQueue_; };