Don't use the ms time value of the Duration time edit control when in frame mode, as with vfr this may not actually represent a consisten number of frames

Originally committed to SVN as r6132.
This commit is contained in:
Thomas Goyne 2011-12-22 21:30:22 +00:00
parent 2c324de29c
commit e5707ca6eb
3 changed files with 33 additions and 8 deletions

View file

@ -363,7 +363,7 @@ void SubsEditBox::Update(int type) {
if (type & AssFile::COMMIT_DIAG_TIME) { if (type & AssFile::COMMIT_DIAG_TIME) {
StartTime->SetTime(line->Start); StartTime->SetTime(line->Start);
EndTime->SetTime(line->End); EndTime->SetTime(line->End);
Duration->SetTime(line->End-line->Start); Duration->SetTime(line->End - line->Start);
} }
if (type & AssFile::COMMIT_DIAG_TEXT) { if (type & AssFile::COMMIT_DIAG_TEXT) {
@ -519,21 +519,30 @@ void SubsEditBox::CommitText(wxString desc) {
} }
void SubsEditBox::CommitTimes(TimeField field) { void SubsEditBox::CommitTimes(TimeField field) {
Duration->SetTime(EndTime->GetTime() - StartTime->GetTime()); if (ByFrame->GetValue())
Duration->SetFrame(EndTime->GetFrame() - StartTime->GetFrame() + 1);
else
Duration->SetTime(EndTime->GetTime() - StartTime->GetTime());
// Update lines // Update lines
for (Selection::iterator cur = sel.begin(); cur != sel.end(); ++cur) { for (Selection::iterator cur = sel.begin(); cur != sel.end(); ++cur) {
AssDialogue *d = *cur;
switch (field) { switch (field) {
case TIME_START: case TIME_START:
(*cur)->Start = StartTime->GetTime(); d->Start = StartTime->GetTime();
if ((*cur)->Start > (*cur)->End) (*cur)->End = (*cur)->Start; if (d->Start > d->End)
d->End = d->Start;
break; break;
case TIME_END: case TIME_END:
(*cur)->End = EndTime->GetTime(); d->End = EndTime->GetTime();
if ((*cur)->Start > (*cur)->End) (*cur)->Start = (*cur)->End; if (d->Start > d->End)
d->Start = d->End;
break; break;
case TIME_DURATION: case TIME_DURATION:
(*cur)->End = (*cur)->Start + Duration->GetTime(); if (ByFrame->GetValue())
d->End = c->videoController->TimeAtFrame(c->videoController->FrameAtTime(d->Start, agi::vfr::START) + Duration->GetFrame(), agi::vfr::END);
else
d->End = d->Start + Duration->GetTime();
break; break;
} }
} }
@ -643,7 +652,10 @@ void SubsEditBox::OnEndTimeChange(wxCommandEvent &) {
} }
void SubsEditBox::OnDurationChange(wxCommandEvent &) { void SubsEditBox::OnDurationChange(wxCommandEvent &) {
EndTime->SetTime(StartTime->GetTime() + Duration->GetTime()); if (ByFrame->GetValue())
EndTime->SetFrame(StartTime->GetFrame() + Duration->GetFrame() - 1);
else
EndTime->SetTime(StartTime->GetTime() + Duration->GetTime());
CommitTimes(TIME_DURATION); CommitTimes(TIME_DURATION);
} }
void SubsEditBox::OnMarginLChange(wxCommandEvent &) { void SubsEditBox::OnMarginLChange(wxCommandEvent &) {

View file

@ -104,6 +104,14 @@ void TimeEdit::SetTime(AssTime new_time) {
} }
} }
int TimeEdit::GetFrame() const {
return c->videoController->FrameAtTime(time, isEnd ? agi::vfr::END : agi::vfr::START);
}
void TimeEdit::SetFrame(int fn) {
SetTime(c->videoController->TimeAtFrame(fn, isEnd ? agi::vfr::END : agi::vfr::START));
}
void TimeEdit::SetByFrame(bool enableByFrame) { void TimeEdit::SetByFrame(bool enableByFrame) {
if (enableByFrame == byFrame) return; if (enableByFrame == byFrame) return;

View file

@ -78,6 +78,11 @@ public:
/// Set the time /// Set the time
void SetTime(AssTime time); void SetTime(AssTime time);
/// Get the current time as a frame number, or 0 if timecodes are unavailable
int GetFrame() const;
/// Set the time to a frame number. Does nothing if timecodes are unavailable
void SetFrame(int fn);
/// Set whether the time is displayed as a time or the corresponding frame number /// Set whether the time is displayed as a time or the corresponding frame number
/// @param enableByFrame If true, frame numbers are displayed /// @param enableByFrame If true, frame numbers are displayed
void SetByFrame(bool enableByFrame); void SetByFrame(bool enableByFrame);