Vital
Loading...
Searching...
No Matches
synthesis_interface.cpp
Go to the documentation of this file.
2
3#include "filter_section.h"
5#include "producers_module.h"
6#include "synth_oscillator.h"
7#include "sample_section.h"
8
10 const vital::output_map& mono_modulations,
11 const vital::output_map& poly_modulations) : SynthSection("synthesis") {
12 filter_section_2_ = std::make_unique<FilterSection>(2, mono_modulations, poly_modulations);
13 addSubSection(filter_section_2_.get());
14 filter_section_2_->addListener(this);
15
16 filter_section_1_ = std::make_unique<FilterSection>(1, mono_modulations, poly_modulations);
17 addSubSection(filter_section_1_.get());
18 filter_section_1_->addListener(this);
19
20 for (int i = 0; i < vital::kNumOscillators; ++i) {
21 oscillators_[i] = std::make_unique<OscillatorSection>(auth, i, mono_modulations, poly_modulations);
22 addSubSection(oscillators_[i].get());
23 oscillators_[i]->addListener(this);
24 }
25
26 sample_section_ = std::make_unique<SampleSection>("SMP");
27 addSubSection(sample_section_.get());
28 sample_section_->addListener(this);
29
30 setOpaque(false);
31}
32
34
38
40 int padding = getPadding();
41 int active_width = getWidth() - padding;
42 int width_left = (active_width - padding) / 2;
43 int width_right = active_width - width_left;
44 int right_x = width_left + padding;
45
46 int oscillator_margin = oscillators_[0]->findValue(Skin::kWidgetMargin);
47 int oscillator_height = 2 * (int)oscillators_[0]->getKnobSectionHeight() - oscillator_margin;
48
49 for (int i = 0; i < vital::kNumOscillators; ++i)
50 oscillators_[i]->setBounds(0, i * (oscillator_height + padding), getWidth(), oscillator_height);
51
52 int sample_y = oscillators_[vital::kNumOscillators - 1]->getBottom() + padding;
53 int sample_height = sample_section_->getKnobSectionHeight();
54 int filter_y = sample_y + sample_height + findValue(Skin::kLargePadding);
55 int filter_height = getHeight() - filter_y;
56
57 sample_section_->setBounds(0, sample_y, getWidth(), sample_height);
58
59 filter_section_1_->setBounds(0, filter_y, width_left, filter_height);
60 filter_section_2_->setBounds(right_x, filter_y, width_right, filter_height);
62}
63
65 if (isShowing()) {
66 for (int i = 0; i < vital::kNumOscillators; ++i)
67 oscillators_[i]->loadBrowserState();
68 }
69}
70
72 bool dependents[vital::kNumOscillators];
73 for (int i = 0; i < vital::kNumOscillators; ++i)
74 dependents[i] = false;
75
76 int index = section->index();
77 int last_index = index;
78 while (!dependents[index]) {
79 dependents[index] = true;
80 last_index = index;
81 int type = oscillators_[index]->getDistortion();
86 else
87 return;
88 }
89
90 oscillators_[last_index]->resetOscillatorModulationDistortionType();
91}
92
94 bool filter1_on = destination == vital::constants::kFilter1 || destination == vital::constants::kDualFilters;
95 bool filter2_on = destination == vital::constants::kFilter2 || destination == vital::constants::kDualFilters;
96 for (int i = 0; i < vital::kNumOscillators; ++i) {
97 if (oscillators_[i].get() == section) {
98 filter_section_1_->setOscillatorInput(i, filter1_on);
99 filter_section_2_->setOscillatorInput(i, filter2_on);
100 }
101 }
102}
103
105 if (section == filter_section_1_.get())
106 filter_section_2_->clearFilterInput();
107 else
108 filter_section_1_->clearFilterInput();
109}
110
111void SynthesisInterface::oscInputToggled(FilterSection* section, int index, bool on) {
112 int filter_index = section == filter_section_1_.get() ? 0 : 1;
113 oscillators_[index]->toggleFilterInput(filter_index, on);
114}
115
117 int filter_index = section == filter_section_1_.get() ? 0 : 1;
118 sample_section_->toggleFilterInput(filter_index, on);
119}
120
122 bool filter1_on = destination == vital::constants::kFilter1 || destination == vital::constants::kDualFilters;
123 bool filter2_on = destination == vital::constants::kFilter2 || destination == vital::constants::kDualFilters;
124 filter_section_1_->setSampleInput(filter1_on);
125 filter_section_2_->setSampleInput(filter2_on);
126}
127
A no-op stub implementation used when authentication is disabled.
Definition authentication.h:163
A graphical user interface component representing a filter section in the synthesizer.
Definition filter_section.h:25
A UI section representing an oscillator in the synthesizer.
Definition oscillator_section.h:32
int index() const
Gets the oscillator index.
Definition oscillator_section.h:310
A UI section for managing and editing a sample source.
Definition sample_section.h:24
@ kWidgetMargin
Definition skin.h:103
@ kLargePadding
Definition skin.h:82
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 addSubSection(SynthSection *section, bool show=true)
Adds a subsection (another SynthSection) as a child.
Definition synth_section.cpp:457
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
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 sampleDestinationChanged(SampleSection *section, int destination) override
Called when the sample routing destination changes.
Definition synthesis_interface.cpp:121
SynthesisInterface(Authentication *auth, const vital::output_map &mono_modulations, const vital::output_map &poly_modulations)
Constructs the SynthesisInterface.
Definition synthesis_interface.cpp:9
virtual ~SynthesisInterface()
Destructor.
Definition synthesis_interface.cpp:33
void paintBackground(Graphics &g) override
Paints the background of the synthesis interface.
Definition synthesis_interface.cpp:35
void distortionTypeChanged(OscillatorSection *section, int type) override
Called when the distortion type changes in one of the oscillators.
Definition synthesis_interface.cpp:71
void sampleInputToggled(FilterSection *section, bool on) override
Called when sample input to a filter is toggled.
Definition synthesis_interface.cpp:116
void oscInputToggled(FilterSection *section, int index, bool on) override
Called when oscillator input to a filter is toggled.
Definition synthesis_interface.cpp:111
void resized() override
Handles component resizing and lays out child components.
Definition synthesis_interface.cpp:39
void visibilityChanged() override
Called when the visibility of this interface changes. Used here to load browser states for oscillator...
Definition synthesis_interface.cpp:64
void filterSerialSelected(FilterSection *section) override
Called when a filter section changes to serial routing.
Definition synthesis_interface.cpp:104
void oscillatorDestinationChanged(OscillatorSection *section, int destination) override
Called when the oscillator routing destination changes.
Definition synthesis_interface.cpp:93
static force_inline int getFirstModulationIndex(int index)
Helper function to determine the first modulation index for a given oscillator index.
Definition producers_module.h:50
static force_inline int getSecondModulationIndex(int index)
Helper function to determine the second modulation index for a given oscillator index.
Definition producers_module.h:60
static bool isFirstModulation(int type)
Checks if distortion type uses the first modulation oscillator.
Definition synth_oscillator.h:185
static bool isSecondModulation(int type)
Checks if distortion type uses the second modulation oscillator.
Definition synth_oscillator.h:194
@ kDualFilters
Route through both filters.
Definition synth_constants.h:118
@ kFilter2
Route through Filter 2.
Definition synth_constants.h:117
@ kFilter1
Route through Filter 1.
Definition synth_constants.h:116
constexpr int kNumOscillators
Number of oscillators available in Vital.
Definition synth_constants.h:16
std::map< std::string, Output * > output_map
Maps parameter names to Output pointers, representing output signals from various modules.
Definition synth_types.h:229