Browse Source

Serialize ModuleBrowser favorites

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
53fdea1cd1
6 changed files with 58 additions and 29 deletions
  1. +1
    -1
      include/app.hpp
  2. +2
    -0
      include/plugin.hpp
  3. +30
    -4
      src/app/ModuleBrowser.cpp
  4. +1
    -23
      src/app/RackWidget.cpp
  5. +23
    -0
      src/plugin.cpp
  6. +1
    -1
      src/ui/ScrollWidget.cpp

+ 1
- 1
include/app.hpp View File

@@ -524,7 +524,7 @@ void appInit();
void appDestroy();
void appModuleBrowserCreate();
json_t *appModuleBrowserToJson();
void appModuleBrowserFromJson(json_t *root);
void appModuleBrowserFromJson(json_t *rootJ);


json_t *colorToJson(NVGcolor color);


+ 2
- 0
include/plugin.hpp View File

@@ -105,6 +105,8 @@ bool pluginIsDownloading();
float pluginGetDownloadProgress();
std::string pluginGetDownloadName();
std::string pluginGetLoginStatus();
Plugin *pluginGetPlugin(std::string pluginSlug);
Model *pluginGetModel(std::string pluginSlug, std::string modelSlug);


extern std::list<Plugin*> gPlugins;


+ 30
- 4
src/app/ModuleBrowser.cpp View File

@@ -377,12 +377,38 @@ void appModuleBrowserCreate() {
}

json_t *appModuleBrowserToJson() {
// TODO
return json_object();
json_t *rootJ = json_object();

json_t *favoritesJ = json_array();
for (Model *model : sFavoriteModels) {
json_t *modelJ = json_object();
json_object_set_new(modelJ, "plugin", json_string(model->plugin->slug.c_str()));
json_object_set_new(modelJ, "model", json_string(model->slug.c_str()));
json_array_append_new(favoritesJ, modelJ);
}
json_object_set_new(rootJ, "favorites", favoritesJ);

return rootJ;
}

void appModuleBrowserFromJson(json_t *root) {
// TODO
void appModuleBrowserFromJson(json_t *rootJ) {
json_t *favoritesJ = json_object_get(rootJ, "favorites");
if (favoritesJ) {
size_t i;
json_t *favoriteJ;
json_array_foreach(favoritesJ, i, favoriteJ) {
json_t *pluginJ = json_object_get(favoriteJ, "plugin");
json_t *modelJ = json_object_get(favoriteJ, "model");
if (!pluginJ || !modelJ)
continue;
std::string pluginSlug = json_string_value(pluginJ);
std::string modelSlug = json_string_value(modelJ);
Model *model = pluginGetModel(pluginSlug, modelSlug);
if (!model)
continue;
sFavoriteModels.insert(model);
}
}
}




+ 1
- 23
src/app/RackWidget.cpp View File

@@ -248,29 +248,7 @@ void RackWidget::fromJson(json_t *rootJ) {
std::string pluginSlug = json_string_value(pluginSlugJ);
std::string modelSlug = json_string_value(modelSlugJ);

// Search for plugin
Plugin *plugin = NULL;
for (Plugin *p : gPlugins) {
if (p->slug == pluginSlug) {
plugin = p;
break;
}
}

if (!plugin) {
message += stringf("Could not find plugin \"%s\" for module \"%s\"\n", pluginSlug.c_str(), modelSlug.c_str());
continue;
}

// Search for model
Model *model = NULL;
for (Model *m : plugin->models) {
if (m->slug == modelSlug) {
model = m;
break;
}
}

Model *model = pluginGetModel(pluginSlug, modelSlug);
if (!model) {
message += stringf("Could not find module \"%s\" in plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str());
continue;


+ 23
- 0
src/plugin.cpp View File

@@ -475,5 +475,28 @@ std::string pluginGetLoginStatus() {
return loginStatus;
}

Plugin *pluginGetPlugin(std::string pluginSlug) {
for (Plugin *plugin : gPlugins) {
if (plugin->slug == pluginSlug) {
return plugin;
}
}
return NULL;
}

Model *pluginGetModel(std::string pluginSlug, std::string modelSlug) {
Plugin *plugin = pluginGetPlugin(pluginSlug);
if (plugin) {
for (Model *model : plugin->models) {
if (model->slug == modelSlug) {
return model;
}
}
}
return NULL;
}




} // namespace rack

+ 1
- 1
src/ui/ScrollWidget.cpp View File

@@ -5,7 +5,7 @@
namespace rack {


static const float SCROLL_SPEED = 1.2;
static const float SCROLL_SPEED = 1.3;


/** Parent must be a ScrollWidget */


Loading…
Cancel
Save