Skip to content

Commit

Permalink
Better preset sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Dec 13, 2023
1 parent 6286a9a commit 283446a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/gui/toolbar/presets/PresetsComp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,28 @@ int PresetsComp::createPresetsMenu (int optionID)
optionID = juce::jmax (optionID, presetItem.itemID);
}

std::optional<juce::PopupMenu> userPresetsMenu {};
for (auto& [vendorName, vendorCollection] : presetMapItems)
{
PopupMenu vendorMenu;
for (auto& [category, categoryMenu] : vendorCollection.categoryPresetMenus)
vendorMenu.addSubMenu (category, categoryMenu);

std::sort (vendorCollection.nonCategoryItems.begin(), vendorCollection.nonCategoryItems.end(), [] (auto& item1, auto& item2)
{ return item1.text < item2.text; });
for (auto& extraItem : vendorCollection.nonCategoryItems)
vendorMenu.addItem (extraItem);

if (vendorName == "User")
{
userPresetsMenu = vendorMenu;
continue;
}
presetBox.getRootMenu()->addSubMenu (vendorName, vendorMenu);
}

// the user presets always go last
if (userPresetsMenu.has_value())
presetBox.getRootMenu()->addSubMenu ("User", *userPresetsMenu);

return optionID;
}

Expand Down
21 changes: 21 additions & 0 deletions src/state/presets/PresetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,25 @@ bool PresetManager::syncServerPresetsToLocal()
}
#endif // BYOD_BUILD_PRESET_SERVER

static void sortPresets (std::vector<chowdsp::Preset>& presets)
{
std::sort (presets.begin(),
presets.end(),
[] (const chowdsp::Preset& p1, const chowdsp::Preset& p2)
{
if (p1.getVendor() != p2.getVendor())
return p1.getVendor() < p2.getVendor();

if (p1.getCategory() != p2.getCategory())
return p1.getCategory() < p2.getCategory();

if (p1.getCategory().isEmpty())
return p1.getName() > p2.getName();

return p1.getName() < p2.getName();
});
}

std::vector<chowdsp::Preset> PresetManager::getFactoryPresets (const ProcessorStore& procStore)
{
std::vector<chowdsp::Preset> factoryPresets;
Expand Down Expand Up @@ -245,6 +264,7 @@ std::vector<chowdsp::Preset> PresetManager::getFactoryPresets (const ProcessorSt
#endif

filterPresets (factoryPresets, procStore);
sortPresets (factoryPresets);

return factoryPresets;
}
Expand Down Expand Up @@ -375,6 +395,7 @@ void PresetManager::loadUserPresetsFromFolder (const juce::File& file)
presetMap.erase (presetID++);

filterPresets (presets, procStore);
sortPresets (presets);
addPresets (presets);
}

Expand Down

0 comments on commit 283446a

Please sign in to comment.