quantumVERB  1.0.0
A FOSS convolution reverb plugin
UIHeaderBlock.cpp
1 /*
2  ==============================================================================
3 
4  UIHeaderBlock.cpp
5 
6  ==============================================================================
7 */
8 
9 #include "UIHeaderBlock.h"
10 #include "PluginEditor.h"
11 
12 namespace reverb
13 {
14 
15  //==============================================================================
16  UIHeaderBlock::UIHeaderBlock(AudioProcessor& p)
17  : UIBlock(3, 3, "Header", "reverb settings"),
18  parameters(p.parameters),
19  previousSelectedIRs(juce::StringArray())
20  {
21  // State button
22  isOn.setButtonText("STATE");
23  isOn.setClickingTogglesState(false);
24  isOn.setInterceptsMouseClicks(false, false);
25 
26  isOn.setComponentID(p.PID_ACTIVE);
27 
28  isOnLabel.setText("reverb", juce::NotificationType::dontSendNotification);
29  isOnLabel.setJustificationType(juce::Justification::topLeft);
30  isOnLabel.attachToComponent(&isOn, false);
31 
32  isOnAttachment.reset(new ButtonAttachment(p.parameters,
33  isOn.getComponentID(),
34  isOn));
35 
36  // IR file box
37  juce::String currentIR = p.parameters.state
38  .getChildWithName(p.PID_IR_FILE_CHOICE)
39  .getProperty("value");
40 
41  irChoice.setButtonText(currentIR);
42 
43  irChoice.setComponentID(p.PID_IR_FILE_CHOICE);
44 
45  irChoiceLabel.setText("impulse response", juce::NotificationType::dontSendNotification);
46  irChoiceLabel.setJustificationType(juce::Justification::topLeft);
47  irChoiceLabel.attachToComponent(&irChoice, false);
48 
49  // Sample rate box
50  auto sampleRateTemp = std::to_string(p.getSampleRate() / 1000);
51 
52  sampleRate.setButtonText(sampleRateTemp.substr(0, 4) + " kHz");
53  sampleRate.setClickingTogglesState(false);
54  sampleRate.setInterceptsMouseClicks(false, false);
55 
56  sampleRateLabel.setText("sample rate", juce::NotificationType::dontSendNotification);
57  sampleRateLabel.setJustificationType(juce::Justification::topLeft);
58  sampleRateLabel.attachToComponent(&sampleRate, false);
59 
60  // TODO: Update sample rate if it changes in DAW (currently set only on construction)
61 
62  // Show all elements
63  addAndMakeVisible(isOn);
64  addAndMakeVisible(irChoice);
65  addAndMakeVisible(sampleRate);
66  }
67 
68  //==============================================================================
69  void reverb::UIHeaderBlock::paint(juce::Graphics& g)
70  {
71  g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
72 
73  g.setColour(juce::Colours::white);
74  g.setFont(15.0f);
75  }
76 
77  //==============================================================================
78  /**
79  * @brief Manages the layout of UIHeaderBlock when the block is resized
80  *
81  * This function defines all the relative positioning of the various UIHeaderBlock
82  * elements.
83  */
85  {
86  juce::Rectangle<int> bounds(getLocalBounds());
87 
88  int boundsWidth = bounds.getWidth();
89  int boundsHeight = bounds.getHeight();
90 
91  int padding = (int)std::ceil(AudioProcessorEditor::PADDING_REL * boundsHeight);
92  int labelHeight = 20;
93 
94  // Draw frame
95  // TODO: Make this look nice
96  /*auto frameBounds = bounds.reduced(padding);
97  frame.setBounds(frameBounds);
98 
99  bounds.reduce(padding, padding);*/
100 
101  // Distribute child elements in columns
102  std::vector<juce::Rectangle<int>> cells(3);
103  std::vector<double> cellWidths = { 0.15, 0.60, 0.25 };
104 
105  for (int i = 0; i < 3; ++i)
106  {
107  cells[i] = bounds.removeFromLeft((int)std::round(cellWidths[i] * boundsWidth));
108 
109  cells[i].removeFromTop(labelHeight);
110  cells[i].reduce(padding, padding);
111  }
112 
113  // Distribute elements in columns
114  isOn.setBounds(cells[0]);
115  irChoice.setBounds(cells[1]);
116  sampleRate.setBounds(cells[2]);
117  }
118 
119 }
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 UIHeaderBlock when the block is resized.