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.
This commit is contained in:
kleines Filmröllchen 2021-10-12 01:15:12 +02:00 committed by Andreas Kling
parent 98058f7efe
commit e7d84da3da
Notes: sideshowbarker 2024-07-17 18:08:48 +09:00
3 changed files with 18 additions and 9 deletions

View File

@ -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);

View File

@ -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>

View File

@ -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);