quantumVERB  1.0.0
A FOSS convolution reverb plugin
UIReverbBlock.cpp
1 /*
2  ==============================================================================
3 
4  UIReverbBlock.cpp
5 
6  ==============================================================================
7 */
8 
9 #include "UIReverbBlock.h"
10 #include "PluginEditor.h"
11 
12 namespace reverb
13 {
14 
15  //==============================================================================
16  /**
17  * @brief Constructs an UIReverbBlock object
18  *
19  * Creates a UIReverbBlock and each of its components. Constructs a
20  * building block for the UI. This block includes all sliders required
21  * for the impulse response parameters and output parammeters. It also
22  * does most of the configuration for these sliders. It also adds its
23  * parameters to the AudioProcessorValueTreeState.
24  */
26  : UIBlock(5, 2, "Reverb", "reverb parameters")
27  {
28  // Sliders
29  irLength.setSliderStyle(juce::Slider::RotaryVerticalDrag);
30  preDelay.setSliderStyle(juce::Slider::RotaryVerticalDrag);
31  irGain.setSliderStyle(juce::Slider::RotaryVerticalDrag);
32  outGain.setSliderStyle(juce::Slider::RotaryVerticalDrag);
33  wetRatio.setSliderStyle(juce::Slider::RotaryVerticalDrag);
34 
35  irLength.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
36  preDelay.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
37  irGain.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
38  outGain.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
39  wetRatio.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
40 
41  irLength.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
42  preDelay.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
43  irGain.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
44  outGain.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
45  wetRatio.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
46 
47  irLength.setComponentID(processor.PID_IR_LENGTH);
48  preDelay.setComponentID(processor.PID_PREDELAY);
49  irGain.setComponentID(processor.PID_IR_GAIN);
50  outGain.setComponentID(processor.PID_AUDIO_OUT_GAIN);
51  wetRatio.setComponentID(processor.PID_WETRATIO);
52 
53  // Labels
54  irLengthLabel.setText("reverb length", juce::NotificationType::dontSendNotification);
55  irLengthLabel.setJustificationType(juce::Justification::centredBottom);
56 
57  preDelayLabel.setText("predelay", juce::NotificationType::dontSendNotification);
58  preDelayLabel.setJustificationType(juce::Justification::centredBottom);
59 
60  irGainLabel.setText("reverb volume", juce::NotificationType::dontSendNotification);
61  irGainLabel.setJustificationType(juce::Justification::centredBottom);
62 
63  outGainLabel.setText("output volume", juce::NotificationType::dontSendNotification);
64  outGainLabel.setJustificationType(juce::Justification::centredBottom);
65 
66  wetRatioLabel.setText("wet ratio", juce::NotificationType::dontSendNotification);
67  wetRatioLabel.setJustificationType(juce::Justification::centredBottom);
68 
69  irLengthLabel.attachToComponent(&irLength, false);
70  preDelayLabel.attachToComponent(&preDelay, false);
71  irGainLabel.attachToComponent(&irGain, false);
72  outGainLabel.attachToComponent(&outGain, false);
73  wetRatioLabel.attachToComponent(&wetRatio, false);
74 
75  // Attachments
76  irLengthAttachment.reset(new SliderAttachment(processor.parameters,
77  irLength.getComponentID(),
78  irLength));
79 
80  preDelayAttachment.reset(new SliderAttachment(processor.parameters,
81  preDelay.getComponentID(),
82  preDelay));
83 
84  irGainAttachment.reset(new SliderAttachment(processor.parameters,
85  irGain.getComponentID(),
86  irGain));
87 
88  outGainAttachment.reset(new SliderAttachment(processor.parameters,
89  outGain.getComponentID(),
90  outGain));
91 
92  wetRatioAttachment.reset(new SliderAttachment(processor.parameters,
93  wetRatio.getComponentID(),
94  wetRatio));
95 
96  // Tweak value box appearance
97  irLength.setNumDecimalPlacesToDisplay(2);
98  irLength.setTextValueSuffix(" s");
99 
100  preDelay.setNumDecimalPlacesToDisplay(2);
101  preDelay.setTextValueSuffix(" ms");
102 
103  irGain.setNumDecimalPlacesToDisplay(2);
104  irGain.setTextValueSuffix(" dB");
105 
106  outGain.setNumDecimalPlacesToDisplay(2);
107  outGain.setTextValueSuffix(" dB");
108 
109  wetRatio.setNumDecimalPlacesToDisplay(2);
110 
111  // Add sliders
112  addAndMakeVisible(irLength);
113  addAndMakeVisible(preDelay);
114  addAndMakeVisible(irGain);
115  addAndMakeVisible(outGain);
116  addAndMakeVisible(wetRatio);
117  }
118 
119  //==============================================================================
120  void reverb::UIReverbBlock::paint(juce::Graphics& g)
121  {
122  g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
123 
124  g.setColour(juce::Colours::white);
125  g.setFont(15.0f);
126 
127  juce::Rectangle<int> bounds(getLocalBounds());
128  getLookAndFeel().drawGroupComponentOutline(g, bounds.getWidth(), bounds.getHeight(), getText(),
129  juce::Justification(juce::Justification::centredTop), *this);
130  }
131 
132  //==============================================================================
133  /**
134  * @brief Manages the layout of UIReverbBlock when the block is resized
135  *
136  * This function defines all the relative positioning of the various UIReverbBlock
137  * elements.
138  */
140  {
141  juce::Rectangle<int> bounds(getLocalBounds());
142 
143  int height = bounds.getHeight();
144  int padding = (int)(height * 0.06);
145  bounds.reduce(padding, padding);
146 
147  // Distribute child elements in columns
148  auto cells = getComponentCells(bounds);
149 
150  irLength.setBounds(cells[0]);
151  preDelay.setBounds(cells[1]);
152  irGain.setBounds(cells[2]);
153  outGain.setBounds(cells[3]);
154  wetRatio.setBounds(cells[4]);
155  }
156 
157 }
float getParam(const juce::AudioProcessorValueTreeState &params, const juce::String &blockId) const
Internal method used to get (and check) a parameter&#39;s value.
Definition: Task.h:111
void resized() override
Manages the layout of UIReverbBlock when the block is resized.
UIReverbBlock(AudioProcessor &processor)
Constructs an UIReverbBlock object.