diff --git a/src/surge-xt/SurgeSynthEditor.h b/src/surge-xt/SurgeSynthEditor.h index 1d2cf165aba..ce09c1d459d 100644 --- a/src/surge-xt/SurgeSynthEditor.h +++ b/src/surge-xt/SurgeSynthEditor.h @@ -29,6 +29,7 @@ #include "juce_audio_utils/juce_audio_utils.h" #include +#include "version.h" class SurgeGUIEditor; class SurgeJUCELookAndFeel; @@ -141,4 +142,32 @@ class SurgeSynthEditor : public juce::AudioProcessorEditor, JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SurgeSynthEditor) }; +struct SurgeSynthStartupErrorEditor : juce::AudioProcessorEditor +{ + SurgeSynthProcessor &ssp; + SurgeSynthStartupErrorEditor(SurgeSynthProcessor &p) : juce::AudioProcessorEditor(p), ssp(p) + { + setSize(700, 700); + } + void paint(juce::Graphics &g) override + { + g.fillAll(juce::Colours::black); + g.setColour(juce::Colour(255, 50, 50)); + + g.setFont(40); + auto lb = getLocalBounds().withHeight(50).translated(0, 100); + g.drawText("Fatal Surge Startup Error", lb, juce::Justification::centred); + + g.setColour(juce::Colours::white); + g.setFont(20); + lb = lb.translated(0, 55).withHeight(120); + g.drawFittedText(ssp.fatalErrorMessage, lb, juce::Justification::centred, 5); + lb = lb.translated(0, 125); + g.drawText(Surge::Build::FullVersionStr, lb, juce::Justification::centred); + lb = lb.translated(0, 25); + g.drawText("Report on Surge discord or github issue with a screenshot of this screen", lb, + juce::Justification::centred); + } +}; + #endif // SURGE_SRC_SURGE_XT_SURGESYNTHEDITOR_H diff --git a/src/surge-xt/SurgeSynthProcessor.cpp b/src/surge-xt/SurgeSynthProcessor.cpp index cb4e392c209..0ca56b636ff 100644 --- a/src/surge-xt/SurgeSynthProcessor.cpp +++ b/src/surge-xt/SurgeSynthProcessor.cpp @@ -65,11 +65,19 @@ SurgeSynthProcessor::SurgeSynthProcessor() << " using " << Surge::Build::BuildCompiler << "\n"; #endif - surge = std::make_unique(this); - + try + { + surge = std::make_unique(this); + } + catch (const std::exception &e) + { + surge.reset(); + fatalErrorMessage = e.what(); + return; + } #if BUILD_IS_DEBUG - oss << " - Data : " << surge->storage.datapath << "\n" - << " - User Data : " << surge->storage.userDataPath << std::endl; + oss << " - Data : " << surge->storage.datapath.u8string() << "\n" + << " - User Data : " << surge->storage.userDataPath.u8string() << std::endl; DBG(oss.str()); #endif @@ -178,6 +186,9 @@ SurgeSynthProcessor::SurgeSynthProcessor() SurgeSynthProcessor::~SurgeSynthProcessor() { + if (!surge) + return; + if (oscHandler.listening) { oscHandler.stopListening(); @@ -345,6 +356,9 @@ void SurgeSynthProcessor::paramChangeToListeners(Parameter *p) void SurgeSynthProcessor::prepareToPlay(double sr, int samplesPerBlock) { + if (!surge) + return; + surge->setSamplerate(sr); // It used to be I 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 @@ -379,6 +393,12 @@ void SurgeSynthProcessor::processBlock(juce::AudioBuffer &buffer, { auto fpuguard = sst::plugininfra::cpufeatures::FPUStateGuard(); + if (!surge) + { + buffer.clear(); + return; + } + priorCallWasProcessBlockNotBypassed = true; // Make sure we have a main output @@ -1076,12 +1096,22 @@ bool SurgeSynthProcessor::hasEditor() const juce::AudioProcessorEditor *SurgeSynthProcessor::createEditor() { - return new SurgeSynthEditor(*this); + if (surge) + { + return new SurgeSynthEditor(*this); + } + else + { + return new SurgeSynthStartupErrorEditor(*this); + } } //============================================================================== void SurgeSynthProcessor::getStateInformation(juce::MemoryBlock &destData) { + if (!surge) + return; + surge->populateDawExtraState(); auto sse = dynamic_cast(getActiveEditor()); if (sse) @@ -1097,6 +1127,9 @@ void SurgeSynthProcessor::getStateInformation(juce::MemoryBlock &destData) void SurgeSynthProcessor::setStateInformation(const void *data, int sizeInBytes) { + if (!surge) + return; + surge->enqueuePatchForLoad(data, sizeInBytes); surge->processAudioThreadOpsWhenAudioEngineUnavailable(); } diff --git a/src/surge-xt/SurgeSynthProcessor.h b/src/surge-xt/SurgeSynthProcessor.h index 3177f5aa679..5313d11bb2a 100644 --- a/src/surge-xt/SurgeSynthProcessor.h +++ b/src/surge-xt/SurgeSynthProcessor.h @@ -469,6 +469,8 @@ class SurgeSynthProcessor : public juce::AudioProcessor, public: bool inputIsLatent{false}; + std::string fatalErrorMessage{false}; + private: // Have we warned about bad configurations bool warnedAboutBadConfig{false};