Vital
Loading...
Searching...
No Matches
envelope_section.cpp
Go to the documentation of this file.
1
3
4#include "envelope_section.h"
5
6#include "skin.h"
7#include "envelope_editor.h"
8#include "fonts.h"
9#include "paths.h"
10#include "modulation_button.h"
11#include "synth_slider.h"
12
16
17void DragMagnifyingGlass::mouseDown(const MouseEvent& e) {
19 last_position_ = e.position;
20
21 MouseInputSource source = e.source;
22 if (source.isMouse() && source.canDoUnboundedMovement()) {
23 source.hideCursor();
24 source.enableUnboundedMouseMovement(true);
25 mouse_down_position_ = e.getScreenPosition();
26 }
27}
28
29void DragMagnifyingGlass::mouseUp(const MouseEvent& e) {
31
32 MouseInputSource source = e.source;
33 if (source.isMouse() && source.canDoUnboundedMovement()) {
34 source.showMouseCursor(MouseCursor::NormalCursor);
35 source.enableUnboundedMouseMovement(false);
36 source.setScreenPosition(mouse_down_position_.toFloat());
37 }
38}
39
40void DragMagnifyingGlass::mouseDrag(const MouseEvent& e) {
41 Point<float> position = e.position;
42 Point<float> delta_position = position - last_position_;
43 last_position_ = position;
44
45 for (Listener* listener : listeners_)
46 listener->magnifyDragged(delta_position);
47
48 OpenGlShapeButton::mouseDrag(e);
49}
50
51void DragMagnifyingGlass::mouseDoubleClick(const MouseEvent& e) {
52 for (Listener* listener : listeners_)
53 listener->magnifyDoubleClicked();
54
55 OpenGlShapeButton::mouseDoubleClick(e);
56}
57
58EnvelopeSection::EnvelopeSection(String name, std::string value_prepend,
59 const vital::output_map& mono_modulations,
60 const vital::output_map& poly_modulations) : SynthSection(name) {
61 delay_ = std::make_unique<SynthSlider>(value_prepend + "_delay");
62 addSlider(delay_.get());
63 delay_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
64 delay_->setPopupPlacement(BubbleComponent::below);
65
66 attack_ = std::make_unique<SynthSlider>(value_prepend + "_attack");
67 addSlider(attack_.get());
68 attack_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
69 attack_->setPopupPlacement(BubbleComponent::below);
70
71 attack_power_ = std::make_unique<SynthSlider>(value_prepend + "_attack_power");
72 addSlider(attack_power_.get());
73 attack_power_->setVisible(false);
74
75 hold_ = std::make_unique<SynthSlider>(value_prepend + "_hold");
76 addSlider(hold_.get());
77 hold_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
78 hold_->setPopupPlacement(BubbleComponent::below);
79
80 decay_ = std::make_unique<SynthSlider>(value_prepend + "_decay");
81 addSlider(decay_.get());
82 decay_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
83 decay_->setPopupPlacement(BubbleComponent::below);
84
85 decay_power_ = std::make_unique<SynthSlider>(value_prepend + "_decay_power");
86 addSlider(decay_power_.get());
87 decay_power_->setVisible(false);
88
89 release_ = std::make_unique<SynthSlider>(value_prepend + "_release");
90 addSlider(release_.get());
91 release_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
92 release_->setPopupPlacement(BubbleComponent::below);
93
94 release_power_ = std::make_unique<SynthSlider>(value_prepend + "_release_power");
95 addSlider(release_power_.get());
96 release_power_->setVisible(false);
97
98 sustain_ = std::make_unique<SynthSlider>(value_prepend + "_sustain");
99 addSlider(sustain_.get());
100 sustain_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
101 sustain_->setPopupPlacement(BubbleComponent::below);
102
103 envelope_ = std::make_unique<EnvelopeEditor>(value_prepend, mono_modulations, poly_modulations);
104 addOpenGlComponent(envelope_.get());
105 envelope_->setName(value_prepend);
106 envelope_->setDelaySlider(delay_.get());
107 envelope_->setAttackSlider(attack_.get());
108 envelope_->setAttackPowerSlider(attack_power_.get());
109 envelope_->setHoldSlider(hold_.get());
110 envelope_->setDecaySlider(decay_.get());
111 envelope_->setDecayPowerSlider(decay_power_.get());
112 envelope_->setSustainSlider(sustain_.get());
113 envelope_->setReleaseSlider(release_.get());
114 envelope_->setReleasePowerSlider(release_power_.get());
115 envelope_->resetEnvelopeLine(-1);
116
117 drag_magnifying_glass_ = std::make_unique<DragMagnifyingGlass>();
118 drag_magnifying_glass_->addListener(this);
119 addAndMakeVisible(drag_magnifying_glass_.get());
120 addOpenGlComponent(drag_magnifying_glass_->getGlComponent());
122}
123
125
127 setLabelFont(g);
128 drawLabelForComponent(g, TRANS("DELAY"), delay_.get());
129 drawLabelForComponent(g, TRANS("ATTACK"), attack_.get());
130 drawLabelForComponent(g, TRANS("HOLD"), hold_.get());
131 drawLabelForComponent(g, TRANS("DECAY"), decay_.get());
132 drawLabelForComponent(g, TRANS("SUSTAIN"), sustain_.get());
133 drawLabelForComponent(g, TRANS("RELEASE"), release_.get());
134
137}
138
140 static constexpr float kMagnifyingHeightRatio = 0.2f;
141 int knob_section_height = getKnobSectionHeight();
142 int knob_y = getHeight() - knob_section_height;
143
144 int widget_margin = findValue(Skin::kWidgetMargin);
145 int envelope_height = knob_y - widget_margin;
146 envelope_->setBounds(widget_margin, widget_margin, getWidth() - 2 * widget_margin, envelope_height);
147
148 Rectangle<int> knobs_area(0, knob_y, getWidth(), knob_section_height);
149 placeKnobsInArea(knobs_area, { delay_.get(), attack_.get(), hold_.get(),
150 decay_.get(), sustain_.get(), release_.get() });
152 envelope_->setSizeRatio(getSizeRatio());
153
154 int magnify_height = envelope_->getHeight() * kMagnifyingHeightRatio;
155 drag_magnifying_glass_->setBounds(envelope_->getRight() - magnify_height, envelope_->getY(),
156 magnify_height, magnify_height);
157}
158
160 envelope_->resetPositions();
162}
163
164void EnvelopeSection::magnifyDragged(Point<float> delta) {
165 envelope_->magnifyZoom(delta);
166}
167
169 envelope_->magnifyReset();
170}
Interface for objects that need to respond to magnification changes.
Definition envelope_section.h:21
void mouseUp(const MouseEvent &e) override
Definition envelope_section.cpp:29
void mouseDrag(const MouseEvent &e) override
Definition envelope_section.cpp:40
void mouseDown(const MouseEvent &e) override
Definition envelope_section.cpp:17
void mouseDoubleClick(const MouseEvent &e) override
Definition envelope_section.cpp:51
DragMagnifyingGlass()
Constructor.
Definition envelope_section.cpp:13
EnvelopeSection(String name, std::string value_prepend, const vital::output_map &mono_modulations, const vital::output_map &poly_modulations)
Definition envelope_section.cpp:58
void magnifyDoubleClicked() override
Called when the magnifying glass is double-clicked. Resets envelope zoom.
Definition envelope_section.cpp:168
virtual ~EnvelopeSection()
Destructor.
Definition envelope_section.cpp:124
void reset() override
Resets the envelope editor to its default positions.
Definition envelope_section.cpp:159
void resized() override
Resizes and lays out child components, including the envelope editor and sliders.
Definition envelope_section.cpp:139
void magnifyDragged(Point< float > delta) override
Definition envelope_section.cpp:164
void paintBackground(Graphics &g) override
Definition envelope_section.cpp:126
A ToggleButton that uses an OpenGlShapeButtonComponent for its rendering.
Definition synth_button.h:110
void mouseUp(const MouseEvent &e) override
Definition synth_button.h:159
void setShape(const Path &shape)
Definition synth_button.h:124
void mouseDown(const MouseEvent &e) override
Definition synth_button.h:152
static Path magnifyingGlass()
Definition paths.h:588
@ kWidgetMargin
Definition skin.h:103
@ kEnvelope
Definition skin.h:39
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
void placeKnobsInArea(Rectangle< int > area, std::vector< Component * > knobs)
Definition synth_section.cpp:601
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 drawLabelForComponent(Graphics &g, String text, Component *component, bool text_component=false)
Draws a label for a given component.
Definition synth_section.h:548
void setLabelFont(Graphics &g)
Sets the Graphics context font and color for labels.
Definition synth_section.cpp:740
float findValue(Skin::ValueId value_id) const
Finds a value in the skin overrides or from the parent if not found locally.
Definition synth_section.cpp:18
float getKnobSectionHeight()
Definition synth_section.cpp:633
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
float getSizeRatio() const
Definition synth_section.h:765
virtual void reset()
Resets the section and all sub-sections.
Definition synth_section.cpp:30
void setSkinOverride(Skin::SectionOverride skin_override)
Definition synth_section.h:303
Declares the EnvelopeSection class, which provides a UI for configuring ADSR-type envelopes.
std::map< std::string, Output * > output_map
Maps parameter names to Output pointers, representing output signals from various modules.
Definition synth_types.h:229
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...