summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugingui/humaniservisualiser.cc13
-rw-r--r--plugingui/humaniservisualiser.h6
-rw-r--r--src/latencyfilter.cc9
-rw-r--r--src/settings.h8
4 files changed, 21 insertions, 15 deletions
diff --git a/plugingui/humaniservisualiser.cc b/plugingui/humaniservisualiser.cc
index f0c016a..92da164 100644
--- a/plugingui/humaniservisualiser.cc
+++ b/plugingui/humaniservisualiser.cc
@@ -66,8 +66,7 @@ HumaniserVisualiser::Canvas::Canvas(GUI::Widget* parent,
SettingsNotifier& settings_notifier)
: GUI::Widget(parent)
, settings_notifier(settings_notifier)
- , latency_max_samples(settings.latency_max_ms.load() *
- settings.samplerate.load() / 1000)
+ , latency_max_ms(settings.latency_max_ms.load())
, settings(settings)
{
CONNECT(this, settings_notifier.enable_latency_modifier,
@@ -99,16 +98,16 @@ void HumaniserVisualiser::Canvas::repaintEvent(GUI::RepaintEvent *repaintEvent)
p.clear();
- const int spx = latency_max_samples * 2 / width(); // samples pr. pixel
+ const float mspx = latency_max_ms * 2 / width(); // ms pr. pixel
- int x = latency_offset / spx + width() / 2;
+ int x = latency_offset / mspx + width() / 2;
float v = (-1.0f * velocity_offset + 1.0f) * 0.8;
int y = height() * 0.2 + v * height();
y = std::max(0, y);
- int w = 50.f * latency_stddev / spx * 3 * 2; // stddev is ~ +/- 3 span
+ int w = (3. * 2.) * latency_stddev / mspx; // stddev is ~ +/- 3 span
int h = velocity_stddev * height() / 4;
- DEBUG(vis, "max: %d, spx: %d, x: %d, w: %d", latency_max_samples, spx, x, w);
+ DEBUG(vis, "max: %f, mspx: %f, x: %d, w: %d", latency_max_ms, mspx, x, w);
// Stddev squares
if(latency_enabled)
@@ -168,7 +167,7 @@ void HumaniserVisualiser::Canvas::velocityEnabledChanged(bool enabled)
redraw();
}
-void HumaniserVisualiser::Canvas::latencyOffsetChanged(int offset)
+void HumaniserVisualiser::Canvas::latencyOffsetChanged(float offset)
{
latency_offset = offset;
redraw();
diff --git a/plugingui/humaniservisualiser.h b/plugingui/humaniservisualiser.h
index 576ae6f..55e37d2 100644
--- a/plugingui/humaniservisualiser.h
+++ b/plugingui/humaniservisualiser.h
@@ -63,7 +63,7 @@ private:
void latencyEnabledChanged(bool enabled);
void velocityEnabledChanged(bool enabled);
- void latencyOffsetChanged(int offset);
+ void latencyOffsetChanged(float offset);
void velocityOffsetChanged(float offset);
void latencyStddevChanged(float stddev);
void latencyLaidbackChanged(float laidback);
@@ -77,13 +77,13 @@ private:
bool latency_enabled{false};
bool velocity_enabled{false};
- int latency_offset;
+ float latency_offset;
float velocity_offset;
float latency_stddev;
int laidback;
float velocity_stddev;
SettingsNotifier& settings_notifier;
- const int latency_max_samples;
+ const float latency_max_ms;
Settings& settings;
};
diff --git a/src/latencyfilter.cc b/src/latencyfilter.cc
index 9410b50..0f3259b 100644
--- a/src/latencyfilter.cc
+++ b/src/latencyfilter.cc
@@ -44,6 +44,12 @@ static T1 getLatencySamples(T1 latency_ms, T2 samplerate)
return latency_ms * samplerate / 1000.;
}
+template<typename T1, typename T2>
+static T1 getLatencyMs(T1 latency_samples, T2 samplerate)
+{
+ return 1000. * latency_samples / samplerate;
+}
+
bool LatencyFilter::filter(event_t& event, std::size_t pos)
{
auto enabled = settings.enable_latency_modifier.load();
@@ -86,7 +92,8 @@ bool LatencyFilter::filter(event_t& event, std::size_t pos)
event.offset += latency_laid_back; // laid back offset (user controlled)
event.offset += latency_offset; // current drift
- settings.latency_current.store(latency_offset + latency_laid_back);
+ auto latency_current_ms = getLatencyMs(latency_offset + latency_laid_back, samplerate);
+ settings.latency_current.store(latency_current_ms);
return true;
}
diff --git a/src/settings.h b/src/settings.h
index f37a810..e698d20 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -126,8 +126,8 @@ struct Settings
static float constexpr latency_regain_default = 0.9f;
Atomic<float> latency_regain{latency_regain_default};
- // Current latency offset - for UI
- Atomic<int> latency_current{0};
+ // Current latency offset in ms - for UI
+ Atomic<float> latency_current{0};
};
//! Settings getter class.
@@ -177,7 +177,7 @@ struct SettingsGetter
SettingRef<float> latency_laid_back_ms;
SettingRef<float> latency_stddev;
SettingRef<float> latency_regain;
- SettingRef<int> latency_current;
+ SettingRef<float> latency_current;
SettingsGetter(Settings& settings)
: drumkit_file(settings.drumkit_file)
@@ -268,7 +268,7 @@ public:
Notifier<float> latency_laid_back_ms;
Notifier<float> latency_stddev;
Notifier<float> latency_regain;
- Notifier<int> latency_current;
+ Notifier<float> latency_current;
void evaluate()
{