Skip to content

Commit

Permalink
OSC Startup from Various Unstream Cases
Browse files Browse the repository at this point in the history
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 surge-synthesizer#7293
  • Loading branch information
baconpaul committed Nov 18, 2023
1 parent ce971d3 commit 08f9f5b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 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
9 changes: 5 additions & 4 deletions src/surge-xt/SurgeSynthProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ struct SurgeMacroToJuceParamAdapter : public SurgeBaseParam
struct SurgeBypassParameter : public juce::RangedAudioParameter
{
explicit SurgeBypassParameter()
: value(0.f),
range(0.f, 1.f, 0.01f), juce::RangedAudioParameter(
juce::ParameterID("surgext-bypass", 1), "Bypass Surge XT",
juce::AudioProcessorParameterWithIDAttributes())
: value(0.f), range(0.f, 1.f, 0.01f),
juce::RangedAudioParameter(juce::ParameterID("surgext-bypass", 1), "Bypass Surge XT",
juce::AudioProcessorParameterWithIDAttributes())
{
setValueNotifyingHost(getValue());
}
Expand Down Expand Up @@ -393,6 +392,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 08f9f5b

Please sign in to comment.