From 3528e492861ef4db040550071ce35b8d74639126 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 15 Apr 2014 08:41:58 -0700 Subject: [PATCH] Make the duration field not completely wrong in frame mode --- src/subs_edit_box.cpp | 25 ++++++++++++++++++------- src/subs_edit_box.h | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/subs_edit_box.cpp b/src/subs_edit_box.cpp index 892b82486..7f7de7c1e 100644 --- a/src/subs_edit_box.cpp +++ b/src/subs_edit_box.cpp @@ -313,7 +313,7 @@ void SubsEditBox::OnCommit(int type) { if (type & AssFile::COMMIT_DIAG_TIME) { start_time->SetTime(line->Start); end_time->SetTime(line->End); - duration->SetTime(line->End - line->Start); + SetDurationField(); } if (type & AssFile::COMMIT_DIAG_TEXT) { @@ -468,7 +468,7 @@ void SubsEditBox::CommitTimes(TimeField field) { case TIME_DURATION: if (by_frame->GetValue()) - d->End = c->videoController->TimeAtFrame(c->videoController->FrameAtTime(d->Start, agi::vfr::START) + duration->GetFrame(), agi::vfr::END); + d->End = c->videoController->TimeAtFrame(c->videoController->FrameAtTime(d->Start, agi::vfr::START) + duration->GetFrame() - 1, agi::vfr::END); else d->End = d->Start + duration->GetTime(); initial_times[d].second = d->End; @@ -479,10 +479,8 @@ void SubsEditBox::CommitTimes(TimeField field) { start_time->SetTime(line->Start); end_time->SetTime(line->End); - if (by_frame->GetValue()) - duration->SetFrame(end_time->GetFrame() - start_time->GetFrame() + 1); - else - duration->SetTime(end_time->GetTime() - start_time->GetTime()); + if (field != TIME_DURATION) + SetDurationField(); if (field != last_time_commit_type) commit_id = -1; @@ -493,6 +491,16 @@ void SubsEditBox::CommitTimes(TimeField field) { file_changed_slot.Unblock(); } +void SubsEditBox::SetDurationField() { + // With VFR, the frame count calculated from the duration in time can be + // completely wrong (since the duration is calculated as if it were a start + // time), so we need to explicitly set it with the correct units. + if (by_frame->GetValue()) + duration->SetFrame(end_time->GetFrame() - start_time->GetFrame() + 1); + else + duration->SetTime(end_time->GetTime() - start_time->GetTime()); +} + void SubsEditBox::OnSize(wxSizeEvent &evt) { int availableWidth = GetVirtualSize().GetWidth(); int midMin = middle_left_sizer->GetMinSize().GetWidth(); @@ -517,12 +525,15 @@ void SubsEditBox::OnSize(wxSizeEvent &evt) { } void SubsEditBox::OnFrameTimeRadio(wxCommandEvent &event) { + event.Skip(); + bool byFrame = by_frame->GetValue(); start_time->SetByFrame(byFrame); end_time->SetByFrame(byFrame); duration->SetByFrame(byFrame); c->subsGrid->SetByFrame(byFrame); - event.Skip(); + + SetDurationField(); } void SubsEditBox::SetControlsState(bool state) { diff --git a/src/subs_edit_box.h b/src/subs_edit_box.h index bc69dda9d..cbb344107 100644 --- a/src/subs_edit_box.h +++ b/src/subs_edit_box.h @@ -195,6 +195,8 @@ class SubsEditBox final : public wxPanel { /// Call a command the restore focus to the edit box void CallCommand(const char *cmd_name); + void SetDurationField(); + SubsTextEditCtrl *edit_ctrl; wxTextCtrl *secondary_editor; std::unique_ptr textSelectionController;