Vital
Loading...
Searching...
No Matches
bend_section.cpp
Go to the documentation of this file.
1
3
4#include "bend_section.h"
5
6#include "skin.h"
7#include "fonts.h"
9#include "sound_engine.h"
10#include "synth_slider.h"
11
13ControlWheel::ControlWheel(String name) : SynthSlider(std::move(name)), parent_(nullptr) {
14 paintToImage(true);
15 setValue(0.0f);
16 setSliderStyle(LinearBarVertical);
17 setSensitivity(0.5f);
18}
19
21void ControlWheel::paintLine(Graphics& g, float y_percent, Colour line_color, Colour fill_color) {
22 static constexpr float kLineWidthRatio = 0.165f;
23 static constexpr float kFadeRatio = 0.12f;
24
25 float buffer = getWidth() * kBufferWidthRatio;
26 float width = getWidth() - 2.0f * buffer;
27 float height = getHeight() - 4.0f * buffer;
28 float end_radians = vital::kPi / 2.0f;
29 float radians = 2.0f * end_radians * y_percent - end_radians;
30
31 if (radians > vital::kPi * 0.6f || radians < -vital::kPi * 0.6f)
32 return;
33
34 float sin_value = sinf(radians);
35 float cos_value = cosf(radians);
36 float y = 2.0f * buffer + height * 0.5f + sin_value * height * 0.45f;
37
38 float round_amount = fabsf(sin_value) * getWidth() * kWheelRoundAmountRatio;
39 float line_height = cos_value * height * kLineWidthRatio;
40
41 float distance_from_edge = std::min(y - 2.0f * buffer, height + 2.0f * buffer - y);
42 float alpha = std::max(0.0f, std::min(1.0f, distance_from_edge / (height * kFadeRatio)));
43 g.setColour(fill_color.interpolatedWith(line_color, alpha));
44 float offset = (line_height + round_amount) / 2.0f;
45 g.fillRoundedRectangle(buffer, y - offset, width, std::max(0.0f, line_height + round_amount), round_amount);
46
47 g.setColour(fill_color);
48 if (sin_value > 0.0f)
49 y -= round_amount;
50 else
51 y += line_height;
52 g.fillRoundedRectangle(buffer, y - offset, width, 2.0f * round_amount, round_amount);
53}
54
56void ControlWheel::paint(Graphics& g) {
57 static constexpr int kNumLines = 6;
58 static constexpr float kRotatePercent = 0.8f;
59
60 float round_amount = getWidth() * kContainerRoundAmountRatio;
61
62 Colour background = findColour(Skin::kWidgetSecondary1, true);
63 Colour line_color = findColour(Skin::kWidgetAccent1, true);
64 Colour fill_color = background;
65 Colour marker_color = findColour(Skin::kWidgetPrimary1, true);
66
67 float buffer = getWidth() * kBufferWidthRatio;
68 g.setColour(background);
69 g.fillRoundedRectangle(getLocalBounds().toFloat().reduced(buffer, buffer), round_amount);
70
71 float t = 1.0f - (getValue() - getMinimum()) / (getMaximum() - getMinimum());
72 t = (t - 0.5f) * kRotatePercent + 0.5f;
73 float ratio_spacing = 1.0f / kNumLines;
74
75 // Draw lines above center
76 for (int i = kNumLines; t + ratio_spacing * i >= 0.5f; --i) {
77 float ratio = t + ratio_spacing * i;
78 if (i == 0)
79 paintLine(g, ratio, marker_color, fill_color);
80 else
81 paintLine(g, ratio, line_color, fill_color);
82 }
83
84 // Draw lines below center
85 for (int i = -kNumLines; t + ratio_spacing * i < 0.5f; ++i) {
86 float ratio = t + ratio_spacing * i;
87 if (i == 0)
88 paintLine(g, ratio, marker_color, fill_color);
89 else
90 paintLine(g, ratio, line_color, fill_color);
91 }
92
93 g.setColour(findColour(Skin::kBody, true));
94 Path erase;
95 erase.addRectangle(getLocalBounds().toFloat());
96 erase.setUsingNonZeroWinding(false);
97 erase.addRoundedRectangle(getLocalBounds().toFloat().reduced(buffer, buffer), round_amount);
98 g.fillPath(erase);
99
100 g.setColour(findColour(Skin::kShadow, true));
101 Path shadow;
102 shadow.addRoundedRectangle(getLocalBounds().toFloat(), round_amount);
103 shadow.setUsingNonZeroWinding(false);
104 shadow.addRoundedRectangle(getLocalBounds().toFloat().reduced(buffer, buffer), round_amount);
105 g.fillPath(shadow);
106}
107
110 if (parent_ == nullptr)
111 parent_ = findParentComponentOfClass<SynthGuiInterface>();
112
114}
115
118
121
123void PitchWheel::mouseUp(const MouseEvent& e) {
125 setValue(0.0, sendNotification);
126}
127
129BendSection::BendSection(const String& name) : SynthSection(name) {
130 pitch_wheel_ = std::make_unique<PitchWheel>();
131 addSlider(pitch_wheel_.get());
132 pitch_wheel_->setPopupPlacement(BubbleComponent::above);
133
134 mod_wheel_ = std::make_unique<ModWheel>();
135 addSlider(mod_wheel_.get());
136 mod_wheel_->setPopupPlacement(BubbleComponent::above);
137
139}
140
142BendSection::~BendSection() = default;
143
151
154 int widget_margin = getWidgetMargin();
155 int x_padding = getWidth() * 0.16f;
156 x_padding -= (getWidth() + x_padding) % 2;
157 int wheel_height = getHeight() - 2 * widget_margin;
158
159 int right1 = (getWidth() - x_padding) / 2;
160 pitch_wheel_->setBounds(x_padding, widget_margin, right1 - x_padding, wheel_height);
161 int x2 = right1 + x_padding;
162 mod_wheel_->setBounds(x2, widget_margin, getWidth() - x_padding - x2, wheel_height);
163
165}
166
168void BendSection::sliderValueChanged(Slider* changed_slider) {
169 SynthSection::sliderValueChanged(changed_slider);
170 SynthGuiInterface* parent = findParentComponentOfClass<SynthGuiInterface>();
171 if (parent == nullptr)
172 return;
173
174 if (changed_slider == mod_wheel_.get())
175 parent->getSynth()->modWheelGuiChanged(changed_slider->getValue());
176 else if (changed_slider == pitch_wheel_.get())
177 parent->getSynth()->pitchWheelGuiChanged(changed_slider->getValue());
178}
Declares classes for pitch and modulation wheels, and the BendSection container.
BendSection(const String &name)
Constructor for BendSection.
Definition bend_section.cpp:129
void paintBackground(Graphics &g) override
Paints the background of the BendSection.
Definition bend_section.cpp:145
void sliderValueChanged(Slider *changed_slider) override
Called when a slider value changes in the BendSection (pitch or mod wheel).
Definition bend_section.cpp:168
~BendSection()
Destructor.
void resized() override
Resizes and lays out the wheels.
Definition bend_section.cpp:153
A specialized SynthSlider representing a wheel control (pitch or modulation).
Definition bend_section.h:17
ControlWheel(String name)
Constructor for ControlWheel.
Definition bend_section.cpp:13
static constexpr float kBufferWidthRatio
Ratio of width used as a buffer space inside the wheel.
Definition bend_section.h:20
SynthGuiInterface * parent_
Reference to the parent SynthGuiInterface.
Definition bend_section.h:45
void parentHierarchyChanged() override
Called when the component's parent hierarchy changes.
Definition bend_section.cpp:109
void paintLine(Graphics &g, float y_percent, Colour line_color, Colour fill_color)
Paints a line segment representing the wheel position.
Definition bend_section.cpp:21
void paint(Graphics &g) override
Paints the ControlWheel.
Definition bend_section.cpp:56
static constexpr float kContainerRoundAmountRatio
Ratio for the rounded corner of the container.
Definition bend_section.h:24
static constexpr float kWheelRoundAmountRatio
Ratio for the rounded amount of the wheel arc.
Definition bend_section.h:22
ModWheel()
Constructor.
Definition bend_section.cpp:117
void paintToImage(bool paint)
Definition synth_slider.h:93
void mouseUp(const MouseEvent &e) override
Mouse up event for PitchWheel resets the value to 0.
Definition bend_section.cpp:123
PitchWheel()
Constructor.
Definition bend_section.cpp:120
@ kWidgetAccent1
Definition skin.h:171
@ kWidgetPrimary1
Definition skin.h:165
@ kWidgetSecondary1
Definition skin.h:168
@ kShadow
Definition skin.h:142
@ kBody
Definition skin.h:129
@ kKeyboard
Definition skin.h:44
void modWheelGuiChanged(vital::mono_float value)
Called when the mod wheel changes via the GUI or another external source.
Definition synth_base.cpp:80
void pitchWheelGuiChanged(vital::mono_float value)
Called when the pitch wheel changes via the GUI or another external source.
Definition synth_base.cpp:76
An interface class linking the Vital synthesizer backend (SynthBase) with a GUI.
Definition synth_gui_interface.h:56
SynthBase * getSynth()
Returns the SynthBase instance this interface is managing.
Definition synth_gui_interface.h:85
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
void addSlider(SynthSlider *slider, bool show=true, bool listen=true)
Definition synth_section.cpp:445
void paintOpenGlChildrenBackgrounds(Graphics &g)
Paints the backgrounds for all OpenGL child components.
Definition synth_section.cpp:267
virtual void resized() override
Called when the component is resized. Arranges layout of child components.
Definition synth_section.cpp:35
virtual void paintBody(Graphics &g, Rectangle< int > bounds)
Paints the body background within given bounds.
Definition synth_section.cpp:165
void paintKnobShadows(Graphics &g)
Paints knob shadows for all sliders.
Definition synth_section.cpp:253
virtual void paintBorder(Graphics &g, Rectangle< int > bounds)
Paints the border around given bounds.
Definition synth_section.cpp:170
virtual void sliderValueChanged(Slider *moved_slider) override
Called when a slider value changes. Updates the synth parameter accordingly.
Definition synth_section.cpp:391
void setSkinOverride(Skin::SectionOverride skin_override)
Definition synth_section.h:303
float getWidgetMargin()
Definition synth_section.cpp:676
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
virtual void parentHierarchyChanged() override
Called when the parent hierarchy changes, updates references to synthesizer.
Definition synth_slider.cpp:499
void setSensitivity(double sensitivity)
Definition synth_slider.h:542
virtual void mouseUp(const MouseEvent &e) override
Definition synth_slider.cpp:302
constexpr mono_float kPi
Pi constant.
Definition common.h:36
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...