summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-09-28 18:00:41 +0200
committerLinus Groh <mail@linusgroh.de>2021-11-16 00:09:58 +0000
commit8f8ae5eb53bfff1b4f0d15e0013cab41208b2bc8 (patch)
treedc6cdf8e8e678cdf44bc8b72ac31a138d59da59e
parent481f7d6afa89de25f0820c7354e91039a841328c (diff)
downloadserenity-8f8ae5eb53bfff1b4f0d15e0013cab41208b2bc8.zip
Piano: Create controller widgets for processor parameters
These widgets attach to a processor parameter and keep the two sides in sync. They will become very useful for smart processor interfaces.
-rw-r--r--Userland/Applications/Piano/CMakeLists.txt2
-rw-r--r--Userland/Applications/Piano/KnobsWidget.h2
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h58
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp (renamed from Userland/Applications/Piano/ProcessorParameterSlider.cpp)5
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/Slider.h (renamed from Userland/Applications/Piano/ProcessorParameterSlider.h)9
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/WidgetWithLabel.h22
6 files changed, 90 insertions, 8 deletions
diff --git a/Userland/Applications/Piano/CMakeLists.txt b/Userland/Applications/Piano/CMakeLists.txt
index 9b86a99345..19717985e8 100644
--- a/Userland/Applications/Piano/CMakeLists.txt
+++ b/Userland/Applications/Piano/CMakeLists.txt
@@ -17,7 +17,7 @@ set(SOURCES
RollWidget.cpp
SamplerWidget.cpp
WaveWidget.cpp
- ProcessorParameterSlider.cpp
+ ProcessorParameterWidget/Slider.cpp
)
serenity_app(Piano ICON app-piano)
diff --git a/Userland/Applications/Piano/KnobsWidget.h b/Userland/Applications/Piano/KnobsWidget.h
index 7fa6b6b8e7..48c4c5f364 100644
--- a/Userland/Applications/Piano/KnobsWidget.h
+++ b/Userland/Applications/Piano/KnobsWidget.h
@@ -7,7 +7,7 @@
#pragma once
-#include "ProcessorParameterSlider.h"
+#include "ProcessorParameterWidget/Slider.h"
#include <AK/NonnullRefPtrVector.h>
#include <LibGUI/Frame.h>
diff --git a/Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h b/Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h
new file mode 100644
index 0000000000..2394ae1f51
--- /dev/null
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include "WidgetWithLabel.h"
+#include <AK/Vector.h>
+#include <LibDSP/ProcessorParameter.h>
+#include <LibGUI/ComboBox.h>
+#include <LibGUI/ItemListModel.h>
+#include <LibGUI/Label.h>
+#include <LibGUI/ModelIndex.h>
+
+template<typename EnumT>
+requires(IsEnum<EnumT>) class ProcessorParameterDropdown : public GUI::ComboBox {
+ C_OBJECT(ProcessorParameterDropdown);
+
+public:
+ ProcessorParameterDropdown(LibDSP::ProcessorEnumParameter<EnumT>& parameter, Vector<String> modes)
+ : ComboBox()
+ , m_parameter(parameter)
+ , m_modes(move(modes))
+ {
+ auto model = GUI::ItemListModel<EnumT, Vector<String>>::create(m_modes);
+ set_model(model);
+ set_only_allow_values_from_model(true);
+ set_model_column(0);
+ set_selected_index(0);
+ m_parameter.set_value(static_cast<EnumT>(0));
+
+ on_change = [this]([[maybe_unused]] auto name, GUI::ModelIndex model_index) {
+ auto value = static_cast<EnumT>(model_index.row());
+ m_parameter.set_value_sneaky(value, LibDSP::Detail::ProcessorParameterSetValueTag {});
+ };
+ m_parameter.did_change_value = [this](auto new_value) {
+ set_selected_index(static_cast<int>(new_value));
+ };
+ }
+
+ // Release focus when escape is pressed
+ virtual void keydown_event(GUI::KeyEvent& event) override
+ {
+ if (event.key() == Key_Escape) {
+ if (is_focused())
+ set_focus(false);
+ event.accept();
+ } else {
+ GUI::ComboBox::keydown_event(event);
+ }
+ }
+
+private:
+ LibDSP::ProcessorEnumParameter<EnumT>& m_parameter;
+ Vector<String> m_modes;
+};
diff --git a/Userland/Applications/Piano/ProcessorParameterSlider.cpp b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp
index e83648f48c..d76c638739 100644
--- a/Userland/Applications/Piano/ProcessorParameterSlider.cpp
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp
@@ -4,12 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include "ProcessorParameterSlider.h"
+#include "Slider.h"
+#include "WidgetWithLabel.h"
ProcessorParameterSlider::ProcessorParameterSlider(Orientation orientation, LibDSP::ProcessorRangeParameter& parameter, RefPtr<GUI::Label> value_label)
: Slider(orientation)
+ , WidgetWithLabel(move(value_label))
, m_parameter(parameter)
- , m_value_label(move(value_label))
{
set_range(m_parameter.min_value().raw(), m_parameter.max_value().raw());
set_value(m_parameter.value().raw());
diff --git a/Userland/Applications/Piano/ProcessorParameterSlider.h b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.h
index 22ed68341e..8093279939 100644
--- a/Userland/Applications/Piano/ProcessorParameterSlider.h
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.h
@@ -6,19 +6,20 @@
#pragma once
+#include "WidgetWithLabel.h"
#include <LibDSP/ProcessorParameter.h>
#include <LibGUI/Label.h>
#include <LibGUI/Slider.h>
#include <LibGfx/Orientation.h>
-class ProcessorParameterSlider : public GUI::Slider {
+class ProcessorParameterSlider
+ : public GUI::Slider
+ , public WidgetWithLabel {
C_OBJECT(ProcessorParameterSlider);
public:
ProcessorParameterSlider(Orientation, LibDSP::ProcessorRangeParameter&, RefPtr<GUI::Label>);
- RefPtr<GUI::Label> value_label() { return m_value_label; }
-private:
+protected:
LibDSP::ProcessorRangeParameter& m_parameter;
- RefPtr<GUI::Label> m_value_label;
};
diff --git a/Userland/Applications/Piano/ProcessorParameterWidget/WidgetWithLabel.h b/Userland/Applications/Piano/ProcessorParameterWidget/WidgetWithLabel.h
new file mode 100644
index 0000000000..9286cb29bb
--- /dev/null
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/WidgetWithLabel.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/RefPtr.h>
+#include <LibGUI/Label.h>
+
+class WidgetWithLabel {
+public:
+ WidgetWithLabel(RefPtr<GUI::Label> value_label)
+ : m_value_label(move(value_label))
+ {
+ }
+ RefPtr<GUI::Label> value_label() { return m_value_label; }
+
+protected:
+ RefPtr<GUI::Label> m_value_label;
+};