summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Nusser <anusser@mpi-inf.mpg.de>2021-02-13 13:17:39 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2024-07-22 11:26:42 +0200
commitb5f155ee26df89e7447735e37d1f9c7ffd877843 (patch)
treece9d1903e961785c6093c1eeec37d5006567efc9
parent39e841af517c0c82a54702eeafb7651e03260601 (diff)
Add position filter.
-rw-r--r--plugin/Makefile.mingw32.in1
-rw-r--r--src/Makefile.am2
-rw-r--r--src/inputprocessor.cc2
-rw-r--r--src/positionfilter.cc48
-rw-r--r--src/positionfilter.h52
-rw-r--r--src/settings.h6
6 files changed, 111 insertions, 0 deletions
diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in
index ad47bcc..1b8c848 100644
--- a/plugin/Makefile.mingw32.in
+++ b/plugin/Makefile.mingw32.in
@@ -49,6 +49,7 @@ DG_SRC = \
@top_srcdir@/src/thread.cc \
@top_srcdir@/src/translation.cc \
@top_srcdir@/src/velocityfilter.cc \
+ @top_srcdir@/src/positionfilter.cc \
@top_srcdir@/src/versionstr.cc
DG_CFLAGS = -I@top_srcdir@ -I@top_srcdir@/src \
-I@top_srcdir@/zita-resampler/libs \
diff --git a/src/Makefile.am b/src/Makefile.am
index a8bdb59..31ce8da 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -76,6 +76,7 @@ libdg_la_SOURCES = \
$(top_srcdir)/src/staminafilter.cc \
$(top_srcdir)/src/thread.cc \
$(top_srcdir)/src/velocityfilter.cc \
+ $(top_srcdir)/src/positionfilter.cc \
$(top_srcdir)/src/versionstr.cc
EXTRA_DIST = \
@@ -140,6 +141,7 @@ EXTRA_DIST = \
thread.h \
translation.h \
velocityfilter.h \
+ positionfilter.h \
versionstr.h \
zrwrapper.h
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index deae8ad..fa3498c 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -36,6 +36,7 @@
#include "powermapfilter.h"
#include "staminafilter.h"
#include "velocityfilter.h"
+#include "positionfilter.h"
#include "cpp11fix.h"
@@ -93,6 +94,7 @@ InputProcessor::InputProcessor(Settings& settings,
filters.emplace_back(std::make_unique<StaminaFilter>(settings));
filters.emplace_back(std::make_unique<LatencyFilter>(settings, random));
filters.emplace_back(std::make_unique<VelocityFilter>(settings, random));
+ filters.emplace_back(std::make_unique<PositionFilter>(settings, random));
filters.emplace_back(std::make_unique<Reporter>(settings, original_velocity));
}
diff --git a/src/positionfilter.cc b/src/positionfilter.cc
new file mode 100644
index 0000000..8d2f987
--- /dev/null
+++ b/src/positionfilter.cc
@@ -0,0 +1,48 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * positionfilter.cc
+ *
+ * Sat 13 Feb 2021 12:46:41 CET
+ * Copyright 2019 André Nusser
+ * andre.nusser@googlemail.com
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "positionfilter.h"
+
+#include "random.h"
+#include "settings.h"
+
+PositionFilter::PositionFilter(Settings& settings, Random& random)
+ : settings(settings), random(random)
+{
+}
+
+bool PositionFilter::filter(event_t& event, size_t pos)
+{
+ if (settings.enable_velocity_modifier.load())
+ {
+ float mean = event.position;
+ float stddev = settings.position_stddev.load();
+ // the 30.0f were determined empirically
+ event.position = random.normalDistribution(mean, stddev / 30.0f); // FIXME: right magic value?
+ }
+
+ return true;
+}
diff --git a/src/positionfilter.h b/src/positionfilter.h
new file mode 100644
index 0000000..ac989f6
--- /dev/null
+++ b/src/positionfilter.h
@@ -0,0 +1,52 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * positionfilter.h
+ *
+ * Sat 13 Feb 2021 12:46:41 CET
+ * Copyright 2019 André Nusser
+ * andre.nusser@googlemail.com
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#pragma once
+
+#include <cstddef>
+#include <map>
+#include <utility>
+
+#include "inputfilter.h"
+#include "instrument.h"
+
+struct Settings;
+class Random;
+
+class PositionFilter
+ : public InputFilter
+{
+public:
+ PositionFilter(Settings& settings, Random& random);
+
+ bool filter(event_t& event, std::size_t pos) override;
+
+ // Note getLatency not overloaded because this filter doesn't add latency.
+
+private:
+ Settings& settings;
+ Random& random;
+};
diff --git a/src/settings.h b/src/settings.h
index a423ae3..5c2e4ee 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -76,6 +76,7 @@ struct Settings
static float constexpr velocity_modifier_falloff_default = 0.5f;
static float constexpr velocity_modifier_weight_default = 0.25f;
static float constexpr velocity_stddev_default = .45f;
+ static float constexpr position_stddev_default = 0.f; // FIXME: set to something sensible
static float constexpr sample_selection_f_close_default = .85f;
static float constexpr sample_selection_f_position_default = 1.f;
static float constexpr sample_selection_f_diverse_default = .16f;
@@ -83,6 +84,7 @@ struct Settings
Atomic<float> velocity_modifier_falloff{velocity_modifier_falloff_default};
Atomic<float> velocity_modifier_weight{velocity_modifier_weight_default};
Atomic<float> velocity_stddev{velocity_stddev_default};
+ Atomic<float> position_stddev{position_stddev_default};
Atomic<float> sample_selection_f_close{sample_selection_f_close_default};
Atomic<float> sample_selection_f_position{sample_selection_f_position_default};
Atomic<float> sample_selection_f_diverse{sample_selection_f_diverse_default};
@@ -202,6 +204,7 @@ struct SettingsGetter
SettingRef<float> velocity_modifier_falloff;
SettingRef<float> velocity_modifier_weight;
SettingRef<float> velocity_stddev;
+ SettingRef<float> position_stddev;
SettingRef<float> sample_selection_f_close;
SettingRef<float> sample_selection_f_position;
SettingRef<float> sample_selection_f_diverse;
@@ -278,6 +281,7 @@ struct SettingsGetter
, velocity_modifier_falloff{settings.velocity_modifier_falloff}
, velocity_modifier_weight{settings.velocity_modifier_weight}
, velocity_stddev{settings.velocity_stddev}
+ , position_stddev{settings.position_stddev}
, sample_selection_f_close{settings.sample_selection_f_close}
, sample_selection_f_position{settings.sample_selection_f_position}
, sample_selection_f_diverse{settings.sample_selection_f_diverse}
@@ -349,6 +353,7 @@ public:
Notifier<float> velocity_modifier_falloff;
Notifier<float> velocity_modifier_weight;
Notifier<float> velocity_stddev;
+ Notifier<float> position_stddev;
Notifier<float> sample_selection_f_close;
Notifier<float> sample_selection_f_position;
Notifier<float> sample_selection_f_diverse;
@@ -429,6 +434,7 @@ public:
EVAL(velocity_modifier_falloff);
EVAL(velocity_modifier_weight);
EVAL(velocity_stddev);
+ EVAL(position_stddev);
EVAL(sample_selection_f_close);
EVAL(sample_selection_f_position);
EVAL(sample_selection_f_diverse);