Fix #825 for good, I hope. Get some sense worked into the handling of AssEntry::StartMS and AssDialogue::Start using some private members and virtual getter/setter functions.

Originally committed to SVN as r2931.
This commit is contained in:
Niels Martin Hansen 2009-05-14 23:45:20 +00:00
parent fb6280b2e7
commit 8ca726119f
13 changed files with 59 additions and 57 deletions

View file

@ -53,9 +53,8 @@ AssDialogue::AssDialogue() {
group = _T("[Events]"); group = _T("[Events]");
Valid = true; Valid = true;
Start.SetMS(0); SetStartMS(0);
End.SetMS(5000); SetEndMS(5000);
StartMS = 0;
Layer = 0; Layer = 0;
for (int i=0;i<4;i++) Margin[i] = 0; for (int i=0;i<4;i++) Margin[i] = 0;
Text = _T(""); Text = _T("");
@ -153,7 +152,7 @@ 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());
StartMS = Start.GetMS(); FixStartMS();
// Get end time // Get end time
if (!tkn.HasMoreTokens()) return false; if (!tkn.HasMoreTokens()) return false;
@ -785,11 +784,10 @@ AssEntry *AssDialogue::Clone() {
final->Actor = Actor; final->Actor = Actor;
final->Comment = Comment; final->Comment = Comment;
final->Effect = Effect; final->Effect = Effect;
final->End = End;
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->Start = Start; final->SetStartMS(GetStartMS());
final->StartMS = Start.GetMS(); // Assume that StartMS might not be valid, because something altered Start without altering StartMS final->SetEndMS(GetEndMS());
final->Style = Style; final->Style = Style;
final->Text = Text; final->Text = Text;
//final->SetEntryData(GetEntryData()); //final->SetEntryData(GetEntryData());

View file

@ -185,6 +185,12 @@ public:
void SetEntryData(wxString newData); void SetEntryData(wxString newData);
void Clear(); // Wipes all data void Clear(); // Wipes all data
virtual int GetStartMS() const { return Start.GetMS(); }
virtual int GetEndMS() const { return End.GetMS(); }
virtual void SetStartMS(const int newStart) { AssEntry::SetStartMS(newStart); Start.SetMS(newStart); }
virtual void SetEndMS(const int newEnd) { End.SetMS(newEnd); }
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

@ -66,7 +66,7 @@ AssEntry::~AssEntry() {
/////////////////////////// ///////////////////////////
// Comparison for STL Sort // Comparison for STL Sort
bool operator < (const AssEntry &t1, const AssEntry &t2) { bool operator < (const AssEntry &t1, const AssEntry &t2) {
return (t1.StartMS < t2.StartMS); return (t1.GetStartMS() < t2.GetStartMS());
} }

View file

@ -65,9 +65,9 @@ enum ASS_EntryType {
class AssEntry { class AssEntry {
private: private:
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)
int StartMS; // This is only stored for sorting issues, in order to keep non-dialogue lines aligned
public: public:
int StartMS; // This is only stored for sorting issues, in order to keep non-dialogue lines aligned
bool Valid; // Flags as valid or not bool Valid; // Flags as valid or not
wxString group; // Group it belongs to, e.g. "[Events]" wxString group; // Group it belongs to, e.g. "[Events]"
@ -77,6 +77,11 @@ public:
virtual AssEntry *Clone(); virtual AssEntry *Clone();
virtual int GetStartMS() const { return StartMS; }
virtual int GetEndMS() const { return StartMS; }
virtual void SetStartMS(const int newStart) { StartMS = newStart; }
virtual void SetEndMS(const int newEnd) { /* do nothing */ (void)newEnd; }
virtual ASS_EntryType GetType() { return ENTRY_BASE; } virtual ASS_EntryType GetType() { return ENTRY_BASE; }
virtual const wxString GetEntryData() { return data; } virtual const wxString GetEntryData() { return data; }
virtual void SetEntryData(wxString newData) { if (newData.IsEmpty()) data.Clear(); else data = newData; } virtual void SetEntryData(wxString newData) { if (newData.IsEmpty()) data.Clear(); else data = newData; }

View file

@ -350,7 +350,7 @@ 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->StartMS = lasttime; attach->SetStartMS(lasttime);
attach->group = group; attach->group = group;
keepGroup = group; keepGroup = group;
return lasttime; return lasttime;
@ -382,15 +382,15 @@ 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->Start.GetMS(); lasttime = diag->GetStartMS();
//diag->ParseASSTags(); //diag->ParseASSTags();
entry = diag; entry = diag;
entry->StartMS = lasttime; 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->StartMS = lasttime; entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
} }
@ -400,12 +400,12 @@ 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->StartMS = lasttime; 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->StartMS = lasttime; entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
} }
@ -438,14 +438,14 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
// Everything // Everything
entry = new AssEntry(data); entry = new AssEntry(data);
entry->StartMS = lasttime; 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->StartMS = lasttime; entry->SetStartMS(lasttime);
entry->group = group; entry->group = group;
} }
@ -536,7 +536,7 @@ 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->StartMS; lasttime = curEntry->GetStartMS();
lastGroup = curEntry->group; lastGroup = curEntry->group;
} }
@ -545,24 +545,24 @@ void AssFile::InsertStyle (AssStyle *style) {
// Add space // Add space
curEntry = new AssEntry(_T("")); curEntry = new AssEntry(_T(""));
curEntry->group = lastGroup; curEntry->group = lastGroup;
curEntry->StartMS = lasttime; 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->StartMS = lasttime; 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->StartMS = lasttime; 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->StartMS = lasttime; style->SetStartMS(lasttime);
Line.push_back(style); Line.push_back(style);
} }
@ -570,7 +570,7 @@ void AssFile::InsertStyle (AssStyle *style) {
else { else {
lastStyle++; lastStyle++;
style->group = (*lastStyle)->group; style->group = (*lastStyle)->group;
style->StartMS = lasttime; style->SetStartMS(lasttime);
Line.insert(lastStyle,style); Line.insert(lastStyle,style);
} }
} }
@ -598,17 +598,17 @@ void AssFile::InsertAttachment (AssAttachment *attach) {
// Found point, insert there // Found point, insert there
if (insPoint != Line.end()) { if (insPoint != Line.end()) {
insPoint++; insPoint++;
attach->StartMS = (*insPoint)->StartMS; 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()->StartMS; int StartMS = Line.back()->GetStartMS();
AddLine(_T(""),Line.back()->group,StartMS,version); AddLine(_T(""),Line.back()->group,StartMS,version);
AddLine(attach->group,attach->group,StartMS,version); AddLine(attach->group,attach->group,StartMS,version);
attach->StartMS = StartMS; attach->SetStartMS(StartMS);
Line.push_back(attach); Line.push_back(attach);
AddLine(_T(""),attach->group,StartMS,version); AddLine(_T(""),attach->group,StartMS,version);
} }
@ -735,7 +735,7 @@ 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->StartMS = (*prev)->StartMS; entry->SetStartMS((*prev)->GetStartMS());
Line.insert(++prev,entry); Line.insert(++prev,entry);
} }
return; return;
@ -805,7 +805,7 @@ 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->StartMS = prev->StartMS; comm->SetStartMS(prev->GetStartMS());
Line.insert(cur,comm); Line.insert(cur,comm);
break; break;
} }

