summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-10-12 01:17:40 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-28 13:59:31 +0100
commit889315e8aa3dba52d8b368fa9de8bc31f6b4702f (patch)
treeb1bef050276907f5c2efb2559267043126c752c7
parente7d84da3daf187193c8fe4702883db93b163d7e8 (diff)
downloadserenity-889315e8aa3dba52d8b368fa9de8bc31f6b4702f.zip
Piano: Respect logarithmic parameters in sliders
If the underlying parameter is logarithmic, the slider respects that and switches to a logarithmic display. Currently, the used base is e, and we'll have to see in practice if 2 or 10 might be better. The parameters that make use of this, as can be seen in the previous commit, are all of the time dependent parameters such as the synth envelope parameters, as with these, usually fine-grained control at small time scales and coarser control at large time scales is desired. This was a good opportunity to refactor the slider step count into a constant.
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp26
-rw-r--r--Userland/Applications/Piano/ProcessorParameterWidget/Slider.h7
2 files changed, 29 insertions, 4 deletions
diff --git a/Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp
index 0a9d78a647..178a6ab8dc 100644
--- a/Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.cpp
@@ -6,21 +6,36 @@
#include "Slider.h"
#include "WidgetWithLabel.h"
+#include <AK/FixedPoint.h>
+#include <AK/Math.h>
ProcessorParameterSlider::ProcessorParameterSlider(Orientation orientation, LibDSP::ProcessorRangeParameter& parameter, RefPtr<GUI::Label> value_label)
: Slider(orientation)
, WidgetWithLabel(move(value_label))
, m_parameter(parameter)
{
- set_range(m_parameter.min_value().raw(), m_parameter.max_value().raw());
- set_value(m_parameter.value().raw());
- set_step((m_parameter.min_value() - m_parameter.max_value()).raw() / 128);
+ if (!is_logarithmic()) {
+ set_range(m_parameter.min_value().raw(), m_parameter.max_value().raw());
+ set_value(m_parameter.value().raw());
+ set_step((m_parameter.min_value() - m_parameter.max_value()).raw() / slider_steps);
+ } else {
+ auto min_log = m_parameter.min_value().log2().raw();
+ auto max_log = m_parameter.max_value().log2().raw();
+ auto value_log = m_parameter.value().log2().raw();
+ set_range(min_log, max_log);
+ set_value(value_log);
+ set_step((min_log - max_log) / slider_steps);
+ }
set_tooltip(m_parameter.name());
m_value_label->set_text(String::formatted("{:.2f}", static_cast<double>(m_parameter)));
on_change = [this](auto value) {
LibDSP::ParameterFixedPoint real_value;
real_value.raw() = value;
+ if (is_logarithmic())
+ // FIXME: Implement exponential for fixed point
+ real_value = exp(static_cast<double>(real_value));
+
m_parameter.set_value_sneaky(real_value, LibDSP::Detail::ProcessorParameterSetValueTag {});
if (m_value_label) {
double value = static_cast<double>(m_parameter);
@@ -34,6 +49,9 @@ ProcessorParameterSlider::ProcessorParameterSlider(Orientation orientation, LibD
}
};
m_parameter.did_change_value = [this](auto value) {
- set_value(value.raw());
+ if (!is_logarithmic())
+ set_value(value.raw());
+ else
+ set_value(value.log2().raw());
};
}
diff --git a/Userland/Applications/Piano/ProcessorParameterWidget/Slider.h b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.h
index dd5220b90b..9546af76bf 100644
--- a/Userland/Applications/Piano/ProcessorParameterWidget/Slider.h
+++ b/Userland/Applications/Piano/ProcessorParameterWidget/Slider.h
@@ -12,6 +12,8 @@
#include <LibGUI/Slider.h>
#include <LibGfx/Orientation.h>
+constexpr int slider_steps = 256;
+
class ProcessorParameterSlider
: public GUI::Slider
, public WidgetWithLabel {
@@ -19,7 +21,12 @@ class ProcessorParameterSlider
public:
ProcessorParameterSlider(Orientation, LibDSP::ProcessorRangeParameter&, RefPtr<GUI::Label>);
+ constexpr bool is_logarithmic() const { return m_parameter.is_logarithmic() == LibDSP::Logarithmic::Yes; }
protected:
LibDSP::ProcessorRangeParameter& m_parameter;
+
+private:
+ // Converts based on processor parameter boundaries.
+ int linear_to_logarithmic(int linear_value);
};