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.

51 lines
1.1KB

  1. #include <plugin/Model.hpp>
  2. #include <plugin.hpp>
  3. #include <asset.hpp>
  4. #include <system.hpp>
  5. #include <string.hpp>
  6. #include <tag.hpp>
  7. namespace rack {
  8. namespace plugin {
  9. void Model::fromJson(json_t* rootJ) {
  10. assert(plugin);
  11. json_t* nameJ = json_object_get(rootJ, "name");
  12. if (nameJ)
  13. name = json_string_value(nameJ);
  14. if (name == "")
  15. throw UserException(string::f("No module name for slug %s", slug.c_str()));
  16. json_t* descriptionJ = json_object_get(rootJ, "description");
  17. if (descriptionJ)
  18. description = json_string_value(descriptionJ);
  19. // Tags
  20. tags.clear();
  21. json_t* tagsJ = json_object_get(rootJ, "tags");
  22. if (tagsJ) {
  23. size_t i;
  24. json_t* tagJ;
  25. json_array_foreach(tagsJ, i, tagJ) {
  26. std::string tag = json_string_value(tagJ);
  27. int tagId = tag::findId(tag);
  28. if (tagId >= 0)
  29. tags.push_back(tagId);
  30. }
  31. }
  32. // Preset paths
  33. presetPaths.clear();
  34. std::string presetDir = asset::plugin(plugin, "presets/" + slug);
  35. for (const std::string& presetPath : system::getEntries(presetDir)) {
  36. presetPaths.push_back(presetPath);
  37. }
  38. }
  39. } // namespace plugin
  40. } // namespace rack