MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / SetJsonValue

Method SetJsonValue

src/effects/Tracker.cpp:207–288  ·  view source on GitHub ↗

Load Json::Value into this object

Source from the content-addressed store, hash-verified

205
206// Load Json::Value into this object
207void Tracker::SetJsonValue(const Json::Value root) {
208
209 // Set parent data
210 EffectBase::SetJsonValue(root);
211
212 if (!root["BaseFPS"].isNull()) {
213 if (!root["BaseFPS"]["num"].isNull())
214 BaseFPS.num = root["BaseFPS"]["num"].asInt();
215 if (!root["BaseFPS"]["den"].isNull())
216 BaseFPS.den = root["BaseFPS"]["den"].asInt();
217 }
218
219 if (!root["TimeScale"].isNull()) {
220 TimeScale = root["TimeScale"].asDouble();
221 }
222
223 if (!root["protobuf_data_path"].isNull()) {
224 std::string new_path = root["protobuf_data_path"].asString();
225 if (protobuf_data_path != new_path || trackedData->GetLength() == 0) {
226 protobuf_data_path = new_path;
227 if (!trackedData->LoadBoxData(protobuf_data_path)) {
228 std::clog << "Invalid protobuf data path " << protobuf_data_path << '\n';
229 protobuf_data_path.clear();
230 }
231 else {
232 // prefix "<effectUUID>-<index>" for each entry
233 for (auto& kv : trackedObjects) {
234 auto idx = kv.first;
235 auto ptr = kv.second;
236 if (ptr) {
237 std::string prefix = this->Id();
238 if (!prefix.empty())
239 prefix += "-";
240 ptr->Id(prefix + std::to_string(idx));
241 }
242 }
243 }
244 }
245 }
246
247 // then any per-object JSON overrides...
248 if (!root["objects"].isNull()) {
249 // Iterate over the supplied objects (indexed by id or position)
250 const auto memberNames = root["objects"].getMemberNames();
251 for (const auto& name : memberNames)
252 {
253 // Determine the numeric index of this object
254 int index = -1;
255 bool numeric_key = std::all_of(name.begin(), name.end(), ::isdigit);
256 if (numeric_key) {
257 index = std::stoi(name);
258 }
259 else
260 {
261 size_t pos = name.find_last_of('-');
262 if (pos != std::string::npos) {
263 try {
264 index = std::stoi(name.substr(pos + 1));

Callers

nothing calls this directly

Calls 4

LoadBoxDataMethod · 0.80
GetLengthMethod · 0.45
clearMethod · 0.45
IdMethod · 0.45

Tested by

no test coverage detected