View file

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

View file

@ -363,7 +363,7 @@ 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->StartMS = tempDiag->Start.GetMS(); tempDiag->FixStartMS();
temp.push_back(tempDiag); temp.push_back(tempDiag);
} }
} }

View file

@ -259,7 +259,7 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) {
AssDialogue *curDialogue; AssDialogue *curDialogue;
for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();cur++) { for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();cur++) {
curEntry = *cur; curEntry = *cur;
curEntry->StartMS = Input->GetTimeAtFrame(Output->GetFrameAtTime(curEntry->StartMS,true),true); curEntry->SetStartMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curEntry->GetStartMS(),true),true));
curDialogue = AssEntry::GetAsDialogue(curEntry); curDialogue = AssEntry::GetAsDialogue(curEntry);
// Update dialogue entries // Update dialogue entries
@ -274,8 +274,8 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) {
// Process stuff // Process stuff
curDialogue->ParseASSTags(); curDialogue->ParseASSTags();
curDialogue->ProcessParameters(TransformTimeTags,&data); curDialogue->ProcessParameters(TransformTimeTags,&data);
curDialogue->Start.SetMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->Start.GetMS(),true),true)); curDialogue->SetStartMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->Start.GetMS(),true),true));
curDialogue->End.SetMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->End.GetMS(),false),false)); curDialogue->SetEndMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->End.GetMS(),false),false));
curDialogue->UpdateText(); curDialogue->UpdateText();
curDialogue->UpdateData(); curDialogue->UpdateData();
curDialogue->ClearBlocks(); curDialogue->ClearBlocks();

