From 775da0186cc3709ecd83239118107eefeedc37c9 Mon Sep 17 00:00:00 2001 From: James Ball Date: Sun, 10 Sep 2023 18:52:21 +0100 Subject: [PATCH] Fix Blender when using MIDI, and change default MIDI enabled --- Source/MidiComponent.cpp | 2 ++ Source/PluginProcessor.h | 2 +- Source/audio/ShapeSound.cpp | 8 ++++++-- Source/audio/ShapeSound.h | 2 +- Source/audio/ShapeVoice.cpp | 2 +- Source/obj/ObjectServer.cpp | 4 ++-- Source/parser/FrameConsumer.h | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Source/MidiComponent.cpp b/Source/MidiComponent.cpp index fe128c8..f69e077 100644 --- a/Source/MidiComponent.cpp +++ b/Source/MidiComponent.cpp @@ -4,6 +4,8 @@ MidiComponent::MidiComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) { addAndMakeVisible(midiToggle); addAndMakeVisible(keyboard); + + midiToggle.setToggleState(audioProcessor.midiEnabled->getBoolValue(), juce::dontSendNotification); midiToggle.onClick = [this]() { audioProcessor.midiEnabled->setBoolValueNotifyingHost(midiToggle.getToggleState()); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 622d827..d3cf572 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -177,7 +177,7 @@ public: std::shared_ptr delayEffect = std::make_shared(); std::shared_ptr perspectiveEffect = std::make_shared(VERSION_HINT); - BooleanParameter* midiEnabled = new BooleanParameter("MIDI Enabled", "midiEnabled", VERSION_HINT, false); + BooleanParameter* midiEnabled = new BooleanParameter("MIDI Enabled", "midiEnabled", VERSION_HINT, !juce::JUCEApplicationBase::isStandaloneApp()); std::atomic frequency = 440.0f; juce::SpinLock parsersLock; diff --git a/Source/audio/ShapeSound.cpp b/Source/audio/ShapeSound.cpp index 9ef27cc..e79d40a 100644 --- a/Source/audio/ShapeSound.cpp +++ b/Source/audio/ShapeSound.cpp @@ -26,8 +26,12 @@ bool ShapeSound::appliesToChannel(int channel) { return true; } -void ShapeSound::addFrame(std::vector>& frame) { - frames.push(std::move(frame)); +void ShapeSound::addFrame(std::vector>& frame, bool force) { + if (force) { + frames.push(std::move(frame)); + } else { + frames.try_push(std::move(frame)); + } } double ShapeSound::updateFrame(std::vector>& frame) { diff --git a/Source/audio/ShapeSound.h b/Source/audio/ShapeSound.h index 0a84a5f..c14ff45 100644 --- a/Source/audio/ShapeSound.h +++ b/Source/audio/ShapeSound.h @@ -13,7 +13,7 @@ public: bool appliesToNote(int note) override; bool appliesToChannel(int channel) override; - void addFrame(std::vector>& frame) override; + void addFrame(std::vector>& frame, bool force = true) override; double updateFrame(std::vector>& frame); std::shared_ptr parser; diff --git a/Source/audio/ShapeVoice.cpp b/Source/audio/ShapeVoice.cpp index 829c979..5b14ef2 100644 --- a/Source/audio/ShapeVoice.cpp +++ b/Source/audio/ShapeVoice.cpp @@ -135,7 +135,7 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star double drawnFrameLength = traceMaxEnabled ? actualTraceMax * frameLength : frameLength; if (!renderingSample && frameDrawn >= drawnFrameLength) { - if (sound.load() != nullptr) { + if (sound.load() != nullptr && currentlyPlaying) { frameLength = sound.load()->updateFrame(frame); } // TODO: updateFrame already iterates over all the shapes, diff --git a/Source/obj/ObjectServer.cpp b/Source/obj/ObjectServer.cpp index f1ca510..3fb9d11 100644 --- a/Source/obj/ObjectServer.cpp +++ b/Source/obj/ObjectServer.cpp @@ -22,7 +22,7 @@ void ObjectServer::run() { if (connection != nullptr) { audioProcessor.setObjectServerRendering(true); - while (!threadShouldExit()) { + while (!threadShouldExit() && connection->isConnected()) { if (connection->waitUntilReady(true, 200) == 1) { int i = 0; @@ -177,7 +177,7 @@ void ObjectServer::run() { } } - audioProcessor.objectServerSound->addFrame(frame); + audioProcessor.objectServerSound->addFrame(frame, false); } } } diff --git a/Source/parser/FrameConsumer.h b/Source/parser/FrameConsumer.h index b1ab19e..4d29942 100644 --- a/Source/parser/FrameConsumer.h +++ b/Source/parser/FrameConsumer.h @@ -6,5 +6,5 @@ class FrameConsumer { public: - virtual void addFrame(std::vector>& frame) = 0; + virtual void addFrame(std::vector>& frame, bool force = true) = 0; }; \ No newline at end of file