2006-02-26 23:45:34 +01:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-02-26 23:45:34 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file subtitle_format.cpp
|
|
|
|
/// @brief Base class for subtitle format handlers
|
|
|
|
/// @ingroup subtitle_io
|
|
|
|
///
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
|
|
|
#include <wx/intl.h>
|
2009-09-11 00:48:29 +02:00
|
|
|
#include <wx/choicdlg.h> // Keep this last so wxUSE_CHOICEDLG is set.
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2006-02-27 22:57:10 +01:00
|
|
|
#include "subtitle_format.h"
|
2006-02-27 01:06:46 +01:00
|
|
|
#include "subtitle_format_ass.h"
|
2007-06-19 07:04:15 +02:00
|
|
|
#include "subtitle_format_encore.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "subtitle_format_microdvd.h"
|
|
|
|
#include "subtitle_format_mkv.h"
|
|
|
|
#include "subtitle_format_srt.h"
|
2008-07-18 03:36:20 +02:00
|
|
|
#include "subtitle_format_transtation.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "subtitle_format_ttxt.h"
|
|
|
|
#include "subtitle_format_txt.h"
|
2011-09-28 21:44:53 +02:00
|
|
|
#include "utils.h"
|
2010-07-08 06:29:04 +02:00
|
|
|
#include "video_context.h"
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
using namespace std::tr1::placeholders;
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
SubtitleFormat::SubtitleFormat(wxString const& name)
|
|
|
|
: name(name)
|
|
|
|
, isCopy(0)
|
|
|
|
, Line(0)
|
|
|
|
{
|
|
|
|
formats.push_back(this);
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
SubtitleFormat::~SubtitleFormat() {
|
|
|
|
formats.remove(this);
|
|
|
|
}
|
2006-02-27 22:57:10 +01:00
|
|
|
|
|
|
|
void SubtitleFormat::SetTarget(AssFile *file) {
|
|
|
|
ClearCopy();
|
2011-09-28 21:44:53 +02:00
|
|
|
Line = file ? &file->Line : 0;
|
2006-02-26 23:45:34 +01:00
|
|
|
assFile = file;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
bool SubtitleFormat::CanReadFile(wxString const& filename) const {
|
|
|
|
return GetReadWildcards().Index(filename.AfterLast('.'), false) != wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SubtitleFormat::CanWriteFile(wxString const& filename) const {
|
|
|
|
return GetWriteWildcards().Index(filename.AfterLast('.'), false) != wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:57:10 +01:00
|
|
|
void SubtitleFormat::CreateCopy() {
|
|
|
|
SetTarget(new AssFile(*assFile));
|
|
|
|
isCopy = true;
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:57:10 +01:00
|
|
|
void SubtitleFormat::ClearCopy() {
|
|
|
|
if (isCopy) {
|
|
|
|
delete assFile;
|
|
|
|
assFile = NULL;
|
|
|
|
isCopy = false;
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:57:10 +01:00
|
|
|
void SubtitleFormat::Clear() {
|
2006-02-26 23:45:34 +01:00
|
|
|
assFile->Clear();
|
|
|
|
}
|
|
|
|
|
2007-01-06 06:04:57 +01:00
|
|
|
void SubtitleFormat::LoadDefault(bool defline) {
|
|
|
|
assFile->LoadDefault(defline);
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
void SubtitleFormat::AddLine(wxString data, wxString group, int &version, wxString *outgroup) {
|
|
|
|
assFile->AddLine(data, group, version, outgroup);
|
2006-12-26 19:26:13 +01:00
|
|
|
}
|
2007-06-18 06:03:58 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Ask the user to enter the FPS
|
2011-12-22 22:27:53 +01:00
|
|
|
FractionalTime SubtitleFormat::AskForFPS(bool showSMPTE) {
|
2007-06-18 06:03:58 +02:00
|
|
|
wxArrayString choices;
|
2011-12-22 22:27:53 +01:00
|
|
|
bool drop = false;
|
2007-06-18 06:03:58 +02:00
|
|
|
|
|
|
|
// Video FPS
|
2010-07-08 06:29:04 +02:00
|
|
|
VideoContext *context = VideoContext::Get();
|
|
|
|
bool vidLoaded = context->TimecodesLoaded();
|
2007-06-18 06:03:58 +02:00
|
|
|
if (vidLoaded) {
|
|
|
|
wxString vidFPS;
|
2011-12-22 22:27:53 +01:00
|
|
|
if (context->FPS().IsVFR())
|
|
|
|
vidFPS = "VFR";
|
|
|
|
else
|
|
|
|
vidFPS = wxString::Format("%.3f", context->FPS().FPS());
|
|
|
|
choices.Add(wxString::Format(_("From video (%s)"), vidFPS));
|
2007-06-18 06:03:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Standard FPS values
|
2009-05-13 22:24:21 +02:00
|
|
|
choices.Add(_("15.000 FPS"));
|
|
|
|
choices.Add(_("23.976 FPS (Decimated NTSC)"));
|
|
|
|
choices.Add(_("24.000 FPS (FILM)"));
|
2007-06-18 06:03:58 +02:00
|
|
|
choices.Add(_("25.000 FPS (PAL)"));
|
|
|
|
choices.Add(_("29.970 FPS (NTSC)"));
|
2009-05-13 22:24:21 +02:00
|
|
|
if (showSMPTE)
|
|
|
|
choices.Add(_("29.970 FPS (NTSC with SMPTE dropframe)"));
|
|
|
|
choices.Add(_("30.000 FPS"));
|
|
|
|
choices.Add(_("50.000 FPS (PAL x2)"));
|
|
|
|
choices.Add(_("59.940 FPS (NTSC x2)"));
|
|
|
|
choices.Add(_("60.000 FPS"));
|
|
|
|
choices.Add(_("119.880 FPS (NTSC x4)"));
|
|
|
|
choices.Add(_("120.000 FPS"));
|
2007-06-18 06:03:58 +02:00
|
|
|
|
2011-12-22 22:28:13 +01:00
|
|
|
using agi::vfr::Framerate;
|
|
|
|
Framerate fps;
|
2007-06-18 06:03:58 +02:00
|
|
|
// Ask
|
2011-09-28 21:44:53 +02:00
|
|
|
int choice = wxGetSingleChoiceIndex(_("Please choose the appropriate FPS for the subtitles:"), _("FPS"), choices);
|
2011-12-22 22:27:53 +01:00
|
|
|
if (choice == -1)
|
2011-12-22 22:28:13 +01:00
|
|
|
return FractionalTime(fps);
|
2007-06-19 07:04:15 +02:00
|
|
|
|
2007-06-18 06:03:58 +02:00
|
|
|
// Get FPS from choice
|
|
|
|
if (vidLoaded) choice--;
|
2009-05-13 22:24:21 +02:00
|
|
|
// dropframe was displayed, that means all choices >4 are bumped up by 1
|
2011-12-22 22:27:53 +01:00
|
|
|
if (!showSMPTE && choice > 4) ++choice;
|
|
|
|
|
|
|
|
switch (choice) {
|
2011-12-22 22:28:13 +01:00
|
|
|
case -1: fps = context->FPS(); break; // VIDEO
|
|
|
|
case 0: fps = Framerate(15, 1); break;
|
|
|
|
case 1: fps = Framerate(24000, 1001); break;
|
|
|
|
case 2: fps = Framerate(24, 1); break;
|
|
|
|
case 3: fps = Framerate(25, 1); break;
|
|
|
|
case 4: fps = Framerate(30000, 1001); break;
|
|
|
|
case 5: fps = Framerate(30000, 1001); drop = true; break;
|
|
|
|
case 6: fps = Framerate(30, 1); break;
|
|
|
|
case 7: fps = Framerate(50, 1); break;
|
|
|
|
case 8: fps = Framerate(60000, 1001); break;
|
|
|
|
case 9: fps = Framerate(60, 1); break;
|
|
|
|
case 10: fps = Framerate(120000, 1001); break;
|
|
|
|
case 11: fps = Framerate(120, 1); break;
|
2007-06-18 06:03:58 +02:00
|
|
|
}
|
2011-12-22 22:27:53 +01:00
|
|
|
|
2011-12-22 22:28:13 +01:00
|
|
|
return FractionalTime(fps, drop);
|
2007-06-18 06:03:58 +02:00
|
|
|
}
|
2007-06-19 05:34:53 +02:00
|
|
|
|
|
|
|
void SubtitleFormat::SortLines() {
|
2010-05-19 02:44:44 +02:00
|
|
|
AssFile::Sort(*Line);
|
2007-06-19 05:34:53 +02:00
|
|
|
}
|
|
|
|
|
2011-11-25 20:28:19 +01:00
|
|
|
void SubtitleFormat::StripTags() {
|
2011-09-28 21:44:53 +02:00
|
|
|
for (std::list<AssEntry*>::iterator cur = Line->begin(); cur != Line->end(); ++cur) {
|
|
|
|
if (AssDialogue *current = dynamic_cast<AssDialogue*>(*cur)) {
|
2011-11-25 20:28:19 +01:00
|
|
|
current->StripTags();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-19 05:34:53 +02:00
|
|
|
|
2011-11-25 20:28:19 +01:00
|
|
|
void SubtitleFormat::ConvertNewlines(wxString const& newline, bool mergeLineBreaks) {
|
|
|
|
for (std::list<AssEntry*>::iterator cur = Line->begin(); cur != Line->end(); ++cur) {
|
|
|
|
if (AssDialogue *current = dynamic_cast<AssDialogue*>(*cur)) {
|
2011-09-28 21:44:53 +02:00
|
|
|
current->Text.Replace("\\h", " ");
|
2011-11-25 20:28:19 +01:00
|
|
|
current->Text.Replace("\\n", newline);
|
|
|
|
current->Text.Replace("\\N", newline);
|
2010-06-20 21:42:13 +02:00
|
|
|
if (mergeLineBreaks) {
|
2011-11-25 20:28:19 +01:00
|
|
|
while (current->Text.Replace(newline+newline, newline));
|
2010-06-20 21:42:13 +02:00
|
|
|
}
|
2007-06-19 05:34:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-18 17:39:34 +02:00
|
|
|
void SubtitleFormat::StripComments() {
|
2011-09-28 21:44:53 +02:00
|
|
|
for (std::list<AssEntry*>::iterator it = Line->begin(); it != Line->end(); ) {
|
|
|
|
AssDialogue *diag = dynamic_cast<AssDialogue*>(*it);
|
|
|
|
if (!diag || (!diag->Comment && diag->Text.size()))
|
|
|
|
++it;
|
|
|
|
else {
|
|
|
|
delete *it;
|
|
|
|
Line->erase(it++);
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleFormat::StripNonDialogue() {
|
2011-09-28 21:44:53 +02:00
|
|
|
for (std::list<AssEntry*>::iterator it = Line->begin(); it != Line->end(); ) {
|
|
|
|
if (dynamic_cast<AssDialogue*>(*it))
|
|
|
|
++it;
|
|
|
|
else {
|
|
|
|
delete *it;
|
|
|
|
Line->erase(it++);
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
static bool dialog_start_lt(AssEntry *pos, AssDialogue *to_insert) {
|
|
|
|
AssDialogue *diag = dynamic_cast<AssDialogue*>(pos);
|
|
|
|
return diag && diag->Start > to_insert->Start;
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
|
2010-01-06 06:23:58 +01:00
|
|
|
/// @brief Split and merge lines so there are no overlapping lines
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2010-01-06 06:23:58 +01:00
|
|
|
/// Algorithm described at http://devel.aegisub.org/wiki/Technical/SplitMerge
|
2008-07-18 17:39:34 +02:00
|
|
|
void SubtitleFormat::RecombineOverlaps() {
|
2011-09-28 21:44:53 +02:00
|
|
|
std::list<AssEntry*>::iterator cur, next = Line->begin();
|
|
|
|
cur = next++;
|
|
|
|
|
|
|
|
for (; next != Line->end(); cur = next++) {
|
2010-05-19 02:44:52 +02:00
|
|
|
AssDialogue *prevdlg = dynamic_cast<AssDialogue*>(*cur);
|
|
|
|
AssDialogue *curdlg = dynamic_cast<AssDialogue*>(*next);
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
if (!curdlg || !prevdlg) continue;
|
|
|
|
if (prevdlg->End <= curdlg->Start) continue;
|
|
|
|
|
|
|
|
// Use names like in the algorithm description and prepare for erasing
|
|
|
|
// old dialogues from the list
|
|
|
|
std::list<AssEntry*>::iterator prev = cur;
|
|
|
|
cur = next;
|
|
|
|
next++;
|
|
|
|
|
|
|
|
// std::list::insert() inserts items before the given iterator, so
|
|
|
|
// we need 'next' for inserting. 'prev' and 'cur' can safely be erased
|
|
|
|
// from the list now.
|
|
|
|
Line->erase(prev);
|
|
|
|
Line->erase(cur);
|
|
|
|
|
|
|
|
//Is there an A part before the overlap?
|
|
|
|
if (curdlg->Start > prevdlg->Start) {
|
|
|
|
// Produce new entry with correct values
|
|
|
|
AssDialogue *newdlg = dynamic_cast<AssDialogue*>(prevdlg->Clone());
|
|
|
|
newdlg->Start = prevdlg->Start;
|
|
|
|
newdlg->End = curdlg->Start;
|
|
|
|
newdlg->Text = prevdlg->Text;
|
|
|
|
|
|
|
|
Line->insert(find_if(next, Line->end(), bind(dialog_start_lt, _1, newdlg)), newdlg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overlapping A+B part
|
|
|
|
{
|
|
|
|
AssDialogue *newdlg = dynamic_cast<AssDialogue*>(prevdlg->Clone());
|
|
|
|
newdlg->Start = curdlg->Start;
|
|
|
|
newdlg->End = (prevdlg->End < curdlg->End) ? prevdlg->End : curdlg->End;
|
|
|
|
// Put an ASS format hard linewrap between lines
|
|
|
|
newdlg->Text = curdlg->Text + "\\N" + prevdlg->Text;
|
|
|
|
|
|
|
|
Line->insert(find_if(next, Line->end(), bind(dialog_start_lt, _1, newdlg)), newdlg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is there an A part after the overlap?
|
|
|
|
if (prevdlg->End > curdlg->End) {
|
|
|
|
// Produce new entry with correct values
|
|
|
|
AssDialogue *newdlg = dynamic_cast<AssDialogue*>(prevdlg->Clone());
|
|
|
|
newdlg->Start = curdlg->End;
|
|
|
|
newdlg->End = prevdlg->End;
|
|
|
|
newdlg->Text = prevdlg->Text;
|
|
|
|
|
|
|
|
Line->insert(find_if(next, Line->end(), bind(dialog_start_lt, _1, newdlg)), newdlg);
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
// Is there a B part after the overlap?
|
|
|
|
if (curdlg->End > prevdlg->End) {
|
|
|
|
// Produce new entry with correct values
|
|
|
|
AssDialogue *newdlg = dynamic_cast<AssDialogue*>(prevdlg->Clone());
|
|
|
|
newdlg->Start = prevdlg->End;
|
|
|
|
newdlg->End = curdlg->End;
|
|
|
|
newdlg->Text = curdlg->Text;
|
|
|
|
|
|
|
|
Line->insert(find_if(next, Line->end(), bind(dialog_start_lt, _1, newdlg)), newdlg);
|
|
|
|
}
|
|
|
|
|
|
|
|
next--;
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Merge identical lines that follow each other
|
2008-07-18 17:39:34 +02:00
|
|
|
void SubtitleFormat::MergeIdentical() {
|
2011-09-28 21:44:53 +02:00
|
|
|
std::list<AssEntry*>::iterator cur, next = Line->begin();
|
|
|
|
cur = next++;
|
2008-07-18 17:39:34 +02:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
for (; next != Line->end(); cur = next++) {
|
2010-05-19 02:44:52 +02:00
|
|
|
AssDialogue *curdlg = dynamic_cast<AssDialogue*>(*cur);
|
|
|
|
AssDialogue *nextdlg = dynamic_cast<AssDialogue*>(*next);
|
2008-07-18 17:39:34 +02:00
|
|
|
|
2008-08-11 02:02:36 +02:00
|
|
|
if (curdlg && nextdlg && curdlg->End == nextdlg->Start && curdlg->Text == nextdlg->Text) {
|
2008-07-18 17:39:34 +02:00
|
|
|
// Merge timing
|
2011-09-28 21:44:53 +02:00
|
|
|
nextdlg->Start = std::min(nextdlg->Start, curdlg->Start);
|
|
|
|
nextdlg->End = std::max(nextdlg->End, curdlg->End);
|
2008-07-18 17:39:34 +02:00
|
|
|
|
|
|
|
// Remove duplicate line
|
|
|
|
delete *cur;
|
|
|
|
Line->erase(cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
std::list<SubtitleFormat*> SubtitleFormat::formats;
|
|
|
|
|
|
|
|
void SubtitleFormat::LoadFormats() {
|
|
|
|
if (formats.empty()) {
|
|
|
|
new ASSSubtitleFormat();
|
|
|
|
new EncoreSubtitleFormat();
|
|
|
|
new MKVSubtitleFormat();
|
|
|
|
new MicroDVDSubtitleFormat();
|
|
|
|
new SRTSubtitleFormat();
|
|
|
|
new TTXTSubtitleFormat();
|
|
|
|
new TXTSubtitleFormat();
|
|
|
|
new TranStationSubtitleFormat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleFormat::DestroyFormats() {
|
|
|
|
for (std::list<SubtitleFormat*>::iterator it = formats.begin(); it != formats.end(); )
|
|
|
|
delete *it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Cont, class Pred>
|
|
|
|
SubtitleFormat *find_or_null(Cont &container, Pred pred) {
|
|
|
|
typename Cont::iterator it = find_if(container.begin(), container.end(), pred);
|
|
|
|
if (it == container.end())
|
|
|
|
return 0;
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubtitleFormat *SubtitleFormat::GetReader(wxString const& filename) {
|
|
|
|
LoadFormats();
|
|
|
|
return find_or_null(formats, bind(&SubtitleFormat::CanReadFile, _1, filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
SubtitleFormat *SubtitleFormat::GetWriter(wxString const& filename) {
|
|
|
|
LoadFormats();
|
|
|
|
return find_or_null(formats, bind(&SubtitleFormat::CanWriteFile, _1, filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString SubtitleFormat::GetWildcards(int mode) {
|
|
|
|
LoadFormats();
|
|
|
|
|
|
|
|
wxArrayString all;
|
|
|
|
wxString final;
|
|
|
|
|
|
|
|
std::list<SubtitleFormat*>::iterator curIter;
|
|
|
|
for (curIter=formats.begin();curIter!=formats.end();curIter++) {
|
|
|
|
SubtitleFormat *format = *curIter;
|
|
|
|
wxArrayString cur = mode == 0 ? format->GetReadWildcards() : format->GetWriteWildcards();
|
|
|
|
if (cur.empty()) continue;
|
|
|
|
|
|
|
|
for_each(cur.begin(), cur.end(), bind(&wxString::Prepend, _1, "*."));
|
|
|
|
copy(cur.begin(), cur.end(), std::back_inserter(all));
|
|
|
|
final += "|" + format->GetName() + " (" + wxJoin(cur, ',') + ")|" + wxJoin(cur, ';');
|
|
|
|
}
|
|
|
|
|
|
|
|
final.Prepend(_("All Supported Formats") + " (" + wxJoin(all, ',') + ")|" + wxJoin(all, ';'));
|
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|