Skip to content

Commit

Permalink
OSC Startup from Various Unstream Cases (#7311)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
baconpaul authored Nov 18, 2023
1 parent db38b1c commit fdb5029
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/surge-xt/SurgeSynthEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ SurgeSynthEditor::SurgeSynthEditor(SurgeSynthProcessor &p)
std::lock_guard<std::mutex> grd(surgeLookAndFeelSetupMutex);
if (auto sp = surgeLookAndFeelWeakPointer.lock())
{
std::cout << "Re-using shared pointer" << std::endl;
surgeLF = sp;
}
else
Expand Down
35 changes: 27 additions & 8 deletions src/surge-xt/SurgeSynthProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -413,6 +406,14 @@ void SurgeSynthProcessor::processBlock(juce::AudioBuffer<float> &buffer,
return;
}

#if SURGE_HAS_OSC
if (oscCheckStartup)
{
tryLazyOscStartupFromStreamedState();
}

#endif

priorCallWasProcessBlockNotBypassed = true;

// Make sure we have a main output
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/SurgeSynthProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ class SurgeSynthProcessor : public juce::AudioProcessor,
sst::cpputils::SimpleRingBuffer<oscToAudio, 4096> oscRingBuf;

Surge::OSC::OpenSoundControl oscHandler;
std::atomic<bool> oscCheckStartup{false};
void tryLazyOscStartupFromStreamedState();

bool initOSCIn(int port);
bool initOSCOut(int port);
Expand Down

0 comments on commit fdb5029

Please sign in to comment.