@@ -524,7 +524,7 @@ void appInit(); | |||||
void appDestroy(); | void appDestroy(); | ||||
void appModuleBrowserCreate(); | void appModuleBrowserCreate(); | ||||
json_t *appModuleBrowserToJson(); | json_t *appModuleBrowserToJson(); | ||||
void appModuleBrowserFromJson(json_t *root); | |||||
void appModuleBrowserFromJson(json_t *rootJ); | |||||
json_t *colorToJson(NVGcolor color); | json_t *colorToJson(NVGcolor color); | ||||
@@ -105,6 +105,8 @@ bool pluginIsDownloading(); | |||||
float pluginGetDownloadProgress(); | float pluginGetDownloadProgress(); | ||||
std::string pluginGetDownloadName(); | std::string pluginGetDownloadName(); | ||||
std::string pluginGetLoginStatus(); | std::string pluginGetLoginStatus(); | ||||
Plugin *pluginGetPlugin(std::string pluginSlug); | |||||
Model *pluginGetModel(std::string pluginSlug, std::string modelSlug); | |||||
extern std::list<Plugin*> gPlugins; | extern std::list<Plugin*> gPlugins; | ||||
@@ -377,12 +377,38 @@ void appModuleBrowserCreate() { | |||||
} | } | ||||
json_t *appModuleBrowserToJson() { | 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); | |||||
} | |||||
} | |||||
} | } | ||||
@@ -248,29 +248,7 @@ void RackWidget::fromJson(json_t *rootJ) { | |||||
std::string pluginSlug = json_string_value(pluginSlugJ); | std::string pluginSlug = json_string_value(pluginSlugJ); | ||||
std::string modelSlug = json_string_value(modelSlugJ); | 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) { | if (!model) { | ||||
message += stringf("Could not find module \"%s\" in plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str()); | message += stringf("Could not find module \"%s\" in plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str()); | ||||
continue; | continue; | ||||
@@ -475,5 +475,28 @@ std::string pluginGetLoginStatus() { | |||||
return loginStatus; | 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 | } // namespace rack |
@@ -5,7 +5,7 @@ | |||||
namespace rack { | namespace rack { | ||||
static const float SCROLL_SPEED = 1.2; | |||||
static const float SCROLL_SPEED = 1.3; | |||||
/** Parent must be a ScrollWidget */ | /** Parent must be a ScrollWidget */ | ||||