diff --git a/Leiwandizer/Source/PluginEditor.cpp b/Leiwandizer/Source/PluginEditor.cpp index 65145e3..0f39550 100644 --- a/Leiwandizer/Source/PluginEditor.cpp +++ b/Leiwandizer/Source/PluginEditor.cpp @@ -25,12 +25,15 @@ LeiwandizerAudioProcessorEditor::LeiwandizerAudioProcessorEditor (LeiwandizerAud btLeiwand.setBounds(97, 66, 45, 75); // x, y, width, height btLeiwand.onClick = [this]() { auto& proc = audioProcessor; - proc.isLeiwand = !proc.isLeiwand; + if (*(proc.processorMode) == 0) *(proc.processorMode) = 1; + else *(proc.processorMode) = 0; }; // Make sure that before the constructor has finished, you've set the // editor's size to whatever you need it to be. setSize (979, 179); + + audioProcessor.processorMode->addListener(this); } LeiwandizerAudioProcessorEditor::~LeiwandizerAudioProcessorEditor() @@ -46,8 +49,8 @@ void LeiwandizerAudioProcessorEditor::paint (juce::Graphics& g) //g.setColour (juce::Colours::white); //g.setFont (juce::FontOptions (15.0f)); //g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1); - if (audioProcessor.isLeiwand) g.drawImage(backgroundOn, getLocalBounds().toFloat()); - else g.drawImage(backgroundOff, getLocalBounds().toFloat()); + if ( *(audioProcessor.processorMode) == 1) g.drawImage(backgroundOn, getLocalBounds().toFloat()); //1 = Leiwand + else g.drawImage(backgroundOff, getLocalBounds().toFloat()); //0 = Oasch } void LeiwandizerAudioProcessorEditor::resized() @@ -55,3 +58,12 @@ void LeiwandizerAudioProcessorEditor::resized() // This is generally where you'll want to lay out the positions of any // subcomponents in your editor.. } + +void LeiwandizerAudioProcessorEditor::parameterValueChanged(int parameterIndex, float newValue) +{ + this->repaint(); +} + +void LeiwandizerAudioProcessorEditor::parameterGestureChanged(int parameterIndex, bool gestureIsStarting) +{ +} diff --git a/Leiwandizer/Source/PluginEditor.h b/Leiwandizer/Source/PluginEditor.h index f636bc3..dd8c0a0 100644 --- a/Leiwandizer/Source/PluginEditor.h +++ b/Leiwandizer/Source/PluginEditor.h @@ -33,7 +33,7 @@ public: //============================================================================== /** */ -class LeiwandizerAudioProcessorEditor : public juce::AudioProcessorEditor +class LeiwandizerAudioProcessorEditor : public juce::AudioProcessorEditor, public juce::AudioProcessorParameter::Listener { public: LeiwandizerAudioProcessorEditor (LeiwandizerAudioProcessor&); @@ -42,6 +42,8 @@ public: //============================================================================== void paint (juce::Graphics&) override; void resized() override; + void parameterValueChanged(int parameterIndex, float newValue) override; + void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override; private: // This reference is provided as a quick way for your editor to diff --git a/Leiwandizer/Source/PluginProcessor.cpp b/Leiwandizer/Source/PluginProcessor.cpp index be3d2a8..086abae 100644 --- a/Leiwandizer/Source/PluginProcessor.cpp +++ b/Leiwandizer/Source/PluginProcessor.cpp @@ -22,6 +22,14 @@ LeiwandizerAudioProcessor::LeiwandizerAudioProcessor() ) #endif { + juce::StringArray modes{ "Oasch", "Leiwand" }; //Order (indexes) matter! + addParameter(processorMode = new juce::AudioParameterChoice( + "mode", + "Mode", + modes, + 0 + )); + } LeiwandizerAudioProcessor::~LeiwandizerAudioProcessor() @@ -239,7 +247,7 @@ void LeiwandizerAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::dsp::AudioBlock block(buffer); juce::dsp::ProcessContextReplacing context(block); - if (isLeiwand) + if (*processorMode == 1) //Leiwand { lowShelfFilterLw.process(context); highShelfFilterLw.process(context); @@ -248,7 +256,7 @@ void LeiwandizerAudioProcessor::processBlock (juce::AudioBuffer& buffer, compressor.process(context); limiter.process(context); } - else + else //Oasch { phaser.process(context); chorus.process(context); @@ -296,12 +304,14 @@ void LeiwandizerAudioProcessor::getStateInformation (juce::MemoryBlock& destData // You should use this method to store your parameters in the memory block. // You could do that either as raw data, or use the XML or ValueTree classes // as intermediaries to make it easy to save and load complex data. + juce::MemoryOutputStream(destData, true).writeInt(*processorMode); } void LeiwandizerAudioProcessor::setStateInformation (const void* data, int sizeInBytes) { // You should use this method to restore your parameters from this memory block, // whose contents will have been created by the getStateInformation() call. + *processorMode = juce::MemoryInputStream(data, static_cast (sizeInBytes), false).readInt(); } //============================================================================== diff --git a/Leiwandizer/Source/PluginProcessor.h b/Leiwandizer/Source/PluginProcessor.h index 00a3cb8..06852c2 100644 --- a/Leiwandizer/Source/PluginProcessor.h +++ b/Leiwandizer/Source/PluginProcessor.h @@ -53,7 +53,7 @@ public: void getStateInformation (juce::MemoryBlock& destData) override; void setStateInformation (const void* data, int sizeInBytes) override; - bool isLeiwand = false; + juce::AudioParameterChoice *processorMode; private: //==============================================================================