Add function to calculate the end time for a subtitle line.

Originally committed to SVN as r5581.
This commit is contained in:
Kevin Ollivier 2011-09-01 06:16:07 +00:00
parent 2c6bee6d19
commit 7867aa9f30
5 changed files with 37 additions and 0 deletions

View File

@ -409,6 +409,8 @@ void FrameMain::InitMenu() {
AppendBitmapMenuItem(timingMenu,Menu_Subs_Snap_End_To_Video, MakeHotkeyText(_("Snap End to Video"), _T("Set End to Video")), _("Set end of selected subtitles to current video frame"), wxBITMAP(subend_to_video));
AppendBitmapMenuItem(timingMenu,Menu_Video_Snap_To_Scene, MakeHotkeyText(_("Snap to Scene"), _T("Snap to Scene")), _("Set start and end of subtitles to the keyframes around current video frame"), wxBITMAP(snap_subs_to_scene));
AppendBitmapMenuItem(timingMenu,Menu_Video_Shift_To_Frame, MakeHotkeyText(_("Shift to Current Frame"), _T("Shift by Current Time")), _("Shift selection so first selected line starts at current frame"), wxBITMAP(shift_to_frame));
timingMenu->Append(Menu_Subs_Calculate_End_Time, _("Calculate End Time for Frame(s)"), _("Calculate end time based on reading speed of 14 chars per second"));
timingMenu->AppendSeparator();
wxMenu *ContinuousMenu = new wxMenu;
wxMenuItem *ContinuousParent = new wxMenuItem(subtitlesMenu,-1,_("Make Times Continuous"),_T(""),wxITEM_NORMAL,ContinuousMenu);

View File

@ -226,6 +226,8 @@ private:
void OnOpenKanjiTimer (wxCommandEvent &event);
void OnOpenVideoDetails (wxCommandEvent &event);
void OnOpenASSDraw (wxCommandEvent &event);
void OnCalculateEndTime (wxCommandEvent &event);
void OnOpenOptions (wxCommandEvent &event);
void OnOpenLog (wxCommandEvent &event);
@ -415,6 +417,7 @@ enum {
Menu_Subs_Snap_End_To_Video,
Menu_Subs_Snap_Video_To_Start,
Menu_Subs_Snap_Video_To_End,
Menu_Subs_Calculate_End_Time,
Menu_Video_Snap_To_Scene,
Menu_Video_Shift_To_Frame,

View File

@ -191,6 +191,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Menu_Subs_Snap_End_To_Video, FrameMain::OnSnapSubsEndToVid)
EVT_MENU(Menu_Subs_Snap_Video_To_Start, FrameMain::OnSnapVidToSubsStart)
EVT_MENU(Menu_Subs_Snap_Video_To_End, FrameMain::OnSnapVidToSubsEnd)
EVT_MENU(Menu_Subs_Calculate_End_Time, FrameMain::OnCalculateEndTime)
EVT_MENU(Menu_Video_Snap_To_Scene, FrameMain::OnSnapToScene)
EVT_MENU(Menu_Video_Shift_To_Frame, FrameMain::OnShiftToFrame)
@ -1205,6 +1206,13 @@ void FrameMain::OnSnapVidToSubsEnd (wxCommandEvent &event) {
}
}
/// @brief Handler for menu event to calculate the end times of subtitles
/// @param event
///
void FrameMain::OnCalculateEndTime (wxCommandEvent &event) {
if (SubsBox)
SubsBox->CalculateEndTimeForLines(SubsBox->GetSelection());
}
/////////////////
// Snap to scene

View File

@ -1024,6 +1024,28 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
EndBatch();
}
/// @brief Calculate the end time for a given set of subtitle strings
/// @param lines
///
void SubtitlesGrid::CalculateEndTimeForLines(wxArrayInt lines)
{
AssDialogue *cur;
int nrows = lines.Count();
float charsPerSecond = 14.0;
for (int i=0;i<nrows;i++) {
int row = lines[i];
cur = GetDialogue(row);
int start = cur->Start.GetMS();
wxString text = cur->GetStrippedText();
float seconds = (float)text.Length() / charsPerSecond;
int lenms = seconds * 1000;
// make sure very short subtitles stay on for at least a second
if (lenms < 1000)
lenms = 1000;
cur->End.SetMS(start + lenms);
}
CommitChanges();
}
/////////////////////////
// Delete selected lines

View File

@ -133,6 +133,8 @@ public:
void CopyLines(wxArrayInt lines);
void CutLines(wxArrayInt lines);
void PasteLines(int pos,bool over=false);
void CalculateEndTimeForLines(wxArrayInt lines);
std::vector<int> GetAbsoluteSelection();
void SetSelectionFromAbsolute(std::vector<int> &selection);