From 4e83b447020c8ddce7e8b4f2b591dc42585df138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Mon, 22 Jul 2019 22:15:46 +0200 Subject: Fix humanizer bug and simplify stamina filter code. --- src/staminafilter.cc | 21 ++++++++------------- src/velocityfilter.cc | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/staminafilter.cc b/src/staminafilter.cc index a8f6a86..5f7599a 100644 --- a/src/staminafilter.cc +++ b/src/staminafilter.cc @@ -41,31 +41,26 @@ bool StaminaFilter::filter(event_t& event, size_t pos) auto enable_velocity_modifier = settings.enable_velocity_modifier.load(); auto velocity_modifier_weight = settings.velocity_modifier_weight.load(); + auto& pair = modifiers[event.instrument]; + if(modifiers.find(event.instrument) == modifiers.end()) { // On first lookup make sure we have sane values. - auto& pair = modifiers[event.instrument]; pair.first = 1.0f; pair.second = 0; } - - auto& pair = modifiers[event.instrument]; auto& mod = pair.first; auto& lastpos = pair.second; - if(enable_velocity_modifier == false) - { - mod = 1.0f; - lastpos = 0; - } - if(enable_velocity_modifier) { mod += (pos - lastpos) / (samplerate * velocity_modifier_falloff); - if(mod > 1.0f) - { - mod = 1.0f; - } + mod = std::min(mod, 1.0f); + } + else + { + mod = 1.0f; + lastpos = 0; } event.velocity *= mod; diff --git a/src/velocityfilter.cc b/src/velocityfilter.cc index a983692..81587d5 100644 --- a/src/velocityfilter.cc +++ b/src/velocityfilter.cc @@ -41,7 +41,7 @@ bool VelocityFilter::filter(event_t& event, size_t pos) float mean = event.velocity; float stddev = settings.velocity_stddev.load(); // the 30.0f were determined empirically - event.velocity += random.normalDistribution(mean, stddev / 30.0f); + event.velocity = random.normalDistribution(mean, stddev / 30.0f); } return true; -- cgit v1.2.3