diff --git a/aegisub/Makefile.am b/aegisub/Makefile.am index cf742be86..c2edee1eb 100644 --- a/aegisub/Makefile.am +++ b/aegisub/Makefile.am @@ -185,6 +185,7 @@ aegisub_SOURCES = \ subs_preview.cpp \ subtitle_format.cpp \ subtitle_format_ass.cpp \ + subtitle_format_encore.cpp \ subtitle_format_microdvd.cpp \ subtitle_format_mkv.cpp \ subtitle_format_srt.cpp \ diff --git a/aegisub/ass_time.cpp b/aegisub/ass_time.cpp index bed7c0066..b85dbcc3e 100644 --- a/aegisub/ass_time.cpp +++ b/aegisub/ass_time.cpp @@ -278,3 +278,12 @@ bool operator != (AssTime &t1, AssTime &t2) { ///////////////// // Static option bool AssTime::UseMSPrecision = false; + + +/////// +// Get +int AssTime::GetTimeHours() { return time / 3600000; } +int AssTime::GetTimeMinutes() { return (time % 3600000)/60000; } +int AssTime::GetTimeSeconds() { return (time % 60000)/1000; } +int AssTime::GetTimeMiliseconds() { return (time % 1000); } +int AssTime::GetTimeCentiseconds() { return (time % 1000)/10; } diff --git a/aegisub/ass_time.h b/aegisub/ass_time.h index 09c1844cb..adcead187 100644 --- a/aegisub/ass_time.h +++ b/aegisub/ass_time.h @@ -53,6 +53,12 @@ public: AssTime(); + int GetTimeHours(); + int GetTimeMinutes(); + int GetTimeSeconds(); + int GetTimeMiliseconds(); + int GetTimeCentiseconds(); + int GetMS(); // Returns miliseconds void SetMS(int ms); // Sets values to miliseconds void ParseASS(const wxString text); // Sets value to text-form time, in ASS format diff --git a/aegisub/subtitle_format.cpp b/aegisub/subtitle_format.cpp index afd2da788..164b21209 100644 --- a/aegisub/subtitle_format.cpp +++ b/aegisub/subtitle_format.cpp @@ -43,6 +43,7 @@ #include "subtitle_format_ttxt.h" #include "subtitle_format_mkv.h" #include "subtitle_format_microdvd.h" +#include "subtitle_format_encore.h" #include "ass_file.h" #include "vfr.h" @@ -129,6 +130,7 @@ void SubtitleFormat::LoadFormats () { new TTXTSubtitleFormat(); new MicroDVDSubtitleFormat(); new MKVSubtitleFormat(); + new EncoreSubtitleFormat(); } loaded = true; } @@ -267,11 +269,11 @@ wxString SubtitleFormat::GetWildcards(int mode) { ///////////////////////////////// // Ask the user to enter the FPS -double SubtitleFormat::AskForFPS() { +double SubtitleFormat::AskForFPS(bool palNtscOnly) { wxArrayString choices; // Video FPS - bool vidLoaded = VFR_Output.IsLoaded(); + bool vidLoaded = !palNtscOnly && VFR_Output.IsLoaded(); if (vidLoaded) { wxString vidFPS; if (VFR_Output.GetFrameRateType() == VFR) vidFPS = _T("VFR"); @@ -280,21 +282,31 @@ double SubtitleFormat::AskForFPS() { } // Standard FPS values - choices.Add(_("15.000 FPS")); - choices.Add(_("23.976 FPS (Decimated NTSC)")); - choices.Add(_("24.000 FPS (FILM)")); + if (!palNtscOnly) { + choices.Add(_("15.000 FPS")); + choices.Add(_("23.976 FPS (Decimated NTSC)")); + choices.Add(_("24.000 FPS (FILM)")); + } choices.Add(_("25.000 FPS (PAL)")); choices.Add(_("29.970 FPS (NTSC)")); - choices.Add(_("30.000 FPS")); - choices.Add(_("59.940 FPS (NTSC x2)")); - choices.Add(_("60.000 FPS")); - choices.Add(_("119.880 FPS (NTSC x4)")); - choices.Add(_("120.000 FPS")); + if (!palNtscOnly) { + choices.Add(_("30.000 FPS")); + choices.Add(_("59.940 FPS (NTSC x2)")); + choices.Add(_("60.000 FPS")); + choices.Add(_("119.880 FPS (NTSC x4)")); + choices.Add(_("120.000 FPS")); + } // Ask int choice = wxGetSingleChoiceIndex(_("Please choose the appropriate FPS for the subtitles:"),_("FPS"),choices); if (choice == -1) return 0.0; + // PAL/NTSC choice + if (palNtscOnly) { + if (choice == 0) return 25.0; + else return 30.0 / 1.001; + } + // Get FPS from choice if (vidLoaded) choice--; switch (choice) { diff --git a/aegisub/subtitle_format.h b/aegisub/subtitle_format.h index d27a68f1f..f6914c885 100644 --- a/aegisub/subtitle_format.h +++ b/aegisub/subtitle_format.h @@ -75,7 +75,7 @@ protected: void LoadDefault(bool defline=true); AssFile *GetAssFile() { return assFile; } int AddLine(wxString data,wxString group,int lasttime,int &version,wxString *outgroup=NULL); - double AskForFPS(); + double AskForFPS(bool palNtscOnly=false); virtual wxString GetName()=0; virtual wxArrayString GetReadWildcards(); diff --git a/aegisub/subtitle_format_encore.cpp b/aegisub/subtitle_format_encore.cpp new file mode 100644 index 000000000..77fd145b3 --- /dev/null +++ b/aegisub/subtitle_format_encore.cpp @@ -0,0 +1,108 @@ +// Copyright (c) 2007, 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 "ass_dialogue.h" +#include "subtitle_format_encore.h" +#include "text_file_writer.h" + + +//////// +// Name +wxString EncoreSubtitleFormat::GetName() { + return _T("Adobe Encore"); +} + + +///////////// +// Wildcards +wxArrayString EncoreSubtitleFormat::GetWriteWildcards() { + wxArrayString formats; + formats.Add(_T("encore.txt")); + return formats; +} + + +/////////////////// +// Can write file? +bool EncoreSubtitleFormat::CanWriteFile(wxString filename) { + return (filename.Right(11).Lower() == _T(".encore.txt")); +} + + +////////////// +// Write file +void EncoreSubtitleFormat::WriteFile(wxString _filename,wxString encoding) { + // Get FPS + double fps = AskForFPS(true); + if (fps <= 0.0) return; + + // Open file + TextFileWriter file(_filename,encoding); + + // Convert to encore + CreateCopy(); + SortLines(); + Merge(true,true,true); + ConvertTags(1,_T("\r\n")); + + // Write lines + using std::list; + int i = 0; + for (list::iterator cur=Line->begin();cur!=Line->end();cur++) { + AssDialogue *current = AssEntry::GetAsDialogue(*cur); + if (current && !current->Comment) { + // Time stamps + i++; + AssTime time = current->Start; + int f = int(time.GetTimeMiliseconds() * fps / 1000.0 + 0.5); + wxString timeStamps = wxString::Format(_T("%i %02i:%02i:%02i:%02i "),i,time.GetTimeHours(),time.GetTimeMinutes(),time.GetTimeSeconds(),f); + time = current->End; + f = int(time.GetTimeMiliseconds() * fps / 1000.0 + 0.5); + timeStamps += wxString::Format(_T("%02i:%02i:%02i:%02i "),time.GetTimeHours(),time.GetTimeMinutes(),time.GetTimeSeconds(),f); + + // Convert : to ; if it's NTSC + if (fps > 26.0) timeStamps.Replace(_T(":"),_T(";")); + + // Write + file.WriteLineToFile(timeStamps + current->Text); + } + } + + // Clean up + ClearCopy(); +} diff --git a/aegisub/subtitle_format_encore.h b/aegisub/subtitle_format_encore.h new file mode 100644 index 000000000..8a7380fc2 --- /dev/null +++ b/aegisub/subtitle_format_encore.h @@ -0,0 +1,53 @@ +// Copyright (c) 2007, 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.h" + + +/////////////////////// +// Adobe Encore writer +class EncoreSubtitleFormat : public SubtitleFormat { +public: + wxString GetName(); + wxArrayString GetWriteWildcards(); + bool CanWriteFile(wxString filename); + void WriteFile(wxString filename,wxString encoding); +}; diff --git a/aegisub/subtitle_format_ttxt.cpp b/aegisub/subtitle_format_ttxt.cpp index 46f5ad2b9..221c5a18c 100644 --- a/aegisub/subtitle_format_ttxt.cpp +++ b/aegisub/subtitle_format_ttxt.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2006, Rodrigo Braz Monteiro +// Copyright (c) 2007, Rodrigo Braz Monteiro // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/aegisub/subtitle_format_ttxt.h b/aegisub/subtitle_format_ttxt.h index 96e414461..c3a783876 100644 --- a/aegisub/subtitle_format_ttxt.h +++ b/aegisub/subtitle_format_ttxt.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006, Rodrigo Braz Monteiro +// Copyright (c) 2007, Rodrigo Braz Monteiro // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/aegisub/subtitle_format_txt.cpp b/aegisub/subtitle_format_txt.cpp index 94e341223..8eb9985fd 100644 --- a/aegisub/subtitle_format_txt.cpp +++ b/aegisub/subtitle_format_txt.cpp @@ -54,7 +54,7 @@ bool TXTSubtitleFormat::CanReadFile(wxString filename) { ////////////// // Can write? bool TXTSubtitleFormat::CanWriteFile(wxString filename) { - return (filename.Right(4).Lower() == _T(".txt")); + return (filename.Right(4).Lower() == _T(".txt") && filename.Right(11).Lower() != _T(".encore.txt")); }