-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASSLine.cpp
More file actions
298 lines (244 loc) · 5.24 KB
/
ASSLine.cpp
File metadata and controls
298 lines (244 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include "ASSLine.h"
#include "SwitchCodes.h"
#include <sstream>
#include <iostream>
#define ONETIME_ZERO_STRING "0:00:00.00"
#define ONETIME_FIVE_STRING "0:00:05.00"
#define DEFAULT_STYLE "Default"
#define DEFAULT_TAG "{\\fad(200,200)\\be11}"
#define UP_TAG "{\\fad(200,200)\\be11\\an8}"
#define TITLE_TAG "{\\fad(200,200)\\be11\\an7}"
#define DIALOGUE_TAG "{\\rAvenir Next LT Pro\\fs60}"
ASSLine::ASSLine()
{
this->start = ONETIME_ZERO_STRING;
this->end = ONETIME_FIVE_STRING;
this->text = "";
this->style = DEFAULT_STYLE;
this->actor = "";
this->leftMargin = 0;
this->rightMargin = 0;
this->verticalMargin = 0;
this->effect = "";
this->layer = 0;
this->iscomment = false;
this->isup = false;
this->isdialogue = false;
}
ASSLine::ASSLine(std::string input) : ASSLine()
{
std::istringstream iss(input);
std::string formatString;
getline(iss, formatString, ' ');
if (formatString == "Comment:") this->iscomment = true;
std::string layerString;
getline(iss, layerString, ',');
this->layer = stoi(layerString);
std::string startString;
getline(iss, startString, ',');
this->start = startString;
std::string endString;
getline(iss, endString, ',');
this->end = endString;
std::string styleString;
getline(iss, styleString, ',');
this->style = styleString;
std::string actorString;
getline(iss, actorString, ',');
this->actor = actorString;
std::string leftMarginString;
getline(iss, leftMarginString, ',');
this->leftMargin = stoi(leftMarginString);
std::string rightMarginString;
getline(iss, rightMarginString, ',');
this->rightMargin = stoi(rightMarginString);
std::string verticalMarginString;
getline(iss, verticalMarginString, ',');
this->verticalMargin = stoi(verticalMarginString);
std::string effectString;
getline(iss, effectString, ',');
this->effect = effectString;
std::string textString;
getline(iss, textString);
while (textString.back() == ' ') textString.pop_back();
this->text = textString;
}
void ASSLine::operator=(ASSLine input)
{
this->start = input.start;
this->end = input.end;
this->text = input.text;
this->style = input.style;
this->actor = input.actor;
this->leftMargin = input.leftMargin;
this->rightMargin = input.rightMargin;
this->verticalMargin = input.verticalMargin;
this->effect = input.effect;
this->layer = input.layer;
this->iscomment = input.isComment();
this->isup = input.isUp();
this->isdialogue = input.isDialogue();
}
int ASSLine::getLayer()
{
return this->layer;
}
ASSTime ASSLine::getStart()
{
return this->start;
}
ASSTime ASSLine::getEnd()
{
return this->end;
}
std::string ASSLine::getText()
{
return this->text;
}
std::string ASSLine::getStyle()
{
return this->style;
}
bool ASSLine::isComment()
{
return this->iscomment;
}
bool ASSLine::isUp()
{
return this->isup;
}
bool ASSLine::isDialogue()
{
return this->isdialogue;
}
void ASSLine::setStart(ASSTime toSet)
{
this->start = toSet;
}
void ASSLine::setEnd(ASSTime toSet)
{
this->end = toSet;
}
void ASSLine::setText(std::string toSet)
{
this->text = toSet;
}
void ASSLine::setStyle(std::string toSet)
{
this->style = toSet;
}
void ASSLine::setLayer(int toSet)
{
this->layer = toSet;
}
void ASSLine::setComment()
{
this->iscomment = true;
}
void ASSLine::unsetComment()
{
this->iscomment = false;
}
void ASSLine::setUp()
{
this->isup = true;
}
void ASSLine::unsetUp()
{
this->isup = false;
}
void ASSLine::setDialogue()
{
this->isdialogue = true;
}
void ASSLine::unsetDialogue()
{
this->isdialogue = false;
}
ASSTime ASSLine::getDuration()
{
return this->end - this->start;
}
std::string ASSLine::printASSLine()
{
std::ostringstream sout;
if (this->isComment()) sout << "Comment: ";
else sout << "Dialogue: ";
sout << this->layer << ',';
sout << this->start.printASSTime() << ',';
sout << this->end.printASSTime() << ',';
sout << this->style << ',';
sout << this->actor << ',';
sout << this->leftMargin << ',';
sout << this->rightMargin << ',';
sout << this->verticalMargin << ',';
sout << this->effect << ',';
if (!this->isComment())
{
if (this->isUp()) sout << UP_TAG;
else if (this->style == "Title") sout << TITLE_TAG;
else if (this->isDialogue()) sout << DIALOGUE_TAG;
else sout << DEFAULT_TAG;
}
sout << this->text;
sout << std::endl;
return sout.str();
}
std::string ASSLine::removeAllTags(std::string input)
{
std::string output = "";
bool writeEnable = true;
for (int i = 0; i < input.size(); i++)
{
if (input[i] == '{')
{
writeEnable = false;
i++;
}
else if (input[i] == '}')
{
writeEnable = true;
i++;
}
if (writeEnable)
output += input[i];
}
return output;
}
void ASSLine::removeAllTags()
{
this->text = removeAllTags(this->text);
}
std::string ASSLine::removeNonKaraokeTags(std::string input)
{
std::string output = "";
bool writeEnable = true;
for (int i = 0; i < input.size(); i++)
{
if (input[i] == '{')
{
if (input[i + 2] != 'k' && input[i + 2] != 'K')
{
writeEnable = false;
i++;
}
}
else if (input[i] == '}' && !writeEnable)
{
writeEnable = true;
i++;
}
if (writeEnable)
output += input[i];
}
return output;
}
void ASSLine::removeNonKaraokeTags()
{
this->text = removeNonKaraokeTags(this->text);
}
void ASSLine::offsetASSLine(ASSTime duration)
{
this->start += duration;
this->end += duration;
}