diff --git a/firmware/src/gui/pages/prefs_tab.hh b/firmware/src/gui/pages/prefs_tab.hh index 542cf4ed7..44d0a61d7 100644 --- a/firmware/src/gui/pages/prefs_tab.hh +++ b/firmware/src/gui/pages/prefs_tab.hh @@ -103,6 +103,9 @@ struct PrefsTab : SystemMenuTab { lv_group_focus_obj(ui_SystemPrefsAudioSampleRateDropdown); lv_group_set_editing(group, true); + //todo: implement this + lv_hide(ui_SystemPrefsCatchupExcludeButtonsCont); + update_dropdowns_from_settings(); } @@ -213,6 +216,7 @@ struct PrefsTab : SystemMenuTab { if (catchup.mode != catchupmode || catchup.button_exclude != catchup_exclude_buttons) { catchup.mode = catchupmode; catchup.button_exclude = catchup_exclude_buttons; + patch_playloader.set_all_param_catchup_mode(catchup.mode, catchup.button_exclude); gui_state.do_write_settings = true; } diff --git a/firmware/src/gui/ui.hh b/firmware/src/gui/ui.hh index 8df43c045..80880278a 100644 --- a/firmware/src/gui/ui.hh +++ b/firmware/src/gui/ui.hh @@ -69,6 +69,7 @@ public: } patch_playloader.request_new_audio_settings(settings.audio.sample_rate, settings.audio.block_size); + patch_playloader.set_all_param_catchup_mode(settings.catchup.mode, settings.catchup.button_exclude); } void update_screen() { diff --git a/firmware/src/medium/conf/catchup_settings.hh b/firmware/src/medium/conf/catchup_settings.hh index 4bbbb866f..d4a26d645 100644 --- a/firmware/src/medium/conf/catchup_settings.hh +++ b/firmware/src/medium/conf/catchup_settings.hh @@ -1,5 +1,5 @@ #pragma once -#include "catchup_param.hh" +#include "params/catchup_param.hh" #include #include #include @@ -34,7 +34,7 @@ struct CatchupSettings { mode = DefaultMode; // Check if deserialized data contains a value other than 0 or 1 - if (*reinterpret_cast(&button_exclude) != 0) + if (*reinterpret_cast(&button_exclude) != 0) button_exclude = true; else button_exclude = false; diff --git a/firmware/src/patch_play/patch_player.hh b/firmware/src/patch_play/patch_player.hh index fb0576a79..7403bac97 100644 --- a/firmware/src/patch_play/patch_player.hh +++ b/firmware/src/patch_play/patch_player.hh @@ -791,6 +791,9 @@ public: // Set mode for one mapping only void set_catchup_mode(int knob_set_idx, unsigned module_id, unsigned param_id, CatchupParam::Mode mode); + // Set mode for one module/param, in any knobset + void set_catchup_mode(unsigned module_id, unsigned param_id, CatchupParam::Mode mode); + bool is_param_tracking(unsigned module_id, unsigned param_id); private: diff --git a/firmware/src/patch_play/patch_player_catchup.cc b/firmware/src/patch_play/patch_player_catchup.cc index 1d20d7f9a..e8433d39b 100644 --- a/firmware/src/patch_play/patch_player_catchup.cc +++ b/firmware/src/patch_play/patch_player_catchup.cc @@ -28,6 +28,7 @@ void PatchPlayer::set_catchup_mode(CatchupParam::Mode mode, int knob_set_idx) { } // Set mode for one mapping only +// If knob_set_idx is out of range, then active knob set will be changed. void PatchPlayer::set_catchup_mode(int knob_set_idx, unsigned module_id, unsigned param_id, CatchupParam::Mode mode) { if (knob_set_idx < 0 || knob_set_idx >= (int)knob_maps.size()) knob_set_idx = active_knob_set; @@ -42,6 +43,20 @@ void PatchPlayer::set_catchup_mode(int knob_set_idx, unsigned module_id, unsigne } } +// Set mode for a particular param on a particular module, in any/all knobsets +void PatchPlayer::set_catchup_mode(unsigned module_id, unsigned param_id, CatchupParam::Mode mode) { + for (auto &knobset : knob_maps) { + for (auto &knob : knobset) { + for (auto &map : knob) { + if (map.map.module_id == module_id && map.map.param_id == param_id) { + map.catchup.set_mode(mode); + return; + } + } + } + } +} + bool PatchPlayer::is_param_tracking(unsigned module_id, unsigned param_id) { for (auto const &knob : knob_maps[active_knob_set]) { for (auto const &map : knob) { diff --git a/firmware/src/patch_play/patch_playloader.hh b/firmware/src/patch_play/patch_playloader.hh index ce7aa8312..4bf7a3e75 100644 --- a/firmware/src/patch_play/patch_playloader.hh +++ b/firmware/src/patch_play/patch_playloader.hh @@ -9,6 +9,7 @@ #include "patch_play/patch_player.hh" #include "pr_dbg.hh" #include "result_t.hh" +#include "util/overloaded.hh" #include size_t get_heap_size(); @@ -269,6 +270,38 @@ struct PatchPlayLoader { return player_.is_param_tracking(module_id, param_id); } + void set_all_param_catchup_mode(CatchupParam::Mode mode, bool exclude_buttons) { + // if (exclude_buttons) { + + // for (auto module_id = 0u; auto slug : patches_.get_view_patch()->module_slugs) { + // auto info = ModuleFactory::getModuleInfo(slug); + + // for (unsigned i = 0; auto const &element : info.elements) { + // auto param_id = info.indices[i].param_idx; + // enum { Ignore, Enable, Disable }; + // auto action = std::visit(overloaded{ + // [](Pot const &el) { return el.integral ? Disable : Enable; }, + // [](Switch const &el) { return Disable; }, + // [](Button const &el) { return Disable; }, + // [](ParamElement const &el) { return Enable; }, + // [](BaseElement const &el) { return Ignore; }, + // }, + // element); + // if (action == Enable) + // player_.set_catchup_mode(module_id, param_id, mode); + // else if (action == Disable) + // player_.set_catchup_mode(module_id, param_id, CatchupParam::Mode::ResumeOnMotion); + + // i++; + // } + // module_id++; + // } + + // } else { + player_.set_catchup_mode(mode); + // } + } + private: PatchPlayer &player_; FileStorageProxy &storage_; diff --git a/firmware/tests/settings_parse_tests.cc b/firmware/tests/settings_parse_tests.cc index 2e8226260..36f8b5d00 100644 --- a/firmware/tests/settings_parse_tests.cc +++ b/firmware/tests/settings_parse_tests.cc @@ -51,6 +51,10 @@ TEST_CASE("Parse settings file") { index: 3 knobs_can_wake: 1 + catchup: + mode: ResumeOnEqual + exclude_buttons: 0 + )"; // clang format-on @@ -91,6 +95,9 @@ TEST_CASE("Parse settings file") { CHECK(settings.screensaver.timeout_ms == 3); CHECK(settings.screensaver.knobs_can_wake == true); + + CHECK(settings.catchup.mode == MetaModule::CatchupParam::Mode::ResumeOnEqual); + CHECK(settings.catchup.button_exclude == false); } TEST_CASE("Get default settings if file is missing fields") { @@ -151,6 +158,18 @@ TEST_CASE("Get default settings if file is missing fields") { screensaver: )"; } + SUBCASE("Bad catchup settings:") { + yaml = R"(Settings: + catchup: + mode: INvaliDmodE +)"; + } + SUBCASE("Bad catchup settings:") { + yaml = R"(Settings: + catchup: + exclude_buttons: 2 +)"; + } MetaModule::UserSettings settings; auto ok = MetaModule::Settings::parse(yaml, &settings); @@ -190,6 +209,9 @@ TEST_CASE("Get default settings if file is missing fields") { CHECK(settings.screensaver.timeout_ms == MetaModule::ScreensaverSettings::defaultTimeout); CHECK(settings.screensaver.knobs_can_wake == true); + + CHECK(settings.catchup.mode == MetaModule::CatchupParam::Mode::ResumeOnMotion); + CHECK(settings.catchup.button_exclude == true); } TEST_CASE("Serialize settings") { @@ -230,6 +252,9 @@ TEST_CASE("Serialize settings") { settings.screensaver.knobs_can_wake = false; settings.screensaver.timeout_ms = 2; + settings.catchup.mode = MetaModule::CatchupParam::Mode::LinearFade; + settings.catchup.button_exclude = false; + // clang format-off std::string expected = R"(Settings: patch_view: @@ -269,6 +294,9 @@ TEST_CASE("Serialize settings") { screensaver: index: 2 knobs_can_wake: 0 + catchup: + mode: LinearFade + exclude_buttons: 0 )"; // clang format-on