From 0eb21a0a705563b6eb7a7008f517d694d81a955c Mon Sep 17 00:00:00 2001 From: James H Ball Date: Mon, 3 Feb 2025 14:33:53 +0000 Subject: [PATCH] Use audio processor properties instead of manually loading and saving --- Source/PluginProcessor.cpp | 13 ++----------- Source/PluginProcessor.h | 2 -- Source/components/AboutComponent.cpp | 8 ++------ Source/components/AboutComponent.h | 3 +-- Source/components/OsciMainMenuBarModel.cpp | 6 +++--- Source/obj/ObjectServer.cpp | 2 +- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 89d9991..6301bfd 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -184,11 +184,6 @@ OscirenderAudioProcessor::OscirenderAudioProcessor() : CommonAudioProcessor(Buse synth.addSound(defaultSound); addAllParameters(); - - if (objectServerPort == 0) { - objectServerPort = 51677; - objectServer.reload(); - } } OscirenderAudioProcessor::~OscirenderAudioProcessor() { @@ -412,7 +407,7 @@ void OscirenderAudioProcessor::setObjectServerRendering(bool enabled) { } void OscirenderAudioProcessor::setObjectServerPort(int port) { - objectServerPort = port; + setProperty("objectServerPort", port); objectServer.reload(); } @@ -674,8 +669,6 @@ void OscirenderAudioProcessor::getStateInformation(juce::MemoryBlock& destData) } xml->setAttribute("currentFile", currentFile); - xml->setAttribute("objectServerPort", objectServerPort); - recordingParameters.save(xml.get()); saveProperties(*xml); @@ -793,12 +786,10 @@ void OscirenderAudioProcessor::setStateInformation(const void* data, int sizeInB } changeCurrentFile(xml->getIntAttribute("currentFile", -1)); - objectServerPort = xml->getIntAttribute("objectServerPort", juce::Random::getSystemRandom().nextInt(juce::Range(51600, 51700))); - objectServer.reload(); - recordingParameters.load(xml.get()); loadProperties(*xml); + objectServer.reload(); broadcaster.sendChangeMessage(); prevMidiEnabled = !midiEnabled->getBoolValue(); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 3649f37..9e2621a 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -184,8 +184,6 @@ public: std::function haltRecording; - int objectServerPort = 0; - void addLuaSlider(); void updateEffectPrecedence(); void updateFileBlock(int index, std::shared_ptr block); diff --git a/Source/components/AboutComponent.cpp b/Source/components/AboutComponent.cpp index 9357487..f4ef4a7 100644 --- a/Source/components/AboutComponent.cpp +++ b/Source/components/AboutComponent.cpp @@ -1,6 +1,6 @@ #include "AboutComponent.h" -AboutComponent::AboutComponent(const void *image, size_t imageSize, juce::String sectionText, int* port) { +AboutComponent::AboutComponent(const void *image, size_t imageSize, juce::String sectionText, int port) { addAndMakeVisible(logoComponent); addAndMakeVisible(text); addAndMakeVisible(portText); @@ -26,11 +26,7 @@ AboutComponent::AboutComponent(const void *image, size_t imageSize, juce::String portText.setColour(juce::TextEditor::backgroundColourId, juce::Colours::transparentBlack); portText.setColour(juce::TextEditor::outlineColourId, juce::Colours::transparentBlack); portText.setJustification(juce::Justification(juce::Justification::centred)); - portText.setText(juce::String("Blender Port: ") + ((port != nullptr) ? juce::String(*port) : juce::String(""))); -} - -void AboutComponent::updatePortText(int* port) { - portText.setText(juce::String("Blender Port: ") + ((port != nullptr) ? juce::String(*port) : juce::String(""))); + portText.setText(juce::String("Blender Port: ") + juce::String(port)); } void AboutComponent::resized() { diff --git a/Source/components/AboutComponent.h b/Source/components/AboutComponent.h index f46ee94..838d475 100644 --- a/Source/components/AboutComponent.h +++ b/Source/components/AboutComponent.h @@ -4,10 +4,9 @@ class AboutComponent : public juce::Component { public: - AboutComponent(const void *image, size_t imageSize, juce::String sectionText, int* port); + AboutComponent(const void *image, size_t imageSize, juce::String sectionText, int port); void resized() override; - void updatePortText(int* port); private: juce::Image logo; diff --git a/Source/components/OsciMainMenuBarModel.cpp b/Source/components/OsciMainMenuBarModel.cpp index 3d6a6ca..10ff9d8 100644 --- a/Source/components/OsciMainMenuBarModel.cpp +++ b/Source/components/OsciMainMenuBarModel.cpp @@ -32,7 +32,7 @@ OsciMainMenuBarModel::OsciMainMenuBarModel(OscirenderAudioProcessor& p, Oscirend "BUS ERROR Collective, for providing the source code for the Hilligoss encoder\n" "Jean Perbet (@jeanprbt) for the osci-render macOS icon\n" "All the community, for suggesting features and reporting issues!", - &audioProcessor.objectServerPort); + std::any_cast(audioProcessor.getProperty("objectServerPort"))); options.content.setOwned(about); options.content->setSize(500, 270); options.dialogTitle = "About"; @@ -48,9 +48,9 @@ OsciMainMenuBarModel::OsciMainMenuBarModel(OscirenderAudioProcessor& p, Oscirend juce::DialogWindow* dw = options.launchAsync(); }); - addMenuItem(1, "Randomize Port", [this] { + addMenuItem(1, "Randomize Blender Port", [this] { audioProcessor.setObjectServerPort(juce::Random::getSystemRandom().nextInt(juce::Range(51600, 51700))); - }); + }); #if !SOSCI_FEATURES addMenuItem(1, "Purchase osci-render premium!", [this] { diff --git a/Source/obj/ObjectServer.cpp b/Source/obj/ObjectServer.cpp index de09608..cfbfdc4 100644 --- a/Source/obj/ObjectServer.cpp +++ b/Source/obj/ObjectServer.cpp @@ -16,7 +16,7 @@ void ObjectServer::reload() { } void ObjectServer::run() { - port = audioProcessor.objectServerPort; + port = std::any_cast(audioProcessor.getProperty("objectServerPort", 51677)); if (socket.createListener(port, "127.0.0.1")) { // preallocating a large buffer to avoid allocations in the loop std::unique_ptr message{ new char[10 * 1024 * 1024] };