Vital
Loading...
Searching...
No Matches
volume_section.cpp
Go to the documentation of this file.
1#include "volume_section.h"
2#include "peak_meter_viewer.h"
3#include "fonts.h"
4#include "skin.h"
5#include "synth_slider.h"
6#include "synth_parameters.h"
7
15class VolumeSlider : public SynthSlider {
16 public:
21 VolumeSlider(String name) : SynthSlider(name), point_y_(0), end_y_(1) {
22 paintToImage(true);
23 details_ = vital::Parameters::getDetails("volume");
24 }
25
30 void paint(Graphics& g) override {
31 float x = getPositionOfValue(getValue());
32
33 Path arrow;
34 arrow.startNewSubPath(x, point_y_);
35 int arrow_height = end_y_ - point_y_;
36 arrow.lineTo(x + arrow_height / 2.0f, end_y_);
37 arrow.lineTo(x - arrow_height / 2.0f, end_y_);
38 arrow.closeSubPath();
39 g.setColour(findColour(Skin::kLinearSliderThumb, true));
40 g.fillPath(arrow);
41 }
42
47 void setPointY(int y) { point_y_ = y; repaint(); }
48
53 void setEndY(int y) { end_y_ = y; repaint(); }
54
59 int getEndY() { return end_y_; }
60
61 private:
62 vital::ValueDetails details_;
63 int point_y_;
64 int end_y_;
65};
66
68 peak_meter_left_ = std::make_unique<PeakMeterViewer>(true);
69 addOpenGlComponent(peak_meter_left_.get());
70 peak_meter_right_ = std::make_unique<PeakMeterViewer>(false);
71 addOpenGlComponent(peak_meter_right_.get());
72
73 volume_ = std::make_unique<VolumeSlider>("volume");
74 addSlider(volume_.get());
75 volume_->setSliderStyle(Slider::LinearBar);
76 volume_->setPopupPlacement(BubbleComponent::below);
77}
78
80
82 return getHeight() / 8;
83}
84
86 return getHeight() / 2 - getMeterHeight();
87}
88
90 int meter_height = getMeterHeight();
91 int volume_height = meter_height * 6.0f;
92 int end_volume = meter_height * 3.5f;
93 int padding = 1;
94 int buffer = getBuffer();
95
96 peak_meter_left_->setBounds(0, buffer, getWidth(), meter_height);
97 peak_meter_right_->setBounds(0, peak_meter_left_->getBottom() + padding, getWidth(), meter_height);
98
99 // Position the volume slider arrow according to the peak meter positions
100 volume_->setPointY(peak_meter_right_->getBottom() + padding - buffer);
101 volume_->setEndY(end_volume);
102 volume_->setBounds(0, buffer, getWidth(), volume_height);
103
105}
106
110
111 int ticks_y = peak_meter_right_->getBottom() + getPadding();
112 int tick_height = peak_meter_right_->getHeight() / 2;
114
115 g.setColour(findColour(Skin::kLightenScreen, true));
116 // Draw vertical dB tick marks at intervals
117 for (int decibel = -66; decibel <= 6; decibel += 6) {
118 float offset = decibel - details.post_offset;
119 float percent = offset * offset / (details.max - details.min);
120 int x = percent * getWidth();
121 g.drawRect(x, ticks_y, 1, tick_height);
122 }
123}
void paintToImage(bool paint)
Definition synth_slider.h:93
@ kLinearSliderThumb
Definition skin.h:161
@ kLightenScreen
Definition skin.h:141
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
float getPadding()
Definition synth_section.cpp:660
void addSlider(SynthSlider *slider, bool show=true, bool listen=true)
Definition synth_section.cpp:445
virtual void resized() override
Called when the component is resized. Arranges layout of child components.
Definition synth_section.cpp:35
void paintChildrenBackgrounds(Graphics &g)
Paints the backgrounds for all child sections.
Definition synth_section.cpp:274
void paintKnobShadows(Graphics &g)
Paints knob shadows for all sliders.
Definition synth_section.cpp:253
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
VolumeSection(String name)
Constructs a VolumeSection with a given name.
Definition volume_section.cpp:67
int getMeterHeight()
Computes the height of each peak meter.
Definition volume_section.cpp:81
void resized() override
Lays out and positions child components after a resize event.
Definition volume_section.cpp:89
~VolumeSection()
Destructor.
Definition volume_section.cpp:79
int getBuffer()
Computes a vertical buffer space used to layout components.
Definition volume_section.cpp:85
void paintBackground(Graphics &g) override
Paints the background of the volume section, including meters and volume slider.
Definition volume_section.cpp:107
A custom slider for controlling the output volume.
Definition volume_section.cpp:15
void setPointY(int y)
Sets the starting Y position of the arrow.
Definition volume_section.cpp:47
void paint(Graphics &g) override
Paints the custom arrow on the volume slider at the current value position.
Definition volume_section.cpp:30
int getEndY()
Gets the current ending Y position of the arrow.
Definition volume_section.cpp:59
void setEndY(int y)
Sets the ending Y position of the arrow.
Definition volume_section.cpp:53
VolumeSlider(String name)
Constructs a VolumeSlider with a given parameter name.
Definition volume_section.cpp:21
static const ValueDetails & getDetails(const std::string &name)
Definition synth_parameters.h:200
Holds metadata about a single parameter (control) in the Vital synthesizer.
Definition synth_parameters.h:23
mono_float max
Maximum parameter value.
Definition synth_parameters.h:41
mono_float post_offset
Offset applied after scaling (for certain scale types).
Definition synth_parameters.h:43
mono_float min
Minimum parameter value.
Definition synth_parameters.h:40
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...