Skip to content

Commit 6cea273

Browse files
committed
Fix timeline cache when updating Clips with ApplyJsonDiff (old and new position)
1 parent 713cf39 commit 6cea273

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Timeline.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,17 +1431,26 @@ void Timeline::apply_json_to_clips(Json::Value change) {
14311431

14321432
// Update existing clip
14331433
if (existing_clip) {
1434+
// Calculate start and end frames prior to the update
1435+
int64_t old_starting_frame = (existing_clip->Position() * info.fps.ToDouble()) + 1;
1436+
int64_t old_ending_frame = ((existing_clip->Position() + existing_clip->Duration()) * info.fps.ToDouble()) + 1;
1437+
14341438
// Update clip properties from JSON
14351439
existing_clip->SetJsonValue(change["value"]);
14361440

1437-
// Calculate start and end frames that this impacts, and remove those frames from the cache
1438-
int64_t old_starting_frame = (existing_clip->Position() * info.fps.ToDouble()) + 1;
1439-
int64_t old_ending_frame = ((existing_clip->Position() + existing_clip->Duration()) * info.fps.ToDouble()) + 1;
1441+
// Calculate new start and end frames after the update
1442+
int64_t new_starting_frame = (existing_clip->Position() * info.fps.ToDouble()) + 1;
1443+
int64_t new_ending_frame = ((existing_clip->Position() + existing_clip->Duration()) * info.fps.ToDouble()) + 1;
1444+
1445+
// Remove both the old and new ranges from the timeline cache
14401446
final_cache->Remove(old_starting_frame - 8, old_ending_frame + 8);
1447+
final_cache->Remove(new_starting_frame - 8, new_ending_frame + 8);
14411448

14421449
// Remove cache on clip's Reader (if found)
1443-
if (existing_clip->Reader() && existing_clip->Reader()->GetCache())
1450+
if (existing_clip->Reader() && existing_clip->Reader()->GetCache()) {
14441451
existing_clip->Reader()->GetCache()->Remove(old_starting_frame - 8, old_ending_frame + 8);
1452+
existing_clip->Reader()->GetCache()->Remove(new_starting_frame - 8, new_ending_frame + 8);
1453+
}
14451454

14461455
// Apply framemapper (or update existing framemapper)
14471456
if (auto_map_clips) {
@@ -1464,13 +1473,6 @@ void Timeline::apply_json_to_clips(Json::Value change) {
14641473

14651474
}
14661475

1467-
// Calculate start and end frames that this impacts, and remove those frames from the cache
1468-
if (!change["value"].isArray() && !change["value"]["position"].isNull()) {
1469-
int64_t new_starting_frame = (change["value"]["position"].asDouble() * info.fps.ToDouble()) + 1;
1470-
int64_t new_ending_frame = ((change["value"]["position"].asDouble() + change["value"]["end"].asDouble() - change["value"]["start"].asDouble()) * info.fps.ToDouble()) + 1;
1471-
final_cache->Remove(new_starting_frame - 8, new_ending_frame + 8);
1472-
}
1473-
14741476
// Re-Sort Clips (since they likely changed)
14751477
sort_clips();
14761478
}

0 commit comments

Comments
 (0)