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:
parent
fb6280b2e7
commit
8ca726119f
13 changed files with 59 additions and 57 deletions
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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++) {
|
||||
curEntry = *cur;
|
||||
curDiag = AssEntry::GetAsDialogue(curEntry);
|
||||
if (curDiag) startMS = curDiag->Start.GetMS();
|
||||
curEntry->StartMS = startMS;
|
||||
if (curDiag) startMS = curDiag->GetStartMS();
|
||||
curEntry->SetStartMS(startMS);
|
||||
}
|
||||
|
||||
// Sort
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue