diff options
-rw-r--r-- | plugin/drumgizmo_plugin.cc | 8 | ||||
-rw-r--r-- | plugingui/humaniservisualiser.cc | 9 | ||||
-rw-r--r-- | plugingui/humaniservisualiser.h | 4 | ||||
-rw-r--r-- | plugingui/timingframecontent.cc | 29 | ||||
-rw-r--r-- | plugingui/timingframecontent.h | 4 | ||||
-rw-r--r-- | src/latencyfilter.cc | 7 | ||||
-rw-r--r-- | src/settings.h | 23 |
7 files changed, 47 insertions, 37 deletions
diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc index 24a9d00..847d8d2 100644 --- a/plugin/drumgizmo_plugin.cc +++ b/plugin/drumgizmo_plugin.cc @@ -576,8 +576,8 @@ std::string DrumGizmoPlugin::ConfigStringIO::get() // Do not store/reload this value //" <value name=\"latency_max\">" + //int2str(settings.latency_max.load()) + "</value>\n" - " <value name=\"latency_laid_back\">" + - int2str(settings.latency_laid_back.load()) + "</value>\n" + " <value name=\"latency_laid_back_ms\">" + + float2str(settings.latency_laid_back_ms.load()) + "</value>\n" " <value name=\"latency_stddev\">" + float2str(settings.latency_stddev.load()) + "</value>\n" " <value name=\"latency_regain\">" + @@ -667,9 +667,9 @@ bool DrumGizmoPlugin::ConfigStringIO::set(std::string config_string) // settings.latency_max.store(str2int(p.value("latency_max"))); //} - if(p.value("latency_laid_back") != "") + if(p.value("latency_laid_back_ms") != "") { - settings.latency_laid_back.store(str2int(p.value("latency_laid_back"))); + settings.latency_laid_back_ms.store(str2float(p.value("latency_laid_back_ms"))); } if(p.value("latency_stddev") != "") diff --git a/plugingui/humaniservisualiser.cc b/plugingui/humaniservisualiser.cc index a823c64..fd643d4 100644 --- a/plugingui/humaniservisualiser.cc +++ b/plugingui/humaniservisualiser.cc @@ -66,8 +66,9 @@ HumaniserVisualiser::Canvas::Canvas(GUI::Widget* parent, SettingsNotifier& settings_notifier) : GUI::Widget(parent) , settings_notifier(settings_notifier) - , latency_max_samples(settings.latency_max.load() * + , latency_max_samples(settings.latency_max_ms.load() * settings.samplerate.load() / 1000) + , settings(settings) { CONNECT(this, settings_notifier.enable_latency_modifier, this, &HumaniserVisualiser::Canvas::latencyEnabledChanged); @@ -81,7 +82,7 @@ HumaniserVisualiser::Canvas::Canvas(GUI::Widget* parent, CONNECT(this, settings_notifier.latency_stddev, this, &HumaniserVisualiser::Canvas::latencyStddevChanged); - CONNECT(this, settings_notifier.latency_laid_back, + CONNECT(this, settings_notifier.latency_laid_back_ms, this, &HumaniserVisualiser::Canvas::latencyLaidbackChanged); CONNECT(this, settings_notifier.velocity_stddev, this, &HumaniserVisualiser::Canvas::velocityStddevChanged); @@ -185,9 +186,9 @@ void HumaniserVisualiser::Canvas::latencyStddevChanged(float stddev) redraw(); } -void HumaniserVisualiser::Canvas::latencyLaidbackChanged(int laidback) +void HumaniserVisualiser::Canvas::latencyLaidbackChanged(float laidback_ms) { - this->laidback = laidback; + this->laidback = laidback_ms * settings.samplerate.load() / 1000; redraw(); } diff --git a/plugingui/humaniservisualiser.h b/plugingui/humaniservisualiser.h index 6ef39b9..576ae6f 100644 --- a/plugingui/humaniservisualiser.h +++ b/plugingui/humaniservisualiser.h @@ -66,7 +66,7 @@ private: void latencyOffsetChanged(int offset); void velocityOffsetChanged(float offset); void latencyStddevChanged(float stddev); - void latencyLaidbackChanged(int laidback); + void latencyLaidbackChanged(float laidback); void velocityStddevChanged(float stddev); GUI::Texture stddev_h{getImageCache(), ":resources/stddev_horizontal.png"}; @@ -84,6 +84,8 @@ private: float velocity_stddev; SettingsNotifier& settings_notifier; const int latency_max_samples; + + Settings& settings; }; Canvas canvas; diff --git a/plugingui/timingframecontent.cc b/plugingui/timingframecontent.cc index d02f86f..0a8d6d4 100644 --- a/plugingui/timingframecontent.cc +++ b/plugingui/timingframecontent.cc @@ -60,7 +60,7 @@ TimingframeContent::TimingframeContent(Widget* parent, laidback.resize(80, 80); laidback_knob.resize(30, 30); laidback_knob.showValue(false); - laidback_knob.setDefaultValue(laidbackSettingsToKnob(Settings::latency_laid_back_default)); + laidback_knob.setDefaultValue(laidbackSettingsToKnob(Settings::latency_laid_back_ms_default)); laidback.setControl(&laidback_knob); layout.addItem(&laidback); // set range to [-1, 1] @@ -75,7 +75,7 @@ TimingframeContent::TimingframeContent(Widget* parent, this, &TimingframeContent::tightnessSettingsValueChanged); CONNECT(this, settings_notifier.latency_regain, this, &TimingframeContent::regainSettingsValueChanged); - CONNECT(this, settings_notifier.latency_laid_back, + CONNECT(this, settings_notifier.latency_laid_back_ms, this, &TimingframeContent::laidbackSettingsValueChanged); CONNECT(&tightness_knob, valueChangedNotifier, @@ -104,20 +104,25 @@ float TimingframeContent::tightnessSettingsToKnob(float value) const return value; } + +static constexpr float laid_back_range = 100.0f; + float TimingframeContent::laidbackKnobToSettings(float value) const { + // knob in range [0, 1] settings in +/- laid_back_range ms value -= 0.5f; - value *= 4.0f; - value *= settings.latency_max.load(); + value *= 2.0f; + value *= laid_back_range; - return std::lround(value); + return value; } -float TimingframeContent::laidbackSettingsToKnob(int int_value) const +float TimingframeContent::laidbackSettingsToKnob(float value) const { - float value = int_value; - value /= (float)settings.latency_max.load(); - value /= 4.0f; + // settings in +/- laid_back_range ms knob in range [0, 1] + + value /= laid_back_range; + value /= 2.0f; value += 0.5f; return value; @@ -148,12 +153,12 @@ void TimingframeContent::regainSettingsValueChanged(float value) void TimingframeContent::laidbackKnobValueChanged(float value) { auto settings_value = laidbackKnobToSettings(value); - settings.latency_laid_back.store(settings_value); + settings.latency_laid_back_ms.store(settings_value); } -void TimingframeContent::laidbackSettingsValueChanged(int int_value) +void TimingframeContent::laidbackSettingsValueChanged(float value) { - auto knob_value = laidbackSettingsToKnob(int_value); + auto knob_value = laidbackSettingsToKnob(value); laidback_knob.setValue(knob_value); } diff --git a/plugingui/timingframecontent.h b/plugingui/timingframecontent.h index a8ed62c..282f08f 100644 --- a/plugingui/timingframecontent.h +++ b/plugingui/timingframecontent.h @@ -54,14 +54,14 @@ private: float thightnessKnobToSettings(float value) const; float tightnessSettingsToKnob(float value) const; float laidbackKnobToSettings(float value) const; - float laidbackSettingsToKnob(int int_value) const; + float laidbackSettingsToKnob(float value) const; void tightnessKnobValueChanged(float value); void tightnessSettingsValueChanged(float value); void regainKnobValueChanged(float value); void regainSettingsValueChanged(float value); void laidbackKnobValueChanged(float value); - void laidbackSettingsValueChanged(int value); + void laidbackSettingsValueChanged(float value); void latencyOffsetChanged(int offset); void velocityOffsetChanged(float offset); diff --git a/src/latencyfilter.cc b/src/latencyfilter.cc index 5cb6db2..abb67cd 100644 --- a/src/latencyfilter.cc +++ b/src/latencyfilter.cc @@ -47,9 +47,9 @@ static T1 getLatencySamples(T1 latency_ms, T2 samplerate) bool LatencyFilter::filter(event_t& event, std::size_t pos) { auto enabled = settings.enable_latency_modifier.load(); - auto latency_ms = settings.latency_max.load(); + auto latency_ms = settings.latency_max_ms.load(); auto samplerate = settings.samplerate.load(); - auto latency_laid_back = settings.latency_laid_back.load(); + auto latency_laid_back_ms = settings.latency_laid_back_ms.load(); auto latency_stddev = settings.latency_stddev.load(); auto latency_regain = settings.latency_regain.load(); @@ -59,6 +59,7 @@ bool LatencyFilter::filter(event_t& event, std::size_t pos) } auto latency = getLatencySamples(latency_ms, samplerate); + auto latency_laid_back = getLatencySamples(latency_laid_back_ms, samplerate); // Assert latency_regain is within range [0; 1]. assert(latency_regain >= 0.0f && latency_regain <= 1.0f); @@ -102,7 +103,7 @@ std::size_t LatencyFilter::getLatency() const bool enabled = settings.enable_latency_modifier.load(); if(enabled) { - auto latency_ms = settings.latency_max.load(); + auto latency_ms = settings.latency_max_ms.load(); auto samplerate = settings.samplerate.load(); return getLatencySamples(latency_ms, samplerate); } diff --git a/src/settings.h b/src/settings.h index b9d627a..6b4048c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -102,13 +102,14 @@ struct Settings Atomic<bool> enable_latency_modifier{false}; //! Maximum "early hits" introduces latency in milliseconds. - Atomic<std::size_t> latency_max{100u}; + Atomic<float> latency_max_ms{150.0f}; //! 0 := on-beat //! positive := laid back //! negative := up-beat - static int constexpr latency_laid_back_default = 0; - Atomic<int> latency_laid_back{latency_laid_back_default}; + //! Same range is [-100; 100] ms + static float constexpr latency_laid_back_ms_default = 0.0f; + Atomic<float> latency_laid_back_ms{latency_laid_back_ms_default}; //! 0 := Robot //! 100 := Good drummer @@ -172,8 +173,8 @@ struct SettingsGetter SettingRef<bool> has_bleed_control; SettingRef<bool> enable_latency_modifier; - SettingRef<std::size_t> latency_max; - SettingRef<int> latency_laid_back; + SettingRef<float> latency_max_ms; + SettingRef<float> latency_laid_back_ms; SettingRef<float> latency_stddev; SettingRef<float> latency_regain; SettingRef<int> latency_current; @@ -210,8 +211,8 @@ struct SettingsGetter , master_bleed{settings.master_bleed} , has_bleed_control{settings.has_bleed_control} , enable_latency_modifier{settings.enable_latency_modifier} - , latency_max{settings.latency_max} - , latency_laid_back{settings.latency_laid_back} + , latency_max_ms{settings.latency_max_ms} + , latency_laid_back_ms{settings.latency_laid_back_ms} , latency_stddev{settings.latency_stddev} , latency_regain{settings.latency_regain} , latency_current{settings.latency_current} @@ -263,8 +264,8 @@ public: Notifier<bool> has_bleed_control; Notifier<bool> enable_latency_modifier; - Notifier<std::size_t> latency_max; - Notifier<int> latency_laid_back; + Notifier<float> latency_max_ms; + Notifier<float> latency_laid_back_ms; Notifier<float> latency_stddev; Notifier<float> latency_regain; Notifier<int> latency_current; @@ -313,8 +314,8 @@ public: EVAL(has_bleed_control); EVAL(enable_latency_modifier); - EVAL(latency_max); - EVAL(latency_laid_back); + EVAL(latency_max_ms); + EVAL(latency_laid_back_ms); EVAL(latency_stddev); EVAL(latency_regain); EVAL(latency_current); |