Vital
Loading...
Searching...
No Matches
voice_section.cpp
Go to the documentation of this file.
1#include "voice_section.h"
2
3#include "fonts.h"
4#include "operators.h"
5#include "paths.h"
6#include "synth_strings.h"
7#include "synth_button.h"
9#include "synth_slider.h"
10#include "text_look_and_feel.h"
11
13 static constexpr double kKnobSensitivity = 0.2;
14
15 // Polyphony slider setup
16 polyphony_ = std::make_unique<SynthSlider>("polyphony");
17 addSlider(polyphony_.get());
18 polyphony_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
19 polyphony_->setSensitivity(kKnobSensitivity);
20 polyphony_->setLookAndFeel(TextLookAndFeel::instance());
21 polyphony_->useSuffix(false);
22
23 // Velocity tracking slider
24 velocity_track_ = std::make_unique<SynthSlider>("velocity_track");
25 addSlider(velocity_track_.get());
26 velocity_track_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
27 velocity_track_->setBipolar(true);
28
29 // Pitch bend range slider
30 pitch_bend_range_ = std::make_unique<SynthSlider>("pitch_bend_range");
31 addSlider(pitch_bend_range_.get());
32 pitch_bend_range_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
33 pitch_bend_range_->setSensitivity(kKnobSensitivity);
34 pitch_bend_range_->setLookAndFeel(TextLookAndFeel::instance());
35 pitch_bend_range_->useSuffix(false);
36
37 // Stereo routing slider
38 stereo_routing_ = std::make_unique<SynthSlider>("stereo_routing");
39 stereo_routing_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
40 addSlider(stereo_routing_.get());
41
42 // Stereo mode text and selector
43 stereo_mode_text_ = std::make_unique<PlainTextComponent>("Stereo Mode Text", "---");
44 addOpenGlComponent(stereo_mode_text_.get());
45 stereo_mode_text_->setText(strings::kStereoModeNames[0]);
46
47 stereo_mode_type_selector_ = std::make_unique<ShapeButton>("Stereo Mode", Colours::black,
48 Colours::black, Colours::black);
49 addAndMakeVisible(stereo_mode_type_selector_.get());
50 stereo_mode_type_selector_->addListener(this);
51 stereo_mode_type_selector_->setTriggeredOnMouseDown(true);
52
54}
55
57
59 paintBody(g);
60 paintBorder(g);
63
64 drawTextComponentBackground(g, polyphony_->getBounds(), true);
65 setLabelFont(g);
66 drawLabelForComponent(g, TRANS("VOICES"), polyphony_.get(), true);
67 drawLabelForComponent(g, TRANS("VEL TRK"), velocity_track_.get());
68 drawLabelForComponent(g, TRANS(""), stereo_routing_.get());
69
70 drawTextComponentBackground(g, pitch_bend_range_->getBounds(), true);
71 drawLabelForComponent(g, TRANS("BEND"), pitch_bend_range_.get(), true);
72}
73
75 stereo_mode_text_->setColor(findColour(Skin::kBodyText, true));
76 int widget_margin = findValue(Skin::kWidgetMargin);
77 int text_width = findValue(Skin::kModulationButtonWidth) - widget_margin;
78 int text_height = getHeight() - 2 * widget_margin;
79
80 // Layout for polyphony and pitch bend sliders
81 polyphony_->setBounds(widget_margin, widget_margin, text_width, text_height);
82 pitch_bend_range_->setBounds(polyphony_->getRight() + widget_margin, widget_margin, text_width, text_height);
83
84 // Layout for velocity track and stereo routing
85 int knobs_x = pitch_bend_range_->getRight();
86 Rectangle<int> knob_bounds(knobs_x, 0, getWidth() - knobs_x, getHeight());
87 placeKnobsInArea(knob_bounds, { velocity_track_.get(), stereo_routing_.get() });
88
89 // Layout for stereo mode text and selector
90 Rectangle<int> stereo_label_bounds = getLabelBackgroundBounds(stereo_routing_->getBounds());
91 stereo_mode_text_->setBounds(stereo_label_bounds);
92 stereo_mode_text_->setTextSize(findValue(Skin::kLabelHeight));
93 stereo_mode_type_selector_->setBounds(stereo_label_bounds);
94
96}
97
100 int stereo_mode = controls["stereo_mode"]->value();
101 stereo_mode_text_->setText(strings::kStereoModeNames[stereo_mode]);
102}
103
104void VoiceSection::buttonClicked(Button* clicked_button) {
106 if (clicked_button == stereo_mode_type_selector_.get()) {
107 PopupItems options;
108
109 for (int i = 0; i < num_modes; ++i)
110 options.addItem(i, strings::kStereoModeNames[i]);
111
112 showPopupSelector(this, Point<int>(clicked_button->getX(), clicked_button->getBottom()), options,
113 [=](int selection) { setStereoModeSelected(selection); });
114 }
115 else
116 SynthSection::buttonClicked(clicked_button);
117}
118
120 stereo_mode_text_->setText(strings::kStereoModeNames[selection]);
121
122 SynthGuiInterface* parent = findParentComponentOfClass<SynthGuiInterface>();
123 if (parent)
124 parent->getSynth()->valueChangedInternal("stereo_mode", selection);
125}
@ kWidgetMargin
Definition skin.h:103
@ kLabelHeight
Definition skin.h:72
@ kModulationButtonWidth
Definition skin.h:101
@ kBodyText
Definition skin.h:133
@ kKeyboard
Definition skin.h:44
void valueChangedInternal(const std::string &name, vital::mono_float value)
Handles internal value changes, updating the parameter and optionally notifying the host.
Definition synth_base.cpp:54
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 drawTextComponentBackground(Graphics &g, Rectangle< int > bounds, bool extend_to_label)
Draws a background for a text component area.
Definition synth_section.cpp:319
virtual void buttonClicked(Button *clicked_button) override
Called when a button is clicked. Updates the synth parameter accordingly.
Definition synth_section.cpp:398
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
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
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
void showPopupSelector(Component *source, Point< int > position, const PopupItems &options, std::function< void(int)> callback, std::function< void()> cancel={ })
Shows a popup selector with options.
Definition synth_section.cpp:119
Rectangle< int > getLabelBackgroundBounds(Rectangle< int > bounds, bool text_component=false)
Gets the background bounds for a label.
Definition synth_section.cpp:782
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
virtual void paintBorder(Graphics &g, Rectangle< int > bounds)
Paints the border around given bounds.
Definition synth_section.cpp:170
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
virtual void setAllValues(vital::control_map &controls)
Sets values for all known parameters from a control map.
Definition synth_section.cpp:827
void setSkinOverride(Skin::SectionOverride skin_override)
Definition synth_section.h:303
static TextLookAndFeel * instance()
Singleton instance access.
Definition text_look_and_feel.h:106
virtual ~VoiceSection()
Destructor.
Definition voice_section.cpp:56
VoiceSection(String name)
Constructs a VoiceSection with a given name.
Definition voice_section.cpp:12
void setAllValues(vital::control_map &controls) override
Updates all parameter values from a given control map.
Definition voice_section.cpp:98
void paintBackground(Graphics &g) override
Paints the background of the voice section, including labels and shadows.
Definition voice_section.cpp:58
void buttonClicked(Button *clicked_button) override
Handles button click events for this section.
Definition voice_section.cpp:104
void resized() override
Lays out child components and adjusts sizing after a resize event.
Definition voice_section.cpp:74
void setStereoModeSelected(int selection)
Sets the selected stereo mode.
Definition voice_section.cpp:119
@ kNumStereoModes
Definition operators.h:524
const std::string kStereoModeNames[vital::StereoEncoder::kNumStereoModes]
Names for stereo routing modes.
Definition synth_strings.h:261
std::map< std::string, Value * > control_map
Maps parameter names to Value pointers representing synth control parameters.
Definition synth_types.h:214
A hierarchical structure of popup menu items for a selector component.
Definition synth_section.h:29
void addItem(int sub_id, const std::string &sub_name, bool sub_selected=false)
Adds a new item as a submenu entry.
Definition synth_section.h:51
Declares classes for OpenGL-based buttons used in the Vital synth UI.
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...