Skip to content

Commit

Permalink
Merge pull request #444 from 4ms/sort-lists-cleanup
Browse files Browse the repository at this point in the history
Sort lists cleanup
  • Loading branch information
danngreen authored Dec 27, 2024
2 parents fcafa0a + 416ac2b commit 4202e4f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion firmware/lib/cpputil
Submodule cpputil updated 1 files
+10 −0 util/string_compare.hh
2 changes: 1 addition & 1 deletion firmware/src/dynload/plugin_file_list.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct PluginFile {
unsigned sdk_minor_version = 0;
};

static constexpr size_t MaxPlugins = 32;
static constexpr size_t MaxPlugins = 64;
using PluginFileList = FixedVector<PluginFile, MaxPlugins>;

} // namespace MetaModule
6 changes: 4 additions & 2 deletions firmware/src/dynload/plugin_file_scan.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ inline bool scan_volume(FileIoC auto &fileio, PluginFileList &plugin_files, std:
if (kind == DirEntryKind::File) {
if (entryname.ends_with(".mmplugin") && !entryname.starts_with(".")) {
entryname.remove_suffix(9);
plugin_files.push_back({fileio.vol_id(), full_path.c_str(), entryname, filesize, "", 1, 0});
pr_trace("Found plugin file %s\n", full_path.c_str());
if (plugin_files.push_back({fileio.vol_id(), full_path.c_str(), entryname, filesize, "", 1, 0}))
pr_trace("Found plugin file %s\n", full_path.c_str());
else
pr_err("More than %zu plugins found\n", plugin_files.max_size());
}
}
});
Expand Down
9 changes: 6 additions & 3 deletions firmware/src/dynload/plugin_loader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "patch_file/file_storage_proxy.hh"
#include "plugin/Plugin.hpp"
#include "util/monotonic_allocator.hh"
#include "util/string_compare.hh"
#include "util/version_tools.hh"
#include <algorithm>
#include <cstdint>
#include <deque>
#include <string>
Expand Down Expand Up @@ -95,9 +97,8 @@ public:

if (message.message_type == IntercoreStorageMessage::PluginFileListOK) {
plugin_files = *plugin_file_list; //make local copy
std::sort(plugin_files.begin(), plugin_files.end(), [](auto const &a, auto const &b) {
return std::string_view{a.plugin_name} < std::string_view{b.plugin_name};
});

std::ranges::sort(plugin_files, less_ci, &PluginFile::plugin_name);
pr_trace("Found %d plugins\n", plugin_files.size());

parse_versions();
Expand Down Expand Up @@ -292,6 +293,8 @@ public:

auto version = VersionUtil::Version(vers);
plugin.version = std::string_view(vers);
plugin.sdk_major_version = version.major;
plugin.sdk_minor_version = version.minor;
pr_trace("Plugin: %s => %s => %u.%u.%u\n",
name.c_str(),
vers.c_str(),
Expand Down
8 changes: 5 additions & 3 deletions firmware/src/gui/pages/main_menu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ struct MainMenuPage : PageBase {
: PageBase{info, PageId::MainMenu} {
init_bg(ui_MainMenu);
lv_group_remove_all_objs(group);
lv_group_add_obj(group, ui_MenuPanelPatches);
lv_group_add_obj(group, ui_MenuPanelSave); //new patch
lv_group_add_obj(group, ui_MenuPanelSettings);

lv_group_add_obj(group, ui_MainMenuNowPlayingPanel);
lv_group_add_obj(group, ui_MainMenuLastViewedPanel);

lv_group_add_obj(group, ui_MenuPanelPatches);
lv_group_add_obj(group, ui_MenuPanelSave); //new patch
lv_group_add_obj(group, ui_MenuPanelSettings);

lv_group_focus_obj(ui_MenuPanelPatches);
lv_group_set_wrap(group, false);

lv_obj_add_event_cb(ui_MenuPanelPatches, patchsel_cb, LV_EVENT_CLICKED, this);
lv_obj_add_event_cb(ui_MenuPanelSettings, settings_cb, LV_EVENT_CLICKED, this);
Expand Down
20 changes: 13 additions & 7 deletions firmware/src/gui/pages/plugin_tab.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ struct PluginTab : SystemMenuTab {

for (unsigned idx = 0; auto plugin : *found_plugins) {
auto pluginname = std::string{plugin.plugin_name};
if (plugin.version.length() > 0)
pluginname += Gui::grey_text(" " + std::string{plugin.version});

if (plugin.version.length() > 0) {
pluginname += " " + Gui::grey_text(plugin.version);

auto pvers = Version(plugin.sdk_major_version, plugin.sdk_minor_version, 0);
if (!sdk_version().can_host_version(pvers)) {
pr_trace("Can't host %s version %s\n", plugin.plugin_name.c_str(), plugin.version.c_str());
continue;
}
}

if (!plugin_already_loaded(plugin)) {

Expand Down Expand Up @@ -166,7 +174,7 @@ private:
auto const &loaded_plugin_list = plugin_manager.loaded_plugins();
for (auto &loaded_plugin_file : loaded_plugin_list) {
auto const &loaded_plugin = loaded_plugin_file.fileinfo;
pr_dbg(
pr_trace(
"Comparing %s (new) and %s (loaded)\n", plugin.plugin_name.c_str(), loaded_plugin.plugin_name.c_str());
if (loaded_plugin.plugin_name == plugin.plugin_name) {
return true;
Expand Down Expand Up @@ -199,8 +207,7 @@ private:
plugin_name = plugin_name.substr(0, colorpos);
}

const auto is_autoloaded =
std::find(page->settings.slug.begin(), page->settings.slug.end(), plugin_name) != page->settings.slug.end();
const auto is_autoloaded = std::ranges::find(page->settings.slug, plugin_name) != page->settings.slug.end();

page->confirm_popup.show(
[page, plugin_name, target](uint8_t opt) {
Expand All @@ -214,8 +221,7 @@ private:
}
},
[page, plugin_name](bool opt) {
const auto autoload_slot =
std::find(page->settings.slug.begin(), page->settings.slug.end(), plugin_name);
const auto autoload_slot = std::ranges::find(page->settings.slug, plugin_name);
if (opt) {
pr_info("Set Autoload Enabled: %s\n", plugin_name.data());
page->settings.slug.push_back(plugin_name);
Expand Down
7 changes: 3 additions & 4 deletions firmware/src/patch_file/patch_fileio.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "patch_file/patch_dir_list.hh"
#include "patches_default.hh"
#include "pr_dbg.hh"
#include "util/string_compare.hh"

namespace MetaModule
{
Expand Down Expand Up @@ -91,10 +92,8 @@ public:
}
}

std::sort(patch_dir.files.begin(), patch_dir.files.end(), [](auto a, auto b) {
return std::string_view{a.patchname} < std::string_view{b.patchname};
});
std::sort(patch_dir.dirs.begin(), patch_dir.dirs.end(), [](auto a, auto b) { return a.name < b.name; });
std::ranges::sort(patch_dir.files, less_ci, &PatchFile::patchname);
std::ranges::sort(patch_dir.dirs, less_ci, &DirTree<PatchFile>::name);

return ok;
}
Expand Down

0 comments on commit 4202e4f

Please sign in to comment.