diff --git a/core/ass_file.cpp b/core/ass_file.cpp index f720477d1..361fc4003 100644 --- a/core/ass_file.cpp +++ b/core/ass_file.cpp @@ -48,6 +48,7 @@ #include "text_file_reader.h" #include "text_file_writer.h" #include "version.h" +#include "subtitle_format_srt.h" ////////////////////// AssFile ////////////////////// @@ -105,7 +106,10 @@ void AssFile::Load (const wxString _filename,const wxString charset) { // SRT else if (extension == _T("srt")) { - LoadSRT(_filename,enc); + //LoadSRT(_filename,enc); + SRTSubtitleFormatReader srt; + srt.SetTarget(this); + srt.ReadFile(_filename,enc); } // SSA @@ -202,83 +206,6 @@ void AssFile::LoadASS (const wxString _filename,const wxString encoding,bool IsS } -//////////////////////////// -// Loads SRT subs from disk -void AssFile::LoadSRT (wxString _filename,wxString encoding) { - using namespace std; - - // Reader - TextFileReader file(_filename,encoding); - - // Default - LoadDefault(false); - IsASS = false; - - // Parse file - int linen = 1; - int fileLine = 0; - int mode = 0; - long templ; - AssDialogue *line = NULL; - while (file.HasMoreLines()) { - // Reads line - wxString curline = file.ReadLineFromFile(); - fileLine++; - - switch (mode) { - case 0: - // Checks if there is anything to read - if (curline.IsEmpty()) continue; - - // Check if it's a line number - if (!curline.IsNumber()) { - Clear(); - throw wxString::Format(_T("Parse error on entry %i at line %i (expecting line number). Possible malformed file."),linen,fileLine); - } - - // Read line number - curline.ToLong(&templ); - if (templ != linen) { - linen = templ; - } - line = new AssDialogue(); - mode = 1; - break; - - case 1: - // Read timestamps - if (curline.substr(13,3) != _T("-->")) { - Clear(); - throw wxString::Format(_T("Parse error on entry %i at line %i (expecting timestamps). Possible malformed file."),linen,fileLine); - } - line->Start.ParseSRT(curline.substr(0,12)); - line->End.ParseSRT(curline.substr(17,12)); - mode = 2; - break; - - case 2: - // Checks if it's done - if (curline.IsEmpty()) { - mode = 0; - linen++; - line->group = _T("[Events]"); - line->Style = _T("Default"); - line->Comment = false; - line->UpdateData(); - line->ParseSRTTags(); - line->StartMS = line->Start.GetMS(); - Line.push_back(line); - break; - } - // Append text - if (line->Text != _T("")) line->Text += _T("\\N"); - line->Text += curline; - break; - } - } -} - - //////////////////////////// // Loads TXT subs from disk void AssFile::LoadTXT (wxString _filename,wxString encoding) { diff --git a/core/ass_file.h b/core/ass_file.h index a18d05e33..6405c3f88 100644 --- a/core/ass_file.h +++ b/core/ass_file.h @@ -69,7 +69,6 @@ private: // I/O operations void LoadASS(const wxString file,const wxString encoding,bool IsSSA=false); - void LoadSRT(const wxString file,const wxString encoding); void LoadTXT(const wxString file,const wxString encoding); void SaveASS(const wxString file,bool setfilename,const wxString encoding=_T("")); void SaveSSA(const wxString file,const wxString encoding=_T("")); @@ -77,10 +76,10 @@ private: // Manipulation operations int AddLine(wxString data,wxString group,int lasttime,bool &IsSSA); + void ConvertToSRT(); void DialogueToSRT(AssDialogue *current,std::list::iterator prev); // Format conversion operations - void ConvertToSRT(); void ConvertToSSA(); public: diff --git a/core/main.cpp b/core/main.cpp index ca032188a..9b11fe8e1 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -70,9 +70,9 @@ bool AegisubApp::OnInit() { // App name SetAppName(_T("Aegisub")); - //#ifndef _DEBUG + #ifndef _DEBUG wxHandleFatalExceptions(true); - //#endif + #endif // Set config file GetFullPath(argv[0]); @@ -126,7 +126,7 @@ bool AegisubApp::OnInit() { } -//#ifndef _DEBUG +#ifndef _DEBUG /////////////////////// // Unhandled exception void AegisubApp::OnUnhandledException() { @@ -155,7 +155,7 @@ void AegisubApp::OnFatalException() { // Inform user of crash wxMessageBox(_T("Aegisub has encountered a fatal error and will terminate now. The subtitles you were working on were saved to \"") + filename + _T("\", but they might be corrupt."), _T("Fatal error"), wxOK | wxICON_ERROR, NULL); } -//#endif +#endif //////////////// diff --git a/core/main.h b/core/main.h index 13f449fb4..ce374bb39 100644 --- a/core/main.h +++ b/core/main.h @@ -73,10 +73,10 @@ public: bool OnInit(); int OnRun(); -//#ifndef _DEBUG +#ifndef _DEBUG void OnUnhandledException(); void OnFatalException(); -//#endif +#endif //int OnRun(); DECLARE_EVENT_TABLE() diff --git a/core/subtitle_format_reader.cpp b/core/subtitle_format_reader.cpp new file mode 100644 index 000000000..4ac0e3a72 --- /dev/null +++ b/core/subtitle_format_reader.cpp @@ -0,0 +1,127 @@ +// 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "subtitle_format_reader.h" +#include "ass_file.h" + + +/////////////// +// Constructor +SubtitleFormatReader::SubtitleFormatReader() { + Line = NULL; + Register(); +} + + +////////////// +// Destructor +SubtitleFormatReader::~SubtitleFormatReader() { + Remove(); +} + + +////////////// +// Set target +void SubtitleFormatReader::SetTarget(AssFile *file) { + if (!file) Line = NULL; + else Line = &file->Line; + assFile = file; +} + + +//////// +// List +std::list SubtitleFormatReader::readers; + + +///////////////////////////// +// Get an appropriate reader +SubtitleFormatReader *SubtitleFormatReader::GetReader(wxString filename) { + std::list::iterator cur; + SubtitleFormatReader *reader; + for (cur=readers.begin();cur!=readers.end();cur++) { + reader = *cur; + if (reader->CanReadFile(filename)) return reader; + } + return NULL; +} + + +//////////// +// Register +void SubtitleFormatReader::Register() { + std::list::iterator cur; + for (cur=readers.begin();cur!=readers.end();cur++) { + if (*cur == this) return; + } + readers.push_back(this); +} + + +////////// +// Remove +void SubtitleFormatReader::Remove() { + std::list::iterator cur; + for (cur=readers.begin();cur!=readers.end();cur++) { + if (*cur == this) { + readers.erase(cur); + return; + } + } +} + + +/////////////////// +// Clear subtitles +void SubtitleFormatReader::Clear() { + assFile->Clear(); +} + + +//////////////// +// Load default +void SubtitleFormatReader::LoadDefault() { + assFile->LoadDefault(); +} + + +/////////////////// +// Set if it's ASS +void SubtitleFormatReader::SetIsASS(bool isASS) { + assFile->IsASS = isASS; +} diff --git a/core/subtitle_format_reader.h b/core/subtitle_format_reader.h new file mode 100644 index 000000000..a95f7bea2 --- /dev/null +++ b/core/subtitle_format_reader.h @@ -0,0 +1,77 @@ +// 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +/////////// +// Headers +#include +#include + + +////////////// +// Prototypes +class AssFile; +class AssEntry; + + +/////////////////// +// Subtitle reader +class SubtitleFormatReader { +private: + void Register(); + void Remove(); + static std::list readers; + AssFile *assFile; + +protected: + std::list *Line; + +public: + SubtitleFormatReader(); + virtual ~SubtitleFormatReader(); + + virtual bool CanReadFile(wxString filename)=0; + virtual void ReadFile(wxString filename,wxString forceEncoding=_T(""))=0; + + void SetTarget(AssFile *file); + void Clear(); + void LoadDefault(); + void SetIsASS(bool isASS); + + static SubtitleFormatReader *GetReader(wxString filename); +}; diff --git a/core/subtitle_format_srt.cpp b/core/subtitle_format_srt.cpp new file mode 100644 index 000000000..ab13e904d --- /dev/null +++ b/core/subtitle_format_srt.cpp @@ -0,0 +1,124 @@ +// 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "subtitle_format_srt.h" +#include "text_file_reader.h" +#include "ass_dialogue.h" + + +///////////// +// Can read? +bool SRTSubtitleFormatReader::CanReadFile(wxString filename) { + return (filename.Right(4).Lower() == _T(".srt")); +} + + +///////////// +// Read file +void SRTSubtitleFormatReader::ReadFile(wxString filename,wxString encoding) { + using namespace std; + + // Reader + TextFileReader file(filename,encoding); + + // Default + LoadDefault(); + + // Parse file + int linen = 1; + int fileLine = 0; + int mode = 0; + long templ; + AssDialogue *line = NULL; + while (file.HasMoreLines()) { + // Reads line + wxString curLine = file.ReadLineFromFile(); + fileLine++; + + switch (mode) { + case 0: + // Checks if there is anything to read + if (curLine.IsEmpty()) continue; + + // Check if it's a line number + if (!curLine.IsNumber()) { + Clear(); + throw wxString::Format(_T("Parse error on entry %i at line %i (expecting line number). Possible malformed file."),linen,fileLine); + } + + // Read line number + curLine.ToLong(&templ); + if (templ != linen) { + linen = templ; + } + line = new AssDialogue(); + mode = 1; + break; + + case 1: + // Read timestamps + if (curLine.substr(13,3) != _T("-->")) { + Clear(); + throw wxString::Format(_T("Parse error on entry %i at line %i (expecting timestamps). Possible malformed file."),linen,fileLine); + } + line->Start.ParseSRT(curLine.substr(0,12)); + line->End.ParseSRT(curLine.substr(17,12)); + mode = 2; + break; + + case 2: + // Checks if it's done + if (curLine.IsEmpty()) { + mode = 0; + linen++; + line->group = _T("[Events]"); + line->Style = _T("Default"); + line->Comment = false; + line->UpdateData(); + line->ParseSRTTags(); + line->StartMS = line->Start.GetMS(); + Line->push_back(line); + break; + } + // Append text + if (line->Text != _T("")) line->Text += _T("\\N"); + line->Text += curLine; + break; + } + } +} diff --git a/core/subtitle_format_srt.h b/core/subtitle_format_srt.h new file mode 100644 index 000000000..e59f661b0 --- /dev/null +++ b/core/subtitle_format_srt.h @@ -0,0 +1,58 @@ +// 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +/////////// +// Headers +#include "subtitle_format_reader.h" + + +////////////// +// Prototypes +class AssDialogue; + + +////////////// +// SRT reader +class SRTSubtitleFormatReader : public SubtitleFormatReader { +private: + +public: + bool CanReadFile(wxString filename); + void ReadFile(wxString filename,wxString forceEncoding); +}; diff --git a/core/text_file_reader.h b/core/text_file_reader.h index ff179ab6a..f0bdf604e 100644 --- a/core/text_file_reader.h +++ b/core/text_file_reader.h @@ -42,6 +42,7 @@ // Headers #include #include +#include ///////// diff --git a/core/video_provider_lavc.cpp b/core/video_provider_lavc.cpp index cbe959615..2bf374675 100644 --- a/core/video_provider_lavc.cpp +++ b/core/video_provider_lavc.cpp @@ -47,6 +47,9 @@ /////////////// // Constructor LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename) { + char temp[1024]; + strcpy(temp,subfilename.mb_str(wxConvUTF8)); + // Init variables codecContext = NULL; formatContext = NULL;