From 9c5efc23764522597a53a8745860cec54ea55d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Fri, 22 Mar 2019 01:09:15 +0100 Subject: Add settings and GUI for new sampling algorithm. --- plugin/drumgizmo_plugin.cc | 21 ++++++++++ plugin/drumgizmo_plugin.h | 2 +- plugingui/humanizerframecontent.cc | 82 +++++++++++++++++++++++++++++++------- plugingui/humanizerframecontent.h | 21 ++++++++-- plugingui/maintab.cc | 2 +- plugingui/maintab.h | 2 +- plugingui/testmain.cc | 4 +- src/powerlist.cc | 2 + src/sample_selection.cc | 7 ++-- src/settings.h | 21 +++++++++- 10 files changed, 138 insertions(+), 26 deletions(-) diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc index 94302a1..acbb5a9 100644 --- a/plugin/drumgizmo_plugin.cc +++ b/plugin/drumgizmo_plugin.cc @@ -593,6 +593,12 @@ std::string DrumGizmoPlugin::ConfigStringIO::get() float2str(settings.velocity_modifier_weight.load()) + "\n" " " + float2str(settings.velocity_stddev.load()) + "\n" + " " + + float2str(settings.sample_selection_f_distance.load()) + "\n" + " " + + float2str(settings.sample_selection_f_recent.load()) + "\n" + " " + + float2str(settings.sample_selection_f_random.load()) + "\n" " " + bool2str(settings.enable_velocity_randomiser.load()) + "\n" " " + @@ -654,6 +660,21 @@ bool DrumGizmoPlugin::ConfigStringIO::set(std::string config_string) settings.velocity_stddev.store(str2float(p.value("velocity_stddev"))); } + if(p.value("sample_selection_f_distance") != "") + { + settings.sample_selection_f_distance.store(str2float(p.value("sample_selection_f_distance"))); + } + + if(p.value("sample_selection_f_recent") != "") + { + settings.sample_selection_f_recent.store(str2float(p.value("sample_selection_f_recent"))); + } + + if(p.value("sample_selection_f_random") != "") + { + settings.sample_selection_f_random.store(str2float(p.value("sample_selection_f_random"))); + } + if(p.value("enable_velocity_randomiser") != "") { settings.enable_velocity_randomiser.store(p.value("enable_velocity_randomiser") == "true"); diff --git a/plugin/drumgizmo_plugin.h b/plugin/drumgizmo_plugin.h index b422430..2f271c6 100644 --- a/plugin/drumgizmo_plugin.h +++ b/plugin/drumgizmo_plugin.h @@ -213,5 +213,5 @@ private: bool inline_image_first_draw{true}; static constexpr std::size_t width{750}; - static constexpr std::size_t height{613}; + static constexpr std::size_t height{733}; }; diff --git a/plugingui/humanizerframecontent.cc b/plugingui/humanizerframecontent.cc index 206d77d..db3fd97 100644 --- a/plugingui/humanizerframecontent.cc +++ b/plugingui/humanizerframecontent.cc @@ -59,13 +59,37 @@ HumanizerframeContent::HumanizerframeContent(Widget* parent, stddev.resize(80, 80); stddev_knob.resize(30, 30); stddev_knob.showValue(false); - stddev_knob.setDefaultValue(stddevSettingsToKnob(Settings::velocity_stddev_default)); + stddev_knob.setDefaultValue(Settings::velocity_stddev_default/stddev_factor); stddev.setControl(&stddev_knob); layout.addItem(&stddev); + f_distance.resize(80, 80); + f_distance_knob.resize(30, 30); + f_distance_knob.showValue(false); + f_distance_knob.setDefaultValue(Settings::sample_selection_f_distance_default/f_distance_factor); + f_distance.setControl(&f_distance_knob); + layout.addItem(&f_distance); + + f_recent.resize(80, 80); + f_recent_knob.resize(30, 30); + f_recent_knob.showValue(false); + f_recent_knob.setDefaultValue(Settings::sample_selection_f_recent_default/f_recent_factor); + f_recent.setControl(&f_recent_knob); + layout.addItem(&f_recent); + + f_random.resize(80, 80); + f_random_knob.resize(30, 30); + f_random_knob.showValue(false); + f_random_knob.setDefaultValue(Settings::sample_selection_f_random_default/f_random_factor); + f_random.setControl(&f_random_knob); + layout.addItem(&f_random); + layout.setPosition(&attack, GridLayout::GridRange{0, 1, 0, 1}); layout.setPosition(&falloff, GridLayout::GridRange{1, 2, 0, 1}); layout.setPosition(&stddev, GridLayout::GridRange{2, 3, 0, 1}); + layout.setPosition(&f_distance, GridLayout::GridRange{0, 1, 1, 2}); + layout.setPosition(&f_recent, GridLayout::GridRange{1, 2, 1, 2}); + layout.setPosition(&f_random, GridLayout::GridRange{2, 3, 1, 2}); CONNECT(this, settings_notifier.velocity_modifier_weight, &attack_knob, &Knob::setValue); @@ -73,6 +97,12 @@ HumanizerframeContent::HumanizerframeContent(Widget* parent, &falloff_knob, &Knob::setValue); CONNECT(this, settings_notifier.velocity_stddev, this, &HumanizerframeContent::stddevSettingsValueChanged); + CONNECT(this, settings_notifier.sample_selection_f_distance, + this, &HumanizerframeContent::fDistanceSettingsValueChanged); + CONNECT(this, settings_notifier.sample_selection_f_recent, + this, &HumanizerframeContent::fRecentSettingsValueChanged); + CONNECT(this, settings_notifier.sample_selection_f_random, + this, &HumanizerframeContent::fRandomSettingsValueChanged); CONNECT(&attack_knob, valueChangedNotifier, this, &HumanizerframeContent::attackValueChanged); @@ -80,38 +110,62 @@ HumanizerframeContent::HumanizerframeContent(Widget* parent, this, &HumanizerframeContent::falloffValueChanged); CONNECT(&stddev_knob, valueChangedNotifier, this, &HumanizerframeContent::stddevKnobValueChanged); + CONNECT(&f_distance_knob, valueChangedNotifier, + this, &HumanizerframeContent::fDistanceKnobValueChanged); + CONNECT(&f_recent_knob, valueChangedNotifier, + this, &HumanizerframeContent::fRecentKnobValueChanged); + CONNECT(&f_random_knob, valueChangedNotifier, + this, &HumanizerframeContent::fRandomKnobValueChanged); } -float HumanizerframeContent::stddevSettingsToKnob(float value) const +void HumanizerframeContent::attackValueChanged(float value) { - return value / 4.5f; + settings.velocity_modifier_weight.store(value); } -float HumanizerframeContent::stddevKnobToSettings(float value) const +void HumanizerframeContent::falloffValueChanged(float value) { - return value * 4.5f; + settings.velocity_modifier_falloff.store(value); } -void HumanizerframeContent::attackValueChanged(float value) +void HumanizerframeContent::stddevKnobValueChanged(float value) { - settings.velocity_modifier_weight.store(value); + settings.velocity_stddev.store(value*stddev_factor); } -void HumanizerframeContent::falloffValueChanged(float value) +void HumanizerframeContent::fDistanceKnobValueChanged(float value) { - settings.velocity_modifier_falloff.store(value); + settings.sample_selection_f_distance.store(value*f_distance_factor); } -void HumanizerframeContent::stddevKnobValueChanged(float value) +void HumanizerframeContent::fRecentKnobValueChanged(float value) { - auto settings_value = stddevKnobToSettings(value); - settings.velocity_stddev.store(settings_value); + settings.sample_selection_f_recent.store(value*f_recent_factor); +} + +void HumanizerframeContent::fRandomKnobValueChanged(float value) +{ + settings.sample_selection_f_random.store(value*f_random_factor); } void HumanizerframeContent::stddevSettingsValueChanged(float value) { - auto knob_value = stddevSettingsToKnob(value); - stddev_knob.setValue(knob_value); + stddev_knob.setValue(value/stddev_factor); +} + +void HumanizerframeContent::fDistanceSettingsValueChanged(float value) +{ + f_distance_knob.setValue(value/f_distance_factor); +} + +void HumanizerframeContent::fRecentSettingsValueChanged(float value) +{ + f_recent_knob.setValue(value/f_recent_factor); +} + +void HumanizerframeContent::fRandomSettingsValueChanged(float value) +{ + f_random_knob.setValue(value/f_random_factor); } } // GUI:: diff --git a/plugingui/humanizerframecontent.h b/plugingui/humanizerframecontent.h index 4befae0..e8c0810 100644 --- a/plugingui/humanizerframecontent.h +++ b/plugingui/humanizerframecontent.h @@ -46,23 +46,38 @@ public: SettingsNotifier& settings_notifier); private: - float stddevSettingsToKnob(float value) const; - float stddevKnobToSettings(float value) const; + static float constexpr stddev_factor = 4.5f; + static float constexpr f_distance_factor = 4.f; + static float constexpr f_recent_factor = 1.f; + static float constexpr f_random_factor = .5f; void attackValueChanged(float value); void falloffValueChanged(float value); void stddevKnobValueChanged(float value); + void fDistanceKnobValueChanged(float value); + void fRecentKnobValueChanged(float value); + void fRandomKnobValueChanged(float value); + void stddevSettingsValueChanged(float value); + void fDistanceSettingsValueChanged(float value); + void fRecentSettingsValueChanged(float value); + void fRandomSettingsValueChanged(float value); - GridLayout layout{this, 3, 1}; + GridLayout layout{this, 3, 2}; LabeledControl attack{this, "Attack"}; // drummer strength LabeledControl falloff{this, "Release"}; // regain LabeledControl stddev{this, "StdDev"}; + LabeledControl f_distance{this, "fDistance"}; + LabeledControl f_recent{this, "fRecent"}; + LabeledControl f_random{this, "fRandom"}; Knob attack_knob{&attack}; Knob falloff_knob{&falloff}; Knob stddev_knob{&stddev}; + Knob f_distance_knob{&f_distance}; + Knob f_recent_knob{&f_recent}; + Knob f_random_knob{&f_random}; Settings& settings; SettingsNotifier& settings_notifier; diff --git a/plugingui/maintab.cc b/plugingui/maintab.cc index 1cf445a..4b65092 100644 --- a/plugingui/maintab.cc +++ b/plugingui/maintab.cc @@ -52,7 +52,7 @@ MainTab::MainTab(Widget* parent, add("Status", status_frame, statusframe_content, 24, 0); add("Resampling", resampling_frame, resamplingframe_content, 10, 0); - add("Velocity Humanizer", humanizer_frame, humanizerframe_content, 10, 1); + add("Velocity Humanizer", humanizer_frame, humanizerframe_content, 20, 1); humanizer_frame.setHelpText("Hello World\nThis is a nice World\n... I think"); add("Timing Humanizer", timing_frame, timingframe_content, 10, 1); add("Visualizer", visualizer_frame, visualizerframe_content, 10, 1); diff --git a/plugingui/maintab.h b/plugingui/maintab.h index 7daa669..897326a 100644 --- a/plugingui/maintab.h +++ b/plugingui/maintab.h @@ -65,7 +65,7 @@ private: Image logo{":resources/logo.png"}; - GridLayout layout{this, 2, 49}; + GridLayout layout{this, 2, 59}; FrameWidget drumkit_frame{this, false}; FrameWidget status_frame{this, false}; diff --git a/plugingui/testmain.cc b/plugingui/testmain.cc index b122756..319abf6 100644 --- a/plugingui/testmain.cc +++ b/plugingui/testmain.cc @@ -57,9 +57,9 @@ int main() // TODO: automatically use drumgizmo_plugin.h size here #ifndef UI_PUGL - parent.resize(750, 613); + parent.resize(750, 733); #else - main_window.resize(750, 613); + main_window.resize(750, 733); #endif while(true) diff --git a/src/powerlist.cc b/src/powerlist.cc index a0510ad..c78b071 100644 --- a/src/powerlist.cc +++ b/src/powerlist.cc @@ -65,6 +65,7 @@ void PowerList::add(Sample* sample) samples.push_back(item); } +// FIXME: remove all? const Channel* PowerList::getMasterChannel() { std::map count; @@ -129,6 +130,7 @@ const Channel* PowerList::getMasterChannel() return master; } +// FIXME: clean up significantly! void PowerList::finalise() { #ifdef AUTO_CALCULATE_POWER diff --git a/src/sample_selection.cc b/src/sample_selection.cc index 6e956df..92c4efc 100644 --- a/src/sample_selection.cc +++ b/src/sample_selection.cc @@ -79,6 +79,7 @@ const Sample* SampleSelection::get(level_t level, std::size_t pos) } } +// FIXME: remove before release and adapt everything const Sample* SampleSelection::getOld(level_t level, std::size_t pos) { auto velocity_stddev = settings.velocity_stddev.load(); @@ -176,9 +177,9 @@ const Sample* SampleSelection::getObjective(level_t level, std::size_t pos) DEBUG(rand, "level: %f, lvl: %f (mean: %.2f, stddev: %.2f," "power_min: %f, power_max: %f)\n", level, lvl, mean, stddev, power_min, power_max); - const float f_distance = 2.0; - const float f_recent = 1.0; - const float f_random = .05; + const float f_distance = settings.sample_selection_f_distance.load(); + const float f_recent = settings.sample_selection_f_recent.load(); + const float f_random = settings.sample_selection_f_random.load(); // start with most promising power value and then stop when reaching far values // which cannot become opt anymore diff --git a/src/settings.h b/src/settings.h index 4a7d904..6abbc72 100644 --- a/src/settings.h +++ b/src/settings.h @@ -75,13 +75,20 @@ 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 = 1.0f; + static float constexpr sample_selection_f_distance_default = 2.f; + static float constexpr sample_selection_f_recent_default = .3f; + static float constexpr sample_selection_f_random_default = 0.05f; Atomic velocity_modifier_falloff{velocity_modifier_falloff_default}; Atomic velocity_modifier_weight{velocity_modifier_weight_default}; - Atomic velocity_stddev{velocity_stddev_default}; // [0.5; 3.0] + Atomic velocity_stddev{velocity_stddev_default}; + Atomic sample_selection_f_distance{sample_selection_f_distance_default}; + Atomic sample_selection_f_recent{sample_selection_f_recent_default}; + Atomic sample_selection_f_random{sample_selection_f_random_default}; //! Control number of times to retry sample selection as long as the sample //! is the same one as the last one. //! 0: will do no retries, ie. just use the first sample found. + // FIXME: remove when new sample algorithm is introduced and also remove other occurences static std::size_t constexpr sample_selection_retry_count_default = 3; Atomic sample_selection_retry_count{sample_selection_retry_count_default}; @@ -163,6 +170,9 @@ struct SettingsGetter SettingRef velocity_modifier_falloff; SettingRef velocity_modifier_weight; SettingRef velocity_stddev; + SettingRef sample_selection_f_distance; + SettingRef sample_selection_f_recent; + SettingRef sample_selection_f_random; SettingRef sample_selection_retry_count; @@ -214,6 +224,9 @@ struct SettingsGetter , velocity_modifier_falloff{settings.velocity_modifier_falloff} , velocity_modifier_weight{settings.velocity_modifier_weight} , velocity_stddev{settings.velocity_stddev} + , sample_selection_f_distance{settings.sample_selection_f_distance} + , sample_selection_f_recent{settings.sample_selection_f_recent} + , sample_selection_f_random{settings.sample_selection_f_random} , sample_selection_retry_count(settings.sample_selection_retry_count) , velocity_modifier_current{settings.velocity_modifier_current} , enable_velocity_randomiser{settings.enable_velocity_randomiser} @@ -265,6 +278,9 @@ public: Notifier velocity_modifier_falloff; Notifier velocity_modifier_weight; Notifier velocity_stddev; + Notifier sample_selection_f_distance; + Notifier sample_selection_f_recent; + Notifier sample_selection_f_random; Notifier sample_selection_retry_count; Notifier velocity_modifier_current; @@ -320,6 +336,9 @@ public: EVAL(velocity_modifier_falloff); EVAL(velocity_modifier_weight); EVAL(velocity_stddev); + EVAL(sample_selection_f_distance); + EVAL(sample_selection_f_recent); + EVAL(sample_selection_f_random); EVAL(sample_selection_retry_count); EVAL(velocity_modifier_current); -- cgit v1.2.3