diff --git a/Source/SosciPluginEditor.h b/Source/SosciPluginEditor.h index 5cb7f294..27b969dc 100644 --- a/Source/SosciPluginEditor.h +++ b/Source/SosciPluginEditor.h @@ -32,7 +32,7 @@ public: VisualiserComponent visualiser{audioProcessor, audioProcessor, visualiserSettings, nullptr, false, true}; std::unique_ptr chooser; - SosciMainMenuBarModel menuBarModel{*this}; + SosciMainMenuBarModel menuBarModel{*this, audioProcessor}; juce::MenuBarComponent menuBar; juce::TooltipWindow tooltipWindow{nullptr, 0}; diff --git a/Source/SosciPluginProcessor.cpp b/Source/SosciPluginProcessor.cpp index 5621a1bb..2def84de 100644 --- a/Source/SosciPluginProcessor.cpp +++ b/Source/SosciPluginProcessor.cpp @@ -13,8 +13,7 @@ //============================================================================== SosciAudioProcessor::SosciAudioProcessor() #ifndef JucePlugin_PreferredChannelConfigurations - : AudioProcessor (BusesProperties().withInput("Input", juce::AudioChannelSet::stereo(), true) - .withInput("Brightness", juce::AudioChannelSet::mono(), true) + : AudioProcessor (BusesProperties().withInput("Input", juce::AudioChannelSet::namedChannelSet(3), true) .withOutput("Output", juce::AudioChannelSet::stereo(), true)) #endif { @@ -121,10 +120,7 @@ void SosciAudioProcessor::releaseResources() { } bool SosciAudioProcessor::isBusesLayoutSupported(const BusesLayout& layouts) const { - auto numIns = layouts.getMainInputChannels(); - auto numOuts = layouts.getMainOutputChannels(); - - return numIns >= 2 && numOuts >= 2; + return true; } // effectsLock should be held when calling this @@ -171,21 +167,30 @@ void SosciAudioProcessor::processBlock(juce::AudioBuffer& buffer, juce::M juce::ScopedNoDenormals noDenormals; auto input = getBusBuffer(buffer, true, 0); - auto brightness = getBusBuffer(buffer, true, 1); + float EPSILON = 0.0001f; midiMessages.clear(); auto inputArray = input.getArrayOfWritePointers(); - auto brightnessArray = brightness.getArrayOfWritePointers(); for (int sample = 0; sample < input.getNumSamples(); ++sample) { juce::SpinLock::ScopedLockType scope(consumerLock); float x = input.getNumChannels() > 0 ? inputArray[0][sample] : 0.0f; float y = input.getNumChannels() > 1 ? inputArray[1][sample] : 0.0f; - float z = brightness.getNumChannels() > 0 ? brightnessArray[0][sample] : 1.0f; + float brightness = 1.0f; + if (input.getNumChannels() > 2 && !forceDisableBrightnessInput) { + float brightnessChannel = inputArray[2][sample]; + // Only enable brightness if we actually receive a signal on the brightness channel + if (!brightnessEnabled && brightnessChannel > EPSILON) { + brightnessEnabled = true; + } + if (brightnessEnabled) { + brightness = brightnessChannel; + } + } - Point point = { x, y, z }; + Point point = { x, y, brightness }; for (auto& effect : allEffects) { point = effect->apply(sample, point); diff --git a/Source/SosciPluginProcessor.h b/Source/SosciPluginProcessor.h index 9c096770..9311e614 100644 --- a/Source/SosciPluginProcessor.h +++ b/Source/SosciPluginProcessor.h @@ -58,6 +58,8 @@ public: std::atomic currentSampleRate = 0.0; juce::SpinLock effectsLock; VisualiserParameters parameters; + + std::atomic forceDisableBrightnessInput = false; // shouldn't be accessed by audio thread, but needs to persist when GUI is closed // so should only be accessed by message thread @@ -66,6 +68,8 @@ public: private: + bool brightnessEnabled = false; + std::vector booleanParameters; std::vector floatParameters; std::vector intParameters; diff --git a/Source/components/SosciMainMenuBarModel.cpp b/Source/components/SosciMainMenuBarModel.cpp index c8a0fca3..614da7be 100644 --- a/Source/components/SosciMainMenuBarModel.cpp +++ b/Source/components/SosciMainMenuBarModel.cpp @@ -1,16 +1,13 @@ #include "SosciMainMenuBarModel.h" #include "../SosciPluginEditor.h" +#include "../SosciPluginProcessor.h" -SosciMainMenuBarModel::SosciMainMenuBarModel(SosciPluginEditor& editor) : editor(editor) {} +SosciMainMenuBarModel::SosciMainMenuBarModel(SosciPluginEditor& editor, SosciAudioProcessor& processor) : editor(editor), processor(processor) {} SosciMainMenuBarModel::~SosciMainMenuBarModel() {} juce::StringArray SosciMainMenuBarModel::getMenuBarNames() { - if (editor.processor.wrapperType == juce::AudioProcessor::WrapperType::wrapperType_Standalone) { - return juce::StringArray("File", "About", "Audio"); - } else { - return juce::StringArray("File", "About"); - } + return juce::StringArray("File", "About", "Audio"); } juce::PopupMenu SosciMainMenuBarModel::getMenuForIndex(int topLevelMenuIndex, const juce::String& menuName) { @@ -26,7 +23,10 @@ juce::PopupMenu SosciMainMenuBarModel::getMenuForIndex(int topLevelMenuIndex, co } else if (topLevelMenuIndex == 1) { menu.addItem(1, "About sosci"); } else if (topLevelMenuIndex == 2) { - menu.addItem(1, "Settings"); + menu.addItem(1, "Force Disable Brightness Input", true, processor.forceDisableBrightnessInput); + if (editor.processor.wrapperType == juce::AudioProcessor::WrapperType::wrapperType_Standalone) { + menu.addItem(2, "Settings..."); + } } return menu; @@ -71,7 +71,17 @@ void SosciMainMenuBarModel::menuItemSelected(int menuItemID, int topLevelMenuInd juce::DialogWindow* dw = options.launchAsync(); } break; case 2: - editor.openAudioSettings(); + switch (menuItemID) { + case 1: + processor.forceDisableBrightnessInput = !processor.forceDisableBrightnessInput; + menuItemsChanged(); + break; + case 2: + editor.openAudioSettings(); + break; + default: + break; + } break; default: break; diff --git a/Source/components/SosciMainMenuBarModel.h b/Source/components/SosciMainMenuBarModel.h index 024386aa..623303d3 100644 --- a/Source/components/SosciMainMenuBarModel.h +++ b/Source/components/SosciMainMenuBarModel.h @@ -4,9 +4,10 @@ class SosciPluginEditor; +class SosciAudioProcessor; class SosciMainMenuBarModel : public juce::MenuBarModel { public: - SosciMainMenuBarModel(SosciPluginEditor& editor); + SosciMainMenuBarModel(SosciPluginEditor& editor, SosciAudioProcessor& processor); ~SosciMainMenuBarModel(); juce::StringArray getMenuBarNames() override; @@ -16,4 +17,5 @@ public: private: SosciPluginEditor& editor; + SosciAudioProcessor& processor; };