You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.6KB

  1. #include <algorithm>
  2. #include <plugin/Model.hpp>
  3. #include <plugin.hpp>
  4. #include <asset.hpp>
  5. #include <system.hpp>
  6. #include <string.hpp>
  7. #include <tag.hpp>
  8. namespace rack {
  9. namespace plugin {
  10. void Model::fromJson(json_t* rootJ) {
  11. assert(plugin);
  12. json_t* nameJ = json_object_get(rootJ, "name");
  13. if (nameJ)
  14. name = json_string_value(nameJ);
  15. if (name == "")
  16. throw Exception("No module name for slug %s", slug.c_str());
  17. json_t* descriptionJ = json_object_get(rootJ, "description");
  18. if (descriptionJ)
  19. description = json_string_value(descriptionJ);
  20. // Tags
  21. tags.clear();
  22. json_t* tagsJ = json_object_get(rootJ, "tags");
  23. if (tagsJ) {
  24. size_t i;
  25. json_t* tagJ;
  26. json_array_foreach(tagsJ, i, tagJ) {
  27. std::string tag = json_string_value(tagJ);
  28. int tagId = tag::findId(tag);
  29. // Omit duplicates
  30. auto it = std::find(tags.begin(), tags.end(), tagId);
  31. if (it != tags.end())
  32. continue;
  33. if (tagId >= 0)
  34. tags.push_back(tagId);
  35. }
  36. }
  37. // manualUrl
  38. json_t* manualUrlJ = json_object_get(rootJ, "manualUrl");
  39. if (manualUrlJ)
  40. manualUrl = json_string_value(manualUrlJ);
  41. // modularGridUrl
  42. json_t* modularGridUrlJ = json_object_get(rootJ, "modularGridUrl");
  43. if (modularGridUrlJ)
  44. modularGridUrl = json_string_value(modularGridUrlJ);
  45. }
  46. std::string Model::getFullName() {
  47. assert(plugin);
  48. return plugin->getBrand() + " " + name;
  49. }
  50. std::string Model::getFactoryPresetDir() {
  51. return asset::plugin(plugin, system::join("presets", slug));
  52. }
  53. std::string Model::getUserPresetDir() {
  54. return asset::user(system::join("presets", plugin->slug, slug));
  55. }
  56. } // namespace plugin
  57. } // namespace rack