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
size_t n=0;
wxString curtok = _T("");
if (curPar < totalPars) {
if (curPar < (signed)totalPars) {
curtok = paramList[curPar];
curPar++;
}
@ -676,7 +676,7 @@ end_tokenizing:
}
// 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)
if (!newparam->ommited) {
curtok = paramList[curPar];

View File

@ -46,7 +46,7 @@
////////////////////// AssTime //////////////////////
// AssTime constructors
AssTime::AssTime () {
h = m = s = ms = 0;
time = 0;
}
@ -94,13 +94,7 @@ void AssTime::ParseASS (const wxString _text) {
}
// OK, set values
h = th;
m = tm;
s = ts;
ms = tms;
// This should clamp values properly
SetMS(GetMS());
time = tms + ts*1000 + tm*60000 + th*3600000;
}
@ -113,6 +107,7 @@ void AssTime::ParseSRT (const wxString _text) {
text.Trim(true);
long tempv;
wxString temp;
int ms,s,m,h;
// Parse
temp = text.Mid(0,2);
@ -127,17 +122,30 @@ void AssTime::ParseSRT (const wxString _text) {
temp = text.Mid(9,3);
temp.ToLong(&tempv);
ms = tempv;
// Set value
time = ms + s*1000 + m*60000 + h*3600000;
}
//////////////////////////////////////////
// AssTime conversion to/from miliseconds
int AssTime::GetMS () {
if (!UseMSPrecision) return ms/10*10 + s*1000 + m*60000 + h*3600000;
else return ms + s*1000 + m*60000 + h*3600000;
if (!UseMSPrecision) return time/10*10;
else return time;
}
void AssTime::SetMS (int _ms) {
time = _ms;
}
////////////////
// ASS Formated
wxString AssTime::GetASSFormated () {
int h,m,s,ms;
int _ms = time;
// Centisecond precision
if (!UseMSPrecision) _ms = _ms/10*10;
@ -157,7 +165,6 @@ void AssTime::SetMS (int _ms) {
m = 59;
s = 59;
ms = 999;
return;
}
// Minutes
@ -172,14 +179,6 @@ void AssTime::SetMS (int _ms) {
s++;
}
// Miliiseconds
ms = _ms;
}
////////////////
// ASS Formated
wxString AssTime::GetASSFormated () {
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);
}
@ -188,6 +187,42 @@ wxString AssTime::GetASSFormated () {
////////////////
// SRT Formated
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);
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
bool operator < (AssTime &t1, AssTime &t2) {

View File

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