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

Method ApplyJsonDiff

src/Timeline.cpp:1367–1405  ·  view source on GitHub ↗

Apply a special formatted JSON object, which represents a change to the timeline (insert, update, delete)

Source from the content-addressed store, hash-verified

1365
1366// Apply a special formatted JSON object, which represents a change to the timeline (insert, update, delete)
1367void Timeline::ApplyJsonDiff(std::string value) {
1368
1369 // Get lock (prevent getting frames while this happens)
1370 const std::lock_guard<std::recursive_mutex> lock(getFrameMutex);
1371
1372 // Parse JSON string into JSON objects
1373 try
1374 {
1375 const Json::Value root = openshot::stringToJson(value);
1376 // Process the JSON change array, loop through each item
1377 for (const Json::Value change : root) {
1378 std::string change_key = change["key"][(uint)0].asString();
1379
1380 // Process each type of change
1381 if (change_key == "clips")
1382 // Apply to CLIPS
1383 apply_json_to_clips(change);
1384
1385 else if (change_key == "effects")
1386 // Apply to EFFECTS
1387 apply_json_to_effects(change);
1388
1389 else
1390 // Apply to TIMELINE
1391 apply_json_to_timeline(change);
1392
1393 }
1394
1395 // Timeline content changed: notify cache clients to rescan active window.
1396 if (!root.empty()) {
1397 BumpCacheEpoch();
1398 }
1399 }
1400 catch (const std::exception& e)
1401 {
1402 // Error parsing JSON (or missing keys)
1403 throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
1404 }
1405}
1406
1407void Timeline::BumpCacheEpoch() {
1408 cache_epoch.fetch_add(1, std::memory_order_relaxed);

Callers 1

Timeline.cppFile · 0.80

Calls 1

InvalidJSONClass · 0.85

Tested by

no test coverage detected