From fdb50299d410d704a2ca5ddcf6defc2121e049d3 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 18 Nov 2023 16:11:47 -0500 Subject: [PATCH] OSC Startup from Various Unstream Cases (#7311) * OSC Startup from Various Unstream Cases now the OSC info is in DawExtra we need to start after a load and no earlier so we do that here by handling it in both the set state and prepare to play inbound cases. Works with 2 things in reaper muted or un on macos. Closes #7293 --- src/surge-xt/SurgeSynthEditor.cpp | 1 - src/surge-xt/SurgeSynthProcessor.cpp | 35 +++++++++++++++++++++------- src/surge-xt/SurgeSynthProcessor.h | 2 ++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/surge-xt/SurgeSynthEditor.cpp b/src/surge-xt/SurgeSynthEditor.cpp index 71e68f592f3..c151b4fef61 100644 --- a/src/surge-xt/SurgeSynthEditor.cpp +++ b/src/surge-xt/SurgeSynthEditor.cpp @@ -142,7 +142,6 @@ SurgeSynthEditor::SurgeSynthEditor(SurgeSynthProcessor &p) std::lock_guard grd(surgeLookAndFeelSetupMutex); if (auto sp = surgeLookAndFeelWeakPointer.lock()) { - std::cout << "Re-using shared pointer" << std::endl; surgeLF = sp; } else diff --git a/src/surge-xt/SurgeSynthProcessor.cpp b/src/surge-xt/SurgeSynthProcessor.cpp index ece4872d9f7..492fa878660 100644 --- a/src/surge-xt/SurgeSynthProcessor.cpp +++ b/src/surge-xt/SurgeSynthProcessor.cpp @@ -366,14 +366,7 @@ void SurgeSynthProcessor::prepareToPlay(double sr, int samplesPerBlock) } surge->setSamplerate(sr); - -#if SURGE_HAS_OSC - if ((!oscHandler.listening && surge->storage.oscStartIn && surge->storage.oscPortIn > 0) || - (!oscHandler.sendingOSC && surge->storage.oscStartOut && surge->storage.oscPortOut > 0)) - { - oscHandler.tryOSCStartup(); - } -#endif + oscCheckStartup = true; // It used to be we would set audio processing active true here *but* REAPER calls this for // inactive muted channels so we didn't load if that was the case. Set it true only @@ -413,6 +406,14 @@ void SurgeSynthProcessor::processBlock(juce::AudioBuffer &buffer, return; } +#if SURGE_HAS_OSC + if (oscCheckStartup) + { + tryLazyOscStartupFromStreamedState(); + } + +#endif + priorCallWasProcessBlockNotBypassed = true; // Make sure we have a main output @@ -1194,6 +1195,14 @@ void SurgeSynthProcessor::setStateInformation(const void *data, int sizeInBytes) surge->enqueuePatchForLoad(data, sizeInBytes); surge->processAudioThreadOpsWhenAudioEngineUnavailable(); + if (surge->audio_processing_active) + { + oscCheckStartup = true; + } + else + { + tryLazyOscStartupFromStreamedState(); + } } void SurgeSynthProcessor::surgeParameterUpdated(const SurgeSynthesizer::ID &id, float f) @@ -1269,6 +1278,16 @@ juce::AudioProcessorParameter *SurgeSynthProcessor::getBypassParameter() const void SurgeSynthProcessor::reset() { blockPos = 0; } +void SurgeSynthProcessor::tryLazyOscStartupFromStreamedState() +{ + if ((!oscHandler.listening && surge->storage.oscStartIn && surge->storage.oscPortIn > 0) || + (!oscHandler.sendingOSC && surge->storage.oscStartOut && surge->storage.oscPortOut > 0)) + { + oscHandler.tryOSCStartup(); + } + oscCheckStartup = false; +} + #if HAS_CLAP_JUCE_EXTENSIONS uint32_t SurgeSynthProcessor::remoteControlsPageCount() noexcept diff --git a/src/surge-xt/SurgeSynthProcessor.h b/src/surge-xt/SurgeSynthProcessor.h index e61ea97dcb7..01314c3282f 100644 --- a/src/surge-xt/SurgeSynthProcessor.h +++ b/src/surge-xt/SurgeSynthProcessor.h @@ -393,6 +393,8 @@ class SurgeSynthProcessor : public juce::AudioProcessor, sst::cpputils::SimpleRingBuffer oscRingBuf; Surge::OSC::OpenSoundControl oscHandler; + std::atomic oscCheckStartup{false}; + void tryLazyOscStartupFromStreamedState(); bool initOSCIn(int port); bool initOSCOut(int port);