diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-10-12 01:15:12 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-28 13:59:31 +0100 |
commit | e7d84da3daf187193c8fe4702883db93b163d7e8 (patch) | |
tree | 421bf748a21b7df60cb0ea058a6b9513d9d58f2a /Userland/Libraries/LibDSP | |
parent | 98058f7efe671f5a7461c57469505c80b7ec017a (diff) | |
download | serenity-e7d84da3daf187193c8fe4702883db93b163d7e8.zip |
LibDSP: Allow ProcessorRangeParameter to specify if it's a log value
This doesn't affect the parameter's own behavior but is part of the
parameter meta-data, just as the name. If a parameter is logarithmic,
UI elements should represent it with an interface that scales
logarithmically.
Diffstat (limited to 'Userland/Libraries/LibDSP')
-rw-r--r-- | Userland/Libraries/LibDSP/Effects.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/ProcessorParameter.h | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Synthesizers.cpp | 8 |
3 files changed, 18 insertions, 9 deletions
diff --git a/Userland/Libraries/LibDSP/Effects.cpp b/Userland/Libraries/LibDSP/Effects.cpp index 9c571ceca4..b62a4b293b 100644 --- a/Userland/Libraries/LibDSP/Effects.cpp +++ b/Userland/Libraries/LibDSP/Effects.cpp @@ -11,9 +11,9 @@ namespace LibDSP::Effects { Delay::Delay(NonnullRefPtr<Transport> transport) : EffectProcessor(move(transport)) - , m_delay_decay("Decay"sv, 0.01, 0.99, 0.33) - , m_delay_time("Delay Time"sv, 3, 2000, 900) - , m_dry_gain("Dry"sv, 0, 1, 0.9) + , m_delay_decay("Decay"sv, 0.01, 0.99, 0.33, Logarithmic::No) + , m_delay_time("Delay Time"sv, 3, 2000, 900, Logarithmic::Yes) + , m_dry_gain("Dry"sv, 0, 1, 0.9, Logarithmic::No) { m_parameters.append(m_delay_decay); diff --git a/Userland/Libraries/LibDSP/ProcessorParameter.h b/Userland/Libraries/LibDSP/ProcessorParameter.h index ae9fd207bc..5d0d06d349 100644 --- a/Userland/Libraries/LibDSP/ProcessorParameter.h +++ b/Userland/Libraries/LibDSP/ProcessorParameter.h @@ -26,6 +26,11 @@ enum class ParameterType : u8 { Boolean, }; +enum class Logarithmic : bool { + No, + Yes +}; + // Processors have modifiable parameters that should be presented to the UI in a uniform way without requiring the processor itself to implement custom interfaces. class ProcessorParameter { public: @@ -101,22 +106,25 @@ public: class ProcessorRangeParameter final : public Detail::ProcessorParameterSingleValue<ParameterFixedPoint> { public: - ProcessorRangeParameter(String name, ParameterFixedPoint min_value, ParameterFixedPoint max_value, ParameterFixedPoint initial_value) + ProcessorRangeParameter(String name, ParameterFixedPoint min_value, ParameterFixedPoint max_value, ParameterFixedPoint initial_value, Logarithmic logarithmic) : Detail::ProcessorParameterSingleValue<ParameterFixedPoint>(move(name), ParameterType::Range, move(initial_value)) , m_min_value(move(min_value)) , m_max_value(move(max_value)) , m_default_value(move(initial_value)) + , m_logarithmic(logarithmic) { VERIFY(initial_value <= max_value && initial_value >= min_value); } ProcessorRangeParameter(ProcessorRangeParameter const& to_copy) - : ProcessorRangeParameter(to_copy.name(), to_copy.min_value(), to_copy.max_value(), to_copy.value()) + : ProcessorRangeParameter(to_copy.name(), to_copy.min_value(), to_copy.max_value(), to_copy.value(), to_copy.is_logarithmic()) { } ParameterFixedPoint min_value() const { return m_min_value; } ParameterFixedPoint max_value() const { return m_max_value; } + ParameterFixedPoint range() const { return m_max_value - m_min_value; } + constexpr Logarithmic is_logarithmic() const { return m_logarithmic; } ParameterFixedPoint default_value() const { return m_default_value; } void set_value(ParameterFixedPoint value) { @@ -128,6 +136,7 @@ private: double const m_min_value; double const m_max_value; double const m_default_value; + Logarithmic const m_logarithmic; }; template<typename EnumT> diff --git a/Userland/Libraries/LibDSP/Synthesizers.cpp b/Userland/Libraries/LibDSP/Synthesizers.cpp index 23b291cc88..38761af048 100644 --- a/Userland/Libraries/LibDSP/Synthesizers.cpp +++ b/Userland/Libraries/LibDSP/Synthesizers.cpp @@ -17,10 +17,10 @@ namespace LibDSP::Synthesizers { Classic::Classic(NonnullRefPtr<Transport> transport) : LibDSP::SynthesizerProcessor(transport) , m_waveform("Waveform"sv, Waveform::Saw) - , m_attack("Attack"sv, 0, 2000, 5) - , m_decay("Decay"sv, 0, 20'000, 80) - , m_sustain("Sustain"sv, 0, 1, 0.725) - , m_release("Release", 0, 6'000, 120) + , m_attack("Attack"sv, 0.01, 2000, 5, Logarithmic::Yes) + , m_decay("Decay"sv, 0.01, 20'000, 80, Logarithmic::Yes) + , m_sustain("Sustain"sv, 0.001, 1, 0.725, Logarithmic::No) + , m_release("Release", 0.01, 6'000, 120, Logarithmic::Yes) { m_parameters.append(m_waveform); m_parameters.append(m_attack); |