Skip to content

Commit

Permalink
Changing catchup settings updates all params in patch
Browse files Browse the repository at this point in the history
  • Loading branch information
danngreen committed Nov 25, 2024
1 parent 326e03e commit a8585a9
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
4 changes: 4 additions & 0 deletions firmware/src/gui/pages/prefs_tab.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions firmware/src/gui/ui.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions firmware/src/medium/conf/catchup_settings.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "catchup_param.hh"
#include "params/catchup_param.hh"
#include <array>
#include <cstdint>
#include <string_view>
Expand Down Expand Up @@ -34,7 +34,7 @@ struct CatchupSettings {
mode = DefaultMode;

// Check if deserialized data contains a value other than 0 or 1
if (*reinterpret_cast<int *>(&button_exclude) != 0)
if (*reinterpret_cast<uint8_t *>(&button_exclude) != 0)
button_exclude = true;
else
button_exclude = false;
Expand Down
3 changes: 3 additions & 0 deletions firmware/src/patch_play/patch_player.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions firmware/src/patch_play/patch_player_catchup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
33 changes: 33 additions & 0 deletions firmware/src/patch_play/patch_playloader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "patch_play/patch_player.hh"
#include "pr_dbg.hh"
#include "result_t.hh"
#include "util/overloaded.hh"
#include <atomic>

size_t get_heap_size();
Expand Down Expand Up @@ -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_;
Expand Down
28 changes: 28 additions & 0 deletions firmware/tests/settings_parse_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ TEST_CASE("Parse settings file") {
index: 3
knobs_can_wake: 1
catchup:
mode: ResumeOnEqual
exclude_buttons: 0
)";
// clang format-on

Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -269,6 +294,9 @@ TEST_CASE("Serialize settings") {
screensaver:
index: 2
knobs_can_wake: 0
catchup:
mode: LinearFade
exclude_buttons: 0
)";
// clang format-on

Expand Down

0 comments on commit a8585a9

Please sign in to comment.