summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-07-23 15:52:50 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-25 15:25:13 +0200
commit29e2b1c386728aa16199330923f5fbc3dc5b2554 (patch)
tree5e8f96bf2a68c88a1d842c193ff0a77cb616a1c7 /Userland
parentb29d27c948acb6eefd6a64e83f577f3b94a66550 (diff)
downloadserenity-29e2b1c386728aa16199330923f5fbc3dc5b2554.zip
Piano: Replace knob instantiations with ProcessorParameterWidgets
The only remaining "manual" knob instatiation is the octave, which will be moved into an entirely different UI in the future.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Piano/KnobsWidget.cpp72
-rw-r--r--Userland/Applications/Piano/KnobsWidget.h22
2 files changed, 18 insertions, 76 deletions
diff --git a/Userland/Applications/Piano/KnobsWidget.cpp b/Userland/Applications/Piano/KnobsWidget.cpp
index cb329bca4a..733d82c1f2 100644
--- a/Userland/Applications/Piano/KnobsWidget.cpp
+++ b/Userland/Applications/Piano/KnobsWidget.cpp
@@ -8,7 +8,7 @@
#include "KnobsWidget.h"
#include "MainWidget.h"
-#include "ProcessorParameterWidget/Slider.h"
+#include "ProcessorParameterWidget/ParameterWidget.h"
#include "TrackManager.h"
#include <LibDSP/ProcessorParameter.h>
#include <LibGUI/BoxLayout.h>
@@ -20,33 +20,16 @@ KnobsWidget::KnobsWidget(TrackManager& track_manager, MainWidget& main_widget)
: m_track_manager(track_manager)
, m_main_widget(main_widget)
{
- set_layout<GUI::VerticalBoxLayout>();
+ set_layout<GUI::HorizontalBoxLayout>();
set_fill_with_background_color(true);
- m_labels_container = add<GUI::Widget>();
- m_labels_container->set_layout<GUI::HorizontalBoxLayout>();
- m_labels_container->set_fixed_height(45);
-
- m_volume_label = m_labels_container->add<GUI::Label>("Volume");
- m_octave_label = m_labels_container->add<GUI::Label>("Octave");
-
- m_values_container = add<GUI::Widget>();
- m_values_container->set_layout<GUI::HorizontalBoxLayout>();
- m_values_container->set_fixed_height(10);
-
- m_volume_value = m_values_container->add<GUI::Label>(String::number(0));
- m_octave_value = m_values_container->add<GUI::Label>(String::number(m_track_manager.keyboard()->virtual_keyboard_octave()));
-
- m_knobs_container = add<GUI::Widget>();
- m_knobs_container->set_layout<GUI::HorizontalBoxLayout>();
+ m_octave_container = add<GUI::Widget>();
+ m_octave_container->set_layout<GUI::VerticalBoxLayout>();
+ m_octave_container->add<GUI::Label>("Octave");
+ m_octave_value = m_octave_container->add<GUI::Label>(String::number(m_track_manager.keyboard()->virtual_keyboard_octave()));
// FIXME: Implement vertical flipping in GUI::Slider, not here.
-
- m_volume_knob = m_knobs_container->add<GUI::VerticalSlider>();
- m_volume_knob->set_range(0, volume_max);
- m_volume_knob->set_step(10);
-
- m_octave_knob = m_knobs_container->add<GUI::VerticalSlider>();
+ m_octave_knob = m_octave_container->add<GUI::VerticalSlider>();
m_octave_knob->set_tooltip("Z: octave down, X: octave up");
m_octave_knob->set_range(octave_min - 1, octave_max - 1);
m_octave_knob->set_value((octave_max - 1) - (m_track_manager.keyboard()->virtual_keyboard_octave() - 1));
@@ -59,41 +42,14 @@ KnobsWidget::KnobsWidget(TrackManager& track_manager, MainWidget& main_widget)
m_octave_value->set_text(String::number(new_octave));
};
- for (auto& raw_parameter : m_track_manager.current_track()->synth()->parameters()) {
- // The synth has range and enum parameters
- switch (raw_parameter.type()) {
- case DSP::ParameterType::Range: {
- auto& parameter = static_cast<DSP::ProcessorRangeParameter&>(raw_parameter);
- m_synth_values.append(m_values_container->add<GUI::Label>(String::number(static_cast<double>(parameter.value()))));
- auto& parameter_knob_value = m_synth_values.last();
- m_synth_labels.append(m_labels_container->add<GUI::Label>(String::formatted("Synth: {}", parameter.name())));
- m_synth_knobs.append(m_knobs_container->add<ProcessorParameterSlider>(Orientation::Vertical, parameter, parameter_knob_value));
- break;
- }
- case DSP::ParameterType::Enum: {
- // FIXME: We shouldn't do that, but we know the synth and it is nice
- auto& parameter = static_cast<DSP::ProcessorEnumParameter<DSP::Synthesizers::Waveform>&>(raw_parameter);
- // The value is empty for enum parameters
- m_synth_values.append(m_values_container->add<GUI::Label>(String::empty()));
- m_synth_labels.append(m_labels_container->add<GUI::Label>(String::formatted("Synth: {}", parameter.name())));
- auto enum_strings = Vector<String> { "Sine", "Triangle", "Square", "Saw", "Noise" };
- m_synth_knobs.append(m_knobs_container->add<ProcessorParameterDropdown<DSP::Synthesizers::Waveform>>(parameter, move(enum_strings)));
- m_synth_waveform = static_cast<ProcessorParameterDropdown<DSP::Synthesizers::Waveform>&>(m_synth_knobs.last());
- break;
- }
- default:
- VERIFY_NOT_REACHED();
- }
- }
+ for (auto& parameter : m_track_manager.current_track()->track_mastering()->parameters())
+ m_parameter_widgets.append(add<ProcessorParameterWidget>(parameter));
+
+ for (auto& parameter : m_track_manager.current_track()->synth()->parameters())
+ m_parameter_widgets.append(add<ProcessorParameterWidget>(parameter));
- for (auto& raw_parameter : m_track_manager.current_track()->delay()->parameters()) {
- // FIXME: We shouldn't do that, but we know the effect and it's nice.
- auto& parameter = static_cast<DSP::ProcessorRangeParameter&>(raw_parameter);
- m_delay_values.append(m_values_container->add<GUI::Label>(String::number(static_cast<double>(parameter.value()))));
- auto& parameter_knob_value = m_delay_values.last();
- m_delay_labels.append(m_labels_container->add<GUI::Label>(String::formatted("Delay: {}", parameter.name())));
- m_delay_knobs.append(m_knobs_container->add<ProcessorParameterSlider>(Orientation::Vertical, parameter, parameter_knob_value));
- }
+ for (auto& parameter : m_track_manager.current_track()->delay()->parameters())
+ m_parameter_widgets.append(add<ProcessorParameterWidget>(parameter));
}
void KnobsWidget::update_knobs()
diff --git a/Userland/Applications/Piano/KnobsWidget.h b/Userland/Applications/Piano/KnobsWidget.h
index b8d9fefcb9..2165697317 100644
--- a/Userland/Applications/Piano/KnobsWidget.h
+++ b/Userland/Applications/Piano/KnobsWidget.h
@@ -8,8 +8,7 @@
#pragma once
-#include "ProcessorParameterWidget/Dropdown.h"
-#include "ProcessorParameterWidget/Slider.h"
+#include "ProcessorParameterWidget/ParameterWidget.h"
#include <AK/NonnullRefPtrVector.h>
#include <LibDSP/ProcessorParameter.h>
#include <LibDSP/Synthesizers.h>
@@ -33,24 +32,11 @@ private:
TrackManager& m_track_manager;
MainWidget& m_main_widget;
- RefPtr<GUI::Widget> m_labels_container;
- RefPtr<GUI::Label> m_volume_label;
- RefPtr<GUI::Label> m_octave_label;
- NonnullRefPtrVector<GUI::Label> m_synth_labels;
- NonnullRefPtrVector<GUI::Label> m_delay_labels;
-
- RefPtr<GUI::Widget> m_values_container;
- RefPtr<GUI::Label> m_volume_value;
+ RefPtr<GUI::Widget> m_octave_container;
+ RefPtr<GUI::Slider> m_octave_knob;
RefPtr<GUI::Label> m_octave_value;
- NonnullRefPtrVector<GUI::Label> m_synth_values;
- NonnullRefPtrVector<GUI::Label> m_delay_values;
- RefPtr<GUI::Widget> m_knobs_container;
- RefPtr<GUI::Slider> m_volume_knob;
- RefPtr<GUI::Slider> m_octave_knob;
- RefPtr<ProcessorParameterDropdown<DSP::Synthesizers::Waveform>> m_synth_waveform;
- NonnullRefPtrVector<GUI::Widget> m_synth_knobs;
- NonnullRefPtrVector<ProcessorParameterSlider> m_delay_knobs;
+ NonnullRefPtrVector<ProcessorParameterWidget> m_parameter_widgets;
bool m_change_underlying { true };
};