Simplify some AssTime-using code

Originally committed to SVN as r6124.
This commit is contained in:
Thomas Goyne 2011-12-22 21:29:09 +00:00
parent 71345af81a
commit 5cbd35e749
5 changed files with 7 additions and 28 deletions

View file

@ -464,13 +464,10 @@ void AudioTimingControllerDialogue::Revert()
{ {
if (AssDialogue *line = context->selectionController->GetActiveLine()) if (AssDialogue *line = context->selectionController->GetActiveLine())
{ {
AssTime new_start = line->Start; if (line->Start != 0 || line->End != 0)
AssTime new_end = line->End;
if (new_start != 0 || new_end != 0)
{ {
active_markers[0].SetPosition(context->audioController->SamplesFromMilliseconds(new_start)); active_markers[0].SetPosition(context->audioController->SamplesFromMilliseconds(line->Start));
active_markers[1].SetPosition(context->audioController->SamplesFromMilliseconds(new_end)); active_markers[1].SetPosition(context->audioController->SamplesFromMilliseconds(line->End));
timing_modified = false; timing_modified = false;
UpdateSelection(); UpdateSelection();
} }

View file

@ -62,7 +62,6 @@ DialogJumpTo::DialogJumpTo(agi::Context *c)
SetIcon(BitmapToIcon(GETIMAGE(jumpto_button_24))); SetIcon(BitmapToIcon(GETIMAGE(jumpto_button_24)));
// Set initial values // Set initial values
AssTime jumptime = c->videoController->TimeAtFrame(jumpframe);
wxString maxLength = wxString::Format("%i",c->videoController->GetLength() - 1); wxString maxLength = wxString::Format("%i",c->videoController->GetLength() - 1);
// Times // Times
@ -70,7 +69,7 @@ DialogJumpTo::DialogJumpTo(agi::Context *c)
wxStaticText *LabelTime = new wxStaticText(this,-1,_("Time: "),wxDefaultPosition,wxSize(60,20)); wxStaticText *LabelTime = new wxStaticText(this,-1,_("Time: "),wxDefaultPosition,wxSize(60,20));
JumpFrame = new wxTextCtrl(this,-1,"",wxDefaultPosition,wxSize(60,20),wxTE_PROCESS_ENTER, NumValidator((int)jumpframe)); JumpFrame = new wxTextCtrl(this,-1,"",wxDefaultPosition,wxSize(60,20),wxTE_PROCESS_ENTER, NumValidator((int)jumpframe));
JumpFrame->SetMaxLength(maxLength.size()); JumpFrame->SetMaxLength(maxLength.size());
JumpTime = new TimeEdit(this, -1, c, jumptime.GetASSFormated(), wxSize(60,20)); JumpTime = new TimeEdit(this, -1, c, AssTime(c->videoController->TimeAtFrame(jumpframe)).GetASSFormated(), wxSize(60,20));
wxSizer *FrameSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *FrameSizer = new wxBoxSizer(wxHORIZONTAL);
wxSizer *TimeSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *TimeSizer = new wxBoxSizer(wxHORIZONTAL);
FrameSizer->Add(LabelFrame,0,wxALIGN_CENTER_VERTICAL,0); FrameSizer->Add(LabelFrame,0,wxALIGN_CENTER_VERTICAL,0);

View file

@ -355,20 +355,7 @@ allparsed:
wxString WriteSRTTime(AssTime const& ts) wxString WriteSRTTime(AssTime const& ts)
{ {
int time = ts; return wxString::Format("%02d:%02d:%02d,%03d", ts.GetTimeHours(), ts.GetTimeMinutes(), ts.GetTimeSeconds(), ts.GetTimeMiliseconds());
int ms_part = time % 1000;
time /= 1000; // now holds seconds
int s_part = time % 60;
time /= 60; // now holds minutes
int m_part = time % 60;
time /= 60; // now holds hours
int h_part = time;
return wxString::Format("%02d:%02d:%02d,%03d", h_part, m_part, s_part, ms_part);
} }
} }
@ -397,7 +384,6 @@ void SRTSubtitleFormat::ReadFile(wxString const& filename, wxString const& encod
// See parsing algorithm at <http://devel.aegisub.org/wiki/SubtitleFormats/SRT> // See parsing algorithm at <http://devel.aegisub.org/wiki/SubtitleFormats/SRT>
// "hh:mm:ss,fff --> hh:mm:ss,fff" (e.g. "00:00:04,070 --> 00:00:10,04") // "hh:mm:ss,fff --> hh:mm:ss,fff" (e.g. "00:00:04,070 --> 00:00:10,04")
/// @todo: move the full parsing of SRT timestamps here, instead of having it in AssTime
wxRegEx timestamp_regex("^([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{1,}) --> ([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{1,})"); wxRegEx timestamp_regex("^([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{1,}) --> ([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{1,})");
if (!timestamp_regex.IsValid()) if (!timestamp_regex.IsValid())
throw agi::InternalError("Parsing SRT: Failed compiling regex", 0); throw agi::InternalError("Parsing SRT: Failed compiling regex", 0);
@ -444,7 +430,6 @@ found_timestamps:
line->group = "[Events]"; line->group = "[Events]";
line->Style = "Default"; line->Style = "Default";
line->Comment = false; line->Comment = false;
// this parsing should best be moved out of AssTime
line->Start = ReadSRTTime(timestamp_regex.GetMatch(text_line, 1)); line->Start = ReadSRTTime(timestamp_regex.GetMatch(text_line, 1));
line->End = ReadSRTTime(timestamp_regex.GetMatch(text_line, 2)); line->End = ReadSRTTime(timestamp_regex.GetMatch(text_line, 2));
// store pointer to subtitle, we'll continue working on it // store pointer to subtitle, we'll continue working on it

View file

@ -112,7 +112,6 @@ wxString TranStationSubtitleFormat::ConvertLine(AssDialogue *current, Fractional
if (current->Text.Find("\\i1") != wxNOT_FOUND) type = "I"; if (current->Text.Find("\\i1") != wxNOT_FOUND) type = "I";
// Write header // Write header
AssTime start = current->Start;
AssTime end = current->End; AssTime end = current->End;
// Subtract one frame if the end time of the current line is equal to the // Subtract one frame if the end time of the current line is equal to the
@ -121,7 +120,7 @@ wxString TranStationSubtitleFormat::ConvertLine(AssDialogue *current, Fractional
if (nextl_start > 0 && end == nextl_start) if (nextl_start > 0 && end == nextl_start)
end = ft->FPS().TimeAtFrame(ft->FPS().FrameAtTime(end, agi::vfr::END) - 1, agi::vfr::END); end = ft->FPS().TimeAtFrame(ft->FPS().FrameAtTime(end, agi::vfr::END) - 1, agi::vfr::END);
wxString header = wxString::Format("SUB[%i%s%s ", valign, halign, type) + ft->ToSMPTE(start) + ">" + ft->ToSMPTE(end) + "]\r\n"; wxString header = wxString::Format("SUB[%i%s%s ", valign, halign, type) + ft->ToSMPTE(current->Start) + ">" + ft->ToSMPTE(end) + "]\r\n";
// Process text // Process text
wxString lineEnd = "\r\n"; wxString lineEnd = "\r\n";

View file

@ -288,8 +288,7 @@ void TTXTSubtitleFormat::ConvertToTTXT () {
// Find last line // Find last line
AssTime lastTime; AssTime lastTime;
for (std::list<AssEntry*>::reverse_iterator cur=Line->rbegin();cur!=Line->rend();cur++) { for (std::list<AssEntry*>::reverse_iterator cur=Line->rbegin();cur!=Line->rend();cur++) {
AssDialogue *prev = dynamic_cast<AssDialogue*>(*cur); if (AssDialogue *prev = dynamic_cast<AssDialogue*>(*cur)) {
if (prev) {
lastTime = prev->End; lastTime = prev->End;
break; break;
} }