-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCTimeTrack.cpp
113 lines (98 loc) · 2.73 KB
/
CTimeTrack.cpp
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
/*
** CDex - Open Source Digital Audio CD Extractor
**
** Copyright (C) 2006 - 2007 Georgy Berdyshev
** Copyright (C) 1999 - 2007 Albert L. Faber
**
** http://cdexos.sourceforge.net/
** http://sourceforge.net/projects/cdexos
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
#include "CTimeTrack.h"
void CTimeTrack::ReInit(DWORD dwTrackLength)
{
m_dwTrackLength=dwTrackLength;
m_dwStartTime=GetTickCount();
m_dwElapsed=0;
m_dwEstimated=0;
m_dwRemaining=0;
m_nPrevPercent=0;
}
CUString CTimeTrack::GetSpeedString()
{
CUString strTmp;
strTmp.Format( _W( "%4.1f" ), m_fSpeed);
return strTmp;
}
CUString CTimeTrack::GetElapsedString()
{
CUString strTmp;
strTmp.Format( _W( "%02d:%02d" ), m_dwElapsed / 60, m_dwElapsed % 60 );
return strTmp;
}
CUString CTimeTrack::GetEstimateString()
{
CUString strTmp;
strTmp.Format( _W( "%02d:%02d" ), m_dwEstimated / 60, m_dwEstimated % 60 );
return strTmp;
}
CUString CTimeTrack::GetRemainingString()
{
CUString strTmp;
strTmp.Format( _W( "%02d:%02d" ), m_dwRemaining / 60, m_dwRemaining % 60 );
return strTmp;
}
/*
void CTimeTrack::Calculate(int nPercent)
{
m_dwElapsed=(GetTickCount()-m_dwStartTime)/1000;
// Update every two percent
if ((nPercent-m_nPrevPercent)>=3)
{
if (nPercent)
{
m_dwEstimated=(DWORD)max(0,m_dwElapsed*100.0/nPercent);
m_nPrevPercent=nPercent;
}
}
m_dwRemaining=(DWORD)max(0,(double)m_dwEstimated-(double)m_dwElapsed);
}
*/
void CTimeTrack::Calculate(int nPercent)
{
DWORD dwElapsed = GetTickCount() - m_dwStartTime;
m_dwElapsed = dwElapsed / 1000;
if ( ( nPercent > 0 ) && ( dwElapsed > 0 ) )
{
if ( ( nPercent != m_nPrevPercent ) && ( m_dwElapsed >= 1 ) && ( nPercent > 0 ))
{
m_dwEstimated = m_dwElapsed * 100 / nPercent;
m_fSpeed = (float)( m_dwTrackLength * nPercent / (dwElapsed * 100.0) );
m_nPrevPercent = nPercent;
}
if (m_dwEstimated != 0)
{
if ( ( (int)m_dwEstimated - (int)m_dwElapsed ) > 0 )
{
m_dwRemaining = m_dwEstimated - m_dwElapsed;
}
else
{
m_dwRemaining = 0;
}
}
}
}