summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
5 files changed, 110 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b656f48..3e691b1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,6 +75,7 @@ libdg_la_SOURCES = \
staminafilter.cc \
thread.cc \
velocityfilter.cc \
+ positionfilter.cc \
versionstr.cc
EXTRA_DIST = \
@@ -138,5 +139,6 @@ 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 9fcff65..a883286 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 d4a2295..0b7c5de 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -75,6 +75,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;
@@ -82,6 +83,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};
@@ -201,6 +203,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;
@@ -277,6 +280,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}
@@ -348,6 +352,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;
@@ -428,6 +433,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);