Make processing mode a vst parameter

This commit is contained in:
Ludwig Frühschütz 2025-04-20 12:37:05 +02:00
parent 40ab4bfe68
commit 6bc416c0c5
4 changed files with 31 additions and 7 deletions

View File

@ -25,12 +25,15 @@ LeiwandizerAudioProcessorEditor::LeiwandizerAudioProcessorEditor (LeiwandizerAud
btLeiwand.setBounds(97, 66, 45, 75); // x, y, width, height btLeiwand.setBounds(97, 66, 45, 75); // x, y, width, height
btLeiwand.onClick = [this]() { btLeiwand.onClick = [this]() {
auto& proc = audioProcessor; 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 // Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be. // editor's size to whatever you need it to be.
setSize (979, 179); setSize (979, 179);
audioProcessor.processorMode->addListener(this);
} }
LeiwandizerAudioProcessorEditor::~LeiwandizerAudioProcessorEditor() LeiwandizerAudioProcessorEditor::~LeiwandizerAudioProcessorEditor()
@ -46,8 +49,8 @@ void LeiwandizerAudioProcessorEditor::paint (juce::Graphics& g)
//g.setColour (juce::Colours::white); //g.setColour (juce::Colours::white);
//g.setFont (juce::FontOptions (15.0f)); //g.setFont (juce::FontOptions (15.0f));
//g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1); //g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1);
if (audioProcessor.isLeiwand) g.drawImage(backgroundOn, getLocalBounds().toFloat()); if ( *(audioProcessor.processorMode) == 1) g.drawImage(backgroundOn, getLocalBounds().toFloat()); //1 = Leiwand
else g.drawImage(backgroundOff, getLocalBounds().toFloat()); else g.drawImage(backgroundOff, getLocalBounds().toFloat()); //0 = Oasch
} }
void LeiwandizerAudioProcessorEditor::resized() void LeiwandizerAudioProcessorEditor::resized()
@ -55,3 +58,12 @@ void LeiwandizerAudioProcessorEditor::resized()
// This is generally where you'll want to lay out the positions of any // This is generally where you'll want to lay out the positions of any
// subcomponents in your editor.. // subcomponents in your editor..
} }
void LeiwandizerAudioProcessorEditor::parameterValueChanged(int parameterIndex, float newValue)
{
this->repaint();
}
void LeiwandizerAudioProcessorEditor::parameterGestureChanged(int parameterIndex, bool gestureIsStarting)
{
}

View File

@ -33,7 +33,7 @@ public:
//============================================================================== //==============================================================================
/** /**
*/ */
class LeiwandizerAudioProcessorEditor : public juce::AudioProcessorEditor class LeiwandizerAudioProcessorEditor : public juce::AudioProcessorEditor, public juce::AudioProcessorParameter::Listener
{ {
public: public:
LeiwandizerAudioProcessorEditor (LeiwandizerAudioProcessor&); LeiwandizerAudioProcessorEditor (LeiwandizerAudioProcessor&);
@ -42,6 +42,8 @@ public:
//============================================================================== //==============================================================================
void paint (juce::Graphics&) override; void paint (juce::Graphics&) override;
void resized() override; void resized() override;
void parameterValueChanged(int parameterIndex, float newValue) override;
void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override;
private: private:
// This reference is provided as a quick way for your editor to // This reference is provided as a quick way for your editor to

View File

@ -22,6 +22,14 @@ LeiwandizerAudioProcessor::LeiwandizerAudioProcessor()
) )
#endif #endif
{ {
juce::StringArray modes{ "Oasch", "Leiwand" }; //Order (indexes) matter!
addParameter(processorMode = new juce::AudioParameterChoice(
"mode",
"Mode",
modes,
0
));
} }
LeiwandizerAudioProcessor::~LeiwandizerAudioProcessor() LeiwandizerAudioProcessor::~LeiwandizerAudioProcessor()
@ -239,7 +247,7 @@ void LeiwandizerAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
juce::dsp::AudioBlock<float> block(buffer); juce::dsp::AudioBlock<float> block(buffer);
juce::dsp::ProcessContextReplacing<float> context(block); juce::dsp::ProcessContextReplacing<float> context(block);
if (isLeiwand) if (*processorMode == 1) //Leiwand
{ {
lowShelfFilterLw.process(context); lowShelfFilterLw.process(context);
highShelfFilterLw.process(context); highShelfFilterLw.process(context);
@ -248,7 +256,7 @@ void LeiwandizerAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
compressor.process(context); compressor.process(context);
limiter.process(context); limiter.process(context);
} }
else else //Oasch
{ {
phaser.process(context); phaser.process(context);
chorus.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 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 // 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. // 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) void LeiwandizerAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{ {
// You should use this method to restore your parameters from this memory block, // You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call. // whose contents will have been created by the getStateInformation() call.
*processorMode = juce::MemoryInputStream(data, static_cast<size_t> (sizeInBytes), false).readInt();
} }
//============================================================================== //==============================================================================

View File

@ -53,7 +53,7 @@ public:
void getStateInformation (juce::MemoryBlock& destData) override; void getStateInformation (juce::MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override; void setStateInformation (const void* data, int sizeInBytes) override;
bool isLeiwand = false; juce::AudioParameterChoice *processorMode;
private: private:
//============================================================================== //==============================================================================