Browse Source

Scan preset directories when preset menu is created. Add user preset directory.

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
38c99ad0a8
4 changed files with 34 additions and 18 deletions
  1. +2
    -0
      .gitignore
  2. +0
    -1
      include/plugin/Model.hpp
  3. +32
    -10
      src/app/ModuleWidget.cpp
  4. +0
    -7
      src/plugin/Model.cpp

+ 2
- 0
.gitignore View File

@@ -12,3 +12,5 @@
/autosave.vcv /autosave.vcv
/settings.json /settings.json
/screenshots /screenshots
/presets
/Fundamental.zip

+ 0
- 1
include/plugin/Model.hpp View File

@@ -23,7 +23,6 @@ namespace plugin {


struct Model { struct Model {
Plugin* plugin = NULL; Plugin* plugin = NULL;
std::vector<std::string> presetPaths;


/** Must be unique. Used for saving patches. Never change this after releasing your module. /** Must be unique. Used for saving patches. Never change this after releasing your module.
The model slug must be unique within your plugin, but it doesn't need to be unique among different plugins. The model slug must be unique within your plugin, but it doesn't need to be unique among different plugins.


+ 32
- 10
src/app/ModuleWidget.cpp View File

@@ -9,6 +9,7 @@
#include <app.hpp> #include <app.hpp>
#include <settings.hpp> #include <settings.hpp>
#include <history.hpp> #include <history.hpp>
#include <string.hpp>


#include <osdialog.h> #include <osdialog.h>
#include <thread> #include <thread>
@@ -198,19 +199,36 @@ struct ModulePresetItem : ui::MenuItem {
saveItem->moduleWidget = moduleWidget; saveItem->moduleWidget = moduleWidget;
menu->addChild(saveItem); menu->addChild(saveItem);


if (!moduleWidget->model->presetPaths.empty()) {
menu->addChild(new MenuEntry);
menu->addChild(createMenuLabel("Factory presets"));
// Create ModulePresetPathItems for each patch in a directory.
auto createPresetItems = [&](std::string presetDir) {
bool hasPresets = false;
// Note: This is not cached, so opening this menu each time might have a bit of latency.
for (const std::string& presetPath : system::getEntries(presetDir)) {
std::string presetFilename = string::filename(presetPath);
if (string::filenameExtension(presetFilename) != "vcvm")
continue;
hasPresets = true;


for (const std::string& presetPath : moduleWidget->model->presetPaths) {
ModulePresetPathItem* presetItem = new ModulePresetPathItem; ModulePresetPathItem* presetItem = new ModulePresetPathItem;
std::string presetName = string::filenameBase(string::filename(presetPath));
presetItem->text = presetName;
presetItem->text = string::filenameBase(presetFilename);
presetItem->presetPath = presetPath; presetItem->presetPath = presetPath;
presetItem->moduleWidget = moduleWidget; presetItem->moduleWidget = moduleWidget;
menu->addChild(presetItem); menu->addChild(presetItem);
} }
}
if (!hasPresets) {
menu->addChild(createMenuLabel("(none)"));
}
};

// Scan `<user dir>/presets/<plugin slug>/<module slug>` for presets.
menu->addChild(new MenuEntry);
menu->addChild(createMenuLabel("User presets"));
createPresetItems(asset::user("presets/" + moduleWidget->model->plugin->slug + "/" + moduleWidget->model->slug));

// Scan `<plugin dir>/presets/<module slug>` for presets.
menu->addChild(new MenuEntry);
menu->addChild(createMenuLabel("Factory presets"));
createPresetItems(asset::plugin(moduleWidget->model->plugin, "presets/" + moduleWidget->model->slug));


return menu; return menu;
} }
@@ -632,15 +650,19 @@ void ModuleWidget::loadDialog() {
} }


void ModuleWidget::saveDialog() { void ModuleWidget::saveDialog() {
std::string dir = asset::user("presets");
system::createDirectory(dir);
std::string presetDir = asset::user("presets");
system::createDirectory(presetDir);
presetDir += "/" + model->plugin->slug;
system::createDirectory(presetDir);
presetDir += "/" + model->slug;
system::createDirectory(presetDir);


osdialog_filters* filters = osdialog_filters_parse(PRESET_FILTERS); osdialog_filters* filters = osdialog_filters_parse(PRESET_FILTERS);
DEFER({ DEFER({
osdialog_filters_free(filters); osdialog_filters_free(filters);
}); });


char* path = osdialog_file(OSDIALOG_SAVE, dir.c_str(), "Untitled.vcvm", filters);
char* path = osdialog_file(OSDIALOG_SAVE, presetDir.c_str(), "Untitled.vcvm", filters);
if (!path) { if (!path) {
// No path selected // No path selected
return; return;


+ 0
- 7
src/plugin/Model.cpp View File

@@ -41,13 +41,6 @@ void Model::fromJson(json_t* rootJ) {
json_t* manualUrlJ = json_object_get(rootJ, "manualUrl"); json_t* manualUrlJ = json_object_get(rootJ, "manualUrl");
if (manualUrlJ) if (manualUrlJ)
manualUrl = json_string_value(manualUrlJ); manualUrl = json_string_value(manualUrlJ);

// Preset paths
presetPaths.clear();
std::string presetDir = asset::plugin(plugin, "presets/" + slug);
for (const std::string& presetPath : system::getEntries(presetDir)) {
presetPaths.push_back(presetPath);
}
} }






Loading…
Cancel
Save