quantumVERB  1.0.0
A FOSS convolution reverb plugin
UIFilterBlock.cpp
1 /*
2  ==============================================================================
3 
4  UIFilterBlock.cpp
5 
6  ==============================================================================
7 */
8 
9 #include "UIFilterBlock.h"
10 #include "PluginEditor.h"
11 
12 namespace reverb
13 {
14 
15  //==============================================================================
16  /**
17  * @brief Constructs a UIFilterBlock object
18  *
19  * Creates a UIFilterBlock and each of its components. Constructs a
20  * building block for the UI. This block includes all sliders required
21  * for a filter as well as does most of its configuration. It also adds its
22  * parameters to the AudioProcessorValueTreeState.
23  */
24  UIFilterBlock::UIFilterBlock(AudioProcessor& processor, int index, const juce::String& displayedName)
25  : UIBlock(3, 2, "Filter", displayedName)
26  {
27  // Sliders
28  freq.setSliderStyle(juce::Slider::RotaryVerticalDrag);
29  q.setSliderStyle(juce::Slider::RotaryVerticalDrag);
30  gain.setSliderStyle(juce::Slider::RotaryVerticalDrag);
31 
32  freq.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
33  q.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
34  gain.setTextBoxStyle(juce::Slider::TextBoxBelow, true, 50, 20);
35 
36  freq.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
37  q.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
38  gain.setColour(juce::Slider::ColourIds::textBoxOutlineColourId, juce::Colour(0x00000000));
39 
40  juce::String filterIDPrefix = processor.PID_FILTER_PREFIX + std::to_string(index);
41 
42  freq.setComponentID(filterIDPrefix + processor.PID_FILTER_FREQ_SUFFIX);
43  q.setComponentID(filterIDPrefix + processor.PID_FILTER_Q_SUFFIX);
44  gain.setComponentID(filterIDPrefix + processor.PID_FILTER_GAIN_SUFFIX);
45 
46  // Labels
47  freqLabel.setText("frequency", juce::NotificationType::dontSendNotification);
48  freqLabel.setJustificationType(juce::Justification::centredBottom);
49 
50  qLabel.setText("q factor", juce::NotificationType::dontSendNotification);
51  qLabel.setJustificationType(juce::Justification::centredBottom);
52 
53  gainLabel.setText("amplitude", juce::NotificationType::dontSendNotification);
54  gainLabel.setJustificationType(juce::Justification::centredBottom);
55 
56  freqLabel.attachToComponent(&freq, false);
57  qLabel.attachToComponent(&q, false);
58  gainLabel.attachToComponent(&gain, false);
59 
60  // Attachments
61  freqAttachment.reset(new SliderAttachment(processor.parameters,
62  freq.getComponentID(),
63  freq));
64 
65  qAttachment.reset(new SliderAttachment(processor.parameters,
66  q.getComponentID(),
67  q));
68 
69  gainAttachment.reset(new SliderAttachment(processor.parameters,
70  gain.getComponentID(),
71  gain));
72 
73  // Tweak value box appearance
74  freq.setNumDecimalPlacesToDisplay(0);
75  freq.setTextValueSuffix(" Hz");
76 
77  q.setNumDecimalPlacesToDisplay(2);
78 
79  gain.setNumDecimalPlacesToDisplay(2);
80  gain.setTextValueSuffix(" dB");
81 
82  // Skew factor
83  freq.setSkewFactor(1.0, false);
84  q.setSkewFactor(1.0, false);
85  gain.setSkewFactor(0.5, false); // Skew factor of 0.5 on all gain filter sliders
86 
87  // Add sliders
88  addAndMakeVisible(freq);
89  addAndMakeVisible(q);
90  addAndMakeVisible(gain);
91  }
92 
93  //==============================================================================
94  void UIFilterBlock::paint(juce::Graphics& g)
95  {
96  g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
97 
98  g.setColour(juce::Colours::white);
99  g.setFont(15.0f);
100 
101  juce::Rectangle<int> bounds(getLocalBounds());
102  getLookAndFeel().drawGroupComponentOutline(g, bounds.getWidth(), bounds.getHeight(), getText(),
103  juce::Justification(juce::Justification::centredTop), *this);
104  }
105 
106  //==============================================================================
107  /**
108  * @brief Manages the layout of UIFilterBlock when the block is resized
109  *
110  * This function defines all the relative positioning of the various UIFilterBlock
111  * elements.
112  */
114  {
115  juce::Rectangle<int> bounds(getLocalBounds());
116 
117  int height = bounds.getHeight();
118  int padding = (int)(height * 0.06);
119  bounds.reduce(padding, padding);
120 
121  // Distribute elements in columns
122  auto cells = getComponentCells(bounds);
123 
124  freq.setBounds(cells[0]);
125  q.setBounds(cells[1]);
126  gain.setBounds(cells[2]);
127  }
128 
129 }
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
UIFilterBlock(AudioProcessor &processor, int index, const juce::String &displayedName=juce::String())
Constructs a UIFilterBlock object.
void resized() override
Manages the layout of UIFilterBlock when the block is resized.