summaryrefslogtreecommitdiff
path: root/src/settings.h
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-04-08 00:15:32 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-04-08 00:15:32 +0200
commit057ef1d83ba263fb2adf1aa86f8e281ab0065c43 (patch)
tree31c1f237e3a9df9fc241d87527f7dd4245665d43 /src/settings.h
parentb530ac02af61e320e137a392decef1b3cc5af2c4 (diff)
Refactoring to finally get rid of MessageHandler/Receiver in favor of the new Settings mechanism.
Diffstat (limited to 'src/settings.h')
-rw-r--r--src/settings.h123
1 files changed, 86 insertions, 37 deletions
diff --git a/src/settings.h b/src/settings.h
index b132c1b..c79e4e5 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -31,10 +31,25 @@
#include <cassert>
#include "atomic.h"
+#include "notifier.h"
+
+enum class LoadStatus : unsigned int
+{
+ Idle,
+ Loading,
+ Done,
+ Error
+};
//! Engine settings
struct Settings
{
+ Atomic<std::string> drumkit_file;
+ Atomic<LoadStatus> drumkit_load_status{LoadStatus::Idle};
+
+ Atomic<std::string> midimap_file;
+ Atomic<LoadStatus> midimap_load_status{LoadStatus::Idle};
+
Atomic<bool> enable_velocity_modifier{true};
Atomic<float> velocity_modifier_falloff{0.5f};
Atomic<float> velocity_modifier_weight{0.25f};
@@ -51,45 +66,15 @@ struct Settings
Atomic<std::string> current_file;
};
-//! Getter utility class.
-template <typename T> class SettingRef
+//! Settings getter class.
+struct SettingsGetter
{
-public:
- SettingRef(Atomic<T>& value)
- : value(value)
- {
- // string isn't lock free either
- assert((std::is_same<T, std::string>::value || value.is_lock_free()));
- }
-
- bool hasChanged()
- {
- T tmp = cache;
- cache.exchange(value);
-
- if(firstAccess)
- {
- firstAccess = false;
- return true;
- }
-
- return tmp != cache;
- }
-
- T getValue() const
- {
- return cache;
- }
+ SettingRef<std::string> drumkit_file;
+ SettingRef<LoadStatus> drumkit_load_status;
-private:
- bool firstAccess{true};
- Atomic<T>& value;
- Atomic<T> cache;
-};
+ SettingRef<std::string> midimap_file;
+ SettingRef<LoadStatus> midimap_load_status;
-//! Combined getter class.
-struct SettingsGetter
-{
SettingRef<bool> enable_velocity_modifier;
SettingRef<float> velocity_modifier_falloff;
SettingRef<float> velocity_modifier_weight;
@@ -106,7 +91,11 @@ struct SettingsGetter
SettingRef<std::string> current_file;
SettingsGetter(Settings& settings)
- : enable_velocity_modifier{settings.enable_velocity_modifier}
+ : drumkit_file(settings.drumkit_file)
+ , drumkit_load_status(settings.drumkit_load_status)
+ , midimap_file(settings.midimap_file)
+ , midimap_load_status(settings.midimap_load_status)
+ , enable_velocity_modifier{settings.enable_velocity_modifier}
, velocity_modifier_falloff{settings.velocity_modifier_falloff}
, velocity_modifier_weight{settings.velocity_modifier_weight}
, enable_velocity_randomiser{settings.enable_velocity_randomiser}
@@ -120,6 +109,66 @@ struct SettingsGetter
}
};
+//! Settings change notifier class.
+class SettingsNotifier
+{
+public:
+ Notifier<std::string> drumkit_file;
+ Notifier<LoadStatus> drumkit_load_status;
+
+ Notifier<std::string> midimap_file;
+ Notifier<LoadStatus> midimap_load_status;
+
+ Notifier<bool> enable_velocity_modifier;
+ Notifier<float> velocity_modifier_falloff;
+ Notifier<float> velocity_modifier_weight;
+
+ Notifier<bool> enable_velocity_randomiser;
+ Notifier<float> velocity_randomiser_weight;
+
+ Notifier<double> samplerate;
+
+ Notifier<bool> enable_resampling;
+
+ Notifier<int> number_of_files;
+ Notifier<int> number_of_files_loaded;
+ Notifier<std::string> current_file;
+
+ void evaluate()
+ {
+#define EVAL(x) if(settings.x.hasChanged()) { x(settings.x.getValue()); }
+
+ EVAL(drumkit_file);
+ EVAL(drumkit_load_status);
+
+ EVAL(midimap_file);
+ EVAL(midimap_load_status);
+
+ EVAL(enable_velocity_modifier);
+ EVAL(velocity_modifier_falloff);
+ EVAL(velocity_modifier_weight);
+
+ EVAL(enable_velocity_randomiser);
+ EVAL(velocity_randomiser_weight);
+
+ EVAL(samplerate);
+
+ EVAL(enable_resampling);
+
+ EVAL(number_of_files);
+ EVAL(number_of_files_loaded);
+ EVAL(current_file);
+ }
+
+ SettingsNotifier(Settings& settings)
+ : settings(settings)
+ {
+ }
+
+private:
+ SettingsGetter settings;
+};
+
// lovely reminder: NO, GLOCKE. NOOOO!!
/*
enum class IntParams {