Vital
Loading...
Searching...
No Matches
modulation_tab_selector.cpp
Go to the documentation of this file.
2#include "modulation_button.h"
3#include "synth_section.h"
4#include "skin.h"
5
6ModulationTabSelector::ModulationTabSelector(std::string prefix, int number) :
7 SynthSection(prefix), vertical_(true), selections_enabled_(false), min_modulations_shown_(0), num_shown_(0) {
8 for (int i = 0; i < number; ++i) {
9 std::string name = prefix + "_" + std::to_string(i + 1);
10 modulation_buttons_.push_back(std::make_unique<ModulationButton>(name));
11 addOpenGlComponent(modulation_buttons_.back().get());
12 modulation_buttons_.back()->addListener(this);
13 }
14}
15
16ModulationTabSelector::ModulationTabSelector(String name, int number, const char** names) :
17 SynthSection(name), vertical_(true), selections_enabled_(false), min_modulations_shown_(0), num_shown_(0) {
18 for (int i = 0; i < number; ++i) {
19 modulation_buttons_.push_back(std::make_unique<ModulationButton>(names[i]));
20 addOpenGlComponent(modulation_buttons_.back().get());
21 modulation_buttons_.back()->addListener(this);
22 }
23}
24
26
28 int num_to_show = getNumModulationsToShow();
29 if (num_shown_ != num_to_show) {
30 checkNumShown(false);
31 num_shown_ = num_to_show;
32 }
33
34 g.fillAll(findColour(Skin::kBackground, true));
36
37 for (auto& button : modulation_buttons_) {
38 if (button->isVisible()) {
39 g.saveState();
40 Rectangle<int> bounds = getLocalArea(button.get(), button->getLocalBounds());
41 g.reduceClipRegion(bounds);
42 g.setOrigin(bounds.getTopLeft());
43 button->paintBackground(g);
44 g.restoreState();
45 }
46 }
47}
48
50 SynthSection* parent = findParentComponentOfClass<SynthSection>();
51 if (parent == nullptr)
52 return;
53
54 int rounding_amount = parent->findValue(Skin::kBodyRounding);
55 g.setColour(findColour(Skin::kShadow, true));
56 g.fillRoundedRectangle(getLocalBounds().toFloat(), rounding_amount);
57}
58
62
63void ModulationTabSelector::checkNumShown(bool should_repaint) {
64 int num_to_show = getNumModulationsToShow();
65
66 if (vertical_) {
67 float cell_height = float(getHeight() + 1) / num_to_show;
68 int y = 0;
69
70 for (int i = 0; i < num_to_show; ++i) {
71 int last_y = y;
72 y = std::round((i + 1) * cell_height);
73 modulation_buttons_[i]->setBounds(0.0f, last_y, getWidth(), y - last_y - 1);
74 modulation_buttons_[i]->setVisible(true);
75 }
76 }
77 else {
78 float cell_width = float(getWidth() + 1) / num_to_show;
79 int x = 0;
80
81 for (int i = 0; i < num_to_show; ++i) {
82 int last_x = x;
83 x = std::round((i + 1) * cell_width);
84 modulation_buttons_[i]->setBounds(last_x, 0, x - last_x - 1, getHeight());
85 modulation_buttons_[i]->setVisible(true);
86 }
87 }
88
89 for (int i = num_to_show; i < modulation_buttons_.size(); ++i)
90 modulation_buttons_[i]->setVisible(false);
91
92 if (num_to_show != num_shown_ && should_repaint)
94}
95
97 for (auto& button : modulation_buttons_) {
98 button->select(false);
99 button->setActiveModulation(false);
100 }
101
102 modulation_buttons_[0]->select(selections_enabled_);
103
104 if (getNumModulationsToShow() != num_shown_)
105 checkNumShown(true);
106
107 modulation_buttons_[0]->select(selections_enabled_);
108 for (Listener *listener : listeners_)
109 listener->modulationSelected(this, 0);
110}
111
113 int index = getModulationIndex(source->getName());
114
115 if (selections_enabled_) {
116 for (int i = 0; i < modulation_buttons_.size(); ++i)
117 modulation_buttons_[i]->select(index == i);
118 }
119
121
122 for (Listener *listener : listeners_)
123 listener->modulationSelected(this, index);
124}
125
127 if (getNumModulationsToShow() != num_shown_)
128 checkNumShown(true);
129}
130
132 if (getNumModulationsToShow() != num_shown_)
133 checkNumShown(true);
134}
135
137 if (getNumModulationsToShow() != num_shown_)
138 checkNumShown(true);
139}
140
142 for (auto& button : modulation_buttons_)
143 synth_section->addModulationButton(button.get(), false);
144}
145
147 for (auto& button : modulation_buttons_)
148 button->setFontSize(font_size);
149}
150
151int ModulationTabSelector::getNumModulationsToShow() {
152 int num_to_show = static_cast<int>(modulation_buttons_.size());
153 if (min_modulations_shown_ > 0) {
154 num_to_show = min_modulations_shown_;
155 for (int i = min_modulations_shown_ - 1; i < modulation_buttons_.size(); ++i) {
156 if (modulation_buttons_[i]->hasAnyModulation())
157 num_to_show = i + 2;
158 }
159 }
160 return std::min(num_to_show, static_cast<int>(modulation_buttons_.size()));
161}
162
163int ModulationTabSelector::getModulationIndex(String name) {
164 for (int i = 0; i < modulation_buttons_.size(); ++i) {
165 if (name == modulation_buttons_[i]->getName())
166 return i;
167 }
168 return 0;
169}
A component representing a modulation source or connection button.
Definition modulation_button.h:21
Interface for objects interested in ModulationTabSelector events.
Definition modulation_tab_selector.h:22
void modulationConnectionChanged() override
Called when a modulation connection changes (e.g., a new connection added or removed).
Definition modulation_tab_selector.cpp:131
virtual ~ModulationTabSelector()
Destructor.
ModulationTabSelector(std::string prefix, int number)
Constructs a ModulationTabSelector with a given prefix and number of tabs.
Definition modulation_tab_selector.cpp:6
void reset() override
Resets the tab selector to its default state.
Definition modulation_tab_selector.cpp:96
void paintBackground(Graphics &g) override
Paints the component background and tab shadows.
Definition modulation_tab_selector.cpp:27
void checkNumShown(bool should_repaint)
Checks the number of modulations that should be displayed and updates the layout.
Definition modulation_tab_selector.cpp:63
void resized() override
Called when the component is resized.
Definition modulation_tab_selector.cpp:59
void paintTabShadow(Graphics &g) override
Paints a shadow behind the tabs.
Definition modulation_tab_selector.cpp:49
void registerModulationButtons(SynthSection *synth_section)
Registers all modulation buttons with a given SynthSection.
Definition modulation_tab_selector.cpp:141
void modulationClicked(ModulationButton *source) override
Called when a modulation button within this selector is clicked.
Definition modulation_tab_selector.cpp:112
void modulationCleared() override
Called when all modulations for a source have been cleared.
Definition modulation_tab_selector.cpp:136
void setFontSize(float font_size)
Sets the font size used for the modulation button labels.
Definition modulation_tab_selector.cpp:146
void endModulationMap() override
Called when modulation mapping ends.
Definition modulation_tab_selector.cpp:126
@ kBodyRounding
Definition skin.h:71
@ kBackground
Definition skin.h:128
@ kShadow
Definition skin.h:142
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
void addModulationButton(ModulationButton *button, bool show=true)
Adds a modulation button to this section.
Definition synth_section.cpp:438
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
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
virtual void repaintBackground()
Requests a repaint of the background.
Definition synth_section.cpp:96