Skip to content

Commit ee58130

Browse files
authored
Merge pull request #973 from OpenShot/drag-off-timeline
Do not add +1 to GetMaxFrame() calculation
2 parents d906231 + 118810f commit ee58130

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Timeline.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ double Timeline::GetMaxTime() {
469469
int64_t Timeline::GetMaxFrame() {
470470
double fps = info.fps.ToDouble();
471471
auto max_time = GetMaxTime();
472-
return std::round(max_time * fps) + 1;
472+
return std::round(max_time * fps);
473473
}
474474

475475
// Apply a FrameMapper to a clip which matches the settings of this timeline

tests/Timeline.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ TEST_CASE( "GetMaxFrame and GetMaxTime", "[libopenshot][timeline]" )
615615
t.AddClip(&clip1);
616616

617617
CHECK(t.GetMaxTime() == Approx(95.0).margin(0.001));
618-
CHECK(t.GetMaxFrame() == 95 * 30 + 1);
618+
CHECK(t.GetMaxFrame() == 95 * 30);
619619

620620
Clip clip2(path1.str());
621621
clip2.Id("C2");
@@ -624,40 +624,40 @@ TEST_CASE( "GetMaxFrame and GetMaxTime", "[libopenshot][timeline]" )
624624
clip2.End(55);
625625
t.AddClip(&clip2);
626626

627-
CHECK(t.GetMaxFrame() == 95 * 30 + 1);
627+
CHECK(t.GetMaxFrame() == 95 * 30);
628628
CHECK(t.GetMaxTime() == Approx(95.0).margin(0.001));
629629

630630
clip1.Position(80);
631631
clip2.Position(100);
632-
CHECK(t.GetMaxFrame() == 155 * 30 + 1);
632+
CHECK(t.GetMaxFrame() == 155 * 30);
633633
CHECK(t.GetMaxTime() == Approx(155.0).margin(0.001));
634634

635635
clip2.Start(20);
636-
CHECK(t.GetMaxFrame() == 135 * 30 + 1);
636+
CHECK(t.GetMaxFrame() == 135 * 30);
637637
CHECK(t.GetMaxTime() == Approx(135.0).margin(0.001));
638638

639639
clip2.End(35);
640-
CHECK(t.GetMaxFrame() == 125 * 30 + 1);
640+
CHECK(t.GetMaxFrame() == 125 * 30);
641641
CHECK(t.GetMaxTime() == Approx(125.0).margin(0.001));
642642

643643
t.RemoveClip(&clip1);
644-
CHECK(t.GetMaxFrame() == 115 * 30 + 1);
644+
CHECK(t.GetMaxFrame() == 115 * 30);
645645
CHECK(t.GetMaxTime() == Approx(115.0).margin(0.001));
646646

647647
// Update Clip's basic properties with JSON Diff
648648
std::stringstream json_change1;
649649
json_change1 << "[{\"type\":\"update\",\"key\":[\"clips\",{\"id\":\"C2\"}],\"value\":{\"id\":\"C2\",\"layer\":4000000,\"position\":0.0,\"start\":0,\"end\":10},\"partial\":false}]";
650650
t.ApplyJsonDiff(json_change1.str());
651651

652-
CHECK(t.GetMaxFrame() == 10 * 30 + 1);
652+
CHECK(t.GetMaxFrame() == 10 * 30);
653653
CHECK(t.GetMaxTime() == Approx(10.0).margin(0.001));
654654

655655
// Insert NEW Clip with JSON Diff
656656
std::stringstream json_change2;
657657
json_change2 << "[{\"type\":\"insert\",\"key\":[\"clips\"],\"value\":{\"id\":\"C3\",\"layer\":4000000,\"position\":10.0,\"start\":0,\"end\":10,\"reader\":{\"acodec\":\"\",\"audio_bit_rate\":0,\"audio_stream_index\":-1,\"audio_timebase\":{\"den\":1,\"num\":1},\"channel_layout\":4,\"channels\":0,\"display_ratio\":{\"den\":1,\"num\":1},\"duration\":3600.0,\"file_size\":\"160000\",\"fps\":{\"den\":1,\"num\":30},\"has_audio\":false,\"has_single_image\":true,\"has_video\":true,\"height\":200,\"interlaced_frame\":false,\"metadata\":{},\"path\":\"" << path1.str() << "\",\"pixel_format\":-1,\"pixel_ratio\":{\"den\":1,\"num\":1},\"sample_rate\":0,\"top_field_first\":true,\"type\":\"QtImageReader\",\"vcodec\":\"\",\"video_bit_rate\":0,\"video_length\":\"108000\",\"video_stream_index\":-1,\"video_timebase\":{\"den\":30,\"num\":1},\"width\":200}},\"partial\":false}]";
658658
t.ApplyJsonDiff(json_change2.str());
659659

660-
CHECK(t.GetMaxFrame() == 20 * 30 + 1);
660+
CHECK(t.GetMaxFrame() == 20 * 30);
661661
CHECK(t.GetMaxTime() == Approx(20.0).margin(0.001));
662662
}
663663

0 commit comments

Comments
 (0)