MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / appendPresetItems

Function appendPresetItems

src/override/ModuleWidget.cpp:973–1013  ·  view source on GitHub ↗

Create ModulePresetPathItems for each patch in a directory.

Source from the content-addressed store, hash-verified

971
972// Create ModulePresetPathItems for each patch in a directory.
973static void appendPresetItems(ui::Menu* menu, WeakPtr<ModuleWidget> moduleWidget, std::string presetDir) {
974 bool hasPresets = false;
975 if (system::isDirectory(presetDir)) {
976 // Note: This is not cached, so opening this menu each time might have a bit of latency.
977 std::vector<std::string> entries = system::getEntries(presetDir);
978 std::sort(entries.begin(), entries.end());
979 for (std::string path : entries) {
980 std::string name = system::getStem(path);
981 // Remove "1_", "42_", "001_", etc at the beginning of preset filenames
982 std::regex r("^\\d+_");
983 name = std::regex_replace(name, r, "");
984
985 if (system::isDirectory(path)) {
986 hasPresets = true;
987
988 menu->addChild(createSubmenuItem(name, "", [=](ui::Menu* menu) {
989 if (!moduleWidget)
990 return;
991 appendPresetItems(menu, moduleWidget, path);
992 }));
993 }
994 else if (system::getExtension(path) == ".vcvm" && name != "template") {
995 hasPresets = true;
996
997 menu->addChild(createMenuItem(name, "", [=]() {
998 if (!moduleWidget)
999 return;
1000 try {
1001 moduleWidget->loadAction(path);
1002 }
1003 catch (Exception& e) {
1004 async_dialog_message(e.what());
1005 }
1006 }));
1007 }
1008 }
1009 }
1010 if (!hasPresets) {
1011 menu->addChild(createMenuLabel("(None)"));
1012 }
1013};
1014
1015
1016void ModuleWidget::createContextMenu() {

Callers 1

createContextMenuMethod · 0.85

Calls 8

createSubmenuItemFunction · 0.85
createMenuItemFunction · 0.85
createMenuLabelFunction · 0.85
addChildMethod · 0.80
async_dialog_messageFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
loadActionMethod · 0.45

Tested by

no test coverage detected