MCPcopy Create free account
hub / github.com/VCVRack/Rack / fromJson

Method fromJson

src/plugin/Plugin.cpp:37–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void Plugin::fromJson(json_t* rootJ) {
38 // slug
39 json_t* slugJ = json_object_get(rootJ, "slug");
40 if (slugJ)
41 slug = json_string_value(slugJ);
42 if (slug == "")
43 throw Exception("No plugin slug");
44 if (!isSlugValid(slug))
45 throw Exception("Plugin slug \"%s\" is invalid", slug.c_str());
46
47 // version
48 json_t* versionJ = json_object_get(rootJ, "version");
49 if (versionJ)
50 version = json_string_value(versionJ);
51 if (version == "")
52 throw Exception("No plugin version");
53 if (!string::startsWith(version, APP_VERSION_MAJOR + "."))
54 throw Exception("Plugin version %s does not match Rack ABI version %s", version.c_str(), APP_VERSION_MAJOR.c_str());
55
56 // name
57 json_t* nameJ = json_object_get(rootJ, "name");
58 if (nameJ)
59 name = json_string_value(nameJ);
60 if (name == "")
61 throw Exception("No plugin name");
62
63 // brand
64 json_t* brandJ = json_object_get(rootJ, "brand");
65 if (brandJ)
66 brand = json_string_value(brandJ);
67 // If brand is not set, fall back to the plugin name
68 if (brand == "")
69 brand = name;
70
71 json_t* descriptionJ = json_object_get(rootJ, "description");
72 if (descriptionJ)
73 description = json_string_value(descriptionJ);
74
75 json_t* authorJ = json_object_get(rootJ, "author");
76 if (authorJ)
77 author = json_string_value(authorJ);
78
79 json_t* licenseJ = json_object_get(rootJ, "license");
80 if (licenseJ)
81 license = json_string_value(licenseJ);
82
83 json_t* authorEmailJ = json_object_get(rootJ, "authorEmail");
84 if (authorEmailJ)
85 authorEmail = json_string_value(authorEmailJ);
86
87 json_t* pluginUrlJ = json_object_get(rootJ, "pluginUrl");
88 if (pluginUrlJ)
89 pluginUrl = json_string_value(pluginUrlJ);
90
91 json_t* authorUrlJ = json_object_get(rootJ, "authorUrl");
92 if (authorUrlJ)
93 authorUrl = json_string_value(authorUrlJ);
94

Callers 1

json_array_foreachFunction · 0.45

Calls 3

ExceptionClass · 0.85
isSlugValidFunction · 0.85
startsWithFunction · 0.85

Tested by

no test coverage detected