Rework how sorting works and add sorting by style

Rather than going through a ton of work to ensure that every AssEvent
has a sensible start time that happens to leave it in the right place
after sorting, simply sort only consecutive blocks of AssDialogues and
leave everything else untouched. Note that this results in different
behavior when there are multiple [Events] sections in a file -- rather
than moving lines between sections and keeping the number of lines per
section constant, each section keeps the lines it had.

As it's now easy to do, also add sorting by style name and end time.

Closes #614.

Originally committed to SVN as r4307.
This commit is contained in:
Thomas Goyne 2010-05-19 00:44:44 +00:00
parent a573b0897b
commit 2124a1dbd3
24 changed files with 220 additions and 529 deletions

View file

@ -32,8 +32,6 @@
/// @file ass_dialogue.cpp /// @file ass_dialogue.cpp
/// @brief Class for dialogue lines in subtitles /// @brief Class for dialogue lines in subtitles
/// @ingroup subs_storage /// @ingroup subs_storage
///
//////////// ////////////
// Includes // Includes
@ -51,38 +49,40 @@
#include "utils.h" #include "utils.h"
#include "vfr.h" #include "vfr.h"
/// @brief Constructs AssDialogue AssDialogue ////////////////////// /// @brief Constructs AssDialogue
/// AssDialogue::AssDialogue()
AssDialogue::AssDialogue() { : Comment(false)
group = _T("[Events]"); , Layer(0)
, Start(0)
, End(5000)
, Style(L"Default")
, Actor(L"")
, Effect(L"")
, Text(L"")
{
group = L"[Events]";
Valid = true; Valid = true;
SetStartMS(0);
SetEndMS(5000);
Layer = 0;
for (int i=0;i<4;i++) Margin[i] = 0; for (int i=0;i<4;i++) Margin[i] = 0;
Text = _T("");
Style = _T("Default");
Actor = _T("");
Effect = _T("");
Comment = false;
UpdateData(); UpdateData();
} }
/// @brief DOCME /// @brief DOCME
/// @param _data /// @param _data
/// @param version /// @param version
/// AssDialogue::AssDialogue(wxString _data,int version)
AssDialogue::AssDialogue(wxString _data,int version) { : Comment(false)
// Set group , Layer(0)
group = _T("[Events]"); , Start(0)
, End(5000)
, Style(L"Default")
, Actor(L"")
, Effect(L"")
, Text(L"")
{
group = L"[Events]";
Valid = false;
// Try parsing in different ways // Try parsing in different ways
int count = 0; int count = 0;
Valid = false;
while (!Valid && count < 3) { while (!Valid && count < 3) {
Valid = Parse(_data,version); Valid = Parse(_data,version);
count++; count++;
@ -95,30 +95,20 @@ AssDialogue::AssDialogue(wxString _data,int version) {
throw _T("Failed parsing line."); throw _T("Failed parsing line.");
} }
// update
UpdateData(); UpdateData();
} }
/// @brief Destructor /// @brief Destructor
///
AssDialogue::~AssDialogue () { AssDialogue::~AssDialogue () {
Clear(); Clear();
} }
/// @brief Clear /// @brief Clear
///
void AssDialogue::Clear () { void AssDialogue::Clear () {
ClearBlocks(); ClearBlocks();
} }
/// @brief Clear blocks /// @brief Clear blocks
///
void AssDialogue::ClearBlocks() { void AssDialogue::ClearBlocks() {
using std::vector; using std::vector;
for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) {
@ -127,13 +117,10 @@ void AssDialogue::ClearBlocks() {
Blocks.clear(); Blocks.clear();
} }
/// @brief Parse ASS Data /// @brief Parse ASS Data
/// @param rawData /// @param rawData
/// @param version /// @param version
/// @return /// @return
///
bool AssDialogue::Parse(wxString rawData, int version) { bool AssDialogue::Parse(wxString rawData, int version) {
size_t pos = 0; size_t pos = 0;
wxString temp; wxString temp;
@ -168,7 +155,6 @@ bool AssDialogue::Parse(wxString rawData, int version) {
// Get start time // Get start time
if (!tkn.HasMoreTokens()) return false; if (!tkn.HasMoreTokens()) return false;
Start.ParseASS(tkn.GetNextToken()); Start.ParseASS(tkn.GetNextToken());
FixStartMS();
// Get end time // Get end time
if (!tkn.HasMoreTokens()) return false; if (!tkn.HasMoreTokens()) return false;
@ -227,11 +213,8 @@ bool AssDialogue::Parse(wxString rawData, int version) {
return true; return true;
} }
/// @brief Make data /// @brief Make data
/// @return /// @return
///
wxString AssDialogue::MakeData() { wxString AssDialogue::MakeData() {
// Prepare // Prepare
static wxString final = _T(""); static wxString final = _T("");
@ -270,35 +253,23 @@ wxString AssDialogue::MakeData() {
return final; return final;
} }
/// @brief Update AssDialogue's data line /// @brief Update AssDialogue's data line
///
void AssDialogue::UpdateData () { void AssDialogue::UpdateData () {
} }
/// @brief Get entry data /// @brief Get entry data
/// @return /// @return
///
const wxString AssDialogue::GetEntryData() { const wxString AssDialogue::GetEntryData() {
return MakeData(); return MakeData();
} }
/// @brief Set entry data /// @brief Set entry data
/// @param newData /// @param newData
///
void AssDialogue::SetEntryData(wxString newData) { void AssDialogue::SetEntryData(wxString newData) {
} }
/// @brief Get SSA version of Dialogue /// @brief Get SSA version of Dialogue
/// @return /// @return
///
wxString AssDialogue::GetSSAText () { wxString AssDialogue::GetSSAText () {
// Prepare // Prepare
wxString work = _T(""); wxString work = _T("");
@ -331,10 +302,7 @@ wxString AssDialogue::GetSSAText () {
return work; return work;
} }
/// @brief Yea, I convert to ASS tags, then parse that. So sue me. -------------- Parse SRT tags /// @brief Yea, I convert to ASS tags, then parse that. So sue me. -------------- Parse SRT tags
///
void AssDialogue::ParseSRTTags () { void AssDialogue::ParseSRTTags () {
// Search and replace // Search and replace
size_t total = 0; size_t total = 0;
@ -470,10 +438,7 @@ void AssDialogue::ParseSRTTags () {
UpdateData(); UpdateData();
} }
/// @brief Parse ASS tags /// @brief Parse ASS tags
///
void AssDialogue::ParseASSTags () { void AssDialogue::ParseASSTags () {
// Clear blocks // Clear blocks
ClearBlocks(); ClearBlocks();
@ -567,20 +532,14 @@ void AssDialogue::ParseASSTags () {
} }
} }
/// @brief Strip tags /// @brief Strip tags
///
void AssDialogue::StripTags () { void AssDialogue::StripTags () {
static wxRegEx reg(_T("\\{[^\\{]*\\}"),wxRE_ADVANCED); static wxRegEx reg(_T("\\{[^\\{]*\\}"),wxRE_ADVANCED);
reg.Replace(&Text,_T("")); reg.Replace(&Text,_T(""));
} }
/// @brief Strip a specific tag /// @brief Strip a specific tag
/// @param tagName /// @param tagName
///
void AssDialogue::StripTag (wxString tagName) { void AssDialogue::StripTag (wxString tagName) {
// Parse // Parse
using std::list; using std::list;
@ -609,10 +568,7 @@ void AssDialogue::StripTag (wxString tagName) {
UpdateData(); UpdateData();
} }
/// @brief TODO: Improve this code ------------------- Convert tags to SRT /// @brief TODO: Improve this code ------------------- Convert tags to SRT
///
void AssDialogue::ConvertTagsToSRT () { void AssDialogue::ConvertTagsToSRT () {
// Setup // Setup
using std::list; using std::list;
@ -712,10 +668,7 @@ void AssDialogue::ConvertTagsToSRT () {
ClearBlocks(); ClearBlocks();
} }
/// @brief Updates text from tags /// @brief Updates text from tags
///
void AssDialogue::UpdateText () { void AssDialogue::UpdateText () {
using std::vector; using std::vector;
Text = _T(""); Text = _T("");
@ -729,12 +682,9 @@ void AssDialogue::UpdateText () {
} }
} }
/// @brief Sets margin from a string /// @brief Sets margin from a string
/// @param origvalue /// @param origvalue
/// @param which /// @param which
///
void AssDialogue::SetMarginString(const wxString origvalue,int which) { void AssDialogue::SetMarginString(const wxString origvalue,int which) {
// Make it numeric // Make it numeric
wxString strvalue = origvalue; wxString strvalue = origvalue;
@ -760,13 +710,10 @@ void AssDialogue::SetMarginString(const wxString origvalue,int which) {
Margin[which] = value; Margin[which] = value;
} }
/// @brief Gets string for margin /// @brief Gets string for margin
/// @param which /// @param which
/// @param pad /// @param pad
/// @return /// @return
///
wxString AssDialogue::GetMarginString(int which,bool pad) { wxString AssDialogue::GetMarginString(int which,bool pad) {
if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError(); if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError();
int value = Margin[which]; int value = Margin[which];
@ -774,8 +721,6 @@ wxString AssDialogue::GetMarginString(int which,bool pad) {
else return wxString::Format(_T("%i"),value); else return wxString::Format(_T("%i"),value);
} }
void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) {
// Apply for all override blocks // Apply for all override blocks
AssDialogueBlockOverride *curBlock; AssDialogueBlockOverride *curBlock;
@ -789,12 +734,9 @@ void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersC
//ClearBlocks(); //ClearBlocks();
} }
/// @brief Checks if two lines collide /// @brief Checks if two lines collide
/// @param target /// @param target
/// @return /// @return
///
bool AssDialogue::CollidesWith(AssDialogue *target) { bool AssDialogue::CollidesWith(AssDialogue *target) {
if (!target) return false; if (!target) return false;
int a = Start.GetMS(); int a = Start.GetMS();
@ -804,11 +746,8 @@ bool AssDialogue::CollidesWith(AssDialogue *target) {
return ((a < c) ? (c < b) : (a < d)); return ((a < c) ? (c < b) : (a < d));
} }
/// @brief Return just the text without any overrides /// @brief Return just the text without any overrides
/// @return /// @return
///
wxString AssDialogue::GetStrippedText() const { wxString AssDialogue::GetStrippedText() const {
wxString justtext = wxString(_T("")); wxString justtext = wxString(_T(""));
bool inCode = false; bool inCode = false;
@ -823,7 +762,6 @@ wxString AssDialogue::GetStrippedText() const {
/// @brief Clone /// @brief Clone
/// @return /// @return
///
AssEntry *AssDialogue::Clone() const { AssEntry *AssDialogue::Clone() const {
// Create clone // Create clone
AssDialogue *final = new AssDialogue(); AssDialogue *final = new AssDialogue();
@ -836,37 +774,26 @@ AssEntry *AssDialogue::Clone() const {
final->Effect = Effect; final->Effect = Effect;
final->Layer = Layer; final->Layer = Layer;
for (int i=0;i<4;i++) final->Margin[i] = Margin[i]; for (int i=0;i<4;i++) final->Margin[i] = Margin[i];
final->SetStartMS(GetStartMS()); final->Start = Start;
final->SetEndMS(GetEndMS()); final->End = End;
final->Style = Style; final->Style = Style;
final->Text = Text; final->Text = Text;
//final->SetEntryData(GetEntryData());
// Return
return final; return final;
} }
/// @brief Constructor AssDialogueBlock
/// @brief Constructor AssDialogueBlock //////////////////////
///
AssDialogueBlock::AssDialogueBlock () { AssDialogueBlock::AssDialogueBlock () {
} }
/// @brief Destructor /// @brief Destructor
/// @return /// @return
///
AssDialogueBlock::~AssDialogueBlock () { AssDialogueBlock::~AssDialogueBlock () {
} }
/// @brief If it isn't a plain block, returns NULL ---------------------- Returns as a plain block /// @brief If it isn't a plain block, returns NULL ---------------------- Returns as a plain block
/// @param base /// @param base
/// @return /// @return
///
AssDialogueBlockPlain *AssDialogueBlock::GetAsPlain(AssDialogueBlock *base) { AssDialogueBlockPlain *AssDialogueBlock::GetAsPlain(AssDialogueBlock *base) {
if (!base) return NULL; if (!base) return NULL;
if (base->GetType() == BLOCK_PLAIN) { if (base->GetType() == BLOCK_PLAIN) {
@ -875,12 +802,9 @@ AssDialogueBlockPlain *AssDialogueBlock::GetAsPlain(AssDialogueBlock *base) {
return NULL; return NULL;
} }
/// @brief If it isn't an override block, returns NULL ---------------------------- Returns as an override block /// @brief If it isn't an override block, returns NULL ---------------------------- Returns as an override block
/// @param base /// @param base
/// @return /// @return
///
AssDialogueBlockOverride *AssDialogueBlock::GetAsOverride(AssDialogueBlock *base) { AssDialogueBlockOverride *AssDialogueBlock::GetAsOverride(AssDialogueBlock *base) {
if (!base) return NULL; if (!base) return NULL;
if (base->GetType() == BLOCK_OVERRIDE) { if (base->GetType() == BLOCK_OVERRIDE) {
@ -889,12 +813,9 @@ AssDialogueBlockOverride *AssDialogueBlock::GetAsOverride(AssDialogueBlock *base
return NULL; return NULL;
} }
/// @brief If it isn't an drawing block, returns NULL ---------------------------- Returns as a drawing block /// @brief If it isn't an drawing block, returns NULL ---------------------------- Returns as a drawing block
/// @param base /// @param base
/// @return /// @return
///
AssDialogueBlockDrawing *AssDialogueBlock::GetAsDrawing(AssDialogueBlock *base) { AssDialogueBlockDrawing *AssDialogueBlock::GetAsDrawing(AssDialogueBlock *base) {
if (!base) return NULL; if (!base) return NULL;
if (base->GetType() == BLOCK_DRAWING) { if (base->GetType() == BLOCK_DRAWING) {
@ -903,28 +824,19 @@ AssDialogueBlockDrawing *AssDialogueBlock::GetAsDrawing(AssDialogueBlock *base)
return NULL; return NULL;
} }
/// @brief Constructor AssDialogueBlockPlain ////////////////////// /// @brief Constructor AssDialogueBlockPlain //////////////////////
///
AssDialogueBlockPlain::AssDialogueBlockPlain () { AssDialogueBlockPlain::AssDialogueBlockPlain () {
} }
/// @brief Constructor AssDialogueBlockDrawing ////////////////////// /// @brief Constructor AssDialogueBlockDrawing //////////////////////
///
AssDialogueBlockDrawing::AssDialogueBlockDrawing () { AssDialogueBlockDrawing::AssDialogueBlockDrawing () {
} }
/// @brief Multiply coordinates /// @brief Multiply coordinates
/// @param mx /// @param mx
/// @param my /// @param my
/// @param x /// @param x
/// @param y /// @param y
///
void AssDialogueBlockDrawing::TransformCoords(int mx,int my,double x,double y) { void AssDialogueBlockDrawing::TransformCoords(int mx,int my,double x,double y) {
// HACK: Implement a proper parser ffs!! // HACK: Implement a proper parser ffs!!
wxStringTokenizer tkn(GetText(),_T(" "),wxTOKEN_DEFAULT); wxStringTokenizer tkn(GetText(),_T(" "),wxTOKEN_DEFAULT);
@ -963,7 +875,3 @@ void AssDialogueBlockDrawing::TransformCoords(int mx,int my,double x,double y) {
text = final; text = final;
} }

View file

@ -202,36 +202,28 @@ private:
public: public:
/// DOCME /// Contains information about each block of text
std::vector<AssDialogueBlock*> Blocks; // Contains information about each block of text std::vector<AssDialogueBlock*> Blocks;
/// DOCME /// Is this a comment line?
bool Comment; // Is this a comment line? bool Comment;
/// Layer number
/// DOCME int Layer;
int Layer; // Layer number /// Margins: 0 = Left, 1 = Right, 2 = Top (Vertical), 3 = Bottom
int Margin[4];
/// DOCME /// Starting time
int Margin[4]; // Margins: 0 = Left, 1 = Right, 2 = Top (Vertical), 3 = Bottom AssTime Start;
/// Ending time
/// DOCME AssTime End;
AssTime Start; // Starting time /// Style name
wxString Style;
/// DOCME /// Actor name
AssTime End; // Ending time wxString Actor;
/// Effect name
/// DOCME wxString Effect;
wxString Style; // Style name /// Raw text data
wxString Text;
/// DOCME
wxString Actor; // Actor name
/// DOCME
wxString Effect; // Effect name
/// DOCME
wxString Text; // Raw text data
/// @brief DOCME /// @brief DOCME
@ -260,30 +252,6 @@ public:
void Clear(); // Wipes all data void Clear(); // Wipes all data
/// @brief DOCME
/// @return
///
virtual int GetStartMS() const { return Start.GetMS(); }
/// @brief DOCME
/// @return
///
virtual int GetEndMS() const { return End.GetMS(); }
/// @brief DOCME
/// @param newStart
///
virtual void SetStartMS(const int newStart) { AssEntry::SetStartMS(newStart); Start.SetMS(newStart); }
/// @brief DOCME
/// @param newEnd
///
virtual void SetEndMS(const int newEnd) { End.SetMS(newEnd); }
/// @brief DOCME
///
void FixStartMS() { AssEntry::SetStartMS(Start.GetMS()); } // Update StartMS in AssEntry from the Start value here
void SetMarginString(const wxString value,int which); // Set string to a margin value (0 = left, 1 = right, 2 = vertical/top, 3 = bottom) void SetMarginString(const wxString value,int which); // Set string to a margin value (0 = left, 1 = right, 2 = vertical/top, 3 = bottom)
wxString GetMarginString(int which,bool pad=true); // Returns the string of a margin value (0 = left, 1 = right, 2 = vertical/top, 3 = bottom) wxString GetMarginString(int which,bool pad=true); // Returns the string of a margin value (0 = left, 1 = right, 2 = vertical/top, 3 = bottom)
wxString GetSSAText(); wxString GetSSAText();

View file

@ -45,13 +45,11 @@
#include "ass_style.h" #include "ass_style.h"
/// @brief Constructs AssEntry AssEntry ////////////////////// /// @brief Constructs AssEntry
///
AssEntry::AssEntry() { AssEntry::AssEntry() {
Valid = true; Valid = true;
} }
/// @brief DOCME /// @brief DOCME
/// @param _data /// @param _data
/// ///
@ -60,26 +58,11 @@ AssEntry::AssEntry(wxString _data) {
Valid = true; Valid = true;
} }
/// @brief Destructor for AssEntry /// @brief Destructor for AssEntry
/// ///
AssEntry::~AssEntry() { AssEntry::~AssEntry() {
} }
/// @brief Comparison for STL Sort
/// @param t1
/// @param t2
/// @return
///
bool operator < (const AssEntry &t1, const AssEntry &t2) {
return (t1.GetStartMS() < t2.GetStartMS());
}
/// @brief Returns an entry as dialogue if possible, else, returns NULL /// @brief Returns an entry as dialogue if possible, else, returns NULL
/// @param base /// @param base
/// @return /// @return
@ -92,8 +75,6 @@ AssDialogue *AssEntry::GetAsDialogue(AssEntry *base) {
return NULL; return NULL;
} }
/// @brief Returns an entry as style if possible, else, returns NULL /// @brief Returns an entry as style if possible, else, returns NULL
/// @param base /// @param base
/// @return /// @return
@ -106,8 +87,6 @@ AssStyle *AssEntry::GetAsStyle(AssEntry *base) {
return NULL; return NULL;
} }
/// @brief Returns an entry as attachment if possible, else, returns NULL /// @brief Returns an entry as attachment if possible, else, returns NULL
/// @param base /// @param base
/// @return /// @return
@ -120,8 +99,6 @@ AssAttachment *AssEntry::GetAsAttachment(AssEntry *base) {
return NULL; return NULL;
} }
/// @brief Get SSA conversion /// @brief Get SSA conversion
/// @return /// @return
/// ///
@ -136,8 +113,6 @@ wxString AssEntry::GetSSAText() {
return GetEntryData(); return GetEntryData();
} }
/// @brief Clone /// @brief Clone
/// ///
AssEntry *AssEntry::Clone() const { AssEntry *AssEntry::Clone() const {
@ -147,11 +122,8 @@ AssEntry *AssEntry::Clone() const {
// Copy data // Copy data
final->data = data; final->data = data;
final->group = group; final->group = group;
final->StartMS = StartMS;
final->Valid = Valid; final->Valid = Valid;
// Return // Return
return final; return final;
} }

View file

@ -109,9 +109,6 @@ private:
/// DOCME /// DOCME
wxString data; // Raw data, exactly the same line that appears on the .ass (note that this will be in ass even if source wasn't) wxString data; // Raw data, exactly the same line that appears on the .ass (note that this will be in ass even if source wasn't)
/// DOCME
int StartMS; // This is only stored for sorting issues, in order to keep non-dialogue lines aligned
public: public:
/// DOCME /// DOCME
@ -126,29 +123,6 @@ public:
virtual AssEntry *Clone() const; virtual AssEntry *Clone() const;
/// @brief DOCME
/// @return
///
virtual int GetStartMS() const { return StartMS; }
/// @brief DOCME
/// @return
///
virtual int GetEndMS() const { return StartMS; }
/// @brief DOCME
/// @param newStart
///
virtual void SetStartMS(const int newStart) { StartMS = newStart; }
/// @brief DOCME
/// @param newEnd
/// @return
///
virtual void SetEndMS(const int newEnd) { /* do nothing */ (void)newEnd; }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -169,8 +143,3 @@ public:
static AssStyle *GetAsStyle(AssEntry *base); // Returns an entry base as a style if it is valid, null otherwise static AssStyle *GetAsStyle(AssEntry *base); // Returns an entry base as a style if it is valid, null otherwise
static AssAttachment *GetAsAttachment(AssEntry *base);// Returns an entry base as an attachment if it is valid, null otherwise static AssAttachment *GetAsAttachment(AssEntry *base);// Returns an entry base as an attachment if it is valid, null otherwise
}; };
// This operator is for sorting
bool operator < (const AssEntry &t1, const AssEntry &t2);

View file

@ -32,11 +32,7 @@
/// @file ass_file.cpp /// @file ass_file.cpp
/// @brief Overall storage of subtitle files, undo management and more /// @brief Overall storage of subtitle files, undo management and more
/// @ingroup subs_storage /// @ingroup subs_storage
///
////////////
// Includes
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
@ -61,28 +57,21 @@
#include "version.h" #include "version.h"
#include "vfr.h" #include "vfr.h"
/// @brief AssFile constructor AssFile ////////////////////// /// @brief AssFile constructor
///
AssFile::AssFile () { AssFile::AssFile () {
AssOverrideTagProto::LoadProtos(); AssOverrideTagProto::LoadProtos();
Clear(); Clear();
} }
/// @brief AssFile destructor /// @brief AssFile destructor
///
AssFile::~AssFile() { AssFile::~AssFile() {
Clear(); Clear();
} }
/// @brief Load generic subs /// @brief Load generic subs
/// @param file /// @param file
/// @param charset /// @param charset
/// @param addToRecent /// @param addToRecent
///
void AssFile::Load (const wxString _filename,const wxString charset,bool addToRecent) { void AssFile::Load (const wxString _filename,const wxString charset,bool addToRecent) {
bool ok = true; bool ok = true;
@ -153,14 +142,11 @@ void AssFile::Load (const wxString _filename,const wxString charset,bool addToRe
if (addToRecent) AddToRecent(_filename); if (addToRecent) AddToRecent(_filename);
} }
/// @brief Save a file to Hard Disk /// @brief Save a file to Hard Disk
/// @param _filename /// @param _filename
/// @param setfilename /// @param setfilename
/// @param addToRecent /// @param addToRecent
/// @param encoding /// @param encoding
///
void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) { void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) {
// Finds last dot // Finds last dot
int i = 0; int i = 0;
@ -192,12 +178,9 @@ void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wx
} }
} }
/// @brief Saves a file to a ram vector /// @brief Saves a file to a ram vector
/// @param dst /// @param dst
/// @param encoding /// @param encoding
///
void AssFile::SaveMemory(std::vector<char> &dst,const wxString encoding) { void AssFile::SaveMemory(std::vector<char> &dst,const wxString encoding) {
// Set encoding // Set encoding
wxString enc = encoding; wxString enc = encoding;
@ -240,22 +223,16 @@ void AssFile::SaveMemory(std::vector<char> &dst,const wxString encoding) {
} }
} }
/// @brief Exports file with proper transformations /// @brief Exports file with proper transformations
/// @param _filename /// @param _filename
///
void AssFile::Export(wxString _filename) { void AssFile::Export(wxString _filename) {
AssExporter exporter(this); AssExporter exporter(this);
exporter.AddAutoFilters(); exporter.AddAutoFilters();
exporter.Export(_filename,_T("UTF-8")); exporter.Export(_filename,_T("UTF-8"));
} }
/// @brief Can save file? /// @brief Can save file?
/// @return /// @return
///
bool AssFile::CanSave() { bool AssFile::CanSave() {
// ASS format? // ASS format?
wxString ext = filename.Lower().Right(4); wxString ext = filename.Lower().Right(4);
@ -307,25 +284,6 @@ bool AssFile::CanSave() {
return true; return true;
} }
////////////////////////////////////
// Returns script as a single string
//wxString AssFile::GetString() {
// using std::list;
// wxString ret;
// AssEntry *entry;
// ret += 0xfeff;
// for (list<AssEntry*>::iterator cur=Line.begin();cur!=Line.end();) {
// entry = *cur;
// ret += entry->GetEntryData();
// ret += L"\n";
// cur++;
// }
// return ret;
//}
/// @brief even moving things out of order might break ASS parsing - AMZ. I strongly advice you against touching this function unless you know what you're doing; ------------------- Appends line to Ass /// @brief even moving things out of order might break ASS parsing - AMZ. I strongly advice you against touching this function unless you know what you're doing; ------------------- Appends line to Ass
/// @param data /// @param data
/// @param group /// @param group
@ -333,8 +291,7 @@ bool AssFile::CanSave() {
/// @param version /// @param version
/// @param outGroup /// @param outGroup
/// @return /// @return
/// void AssFile::AddLine (wxString data,wxString group,int &version,wxString *outGroup) {
int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxString *outGroup) {
// Group // Group
AssEntry *entry = NULL; AssEntry *entry = NULL;
wxString origGroup = group; wxString origGroup = group;
@ -372,10 +329,9 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
// Create attachment if needed // Create attachment if needed
if (isFilename) { if (isFilename) {
attach = new AssAttachment(data.Mid(10)); attach = new AssAttachment(data.Mid(10));
attach->SetStartMS(lasttime);
attach->group = group; attach->group = group;
keepGroup = group; keepGroup = group;
return lasttime; return;
} }
// Valid data? // Valid data?
@ -395,7 +351,7 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
// Not done // Not done
else { else {
return lasttime; return;
} }
} }
} }
@ -404,15 +360,12 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
if (lowGroup == _T("[events]")) { if (lowGroup == _T("[events]")) {
if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) { if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) {
AssDialogue *diag = new AssDialogue(data,version); AssDialogue *diag = new AssDialogue(data,version);
lasttime = diag->GetStartMS();
//diag->ParseASSTags(); //diag->ParseASSTags();
entry = diag; entry = diag;
entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
if (data.Left(7) == _T("Format:")) { if (data.Left(7) == _T("Format:")) {
entry = new AssEntry(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text")); entry = new AssEntry(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"));
entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
} }
@ -422,12 +375,10 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
if (data.Left(6) == _T("Style:")) { if (data.Left(6) == _T("Style:")) {
AssStyle *style = new AssStyle(data,version); AssStyle *style = new AssStyle(data,version);
entry = style; entry = style;
entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
if (data.Left(7) == _T("Format:")) { if (data.Left(7) == _T("Format:")) {
entry = new AssEntry(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding")); entry = new AssEntry(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"));
entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
} }
@ -438,7 +389,7 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
if (data.Left(1) == _T(";")) { if (data.Left(1) == _T(";")) {
// Skip stupid comments added by other programs // Skip stupid comments added by other programs
// Of course, we'll add our own in place later... ;) // Of course, we'll add our own in place later... ;)
return lasttime; return;
} }
// Version // Version
@ -460,26 +411,21 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
// Everything // Everything
entry = new AssEntry(data); entry = new AssEntry(data);
entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
// Common entry // Common entry
if (entry == NULL) { if (entry == NULL) {
entry = new AssEntry(data); entry = new AssEntry(data);
entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
// Insert the line // Insert the line
Line.push_back(entry); Line.push_back(entry);
return lasttime; return;
} }
/// @brief Clears contents of assfile /// @brief Clears contents of assfile
///
void AssFile::Clear () { void AssFile::Clear () {
for (std::list<AssEntry*>::iterator cur=Line.begin();cur != Line.end();cur++) { for (std::list<AssEntry*>::iterator cur=Line.begin();cur != Line.end();cur++) {
if (*cur) delete *cur; if (*cur) delete *cur;
@ -491,11 +437,8 @@ void AssFile::Clear () {
Modified = false; Modified = false;
} }
/// @brief Loads default subs /// @brief Loads default subs
/// @param defline /// @param defline
///
void AssFile::LoadDefault (bool defline) { void AssFile::LoadDefault (bool defline) {
// Clear first // Clear first
Clear(); Clear();
@ -503,34 +446,31 @@ void AssFile::LoadDefault (bool defline) {
// Write headers // Write headers
AssStyle defstyle; AssStyle defstyle;
int version = 1; int version = 1;
AddLine(_T("[Script Info]"),_T("[Script Info]"),-1,version); AddLine(_T("[Script Info]"),_T("[Script Info]"),version);
AddLine(_T("Title: Default Aegisub file"),_T("[Script Info]"),-1,version); AddLine(_T("Title: Default Aegisub file"),_T("[Script Info]"),version);
AddLine(_T("ScriptType: v4.00+"),_T("[Script Info]"),-1,version); AddLine(_T("ScriptType: v4.00+"),_T("[Script Info]"),version);
AddLine(_T("WrapStyle: 0"), _T("[Script Info]"),-1,version); AddLine(_T("WrapStyle: 0"), _T("[Script Info]"),version);
AddLine(_T("PlayResX: 640"),_T("[Script Info]"),-1,version); AddLine(_T("PlayResX: 640"),_T("[Script Info]"),version);
AddLine(_T("PlayResY: 480"),_T("[Script Info]"),-1,version); AddLine(_T("PlayResY: 480"),_T("[Script Info]"),version);
AddLine(_T("ScaledBorderAndShadow: yes"),_T("[Script Info]"),-1,version); AddLine(_T("ScaledBorderAndShadow: yes"),_T("[Script Info]"),version);
AddLine(_T(""),_T("[Script Info]"),-1,version); AddLine(_T(""),_T("[Script Info]"),version);
AddLine(_T("[V4+ Styles]"),_T("[V4+ Styles]"),-1,version); AddLine(_T("[V4+ Styles]"),_T("[V4+ Styles]"),version);
AddLine(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"),_T("[V4+ Styles]"),-1,version); AddLine(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"),_T("[V4+ Styles]"),version);
AddLine(defstyle.GetEntryData(),_T("[V4+ Styles]"),-1,version); AddLine(defstyle.GetEntryData(),_T("[V4+ Styles]"),version);
AddLine(_T(""),_T("[V4+ Styles]"),-1,version); AddLine(_T(""),_T("[V4+ Styles]"),version);
AddLine(_T("[Events]"),_T("[Events]"),-1,version); AddLine(_T("[Events]"),_T("[Events]"),version);
AddLine(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"),_T("[Events]"),-1,version); AddLine(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"),_T("[Events]"),version);
if (defline) { if (defline) {
AssDialogue def; AssDialogue def;
AddLine(def.GetEntryData(),_T("[Events]"),0,version); AddLine(def.GetEntryData(),_T("[Events]"),version);
} }
loaded = true; loaded = true;
} }
/// @brief Copy constructor /// @brief Copy constructor
/// @param from /// @param from
///
AssFile::AssFile (AssFile &from) { AssFile::AssFile (AssFile &from) {
using std::list; using std::list;
@ -545,11 +485,8 @@ AssFile::AssFile (AssFile &from) {
} }
} }
/// @brief Insert a new style /// @brief Insert a new style
/// @param style /// @param style
///
void AssFile::InsertStyle (AssStyle *style) { void AssFile::InsertStyle (AssStyle *style) {
// Variables // Variables
using std::list; using std::list;
@ -565,7 +502,6 @@ void AssFile::InsertStyle (AssStyle *style) {
if (curEntry->GetType() == ENTRY_STYLE || (lastGroup == _T("[V4+ Styles]") && curEntry->GetEntryData().substr(0,7) == _T("Format:"))) { if (curEntry->GetType() == ENTRY_STYLE || (lastGroup == _T("[V4+ Styles]") && curEntry->GetEntryData().substr(0,7) == _T("Format:"))) {
lastStyle = cur; lastStyle = cur;
} }
lasttime = curEntry->GetStartMS();
lastGroup = curEntry->group; lastGroup = curEntry->group;
} }
@ -574,24 +510,20 @@ void AssFile::InsertStyle (AssStyle *style) {
// Add space // Add space
curEntry = new AssEntry(_T("")); curEntry = new AssEntry(_T(""));
curEntry->group = lastGroup; curEntry->group = lastGroup;
curEntry->SetStartMS(lasttime);
Line.push_back(curEntry); Line.push_back(curEntry);
// Add header // Add header
curEntry = new AssEntry(_T("[V4+ Styles]")); curEntry = new AssEntry(_T("[V4+ Styles]"));
curEntry->group = _T("[V4+ Styles]"); curEntry->group = _T("[V4+ Styles]");
curEntry->SetStartMS(lasttime);
Line.push_back(curEntry); Line.push_back(curEntry);
// Add format line // Add format line
curEntry = new AssEntry(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding")); curEntry = new AssEntry(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"));
curEntry->group = _T("[V4+ Styles]"); curEntry->group = _T("[V4+ Styles]");
curEntry->SetStartMS(lasttime);
Line.push_back(curEntry); Line.push_back(curEntry);
// Add style // Add style
style->group = _T("[V4+ Styles]"); style->group = _T("[V4+ Styles]");
style->SetStartMS(lasttime);
Line.push_back(style); Line.push_back(style);
} }
@ -599,16 +531,12 @@ void AssFile::InsertStyle (AssStyle *style) {
else { else {
lastStyle++; lastStyle++;
style->group = (*lastStyle)->group; style->group = (*lastStyle)->group;
style->SetStartMS(lasttime);
Line.insert(lastStyle,style); Line.insert(lastStyle,style);
} }
} }
/// @brief Insert attachment /// @brief Insert attachment
/// @param attach /// @param attach
///
void AssFile::InsertAttachment (AssAttachment *attach) { void AssFile::InsertAttachment (AssAttachment *attach) {
// Search for insertion point // Search for insertion point
std::list<AssEntry*>::iterator insPoint=Line.end(),cur; std::list<AssEntry*>::iterator insPoint=Line.end(),cur;
@ -629,27 +557,21 @@ void AssFile::InsertAttachment (AssAttachment *attach) {
// Found point, insert there // Found point, insert there
if (insPoint != Line.end()) { if (insPoint != Line.end()) {
insPoint++; insPoint++;
attach->SetStartMS((*insPoint)->GetStartMS());
Line.insert(insPoint,attach); Line.insert(insPoint,attach);
} }
// Otherwise, create the [Fonts] group and insert // Otherwise, create the [Fonts] group and insert
else { else {
int version=1; int version=1;
int StartMS = Line.back()->GetStartMS(); AddLine(_T(""),Line.back()->group,version);
AddLine(_T(""),Line.back()->group,StartMS,version); AddLine(attach->group,attach->group,version);
AddLine(attach->group,attach->group,StartMS,version);
attach->SetStartMS(StartMS);
Line.push_back(attach); Line.push_back(attach);
AddLine(_T(""),attach->group,StartMS,version); AddLine(_T(""),attach->group,version);
} }
} }
/// @brief Insert attachment from file /// @brief Insert attachment from file
/// @param filename /// @param filename
///
void AssFile::InsertAttachment (wxString filename) { void AssFile::InsertAttachment (wxString filename) {
// Get name // Get name
wxFileName fname(filename); wxFileName fname(filename);
@ -673,12 +595,9 @@ void AssFile::InsertAttachment (wxString filename) {
InsertAttachment(newAttach); InsertAttachment(newAttach);
} }
/// @brief Gets script info /// @brief Gets script info
/// @param _key /// @param _key
/// @return /// @return
///
wxString AssFile::GetScriptInfo(const wxString _key) { wxString AssFile::GetScriptInfo(const wxString _key) {
// Prepare // Prepare
wxString key = _key;; wxString key = _key;;
@ -709,12 +628,9 @@ wxString AssFile::GetScriptInfo(const wxString _key) {
return _T(""); return _T("");
} }
/// @brief Get script info as int /// @brief Get script info as int
/// @param key /// @param key
/// @return /// @return
///
int AssFile::GetScriptInfoAsInt(const wxString key) { int AssFile::GetScriptInfoAsInt(const wxString key) {
long temp = 0; long temp = 0;
try { try {
@ -726,13 +642,10 @@ int AssFile::GetScriptInfoAsInt(const wxString key) {
return temp; return temp;
} }
/// @brief Set a script info line /// @brief Set a script info line
/// @param _key /// @param _key
/// @param value /// @param value
/// @return /// @return
///
void AssFile::SetScriptInfo(const wxString _key,const wxString value) { void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
// Prepare // Prepare
wxString key = _key;; wxString key = _key;;
@ -778,7 +691,6 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
result += value; result += value;
AssEntry *entry = new AssEntry(result); AssEntry *entry = new AssEntry(result);
entry->group = (*prev)->group; entry->group = (*prev)->group;
entry->SetStartMS((*prev)->GetStartMS());
Line.insert(++prev,entry); Line.insert(++prev,entry);
} }
return; return;
@ -786,12 +698,9 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
} }
} }
/// @brief Get resolution /// @brief Get resolution
/// @param sw /// @param sw
/// @param sh /// @param sh
///
void AssFile::GetResolution(int &sw,int &sh) { void AssFile::GetResolution(int &sw,int &sh) {
// Height // Height
wxString temp = GetScriptInfo(_T("PlayResY")); wxString temp = GetScriptInfo(_T("PlayResY"));
@ -832,11 +741,8 @@ void AssFile::GetResolution(int &sw,int &sh) {
} }
} }
/// @brief Adds a comment to [Script Info] /// @brief Adds a comment to [Script Info]
/// @param _comment /// @param _comment
///
void AssFile::AddComment(const wxString _comment) { void AssFile::AddComment(const wxString _comment) {
wxString comment = _T("; "); wxString comment = _T("; ");
comment += _comment; comment += _comment;
@ -853,18 +759,14 @@ void AssFile::AddComment(const wxString _comment) {
AssEntry *prev = *cur; AssEntry *prev = *cur;
AssEntry *comm = new AssEntry(comment); AssEntry *comm = new AssEntry(comment);
comm->group = prev->group; comm->group = prev->group;
comm->SetStartMS(prev->GetStartMS());
Line.insert(cur,comm); Line.insert(cur,comm);
break; break;
} }
} }
} }
/// @brief Get list of styles /// @brief Get list of styles
/// @return /// @return
///
wxArrayString AssFile::GetStyles() { wxArrayString AssFile::GetStyles() {
wxArrayString styles; wxArrayString styles;
AssStyle *curstyle; AssStyle *curstyle;
@ -877,12 +779,9 @@ wxArrayString AssFile::GetStyles() {
return styles; return styles;
} }
/// @brief Gets style of specific name /// @brief Gets style of specific name
/// @param name /// @param name
/// @return /// @return
///
AssStyle *AssFile::GetStyle(wxString name) { AssStyle *AssFile::GetStyle(wxString name) {
AssStyle *curstyle; AssStyle *curstyle;
for (entryIter cur=Line.begin();cur!=Line.end();cur++) { for (entryIter cur=Line.begin();cur!=Line.end();cur++) {
@ -894,38 +793,24 @@ AssStyle *AssFile::GetStyle(wxString name) {
return NULL; return NULL;
} }
/// @brief Adds file name to list of recent /// @brief Adds file name to list of recent
/// @param file /// @param file
///
void AssFile::AddToRecent(wxString file) { void AssFile::AddToRecent(wxString file) {
Options.AddToRecentList(file,_T("Recent sub")); Options.AddToRecentList(file,_T("Recent sub"));
} }
/// @brief List of supported wildcards /// @brief List of supported wildcards
/// @param mode /// @param mode
/// @return /// @return
///
wxString AssFile::GetWildcardList(int mode) { wxString AssFile::GetWildcardList(int mode) {
//if (mode == 0) return _T("All Supported Types (*.ass,*.ssa,*.srt,*.txt,*.mkv,*.mks,*.mka)|*.ass;*.ssa;*.srt;*.txt;*.mkv;*.mks;*.mka|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt|Matroska (*.mkv,*.mks,*.mka)|*.mkv;*.mks;*.mka");
//else if (mode == 1) return _T("Advanced Substation Alpha (*.ass)|*.ass");
//else if (mode == 2) return _T("All Supported Types (*.ass,*.ssa,*.srt,*.txt,*.mkv,*.mks,*.mka)|*.ass;*.ssa;*.srt;*.txt|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt");
//else return _T("");
if (mode == 0) return SubtitleFormat::GetWildcards(0); if (mode == 0) return SubtitleFormat::GetWildcards(0);
else if (mode == 1) return _T("Advanced Substation Alpha (*.ass)|*.ass"); else if (mode == 1) return _T("Advanced Substation Alpha (*.ass)|*.ass");
else if (mode == 2) return SubtitleFormat::GetWildcards(1); else if (mode == 2) return SubtitleFormat::GetWildcards(1);
else return _T(""); else return _T("");
} }
/// @brief Compress/decompress for storage on stack /// @brief Compress/decompress for storage on stack
/// @param compress /// @param compress
///
void AssFile::CompressForStack(bool compress) { void AssFile::CompressForStack(bool compress) {
AssDialogue *diag; AssDialogue *diag;
for (entryIter cur=Line.begin();cur!=Line.end();cur++) { for (entryIter cur=Line.begin();cur!=Line.end();cur++) {
@ -940,20 +825,14 @@ void AssFile::CompressForStack(bool compress) {
} }
} }
/// @brief Checks if file is modified /// @brief Checks if file is modified
/// @return /// @return
///
bool AssFile::IsModified() { bool AssFile::IsModified() {
return Modified; return Modified;
} }
/// @brief Flag file as modified /// @brief Flag file as modified
/// @param desc /// @param desc
///
void AssFile::FlagAsModified(wxString desc) { void AssFile::FlagAsModified(wxString desc) {
// Clear redo // Clear redo
if (!RedoStack.empty()) { if (!RedoStack.empty()) {
@ -969,11 +848,8 @@ void AssFile::FlagAsModified(wxString desc) {
StackPush(desc); StackPush(desc);
} }
/// @brief Stack push /// @brief Stack push
/// @param desc /// @param desc
///
void AssFile::StackPush(wxString desc) { void AssFile::StackPush(wxString desc) {
// Places copy on stack // Places copy on stack
AssFile *curcopy = new AssFile(*top); AssFile *curcopy = new AssFile(*top);
@ -995,10 +871,7 @@ void AssFile::StackPush(wxString desc) {
} }
} }
/// @brief Stack pop /// @brief Stack pop
///
void AssFile::StackPop() { void AssFile::StackPop() {
bool addcopy = false; bool addcopy = false;
wxString undodesc=_T(""); wxString undodesc=_T("");
@ -1029,10 +902,7 @@ void AssFile::StackPop() {
} }
} }
/// @brief Stack redo /// @brief Stack redo
///
void AssFile::StackRedo() { void AssFile::StackRedo() {
bool addcopy = false; bool addcopy = false;
@ -1058,10 +928,7 @@ void AssFile::StackRedo() {
} }
} }
/// @brief Stack clear /// @brief Stack clear
///
void AssFile::StackClear() { void AssFile::StackClear() {
// Clear undo // Clear undo
for (std::list<AssFile*>::iterator cur=UndoStack.begin();cur!=UndoStack.end();cur++) { for (std::list<AssFile*>::iterator cur=UndoStack.begin();cur!=UndoStack.end();cur++) {
@ -1078,11 +945,8 @@ void AssFile::StackClear() {
Popping = false; Popping = false;
} }
/// @brief Stack reset /// @brief Stack reset
/// @return /// @return
///
void AssFile::StackReset() { void AssFile::StackReset() {
StackClear(); StackClear();
delete top; delete top;
@ -1090,42 +954,73 @@ void AssFile::StackReset() {
StackModified = false; StackModified = false;
} }
/// @brief Returns if undo stack is empty /// @brief Returns if undo stack is empty
/// @return /// @return
///
bool AssFile::IsUndoStackEmpty() { bool AssFile::IsUndoStackEmpty() {
if (StackModified) return (UndoStack.size() <= 1); if (StackModified) return (UndoStack.size() <= 1);
else return UndoStack.empty(); else return UndoStack.empty();
} }
/// @brief Returns if redo stack is empty /// @brief Returns if redo stack is empty
/// @return /// @return
///
bool AssFile::IsRedoStackEmpty() { bool AssFile::IsRedoStackEmpty() {
return RedoStack.empty(); return RedoStack.empty();
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
///
wxString AssFile::GetUndoDescription() { wxString AssFile::GetUndoDescription() {
return (IsUndoStackEmpty())?_T(""):(UndoStack.back())->undodescription; return (IsUndoStackEmpty())?_T(""):(UndoStack.back())->undodescription;
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
///
wxString AssFile::GetRedoDescription() { wxString AssFile::GetRedoDescription() {
return (IsRedoStackEmpty())?_T(""):(RedoStack.back())->undodescription; return (IsRedoStackEmpty())?_T(""):(RedoStack.back())->undodescription;
} }
bool AssFile::CompStart(const AssDialogue* lft, const AssDialogue* rgt) {
return lft->Start < rgt->Start;
}
bool AssFile::CompEnd(const AssDialogue* lft, const AssDialogue* rgt) {
return lft->End < rgt->End;
}
bool AssFile::CompStyle(const AssDialogue* lft, const AssDialogue* rgt) {
return lft->Style < rgt->Style;
}
void AssFile::Sort(CompFunc comp) {
Sort(Line, comp);
}
void AssFile::Sort(std::list<AssEntry*> &lst, CompFunc comp) {
// uguu c++ closures uguu
struct : public std::binary_function<const AssEntry*, const AssEntry*, bool> {
CompFunc comp;
bool operator()(const AssEntry* a, const AssEntry* b) const {
return comp(static_cast<const AssDialogue*>(a), static_cast<const AssDialogue*>(b));
}
} compE;
compE.comp = comp;
// Sort each block of AssDialogues separately, leaving everything else untouched
for (entryIter begin = lst.begin(); begin != lst.end(); ++begin) {
if (!dynamic_cast<AssDialogue*>(*begin)) continue;
entryIter end = begin;
while (end != lst.end() && dynamic_cast<AssDialogue*>(*end)) ++end;
// std::list::sort doesn't support sorting only part of the list, but
// splice is constant-time, so just sort a temp list with only the part we
// want sorted
std::list<AssEntry*> tmp;
tmp.splice(tmp.begin(), lst, begin, end);
tmp.sort(compE);
lst.splice(end, tmp);
begin = --end;
}
}
void AssFile::Sort(std::list<AssDialogue*> &lst, CompFunc comp) {
lst.sort(comp);
}
/// DOCME /// DOCME
AssFile *AssFile::top; AssFile *AssFile::top;
@ -1141,9 +1036,3 @@ bool AssFile::Popping;
/// DOCME /// DOCME
bool AssFile::StackModified; bool AssFile::StackModified;

View file

@ -37,9 +37,6 @@
#pragma once #pragma once
///////////
// Headers
#ifndef AGI_PRE #ifndef AGI_PRE
#include <fstream> #include <fstream>
#include <list> #include <list>
@ -48,9 +45,6 @@
#include <wx/arrstr.h> #include <wx/arrstr.h>
#endif #endif
//////////////
// Prototypes
class FrameRate; class FrameRate;
class AssDialogue; class AssDialogue;
class AssStyle; class AssStyle;
@ -60,7 +54,7 @@ class AssDialogueBlockOverride;
class AssDialogueBlockPlain; class AssDialogueBlockPlain;
class AssEntry; class AssEntry;
typedef std::list<AssEntry*>::iterator entryIter;
/// DOCME /// DOCME
/// @class AssFile /// @class AssFile
@ -128,7 +122,7 @@ public:
wxString GetScriptInfo(const wxString key); // Returns the value in a [Script Info] key as string. wxString GetScriptInfo(const wxString key); // Returns the value in a [Script Info] key as string.
void SetScriptInfo(const wxString key,const wxString value); // Sets the value of a [Script Info] key. Adds it if it doesn't exist. void SetScriptInfo(const wxString key,const wxString value); // Sets the value of a [Script Info] key. Adds it if it doesn't exist.
void AddComment(const wxString comment); // Adds a ";" comment under [Script Info]. void AddComment(const wxString comment); // Adds a ";" comment under [Script Info].
int AddLine(wxString data,wxString group,int lasttime,int &version,wxString *outGroup=NULL); void AddLine(wxString data,wxString group,int &version,wxString *outGroup=NULL);
static void StackPop(); // Pop subs from stack and sets 'top' to it static void StackPop(); // Pop subs from stack and sets 'top' to it
static void StackRedo(); // Redoes action on stack static void StackRedo(); // Redoes action on stack
@ -144,33 +138,24 @@ public:
/// DOCME /// DOCME
static AssFile *top; // Current script file. It is "above" the stack. static AssFile *top; // Current script file. It is "above" the stack.
/// Comparison function for use when sorting
typedef bool (*CompFunc)(const AssDialogue* lft, const AssDialogue* rgt);
/// @brief Compare based on start time
static bool CompStart(const AssDialogue* lft, const AssDialogue* rgt);
/// @brief Compare based on end time
static bool CompEnd(const AssDialogue* lft, const AssDialogue* rgt);
/// @brief Compare based on end time
static bool CompStyle(const AssDialogue* lft, const AssDialogue* rgt);
/// @brief Sort the dialogue lines in this file
/// @param comp Comparison function to use. Defaults to sorting by start time.
void Sort(CompFunc comp = CompStart);
/// @brief Sort the dialogue lines in the given list
/// @param comp Comparison function to use. Defaults to sorting by start time.
static void Sort(std::list<AssEntry*>& lst, CompFunc comp = CompStart);
/// @brief Sort the dialogue lines in the given list
/// @param comp Comparison function to use. Defaults to sorting by start time.
static void Sort(std::list<AssDialogue*>& lst, CompFunc comp = CompStart);
}; };
/// DOCME
typedef std::list<AssEntry*>::iterator entryIter;
//////////////////////////////////////////////////////
// Hack to get STL sort to work on a list of pointers
template <typename T>
/// DOCME
/// @class LessByPointedToValue
/// @brief DOCME
///
/// DOCME
class LessByPointedToValue : std::binary_function<T const *, T const *, bool> {
public:
/// @brief DOCME
/// @param x
/// @param y
///
bool operator()(T const * x, T const * y) const {
return std::less<T>()(*x, *y);
}
};

View file

@ -549,7 +549,6 @@ AssEntry *AssStyle::Clone() const {
// Copy data // Copy data
final->group = group; final->group = group;
final->SetStartMS(GetStartMS());
final->Valid = Valid; final->Valid = Valid;
final->alignment = alignment; final->alignment = alignment;
final->angle = angle; final->angle = angle;

View file

@ -53,11 +53,9 @@
#include "vfr.h" #include "vfr.h"
/// @brief AssTime constructors AssTime ////////////////////// /// @brief AssTime constructors
/// AssTime::AssTime () : time(0) { }
AssTime::AssTime () { AssTime::AssTime (int time) : time(time) { }
time = 0;
}
@ -271,7 +269,7 @@ wxString AssTime::GetSRTFormated () {
/// @param t2 /// @param t2
/// @return /// @return
/// ///
bool operator < (AssTime &t1, AssTime &t2) { bool operator < (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() < t2.GetMS()); return (t1.GetMS() < t2.GetMS());
} }
@ -281,7 +279,7 @@ bool operator < (AssTime &t1, AssTime &t2) {
/// @param t2 /// @param t2
/// @return /// @return
/// ///
bool operator > (AssTime &t1, AssTime &t2) { bool operator > (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() > t2.GetMS()); return (t1.GetMS() > t2.GetMS());
} }
@ -291,7 +289,7 @@ bool operator > (AssTime &t1, AssTime &t2) {
/// @param t2 /// @param t2
/// @return /// @return
/// ///
bool operator <= (AssTime &t1, AssTime &t2) { bool operator <= (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() <= t2.GetMS()); return (t1.GetMS() <= t2.GetMS());
} }
@ -301,7 +299,7 @@ bool operator <= (AssTime &t1, AssTime &t2) {
/// @param t2 /// @param t2
/// @return /// @return
/// ///
bool operator >= (AssTime &t1, AssTime &t2) { bool operator >= (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() >= t2.GetMS()); return (t1.GetMS() >= t2.GetMS());
} }
@ -311,7 +309,7 @@ bool operator >= (AssTime &t1, AssTime &t2) {
/// @param t2 /// @param t2
/// @return /// @return
/// ///
bool operator == (AssTime &t1, AssTime &t2) { bool operator == (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() == t2.GetMS()); return (t1.GetMS() == t2.GetMS());
} }
@ -321,7 +319,7 @@ bool operator == (AssTime &t1, AssTime &t2) {
/// @param t2 /// @param t2
/// @return /// @return
/// ///
bool operator != (AssTime &t1, AssTime &t2) { bool operator != (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() != t2.GetMS()); return (t1.GetMS() != t2.GetMS());
} }

View file

@ -64,6 +64,7 @@ public:
static bool UseMSPrecision; static bool UseMSPrecision;
AssTime(); AssTime();
AssTime(int ms);
int GetTimeHours(); int GetTimeHours();
int GetTimeMinutes(); int GetTimeMinutes();
@ -80,12 +81,12 @@ public:
}; };
// Comparison operators // Comparison operators
bool operator == (AssTime &t1, AssTime &t2); bool operator == (const AssTime &t1, const AssTime &t2);
bool operator != (AssTime &t1, AssTime &t2); bool operator != (const AssTime &t1, const AssTime &t2);
bool operator < (AssTime &t1, AssTime &t2); bool operator < (const AssTime &t1, const AssTime &t2);
bool operator > (AssTime &t1, AssTime &t2); bool operator > (const AssTime &t1, const AssTime &t2);
bool operator <= (AssTime &t1, AssTime &t2); bool operator <= (const AssTime &t1, const AssTime &t2);
bool operator >= (AssTime &t1, AssTime &t2); bool operator >= (const AssTime &t1, const AssTime &t2);

View file

@ -384,14 +384,13 @@ void DialogTimingProcessor::SortDialogues() {
tempDiag = grid->GetDialogue(i); tempDiag = grid->GetDialogue(i);
if (tempDiag && StyleOK(tempDiag->Style) && !tempDiag->Comment) { if (tempDiag && StyleOK(tempDiag->Style) && !tempDiag->Comment) {
if (!onlySelection->IsChecked() || grid->IsInSelection(i)) { if (!onlySelection->IsChecked() || grid->IsInSelection(i)) {
tempDiag->FixStartMS();
temp.push_back(tempDiag); temp.push_back(tempDiag);
} }
} }
} }
// Sort temporary list // Sort temporary list
temp.sort(LessByPointedToValue<AssDialogue>()); AssFile::Sort(temp);
// Copy temporary list to final vector // Copy temporary list to final vector
Sorted.clear(); Sorted.clear();

View file

@ -284,7 +284,7 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) {
// yes, let's framerate compensate the start timestamp and then use the changed value to // yes, let's framerate compensate the start timestamp and then use the changed value to
// compensate it AGAIN 20 lines down? I DO NOT GET IT // compensate it AGAIN 20 lines down? I DO NOT GET IT
// -Fluff // -Fluff
//curEntry->SetStartMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curEntry->GetStartMS(),true),true)); //curEntry->Start.SetMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curEntry->GetStartMS(),true),true));
curDialogue = AssEntry::GetAsDialogue(curEntry); curDialogue = AssEntry::GetAsDialogue(curEntry);
// Update dialogue entries // Update dialogue entries
@ -299,8 +299,8 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) {
// Process stuff // Process stuff
curDialogue->ParseASSTags(); curDialogue->ParseASSTags();
curDialogue->ProcessParameters(TransformTimeTags,&data); curDialogue->ProcessParameters(TransformTimeTags,&data);
curDialogue->SetStartMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->Start.GetMS(),true),true)); curDialogue->Start.SetMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->Start.GetMS(),true),true));
curDialogue->SetEndMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->End.GetMS(),false),false)); curDialogue->End.SetMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->End.GetMS(),false),false));
curDialogue->UpdateText(); curDialogue->UpdateText();
curDialogue->UpdateData(); curDialogue->UpdateData();
curDialogue->ClearBlocks(); curDialogue->ClearBlocks();

View file

@ -432,6 +432,15 @@ void FrameMain::InitMenu() {
AppendBitmapMenuItem(subtitlesMenu,MENU_RECOMBINE,_("Recombine Lines"),_("Recombine subtitles when they have been split and merged"),GETIMAGE(blank_button_16)); AppendBitmapMenuItem(subtitlesMenu,MENU_RECOMBINE,_("Recombine Lines"),_("Recombine subtitles when they have been split and merged"),GETIMAGE(blank_button_16));
AppendBitmapMenuItem(subtitlesMenu,MENU_SPLIT_BY_KARAOKE,_("Split Lines (by karaoke)"),_("Uses karaoke timing to split line into multiple smaller lines"),GETIMAGE(blank_button_16)); AppendBitmapMenuItem(subtitlesMenu,MENU_SPLIT_BY_KARAOKE,_("Split Lines (by karaoke)"),_("Uses karaoke timing to split line into multiple smaller lines"),GETIMAGE(blank_button_16));
subtitlesMenu->AppendSeparator(); subtitlesMenu->AppendSeparator();
wxMenu *SortMenu = new wxMenu;
wxMenuItem *SortParent = new wxMenuItem(subtitlesMenu,Menu_Subtitles_Sort_Start,_("Sort Lines"),_T(""),wxITEM_NORMAL,SortMenu);
#ifndef __APPLE__
SortParent->SetBitmap(GETIMAGE(sort_times_button_16));
#endif
AppendBitmapMenuItem(SortMenu,Menu_Subtitles_Sort_Start,_("&Start Time"),_("Sort all subtitles by their start times"),GETIMAGE(blank_button_16));
AppendBitmapMenuItem(SortMenu,Menu_Subtitles_Sort_End,_("&End Time"),_("Sort all subtitles by their end times"),GETIMAGE(blank_button_16));
AppendBitmapMenuItem(SortMenu,Menu_Subtitles_Sort_Style,_("St&yle Name"),_("Sort all subtitles by their style names"),GETIMAGE(blank_button_16));
subtitlesMenu->Append(SortParent);
AppendBitmapMenuItem(subtitlesMenu,MENU_SWAP,_("Swap Lines"),_("Swaps the two selected lines"),GETIMAGE(arrow_sort_16)); AppendBitmapMenuItem(subtitlesMenu,MENU_SWAP,_("Swap Lines"),_("Swaps the two selected lines"),GETIMAGE(arrow_sort_16));
AppendBitmapMenuItem (subtitlesMenu,Menu_Edit_Select, MakeHotkeyText(_("Select Lines..."), _T("Select lines")), _("Selects lines based on defined criterea"),GETIMAGE(select_lines_button_16)); AppendBitmapMenuItem (subtitlesMenu,Menu_Edit_Select, MakeHotkeyText(_("Select Lines..."), _T("Select lines")), _("Selects lines based on defined criterea"),GETIMAGE(select_lines_button_16));
MenuBar->Append(subtitlesMenu, _("&Subtitles")); MenuBar->Append(subtitlesMenu, _("&Subtitles"));
@ -439,7 +448,6 @@ void FrameMain::InitMenu() {
// Create timing menu // Create timing menu
timingMenu = new wxMenu(); timingMenu = new wxMenu();
AppendBitmapMenuItem(timingMenu,Menu_Edit_Shift, MakeHotkeyText(_("S&hift Times..."), _T("Shift times")), _("Shift subtitles by time or frames"),GETIMAGE(shift_times_toolbutton_16)); AppendBitmapMenuItem(timingMenu,Menu_Edit_Shift, MakeHotkeyText(_("S&hift Times..."), _T("Shift times")), _("Shift subtitles by time or frames"),GETIMAGE(shift_times_toolbutton_16));
AppendBitmapMenuItem(timingMenu,Menu_Edit_Sort, _("Sort by Time"), _("Sort all subtitles by their start times"),GETIMAGE(sort_times_button_16));
AppendBitmapMenuItem(timingMenu,Menu_Tools_Timing_Processor,_("Timing Post-Processor..."), _("Runs a post-processor for timing to deal with lead-ins, lead-outs, scene timing and etc."), GETIMAGE(timing_processor_toolbutton_16)); AppendBitmapMenuItem(timingMenu,Menu_Tools_Timing_Processor,_("Timing Post-Processor..."), _("Runs a post-processor for timing to deal with lead-ins, lead-outs, scene timing and etc."), GETIMAGE(timing_processor_toolbutton_16));
AppendBitmapMenuItem (timingMenu,Menu_Tools_Kanji_Timer,_("Kanji Timer..."),_("Open Kanji timer"),GETIMAGE(kara_timing_copier_16)); AppendBitmapMenuItem (timingMenu,Menu_Tools_Kanji_Timer,_("Kanji Timer..."),_("Open Kanji timer"),GETIMAGE(kara_timing_copier_16));
timingMenu->AppendSeparator(); timingMenu->AppendSeparator();

View file

@ -270,7 +270,9 @@ private:
void OnReplace (wxCommandEvent &event); void OnReplace (wxCommandEvent &event);
void OnJumpTo (wxCommandEvent &event); void OnJumpTo (wxCommandEvent &event);
void OnShift (wxCommandEvent &event); void OnShift (wxCommandEvent &event);
void OnSort (wxCommandEvent &event); void OnSortStart (wxCommandEvent &event);
void OnSortEnd (wxCommandEvent &event);
void OnSortStyle (wxCommandEvent &event);
void OnEditBoxCommit (wxCommandEvent &event); void OnEditBoxCommit (wxCommandEvent &event);
void OnOpenProperties (wxCommandEvent &event); void OnOpenProperties (wxCommandEvent &event);
void OnOpenStylesManager (wxCommandEvent &event); void OnOpenStylesManager (wxCommandEvent &event);
@ -559,9 +561,6 @@ enum {
/// DOCME /// DOCME
Menu_Edit_Redo, Menu_Edit_Redo,
/// DOCME
Menu_Edit_Sort,
/// DOCME /// DOCME
Menu_Edit_Find, Menu_Edit_Find,
@ -617,6 +616,10 @@ enum {
/// DOCME /// DOCME
Menu_Subtitles_Insert, Menu_Subtitles_Insert,
Menu_Subtitles_Sort_Start,
Menu_Subtitles_Sort_End,
Menu_Subtitles_Sort_Style,
/// DOCME /// DOCME

View file

@ -176,7 +176,10 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Menu_Edit_Replace, FrameMain::OnReplace) EVT_MENU(Menu_Edit_Replace, FrameMain::OnReplace)
EVT_MENU(Menu_Edit_Shift, FrameMain::OnShift) EVT_MENU(Menu_Edit_Shift, FrameMain::OnShift)
EVT_MENU(Menu_Edit_Select, FrameMain::OnSelect) EVT_MENU(Menu_Edit_Select, FrameMain::OnSelect)
EVT_MENU(Menu_Edit_Sort, FrameMain::OnSort)
EVT_MENU(Menu_Subtitles_Sort_Start, FrameMain::OnSortStart)
EVT_MENU(Menu_Subtitles_Sort_End, FrameMain::OnSortEnd)
EVT_MENU(Menu_Subtitles_Sort_Style, FrameMain::OnSortStyle)
EVT_MENU(Menu_Tools_Properties, FrameMain::OnOpenProperties) EVT_MENU(Menu_Tools_Properties, FrameMain::OnOpenProperties)
EVT_MENU(Menu_Tools_Styles_Manager, FrameMain::OnOpenStylesManager) EVT_MENU(Menu_Tools_Styles_Manager, FrameMain::OnOpenStylesManager)
@ -1693,31 +1696,27 @@ void FrameMain::OnSelect (wxCommandEvent &event) {
select.ShowModal(); select.ShowModal();
} }
/// @brief Sort subtitles by start time
void FrameMain::OnSortStart (wxCommandEvent &) {
/// @brief Sort subtitles AssFile::top->Sort();
/// @param event AssFile::top->FlagAsModified(_("sort"));
/// SubsBox->UpdateMaps();
void FrameMain::OnSort (wxCommandEvent &event) { SubsBox->CommitChanges();
// Ensure that StartMS is set properly }
AssEntry *curEntry; /// @brief Sort subtitles by end time
AssDialogue *curDiag; void FrameMain::OnSortEnd (wxCommandEvent &) {
int startMS = -1; AssFile::top->Sort(AssFile::CompEnd);
for (std::list<AssEntry*>::iterator cur = AssFile::top->Line.begin(); cur != AssFile::top->Line.end(); cur++) { AssFile::top->FlagAsModified(_("sort"));
curEntry = *cur; SubsBox->UpdateMaps();
curDiag = AssEntry::GetAsDialogue(curEntry); SubsBox->CommitChanges();
if (curDiag) startMS = curDiag->GetStartMS(); }
curEntry->SetStartMS(startMS); /// @brief Sort subtitles by style name
} void FrameMain::OnSortStyle (wxCommandEvent &) {
AssFile::top->Sort(AssFile::CompStyle);
// Sort
AssFile::top->Line.sort(LessByPointedToValue<AssEntry>());
AssFile::top->FlagAsModified(_("sort")); AssFile::top->FlagAsModified(_("sort"));
SubsBox->UpdateMaps(); SubsBox->UpdateMaps();
SubsBox->CommitChanges(); SubsBox->CommitChanges();
} }
/// @brief Open styling assistant /// @brief Open styling assistant
/// @param event /// @param event

View file

@ -387,14 +387,13 @@ void MatroskaWrapper::GetSubtitles(AssFile *target) {
// Load into file // Load into file
wxString group = _T("[Script Info]"); wxString group = _T("[Script Info]");
int lasttime = 0;
int version = 1; int version = 1;
if (CodecID == _T("S_TEXT/SSA")) version = 0; if (CodecID == _T("S_TEXT/SSA")) version = 0;
wxStringTokenizer token(privString,_T("\r\n"),wxTOKEN_STRTOK); wxStringTokenizer token(privString,_T("\r\n"),wxTOKEN_STRTOK);
while (token.HasMoreTokens()) { while (token.HasMoreTokens()) {
wxString next = token.GetNextToken(); wxString next = token.GetNextToken();
if (next[0] == _T('[')) group = next; if (next[0] == _T('[')) group = next;
lasttime = target->AddLine(next,group,lasttime,version,&group); target->AddLine(next,group,version,&group);
} }
// Insert "[Events]" // Insert "[Events]"
@ -492,10 +491,9 @@ void MatroskaWrapper::GetSubtitles(AssFile *target) {
// Insert into file // Insert into file
wxString group = _T("[Events]"); wxString group = _T("[Events]");
int lasttime = 0;
int version = (CodecID == _T("S_TEXT/SSA")); int version = (CodecID == _T("S_TEXT/SSA"));
for (unsigned int i=0;i<subList.size();i++) { for (unsigned int i=0;i<subList.size();i++) {
lasttime = target->AddLine(subList[i],group,lasttime,version,&group); target->AddLine(subList[i],group,version,&group);
} }
// Close progress bar // Close progress bar

View file

@ -1450,7 +1450,7 @@ bool SubtitlesGrid::SplitLineByKaraoke(int lineNumber) {
if (syls.size() < 2) return false; if (syls.size() < 2) return false;
// Insert a new line for each syllable // Insert a new line for each syllable
int start_ms = line->GetStartMS(); int start_ms = line->Start.GetMS();
int nextpos = lineNumber; int nextpos = lineNumber;
for (AssKaraokeVector::iterator syl = syls.begin(); syl != syls.end(); ++syl) for (AssKaraokeVector::iterator syl = syls.begin(); syl != syls.end(); ++syl)
{ {
@ -1458,9 +1458,9 @@ bool SubtitlesGrid::SplitLineByKaraoke(int lineNumber) {
if (syl->unstripped_text.IsEmpty()) continue; if (syl->unstripped_text.IsEmpty()) continue;
AssDialogue *nl = new AssDialogue(line->GetEntryData()); AssDialogue *nl = new AssDialogue(line->GetEntryData());
nl->SetStartMS(start_ms); nl->Start.SetMS(start_ms);
start_ms += syl->duration * 10; start_ms += syl->duration * 10;
nl->SetEndMS(start_ms); nl->End.SetMS(start_ms);
nl->Text = syl->unstripped_text; nl->Text = syl->unstripped_text;
nl->UpdateData(); nl->UpdateData();
InsertLine(nl, nextpos++, true, false); InsertLine(nl, nextpos++, true, false);

View file

@ -181,7 +181,7 @@ void SubtitlesPreview::UpdateBitmap(int w,int h) {
subs->InsertStyle((AssStyle *)style->Clone()); subs->InsertStyle((AssStyle *)style->Clone());
subs->SetScriptInfo(_T("PlayResX"),wxString::Format(_T("%i"),w)); subs->SetScriptInfo(_T("PlayResX"),wxString::Format(_T("%i"),w));
subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),h)); subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),h));
subs->AddLine(_T("Dialogue: 0,0:00:00.00,0:00:05.00,Preview,,0000,0000,0000,,{\\q2}") + showText,_T("[Events]"),0,ver,&outGroup); subs->AddLine(_T("Dialogue: 0,0:00:00.00,0:00:05.00,Preview,,0000,0000,0000,,{\\q2}") + showText,_T("[Events]"),ver,&outGroup);
// Apply subtitles // Apply subtitles
try { try {

View file

@ -137,13 +137,10 @@ void SubtitleFormat::LoadDefault(bool defline) {
/// @brief Add line /// @brief Add line
/// @param data /// @param data
/// @param group /// @param group
/// @param lasttime
/// @param version /// @param version
/// @param outgroup /// @param outgroup
/// @return void SubtitleFormat::AddLine(wxString data,wxString group,int &version,wxString *outgroup) {
/// assFile->AddLine(data,group,version,outgroup);
int SubtitleFormat::AddLine(wxString data,wxString group,int lasttime,int &version,wxString *outgroup) {
return assFile->AddLine(data,group,lasttime,version,outgroup);
} }
@ -411,7 +408,7 @@ SubtitleFormat::FPSRational SubtitleFormat::AskForFPS(bool showSMPTE) {
/// @brief Sort lines /// @brief Sort lines
/// ///
void SubtitleFormat::SortLines() { void SubtitleFormat::SortLines() {
Line->sort(LessByPointedToValue<AssEntry>()); AssFile::Sort(*Line);
} }

View file

@ -115,7 +115,7 @@ protected:
/// @return /// @return
/// ///
AssFile *GetAssFile() { return assFile; } AssFile *GetAssFile() { return assFile; }
int AddLine(wxString data,wxString group,int lasttime,int &version,wxString *outgroup=NULL); void AddLine(wxString data,wxString group,int &version,wxString *outgroup=NULL);
FPSRational AskForFPS(bool showSMPTE=false); FPSRational AskForFPS(bool showSMPTE=false);
virtual wxString GetName()=0; virtual wxString GetName()=0;

View file

@ -102,7 +102,6 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
// Parse file // Parse file
wxString curgroup; wxString curgroup;
int lasttime = -1;
wxString wxbuffer; wxString wxbuffer;
while (file.HasMoreLines()) { while (file.HasMoreLines()) {
// Reads line // Reads line
@ -112,7 +111,7 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
// is really [Script Info] // is really [Script Info]
if (curgroup.IsEmpty() && !wxbuffer.IsEmpty() && wxbuffer[0] != _T(';') && wxbuffer[0] != _T('[')) { if (curgroup.IsEmpty() && !wxbuffer.IsEmpty() && wxbuffer[0] != _T(';') && wxbuffer[0] != _T('[')) {
curgroup = _T("[Script Info]"); curgroup = _T("[Script Info]");
lasttime = AddLine(curgroup,curgroup,lasttime,version,&curgroup); AddLine(curgroup,curgroup,version,&curgroup);
} }
// Convert v4 styles to v4+ styles // Convert v4 styles to v4+ styles
@ -145,7 +144,7 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
// Add line // Add line
try { try {
lasttime = AddLine(wxbuffer,curgroup,lasttime,version,&curgroup); AddLine(wxbuffer,curgroup,version,&curgroup);
} }
catch (const wchar_t *err) { catch (const wchar_t *err) {
Clear(); Clear();
@ -158,7 +157,7 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
} }
// Add one last empty line in case it didn't end with one // Add one last empty line in case it didn't end with one
if (!wxbuffer.IsEmpty()) AddLine(_T(""),curgroup,lasttime,version); if (!wxbuffer.IsEmpty()) AddLine(_T(""),curgroup,version);
} }

View file

@ -176,8 +176,8 @@ void MicroDVDSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding)
AssDialogue *line = new AssDialogue(); AssDialogue *line = new AssDialogue();
line->group = _T("[Events]"); line->group = _T("[Events]");
line->Style = _T("Default"); line->Style = _T("Default");
line->SetStartMS(start); line->Start.SetMS(start);
line->SetEndMS(end); line->End.SetMS(end);
line->Text = text; line->Text = text;
Line->push_back(line); Line->push_back(line);
} }

View file

@ -170,7 +170,6 @@ void SRTSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
line->Comment = false; line->Comment = false;
line->UpdateData(); line->UpdateData();
line->ParseSRTTags(); line->ParseSRTTags();
line->FixStartMS();
Line->push_back(line); Line->push_back(line);
lines++; lines++;
} }
@ -182,8 +181,8 @@ void SRTSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
AssDialogue *line = new AssDialogue(); AssDialogue *line = new AssDialogue();
line->group = _T("[Events]"); line->group = _T("[Events]");
line->Style = _T("Default"); line->Style = _T("Default");
line->SetStartMS(0); line->Start.SetMS(0);
line->SetEndMS(5000); line->End.SetMS(5000);
Line->push_back(line); Line->push_back(line);
} }
} }

View file

@ -142,8 +142,8 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) {
AssDialogue *line = new AssDialogue(); AssDialogue *line = new AssDialogue();
line->group = _T("[Events]"); line->group = _T("[Events]");
line->Style = _T("Default"); line->Style = _T("Default");
line->SetStartMS(0); line->Start.SetMS(0);
line->SetEndMS(5000); line->End.SetMS(5000);
Line->push_back(line); Line->push_back(line);
} }
} }
@ -173,8 +173,8 @@ bool TTXTSubtitleFormat::ProcessLine(wxXmlNode *node) {
if (!text.IsEmpty()) { if (!text.IsEmpty()) {
// Create dialogue // Create dialogue
diag = new AssDialogue(); diag = new AssDialogue();
diag->SetStartMS(time.GetMS()); diag->Start.SetMS(time.GetMS());
diag->SetEndMS(36000000-10); diag->End.SetMS(36000000-10);
diag->group = _T("[Events]"); diag->group = _T("[Events]");
diag->Style = _T("Default"); diag->Style = _T("Default");
diag->Comment = false; diag->Comment = false;
@ -368,8 +368,8 @@ void TTXTSubtitleFormat::ConvertToTTXT () {
// Insert blank line at the end // Insert blank line at the end
AssDialogue *diag = new AssDialogue(); AssDialogue *diag = new AssDialogue();
diag->SetStartMS(lastTime.GetMS()); diag->Start.SetMS(lastTime.GetMS());
diag->SetEndMS(lastTime.GetMS()+Options.AsInt(_T("Timing Default Duration"))); diag->End.SetMS(lastTime.GetMS()+Options.AsInt(_T("Timing Default Duration")));
diag->group = _T("[Events]"); diag->group = _T("[Events]");
diag->Style = _T("Default"); diag->Style = _T("Default");
diag->Comment = false; diag->Comment = false;

View file

@ -168,8 +168,8 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na
} }
line->Comment = isComment; line->Comment = isComment;
line->Text = value; line->Text = value;
line->SetStartMS(0); line->Start.SetMS(0);
line->SetEndMS(0); line->End.SetMS(0);
line->UpdateData(); line->UpdateData();
//line->ParseASSTags(); //line->ParseASSTags();
@ -183,8 +183,8 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na
AssDialogue *line = new AssDialogue(); AssDialogue *line = new AssDialogue();
line->group = _T("[Events]"); line->group = _T("[Events]");
line->Style = _T("Default"); line->Style = _T("Default");
line->SetStartMS(0); line->Start.SetMS(0);
line->SetEndMS(Options.AsInt(_T("Timing Default Duration"))); line->End.SetMS(Options.AsInt(_T("Timing Default Duration")));
Line->push_back(line); Line->push_back(line);
} }
} }