AssTime changed to store data as miliseconds internally (overall faster, uses less ram)

Originally committed to SVN as r100.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-21 22:09:15 +00:00
parent d759aae2b3
commit 87307940ca
3 changed files with 57 additions and 33 deletions

View File

@ -615,7 +615,7 @@ end_tokenizing:
// Get parameters // Get parameters
size_t n=0; size_t n=0;
wxString curtok = _T(""); wxString curtok = _T("");
if (curPar < totalPars) { if (curPar < (signed)totalPars) {
curtok = paramList[curPar]; curtok = paramList[curPar];
curPar++; curPar++;
} }
@ -676,7 +676,7 @@ end_tokenizing:
} }
// Get next actual parameter // Get next actual parameter
if (curPar < totalPars) { if (curPar < (signed)totalPars) {
// Unless this parameter was omitted (in which case the token shouldn't be eaten) // Unless this parameter was omitted (in which case the token shouldn't be eaten)
if (!newparam->ommited) { if (!newparam->ommited) {
curtok = paramList[curPar]; curtok = paramList[curPar];

View File

@ -46,7 +46,7 @@
////////////////////// AssTime ////////////////////// ////////////////////// AssTime //////////////////////
// AssTime constructors // AssTime constructors
AssTime::AssTime () { AssTime::AssTime () {
h = m = s = ms = 0; time = 0;
} }
@ -94,13 +94,7 @@ void AssTime::ParseASS (const wxString _text) {
} }
// OK, set values // OK, set values
h = th; time = tms + ts*1000 + tm*60000 + th*3600000;
m = tm;
s = ts;
ms = tms;
// This should clamp values properly
SetMS(GetMS());
} }
@ -113,6 +107,7 @@ void AssTime::ParseSRT (const wxString _text) {
text.Trim(true); text.Trim(true);
long tempv; long tempv;
wxString temp; wxString temp;
int ms,s,m,h;
// Parse // Parse
temp = text.Mid(0,2); temp = text.Mid(0,2);
@ -127,17 +122,30 @@ void AssTime::ParseSRT (const wxString _text) {
temp = text.Mid(9,3); temp = text.Mid(9,3);
temp.ToLong(&tempv); temp.ToLong(&tempv);
ms = tempv; ms = tempv;
// Set value
time = ms + s*1000 + m*60000 + h*3600000;
} }
////////////////////////////////////////// //////////////////////////////////////////
// AssTime conversion to/from miliseconds // AssTime conversion to/from miliseconds
int AssTime::GetMS () { int AssTime::GetMS () {
if (!UseMSPrecision) return ms/10*10 + s*1000 + m*60000 + h*3600000; if (!UseMSPrecision) return time/10*10;
else return ms + s*1000 + m*60000 + h*3600000; else return time;
} }
void AssTime::SetMS (int _ms) { void AssTime::SetMS (int _ms) {
time = _ms;
}
////////////////
// ASS Formated
wxString AssTime::GetASSFormated () {
int h,m,s,ms;
int _ms = time;
// Centisecond precision // Centisecond precision
if (!UseMSPrecision) _ms = _ms/10*10; if (!UseMSPrecision) _ms = _ms/10*10;
@ -157,7 +165,6 @@ void AssTime::SetMS (int _ms) {
m = 59; m = 59;
s = 59; s = 59;
ms = 999; ms = 999;
return;
} }
// Minutes // Minutes
@ -172,14 +179,6 @@ void AssTime::SetMS (int _ms) {
s++; s++;
} }
// Miliiseconds
ms = _ms;
}
////////////////
// ASS Formated
wxString AssTime::GetASSFormated () {
if (UseMSPrecision) return wxString::Format(_T("%01i:%02i:%02i.%03i"),h,m,s,ms); if (UseMSPrecision) return wxString::Format(_T("%01i:%02i:%02i.%03i"),h,m,s,ms);
else return wxString::Format(_T("%01i:%02i:%02i.%02i"),h,m,s,ms/10); else return wxString::Format(_T("%01i:%02i:%02i.%02i"),h,m,s,ms/10);
} }
@ -188,6 +187,42 @@ wxString AssTime::GetASSFormated () {
//////////////// ////////////////
// SRT Formated // SRT Formated
wxString AssTime::GetSRTFormated () { wxString AssTime::GetSRTFormated () {
int h,m,s,ms;
int _ms = time;
// Centisecond precision
if (!UseMSPrecision) _ms = _ms/10*10;
// Reset
h = m = s = ms = 0;
if (_ms < 0) _ms = 0;
// Hours
while (_ms >= 3600000) {
_ms -= 3600000;
h++;
}
// Ass overflow
if (h > 9) {
h = 9;
m = 59;
s = 59;
ms = 999;
}
// Minutes
while (_ms >= 60000) {
_ms -= 60000;
m++;
}
// Seconds
while (_ms >= 1000) {
_ms -= 1000;
s++;
}
wxString result = wxString::Format(_T("%02i:%02i:%02i,%03i"),h,m,s,ms); wxString result = wxString::Format(_T("%02i:%02i:%02i,%03i"),h,m,s,ms);
return result; return result;
} }
@ -221,14 +256,6 @@ void AssTime::UpdateFromTextCtrl(wxTextCtrl *ctrl) {
} }
///////////////////
// AssTime ostream
std::ostream& operator << (std::ostream &os,AssTime &time) {
os << time.GetASSFormated();
return os;
}
////////////////////// //////////////////////
// AssTime comparison // AssTime comparison
bool operator < (AssTime &t1, AssTime &t2) { bool operator < (AssTime &t1, AssTime &t2) {

View File

@ -46,10 +46,7 @@
// Class for Ass format time // Class for Ass format time
class AssTime { class AssTime {
private: private:
int h; // Hours int time; // Miliseconds
int m; // Minutes
int s; // Seconds
int ms; // Miliseconds
public: public:
static bool UseMSPrecision; static bool UseMSPrecision;