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

OSC Startup from Various Unstream Cases #7311

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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