diff --git a/firmware/lib/CoreModules b/firmware/lib/CoreModules index f668f66b6..6112770ea 160000 --- a/firmware/lib/CoreModules +++ b/firmware/lib/CoreModules @@ -1 +1 @@ -Subproject commit f668f66b6130dcbf452d090f1241eadf1ff55681 +Subproject commit 6112770ea555dfb7afa8e7494ba94bba7a687294 diff --git a/firmware/src/gui/pages/patch_selector.hh b/firmware/src/gui/pages/patch_selector.hh index 91f0a34a9..aa7ec7a5d 100644 --- a/firmware/src/gui/pages/patch_selector.hh +++ b/firmware/src/gui/pages/patch_selector.hh @@ -36,6 +36,9 @@ struct PatchSelectorPage : PageBase { void prepare_focus() override { abort_cable(gui_state, notify_queue); + // Don't persist module selection + args.module_id = std::nullopt; + state = State::TryingToRequestPatchList; hide_spinner(); blur_subdir_panel(); @@ -243,7 +246,7 @@ struct PatchSelectorPage : PageBase { lv_obj_clear_state(ui_PatchListRoller, LV_STATE_FOCUSED); subdir_panel.focus(); } else { - page_list.request_last_page(); + page_list.request_new_page_no_history(PageId::MainMenu, args); } } diff --git a/firmware/src/gui/pages/patch_view.hh b/firmware/src/gui/pages/patch_view.hh index ed1a61c79..444b2cb2f 100644 --- a/firmware/src/gui/pages/patch_view.hh +++ b/firmware/src/gui/pages/patch_view.hh @@ -279,7 +279,7 @@ struct PatchViewPage : PageBase { } else { abort_cable(gui_state, notify_queue); - page_list.request_last_page(); + page_list.request_new_page_no_history(PageId::PatchSel, args); blur(); } } @@ -292,6 +292,8 @@ struct PatchViewPage : PageBase { if (file_menu.did_filesystem_change()) { gui_state.force_refresh_vol = patches.get_view_patch_vol(); + displayed_patch_loc_hash = patches.get_view_patch_loc_hash(); + args.patch_loc_hash = patches.get_view_patch_loc_hash(); } if (is_patch_playing && !patch_playloader.is_audio_muted()) { diff --git a/firmware/src/gui/pages/save_dialog.hh b/firmware/src/gui/pages/save_dialog.hh index a85506ec4..8243fd8d5 100644 --- a/firmware/src/gui/pages/save_dialog.hh +++ b/firmware/src/gui/pages/save_dialog.hh @@ -250,7 +250,8 @@ private: page->file_name = lv_textarea_get_text(ui_SaveDialogFilename); - std::string fullpath = page->file_path + "/" + page->file_name; + std::string fullpath = page->file_path.length() ? (page->file_path + "/") : ""; + fullpath += page->file_name; if (!fullpath.ends_with(".yml")) { fullpath.append(".yml"); } diff --git a/firmware/src/patch_file/open_patch_manager.hh b/firmware/src/patch_file/open_patch_manager.hh index a37ee61c2..1057d5ec6 100644 --- a/firmware/src/patch_file/open_patch_manager.hh +++ b/firmware/src/patch_file/open_patch_manager.hh @@ -86,9 +86,17 @@ public: // Parses and opens the loaded patch, and sets the view patch to point to it bool open_patch(std::span file_data, PatchLocation const &patch_loc) { + bool patch_is_playing = false; - if (open_patches_.find(patch_loc)) { + if (auto patch = open_patches_.find(patch_loc)) { + open_patches_.dump_open_patches(); + + if (patch == playing_patch_) + patch_is_playing = true; + + pr_warn("open patch found already. p:%d\n", patch_is_playing); open_patches_.remove(patch_loc); + open_patches_.dump_open_patches(); } auto *new_patch = open_patches_.emplace_back(patch_loc); @@ -96,6 +104,10 @@ public: if (!yaml_raw_to_patch(file_data, new_patch->patch)) { pr_err("Failed to parse\n"); open_patches_.remove_last(); + + if (patch_is_playing) + playing_patch_ = nullptr; + return false; } @@ -104,6 +116,9 @@ public: view_patch_ = new_patch; + if (patch_is_playing) + playing_patch_ = new_patch; + return true; } @@ -111,9 +126,15 @@ public: // playing_patch: (copy of) patch currently playing in the audio thread // PatchData *get_playing_patch() { - if (playing_patch_) - return &playing_patch_->patch; - else { + 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"); + return nullptr; + } + } else { return nullptr; } } @@ -193,7 +214,7 @@ public: void new_patch() { std::string name = "Untitled Patch " + std::to_string((uint8_t)std::rand()); - std::string filename = "/" + name + ".yml"; + std::string filename = name + ".yml"; PatchLocation loc{std::string_view{filename}, Volume::RamDisk}; view_patch_ = open_patches_.emplace_back(loc); view_patch_->patch.blank_patch(name); diff --git a/firmware/src/patch_file/open_patches.hh b/firmware/src/patch_file/open_patches.hh index 68517d23e..f6bf07cd7 100644 --- a/firmware/src/patch_file/open_patches.hh +++ b/firmware/src/patch_file/open_patches.hh @@ -57,6 +57,16 @@ struct OpenPatchList { return num_erased > 0; } + bool exists(OpenPatch const *patch) { + for (auto const &p : list) { + if (&p == patch) + return true; + } + return false; + + // return (std::find(list.begin(), list.end(), patch) != list.end()); + } + void remove(std::list::iterator item) { list.erase(item); } @@ -81,7 +91,6 @@ struct OpenPatchList { return list.size(); } -private: void dump_open_patches() { unsigned i = 0; size_t total_size = 0; @@ -100,6 +109,7 @@ private: pr_dbg("TOTAL: %zu\n", total_size); } +private: static size_t patch_size(PatchData const &p) { auto sz = sizeof(PatchData); sz += p.module_slugs.size() * sizeof(BrandModuleSlug);