From c7c95d20c05046656bd34c4276990ebc7d9e7c84 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Thu, 14 May 2009 23:45:20 +0000 Subject: [PATCH] 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. --- aegisub/src/ass_dialogue.cpp | 12 ++++---- aegisub/src/ass_dialogue.h | 6 ++++ aegisub/src/ass_entry.cpp | 2 +- aegisub/src/ass_entry.h | 7 ++++- aegisub/src/ass_file.cpp | 38 ++++++++++++------------ aegisub/src/ass_style.cpp | 2 +- aegisub/src/dialog_timing_processor.cpp | 2 +- aegisub/src/export_framerate.cpp | 6 ++-- aegisub/src/frame_main_events.cpp | 4 +-- aegisub/src/subtitle_format_microdvd.cpp | 5 ++-- aegisub/src/subtitle_format_srt.cpp | 7 ++--- aegisub/src/subtitle_format_ttxt.cpp | 15 ++++------ aegisub/src/subtitle_format_txt.cpp | 10 +++---- 13 files changed, 59 insertions(+), 57 deletions(-) diff --git a/aegisub/src/ass_dialogue.cpp b/aegisub/src/ass_dialogue.cpp index 2619d5964..ae6187101 100644 --- a/aegisub/src/ass_dialogue.cpp +++ b/aegisub/src/ass_dialogue.cpp @@ -53,9 +53,8 @@ AssDialogue::AssDialogue() { group = _T("[Events]"); Valid = true; - Start.SetMS(0); - End.SetMS(5000); - StartMS = 0; + SetStartMS(0); + SetEndMS(5000); Layer = 0; for (int i=0;i<4;i++) Margin[i] = 0; Text = _T(""); @@ -153,7 +152,7 @@ bool AssDialogue::Parse(wxString rawData, int version) { // Get start time if (!tkn.HasMoreTokens()) return false; Start.ParseASS(tkn.GetNextToken()); - StartMS = Start.GetMS(); + FixStartMS(); // Get end time if (!tkn.HasMoreTokens()) return false; @@ -785,11 +784,10 @@ AssEntry *AssDialogue::Clone() { final->Actor = Actor; final->Comment = Comment; final->Effect = Effect; - final->End = End; final->Layer = Layer; for (int i=0;i<4;i++) final->Margin[i] = Margin[i]; - final->Start = Start; - final->StartMS = Start.GetMS(); // Assume that StartMS might not be valid, because something altered Start without altering StartMS + final->SetStartMS(GetStartMS()); + final->SetEndMS(GetEndMS()); final->Style = Style; final->Text = Text; //final->SetEntryData(GetEntryData()); diff --git a/aegisub/src/ass_dialogue.h b/aegisub/src/ass_dialogue.h index 528a72427..805abcb35 100644 --- a/aegisub/src/ass_dialogue.h +++ b/aegisub/src/ass_dialogue.h @@ -185,6 +185,12 @@ public: void SetEntryData(wxString newData); 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) 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(); diff --git a/aegisub/src/ass_entry.cpp b/aegisub/src/ass_entry.cpp index 875312fa2..05b33a6ba 100644 --- a/aegisub/src/ass_entry.cpp +++ b/aegisub/src/ass_entry.cpp @@ -66,7 +66,7 @@ AssEntry::~AssEntry() { /////////////////////////// // Comparison for STL Sort bool operator < (const AssEntry &t1, const AssEntry &t2) { - return (t1.StartMS < t2.StartMS); + return (t1.GetStartMS() < t2.GetStartMS()); } diff --git a/aegisub/src/ass_entry.h b/aegisub/src/ass_entry.h index a8d693477..40745d9c6 100644 --- a/aegisub/src/ass_entry.h +++ b/aegisub/src/ass_entry.h @@ -65,9 +65,9 @@ enum ASS_EntryType { class AssEntry { 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) + int StartMS; // This is only stored for sorting issues, in order to keep non-dialogue lines aligned 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 wxString group; // Group it belongs to, e.g. "[Events]" @@ -77,6 +77,11 @@ public: 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 const wxString GetEntryData() { return data; } virtual void SetEntryData(wxString newData) { if (newData.IsEmpty()) data.Clear(); else data = newData; } diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index 85b90ee57..d3894de34 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -350,7 +350,7 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS // Create attachment if needed if (isFilename) { attach = new AssAttachment(data.Mid(10)); - attach->StartMS = lasttime; + attach->SetStartMS(lasttime); attach->group = group; keepGroup = group; return lasttime; @@ -382,15 +382,15 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS if (lowGroup == _T("[events]")) { if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) { AssDialogue *diag = new AssDialogue(data,version); - lasttime = diag->Start.GetMS(); + lasttime = diag->GetStartMS(); //diag->ParseASSTags(); entry = diag; - entry->StartMS = lasttime; + entry->SetStartMS(lasttime); entry->group = group; } if (data.Left(7) == _T("Format:")) { entry = new AssEntry(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text")); - entry->StartMS = lasttime; + entry->SetStartMS(lasttime); 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:")) { AssStyle *style = new AssStyle(data,version); entry = style; - entry->StartMS = lasttime; + entry->SetStartMS(lasttime); entry->group = group; } 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->StartMS = lasttime; + entry->SetStartMS(lasttime); entry->group = group; } } @@ -438,14 +438,14 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS // Everything entry = new AssEntry(data); - entry->StartMS = lasttime; + entry->SetStartMS(lasttime); entry->group = group; } // Common entry if (entry == NULL) { entry = new AssEntry(data); - entry->StartMS = lasttime; + entry->SetStartMS(lasttime); 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:"))) { lastStyle = cur; } - lasttime = curEntry->StartMS; + lasttime = curEntry->GetStartMS(); lastGroup = curEntry->group; } @@ -545,24 +545,24 @@ void AssFile::InsertStyle (AssStyle *style) { // Add space curEntry = new AssEntry(_T("")); curEntry->group = lastGroup; - curEntry->StartMS = lasttime; + curEntry->SetStartMS(lasttime); Line.push_back(curEntry); // Add header curEntry = new AssEntry(_T("[V4+ Styles]")); curEntry->group = _T("[V4+ Styles]"); - curEntry->StartMS = lasttime; + curEntry->SetStartMS(lasttime); Line.push_back(curEntry); // 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->group = _T("[V4+ Styles]"); - curEntry->StartMS = lasttime; + curEntry->SetStartMS(lasttime); Line.push_back(curEntry); // Add style style->group = _T("[V4+ Styles]"); - style->StartMS = lasttime; + style->SetStartMS(lasttime); Line.push_back(style); } @@ -570,7 +570,7 @@ void AssFile::InsertStyle (AssStyle *style) { else { lastStyle++; style->group = (*lastStyle)->group; - style->StartMS = lasttime; + style->SetStartMS(lasttime); Line.insert(lastStyle,style); } } @@ -598,17 +598,17 @@ void AssFile::InsertAttachment (AssAttachment *attach) { // Found point, insert there if (insPoint != Line.end()) { insPoint++; - attach->StartMS = (*insPoint)->StartMS; + attach->SetStartMS((*insPoint)->GetStartMS()); Line.insert(insPoint,attach); } // Otherwise, create the [Fonts] group and insert else { int version=1; - int StartMS = Line.back()->StartMS; + int StartMS = Line.back()->GetStartMS(); AddLine(_T(""),Line.back()->group,StartMS,version); AddLine(attach->group,attach->group,StartMS,version); - attach->StartMS = StartMS; + attach->SetStartMS(StartMS); Line.push_back(attach); AddLine(_T(""),attach->group,StartMS,version); } @@ -735,7 +735,7 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) { result += value; AssEntry *entry = new AssEntry(result); entry->group = (*prev)->group; - entry->StartMS = (*prev)->StartMS; + entry->SetStartMS((*prev)->GetStartMS()); Line.insert(++prev,entry); } return; @@ -805,7 +805,7 @@ void AssFile::AddComment(const wxString _comment) { AssEntry *prev = *cur; AssEntry *comm = new AssEntry(comment); comm->group = prev->group; - comm->StartMS = prev->StartMS; + comm->SetStartMS(prev->GetStartMS()); Line.insert(cur,comm); break; } diff --git a/aegisub/src/ass_style.cpp b/aegisub/src/ass_style.cpp index bdec3b7f7..462383596 100644 --- a/aegisub/src/ass_style.cpp +++ b/aegisub/src/ass_style.cpp @@ -499,7 +499,7 @@ AssEntry *AssStyle::Clone() { // Copy data final->group = group; - final->StartMS = StartMS; + final->SetStartMS(GetStartMS()); final->Valid = Valid; final->alignment = alignment; final->angle = angle; diff --git a/aegisub/src/dialog_timing_processor.cpp b/aegisub/src/dialog_timing_processor.cpp index 226e90676..e229c5bfe 100644 --- a/aegisub/src/dialog_timing_processor.cpp +++ b/aegisub/src/dialog_timing_processor.cpp @@ -363,7 +363,7 @@ void DialogTimingProcessor::SortDialogues() { tempDiag = grid->GetDialogue(i); if (tempDiag && StyleOK(tempDiag->Style) && !tempDiag->Comment) { if (!onlySelection->IsChecked() || grid->IsInSelection(i)) { - tempDiag->StartMS = tempDiag->Start.GetMS(); + tempDiag->FixStartMS(); temp.push_back(tempDiag); } } diff --git a/aegisub/src/export_framerate.cpp b/aegisub/src/export_framerate.cpp index a4aa9450a..cb6ea55d1 100644 --- a/aegisub/src/export_framerate.cpp +++ b/aegisub/src/export_framerate.cpp @@ -259,7 +259,7 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) { AssDialogue *curDialogue; for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();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); // Update dialogue entries @@ -274,8 +274,8 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) { // Process stuff curDialogue->ParseASSTags(); curDialogue->ProcessParameters(TransformTimeTags,&data); - curDialogue->Start.SetMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->Start.GetMS(),true),true)); - curDialogue->End.SetMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->End.GetMS(),false),false)); + curDialogue->SetStartMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->Start.GetMS(),true),true)); + curDialogue->SetEndMS(Input->GetTimeAtFrame(Output->GetFrameAtTime(curDialogue->End.GetMS(),false),false)); curDialogue->UpdateText(); curDialogue->UpdateData(); curDialogue->ClearBlocks(); diff --git a/aegisub/src/frame_main_events.cpp b/aegisub/src/frame_main_events.cpp index 838212035..12a660d8e 100644 --- a/aegisub/src/frame_main_events.cpp +++ b/aegisub/src/frame_main_events.cpp @@ -1475,8 +1475,8 @@ void FrameMain::OnSort (wxCommandEvent &event) { for (std::list::iterator cur = AssFile::top->Line.begin(); cur != AssFile::top->Line.end(); cur++) { curEntry = *cur; curDiag = AssEntry::GetAsDialogue(curEntry); - if (curDiag) startMS = curDiag->Start.GetMS(); - curEntry->StartMS = startMS; + if (curDiag) startMS = curDiag->GetStartMS(); + curEntry->SetStartMS(startMS); } // Sort diff --git a/aegisub/src/subtitle_format_microdvd.cpp b/aegisub/src/subtitle_format_microdvd.cpp index d8577d3f0..e517bdc4f 100644 --- a/aegisub/src/subtitle_format_microdvd.cpp +++ b/aegisub/src/subtitle_format_microdvd.cpp @@ -157,9 +157,8 @@ void MicroDVDSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) AssDialogue *line = new AssDialogue(); line->group = _T("[Events]"); line->Style = _T("Default"); - line->StartMS = start; - line->Start.SetMS(start); - line->End.SetMS(end); + line->SetStartMS(start); + line->SetEndMS(end); line->Text = text; Line->push_back(line); } diff --git a/aegisub/src/subtitle_format_srt.cpp b/aegisub/src/subtitle_format_srt.cpp index 1f2365903..db3328fec 100644 --- a/aegisub/src/subtitle_format_srt.cpp +++ b/aegisub/src/subtitle_format_srt.cpp @@ -155,7 +155,7 @@ void SRTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { line->Comment = false; line->UpdateData(); line->ParseSRTTags(); - line->StartMS = line->Start.GetMS(); + line->FixStartMS(); Line->push_back(line); lines++; } @@ -167,9 +167,8 @@ void SRTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { AssDialogue *line = new AssDialogue(); line->group = _T("[Events]"); line->Style = _T("Default"); - line->StartMS = 0; - line->Start.SetMS(0); - line->End.SetMS(5000); + line->SetStartMS(0); + line->SetEndMS(5000); Line->push_back(line); } } diff --git a/aegisub/src/subtitle_format_ttxt.cpp b/aegisub/src/subtitle_format_ttxt.cpp index adeb8e704..ef9b31169 100644 --- a/aegisub/src/subtitle_format_ttxt.cpp +++ b/aegisub/src/subtitle_format_ttxt.cpp @@ -127,9 +127,8 @@ void TTXTSubtitleFormat::ReadFile(wxString filename,wxString forceEncoding) { AssDialogue *line = new AssDialogue(); line->group = _T("[Events]"); line->Style = _T("Default"); - line->StartMS = 0; - line->Start.SetMS(0); - line->End.SetMS(5000); + line->SetStartMS(0); + line->SetEndMS(5000); Line->push_back(line); } } @@ -156,12 +155,11 @@ bool TTXTSubtitleFormat::ProcessLine(wxXmlNode *node) { if (!text.IsEmpty()) { // Create dialogue diag = new AssDialogue(); - diag->Start = time; - diag->End.SetMS(36000000-10); + diag->SetStartMS(time.GetMS()); + diag->SetEndMS(36000000-10); diag->group = _T("[Events]"); diag->Style = _T("Default"); diag->Comment = false; - diag->StartMS = diag->Start.GetMS(); // Process text for 1.0 if (version == 0) { @@ -341,11 +339,10 @@ void TTXTSubtitleFormat::ConvertToTTXT () { // Insert blank line at the end AssDialogue *diag = new AssDialogue(); - diag->Start = lastTime; - diag->End.SetMS(lastTime.GetMS()+Options.AsInt(_T("Timing Default Duration"))); + diag->SetStartMS(lastTime.GetMS()); + diag->SetEndMS(lastTime.GetMS()+Options.AsInt(_T("Timing Default Duration"))); diag->group = _T("[Events]"); diag->Style = _T("Default"); diag->Comment = false; - diag->StartMS = diag->Start.GetMS(); Line->push_back(diag); } diff --git a/aegisub/src/subtitle_format_txt.cpp b/aegisub/src/subtitle_format_txt.cpp index a05212f25..b20e55c5f 100644 --- a/aegisub/src/subtitle_format_txt.cpp +++ b/aegisub/src/subtitle_format_txt.cpp @@ -152,9 +152,8 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na } line->Comment = isComment; line->Text = value; - line->StartMS = 0; - line->Start.SetMS(0); - line->End.SetMS(0); + line->SetStartMS(0); + line->SetEndMS(0); line->UpdateData(); //line->ParseASSTags(); @@ -168,9 +167,8 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na AssDialogue *line = new AssDialogue(); line->group = _T("[Events]"); line->Style = _T("Default"); - line->StartMS = 0; - line->Start.SetMS(0); - line->End.SetMS(Options.AsInt(_T("Timing Default Duration"))); + line->SetStartMS(0); + line->SetEndMS(Options.AsInt(_T("Timing Default Duration"))); Line->push_back(line); } }