From 26bda06eb7124df3c4403941489981b382c62145 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 12 Nov 2019 01:24:33 -0500 Subject: [PATCH] Move slug normalization from getPlugin or getModel functions to fromJson functions. --- src/app/RackWidget.cpp | 5 ++++- src/engine/Module.cpp | 3 +++ src/plugin.cpp | 3 +-- src/plugin/Plugin.cpp | 1 - 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 75ed3952..adc3d978 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -24,11 +24,14 @@ static ModuleWidget* moduleFromJson(json_t* moduleJ) { json_t* pluginSlugJ = json_object_get(moduleJ, "plugin"); if (!pluginSlugJ) return NULL; + std::string pluginSlug = json_string_value(pluginSlugJ); + pluginSlug = plugin::normalizeSlug(pluginSlug); + json_t* modelSlugJ = json_object_get(moduleJ, "model"); if (!modelSlugJ) return NULL; - std::string pluginSlug = json_string_value(pluginSlugJ); std::string modelSlug = json_string_value(modelSlugJ); + modelSlug = plugin::normalizeSlug(modelSlug); // Get Model plugin::Model* model = plugin::getModel(pluginSlug, modelSlug); diff --git a/src/engine/Module.cpp b/src/engine/Module.cpp index 6fa78044..3000edad 100644 --- a/src/engine/Module.cpp +++ b/src/engine/Module.cpp @@ -1,4 +1,5 @@ #include +#include namespace rack { @@ -89,6 +90,7 @@ void Module::fromJson(json_t* rootJ) { std::string pluginSlug; if (pluginJ) { pluginSlug = json_string_value(pluginJ); + pluginSlug = plugin::normalizeSlug(pluginSlug); if (pluginSlug != model->plugin->slug) { WARN("Plugin %s does not match Module's plugin %s.", pluginSlug.c_str(), model->plugin->slug.c_str()); return; @@ -99,6 +101,7 @@ void Module::fromJson(json_t* rootJ) { std::string modelSlug; if (modelJ) { modelSlug = json_string_value(modelJ); + modelSlug = plugin::normalizeSlug(modelSlug); if (modelSlug != model->slug) { WARN("Model %s does not match Module's model %s.", modelSlug.c_str(), model->slug.c_str()); return; diff --git a/src/plugin.cpp b/src/plugin.cpp index c0090db7..b0b4a36c 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -446,9 +446,8 @@ bool isSyncing() { } Plugin* getPlugin(const std::string& pluginSlug) { - std::string slug = normalizeSlug(pluginSlug); for (Plugin* plugin : plugins) { - if (plugin->slug == slug) { + if (plugin->slug == pluginSlug) { return plugin; } } diff --git a/src/plugin/Plugin.cpp b/src/plugin/Plugin.cpp index 359d3d88..12f363ff 100644 --- a/src/plugin/Plugin.cpp +++ b/src/plugin/Plugin.cpp @@ -23,7 +23,6 @@ void Plugin::addModel(Model* model) { } Model* Plugin::getModel(std::string slug) { - slug = normalizeSlug(slug); for (Model* model : models) { if (model->slug == slug) { return model;