Display module presets when available
Fixes #58 Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
f9e5a03ecb
commit
1311b6a127
1 changed files with 41 additions and 4 deletions
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "CardinalCommon.hpp"
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include <app/ModuleWidget.hpp>
|
||||
#include <app/RackWidget.hpp>
|
||||
#include <app/Scene.hpp>
|
||||
|
@ -126,6 +128,43 @@ void CardinalModuleWidget__saveDialog(ModuleWidget* const w)
|
|||
});
|
||||
}
|
||||
|
||||
// Create ModulePresetPathItems for each patch in a directory.
|
||||
static void appendPresetItems(ui::Menu* menu, WeakPtr<ModuleWidget> moduleWidget, std::string presetDir) {
|
||||
bool foundPresets = false;
|
||||
|
||||
// Note: This is not cached, so opening this menu each time might have a bit of latency.
|
||||
if (system::isDirectory(presetDir))
|
||||
{
|
||||
std::vector<std::string> entries = system::getEntries(presetDir);
|
||||
std::sort(entries.begin(), entries.end());
|
||||
for (std::string path : entries) {
|
||||
std::string name = system::getStem(path);
|
||||
// Remove "1_", "42_", "001_", etc at the beginning of preset filenames
|
||||
std::regex r("^\\d+_");
|
||||
name = std::regex_replace(name, r, "");
|
||||
|
||||
if (system::getExtension(path) == ".vcvm")
|
||||
{
|
||||
if (!foundPresets)
|
||||
menu->addChild(new ui::MenuSeparator);
|
||||
|
||||
foundPresets = true;
|
||||
|
||||
menu->addChild(createMenuItem(name, "", [=]() {
|
||||
if (!moduleWidget)
|
||||
return;
|
||||
try {
|
||||
moduleWidget->loadAction(path);
|
||||
}
|
||||
catch (Exception& e) {
|
||||
async_dialog_message(e.what());
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void CardinalModuleWidget__createContextMenu(ModuleWidget* const w,
|
||||
plugin::Model* const model,
|
||||
engine::Module* const module) {
|
||||
|
@ -164,23 +203,21 @@ static void CardinalModuleWidget__createContextMenu(ModuleWidget* const w,
|
|||
CardinalModuleWidget__loadDialog(weakThis);
|
||||
}));
|
||||
|
||||
/* TODO requires setting up user dir
|
||||
menu->addChild(createMenuItem("Save as", "", [weakThis]() {
|
||||
if (!weakThis)
|
||||
return;
|
||||
CardinalModuleWidget__saveDialog(weakThis);
|
||||
}));
|
||||
|
||||
/* TODO
|
||||
// Scan `<user dir>/presets/<plugin slug>/<module slug>` for presets.
|
||||
menu->addChild(new ui::MenuSeparator);
|
||||
menu->addChild(createMenuLabel("User presets"));
|
||||
appendPresetItems(menu, weakThis, weakThis->model->getUserPresetDirectory());
|
||||
*/
|
||||
|
||||
// Scan `<plugin dir>/presets/<module slug>` for presets.
|
||||
menu->addChild(new ui::MenuSeparator);
|
||||
menu->addChild(createMenuLabel("Factory presets"));
|
||||
appendPresetItems(menu, weakThis, weakThis->model->getFactoryPresetDirectory());
|
||||
*/
|
||||
}));
|
||||
|
||||
// Initialize
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue