Skip to content

Commit

Permalink
Merge pull request #343 from 4ms/patch-list-refresh-fix
Browse files Browse the repository at this point in the history
Patch list refresh fix
  • Loading branch information
danngreen authored Aug 24, 2024
2 parents f5a8ead + 6a6a512 commit 57b0987
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
36 changes: 27 additions & 9 deletions firmware/src/gui/pages/patch_selector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct PatchSelectorPage : PageBase {

PatchSelectorPage(PatchContext info, PatchSelectorSubdirPanel &subdir_panel)
: PageBase{info, PageId::PatchSel}
, subdir_panel{subdir_panel} {
, subdir_panel{subdir_panel}
, patchfiles{patch_storage.get_patch_list()} {

init_bg(ui_PatchSelectorPage);

Expand All @@ -39,7 +40,10 @@ struct PatchSelectorPage : PageBase {
// Don't persist module selection
args.module_id = std::nullopt;

state = State::TryingToRequestPatchList;
if (last_refresh_check_tm == 0)
state = State::ReloadingPatchList;
else
state = State::TryingToRequestPatchList;
hide_spinner();
blur_subdir_panel();

Expand All @@ -58,6 +62,7 @@ struct PatchSelectorPage : PageBase {
is_populating_subdir_panel = true;
setup_subdir_panel();

patchfiles_locked = false;
refresh_patchlist();
}

Expand Down Expand Up @@ -88,10 +93,14 @@ struct PatchSelectorPage : PageBase {
}

void refresh_patchlist() {
is_populating_subdir_panel = true;
update_open_patches();
subdir_panel.populate(patchfiles);
populate_roller();
// Do not access patchfiles while M4 is accessing them
if (!patchfiles_locked) {
is_populating_subdir_panel = true;
update_open_patches();
subdir_panel.populate(patchfiles);
subdir_panel.show_recent_files();
populate_roller();
}
}

void blur_subdir_panel() {
Expand Down Expand Up @@ -266,6 +275,8 @@ struct PatchSelectorPage : PageBase {

case State::TryingToRequestPatchList:
if (patch_storage.request_patchlist(gui_state.force_refresh_vol)) {
// Lock patchesfiles: we are not allowed to access it, because M4 has access now
patchfiles_locked = true;
state = State::RequestedPatchList;
show_spinner();
}
Expand All @@ -288,15 +299,21 @@ struct PatchSelectorPage : PageBase {
patches.mark_patches_no_reload(Volume::SDCard);
}
state = State::ReloadingPatchList;

// Unlock patchesfiles: M4 is done with it
patchfiles_locked = false;

} else if (message.message_type == FileStorageProxy::PatchListUnchanged) {
gui_state.force_refresh_vol = std::nullopt;
hide_spinner();
state = State::Idle;

// Unlock patchesfiles: M4 is done with it
patchfiles_locked = false;
}
} break;

case State::ReloadingPatchList:
patchfiles = patch_storage.get_patch_list(); //copy
refresh_patchlist();
refresh_subdir_panel();
hide_spinner();
Expand Down Expand Up @@ -430,7 +447,7 @@ private:
auto selected_patch = page->get_roller_item_patchloc(idx);
if (selected_patch) {
page->selected_patch = *selected_patch;
page->state = State::TryingToRequestPatchData; // will load from RAM if open
page->state = State::TryingToRequestPatchData;
page->last_selected_idx = idx;
} else {
//Do nothing? Close/open directory? Focus subdir panel?
Expand Down Expand Up @@ -465,7 +482,8 @@ private:
unsigned last_selected_idx = 0;

PatchSelectorSubdirPanel &subdir_panel;
PatchDirList patchfiles;
PatchDirList &patchfiles;
bool patchfiles_locked = true;

bool is_populating_subdir_panel = false;

Expand Down
20 changes: 14 additions & 6 deletions firmware/src/gui/pages/patch_selector_sidebar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct PatchSelectorSubdirPanel {
}
}

void populate(PatchDirList &patchfiles) {
void populate(PatchDirList const &patchfiles) {
if (group == nullptr)
group = lv_group_create();

Expand Down Expand Up @@ -58,7 +58,7 @@ struct PatchSelectorSubdirPanel {
}

// Add root-level dir on volume
lv_obj_set_user_data(vol_item, &root);
lv_obj_set_user_data(vol_item, (void *)&root);
lv_group_add_obj(group, vol_item);

// Add all dirs on volume
Expand All @@ -70,6 +70,14 @@ struct PatchSelectorSubdirPanel {
}
}

void hide_recent_files() {
lv_hide(vol_conts[0]);
}

void show_recent_files() {
lv_show(vol_conts[0]);
}

void refresh(EntryInfo const &selected_patch) {
// TODO: check if list was re-populated, or if entry info dir name changed, and only refresh if so

Expand Down Expand Up @@ -155,7 +163,7 @@ struct PatchSelectorSubdirPanel {
}

std::string_view dirname = "";
if (auto dir = static_cast<PatchDir *>(event->target->user_data); dir) {
if (auto dir = static_cast<PatchDir const *>(event->target->user_data); dir) {
dirname = std::string_view{dir->name};
}

Expand Down Expand Up @@ -184,7 +192,7 @@ struct PatchSelectorSubdirPanel {
}

std::string_view dirname = "";
if (auto dir = static_cast<PatchDir *>(event->target->user_data); dir) {
if (auto dir = static_cast<PatchDir const *>(event->target->user_data); dir) {
dirname = std::string_view{dir->name};
}

Expand All @@ -198,7 +206,7 @@ struct PatchSelectorSubdirPanel {
std::function<void(Volume vol, std::string_view dirname)> click_cb;

private:
void add_subdir_to_panel(PatchDir &dir, lv_obj_t *vol_label) {
void add_subdir_to_panel(PatchDir const &dir, lv_obj_t *vol_label) {
if (dir.files.size() == 0)
return;

Expand All @@ -215,7 +223,7 @@ private:
lv_obj_set_width(name_label, LV_PCT(100));

lv_obj_add_flag(btn, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_set_user_data(btn, &dir);
lv_obj_set_user_data(btn, (void *)&dir);

while (lv_obj_remove_event_cb(btn, nullptr)) {
}
Expand Down
2 changes: 2 additions & 0 deletions firmware/src/gui/pages/save_dialog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct SaveDialog {

case RefreshState::ReloadingPatchList:
subdir_panel.populate(patch_storage.get_patch_list());
subdir_panel.hide_recent_files();
// hide_spinner();
subdir_panel.focus();
refresh_state = RefreshState::Idle;
Expand Down Expand Up @@ -188,6 +189,7 @@ struct SaveDialog {

EntryInfo selected_patch{.kind = DirEntryKind::Dir, .vol = patches.get_view_patch_vol(), .path = file_path};
subdir_panel.refresh(selected_patch);
subdir_panel.hide_recent_files();
}

void hide_subdir_panel() {
Expand Down
1 change: 0 additions & 1 deletion firmware/src/patch_file/open_patch_manager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public:
PatchData *get_playing_patch() {
if (playing_patch_) {
if (open_patches_.exists(playing_patch_)) {
pr_dbg("Playing patch exists\n");
return &playing_patch_->patch;
} else {
pr_err("Playing patch not null and not found in open patches!\n");
Expand Down

0 comments on commit 57b0987

Please sign in to comment.