View file

@ -1475,8 +1475,8 @@ void FrameMain::OnSort (wxCommandEvent &event) {
for (std::list<AssEntry*>::iterator cur = AssFile::top->Line.begin(); cur != AssFile::top->Line.end(); cur++) { for (std::list<AssEntry*>::iterator cur = AssFile::top->Line.begin(); cur != AssFile::top->Line.end(); cur++) {
curEntry = *cur; curEntry = *cur;
curDiag = AssEntry::GetAsDialogue(curEntry); curDiag = AssEntry::GetAsDialogue(curEntry);
if (curDiag) startMS = curDiag->Start.GetMS(); if (curDiag) startMS = curDiag->GetStartMS();
curEntry->StartMS = startMS; curEntry->SetStartMS(startMS);
} }
// Sort // Sort

View file

@ -157,9 +157,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->StartMS = start; 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

@ -155,7 +155,7 @@ void SRTSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
line->Comment = false; line->Comment = false;
line->UpdateData(); line->UpdateData();
line->ParseSRTTags(); line->ParseSRTTags();
line->StartMS = line->Start.GetMS(); line->FixStartMS();
Line->push_back(line); Line->push_back(line);
lines++; lines++;
} }
@ -167,9 +167,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->StartMS = 0; line->SetStartMS(0);
line->Start.SetMS(0); line->SetEndMS(5000);
line->End.SetMS(5000);
Line->push_back(line); Line->push_back(line);
} }
} }

View file

@ -127,9 +127,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->StartMS = 0; line->SetStartMS(0);
line->Start.SetMS(0); line->SetEndMS(5000);
line->End.SetMS(5000);
Line->push_back(line); Line->push_back(line);
} }
} }
@ -156,12 +155,11 @@ bool TTXTSubtitleFormat::ProcessLine(wxXmlNode *node) {
if (!text.IsEmpty()) { if (!text.IsEmpty()) {
// Create dialogue // Create dialogue
diag = new AssDialogue(); diag = new AssDialogue();
diag->Start = time; diag->SetStartMS(time.GetMS());
diag->End.SetMS(36000000-10); diag->SetEndMS(36000000-10);
diag->group = _T("[Events]"); diag->group = _T("[Events]");
diag->Style = _T("Default"); diag->Style = _T("Default");
diag->Comment = false; diag->Comment = false;
diag->StartMS = diag->Start.GetMS();
// Process text for 1.0 // Process text for 1.0
if (version == 0) { if (version == 0) {
@ -341,11 +339,10 @@ void TTXTSubtitleFormat::ConvertToTTXT () {
// Insert blank line at the end // Insert blank line at the end
AssDialogue *diag = new AssDialogue(); AssDialogue *diag = new AssDialogue();
diag->Start = lastTime; diag->SetStartMS(lastTime.GetMS());
diag->End.SetMS(lastTime.GetMS()+Options.AsInt(_T("Timing Default Duration"))); diag->SetEndMS(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;
diag->StartMS = diag->Start.GetMS();
Line->push_back(diag); Line->push_back(diag);
} }

View file

@ -152,9 +152,8 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na
} }
line->Comment = isComment; line->Comment = isComment;
line->Text = value; line->Text = value;
line->StartMS = 0; line->SetStartMS(0);
line->Start.SetMS(0); line->SetEndMS(0);
line->End.SetMS(0);
line->UpdateData(); line->UpdateData();
//line->ParseASSTags(); //line->ParseASSTags();
@ -168,9 +167,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->StartMS = 0; 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);
} }
} }