summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-07-23 15:38:42 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-25 15:25:13 +0200
commit196841fd3a3ee6f6c0d2152ba880a415ebe6e2f7 (patch)
tree4a8cd6c71b51abfda1770352686e9e87953c60cc /Userland/Applications
parent6389384882db8e72f1f77fd0430bde233224b642 (diff)
downloadserenity-196841fd3a3ee6f6c0d2152ba880a415ebe6e2f7.zip
Piano: Add a generic processor parameter widget
This automatically creates the correct collection of name label, value label and "editor" (knob, checkbox, dropdown) depending on the processor type and layouts them vertically.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Piano/CMakeLists.txt1
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.cpp41
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.h27
3 files changed, 69 insertions, 0 deletions
diff --git a/Userland/Applications/Piano/CMakeLists.txt b/Userland/Applications/Piano/CMakeLists.txt
index 377b892a49..0fd50c01b1 100644
--- a/Userland/Applications/Piano/CMakeLists.txt
+++ b/Userland/Applications/Piano/CMakeLists.txt
@@ -17,6 +17,7 @@ set(SOURCES
SamplerWidget.cpp
WaveWidget.cpp
ProcessorParameterWidget/Slider.cpp
+ ProcessorParameterWidget/ParameterWidget.cpp
)
serenity_app(Piano ICON app-piano)
diff --git a/Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.cpp b/Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.cpp
new file mode 100644
index 0000000000..23ba1105d4
--- /dev/null
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "ParameterWidget.h"
+#include "Dropdown.h"
+#include "Slider.h"
+#include "Toggle.h"
+#include <LibDSP/Synthesizers.h>
+#include <LibGUI/BoxLayout.h>
+
+ProcessorParameterWidget::ProcessorParameterWidget(DSP::ProcessorParameter& raw_parameter)
+ : m_parameter(raw_parameter)
+{
+ set_layout<GUI::VerticalBoxLayout>();
+ m_label = add<GUI::Label>(raw_parameter.name());
+ switch (raw_parameter.type()) {
+ case DSP::ParameterType::Range: {
+ auto& parameter = static_cast<DSP::ProcessorRangeParameter&>(raw_parameter);
+ m_value_label = add<GUI::Label>(String::number(static_cast<double>(parameter.value())));
+ m_parameter_modifier = add<ProcessorParameterSlider>(Orientation::Vertical, parameter, m_value_label);
+ break;
+ }
+ case DSP::ParameterType::Enum: {
+ // FIXME: We shouldn't do that, but the only user is the synth right now.
+ auto& parameter = static_cast<DSP::ProcessorEnumParameter<DSP::Synthesizers::Waveform>&>(raw_parameter);
+ auto enum_strings = Vector<String> { "Sine", "Triangle", "Square", "Saw", "Noise" };
+ m_parameter_modifier = add<ProcessorParameterDropdown<DSP::Synthesizers::Waveform>>(parameter, move(enum_strings));
+ break;
+ }
+ case DSP::ParameterType::Boolean: {
+ auto& parameter = static_cast<DSP::ProcessorBooleanParameter&>(raw_parameter);
+ m_parameter_modifier = add<ProcessorParameterToggle>(parameter);
+ break;
+ }
+ default:
+ VERIFY_NOT_REACHED();
+ }
+}
diff --git a/Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.h b/Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.h
new file mode 100644
index 0000000000..89baf3c24c
--- /dev/null
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/ParameterWidget.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/NonnullRefPtr.h>
+#include <AK/StdLibExtraDetails.h>
+#include <LibCore/Object.h>
+#include <LibDSP/ProcessorParameter.h>
+#include <LibGUI/Label.h>
+#include <LibGUI/Widget.h>
+
+class ProcessorParameterWidget : public GUI::Widget {
+ C_OBJECT(ProcessorParameterWidget)
+public:
+ ProcessorParameterWidget(DSP::ProcessorParameter& parameter);
+ virtual ~ProcessorParameterWidget() = default;
+
+private:
+ DSP::ProcessorParameter& m_parameter;
+ RefPtr<GUI::Widget> m_parameter_modifier;
+ RefPtr<GUI::Label> m_label;
+ RefPtr<GUI::Label> m_value_label;
+};