Mercurial > hg > vamp-plugin-sdk
comparison src/vamp-sdk/RealTime.cpp @ 413:3ee97caa8fb6
Fix to RealTime::toText following similar fix in SV
author | Chris Cannam |
---|---|
date | Fri, 04 Sep 2015 12:37:58 +0100 |
parents | 521734d2b498 |
children | 6f88563ea26f |
comparison
equal
deleted
inserted
replaced
412:6c38ae0a25e5 | 413:3ee97caa8fb6 |
---|---|
90 } | 90 } |
91 | 91 |
92 RealTime | 92 RealTime |
93 RealTime::fromSeconds(double sec) | 93 RealTime::fromSeconds(double sec) |
94 { | 94 { |
95 return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5)); | 95 if (sec >= 0) { |
96 return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5)); | |
97 } else { | |
98 return -fromSeconds(-sec); | |
99 } | |
96 } | 100 } |
97 | 101 |
98 RealTime | 102 RealTime |
99 RealTime::fromMilliseconds(int msec) | 103 RealTime::fromMilliseconds(int msec) |
100 { | 104 { |
137 RealTime::toString() const | 141 RealTime::toString() const |
138 { | 142 { |
139 std::stringstream out; | 143 std::stringstream out; |
140 out << *this; | 144 out << *this; |
141 | 145 |
142 #if (__GNUC__ < 3) | |
143 out << std::ends; | |
144 #endif | |
145 | |
146 std::string s = out.str(); | 146 std::string s = out.str(); |
147 | 147 |
148 // remove trailing R | 148 // remove trailing R |
149 return s.substr(0, s.length() - 1); | 149 return s.substr(0, s.length() - 1); |
150 } | 150 } |
155 if (*this < RealTime::zeroTime) return "-" + (-*this).toText(); | 155 if (*this < RealTime::zeroTime) return "-" + (-*this).toText(); |
156 | 156 |
157 std::stringstream out; | 157 std::stringstream out; |
158 | 158 |
159 if (sec >= 3600) { | 159 if (sec >= 3600) { |
160 out << (sec / 3600) << ":"; | 160 out << (sec / 3600) << ":"; |
161 } | 161 } |
162 | 162 |
163 if (sec >= 60) { | 163 if (sec >= 60) { |
164 out << (sec % 3600) / 60 << ":"; | 164 int minutes = (sec % 3600) / 60; |
165 } | 165 if (sec >= 3600 && minutes < 10) out << "0"; |
166 | 166 out << minutes << ":"; |
167 } | |
168 | |
167 if (sec >= 10) { | 169 if (sec >= 10) { |
168 out << ((sec % 60) / 10); | 170 out << ((sec % 60) / 10); |
169 } | 171 } |
170 | 172 |
171 out << (sec % 10); | 173 out << (sec % 10); |
172 | 174 |
173 int ms = msec(); | 175 int ms = msec(); |
174 | 176 |
175 if (ms != 0) { | 177 if (ms != 0) { |
189 } | 191 } |
190 } else if (fixedDp) { | 192 } else if (fixedDp) { |
191 out << ".000"; | 193 out << ".000"; |
192 } | 194 } |
193 | 195 |
194 #if (__GNUC__ < 3) | |
195 out << std::ends; | |
196 #endif | |
197 | |
198 std::string s = out.str(); | 196 std::string s = out.str(); |
199 | 197 |
200 return s; | 198 return s; |
201 } | 199 } |
202 | |
203 | 200 |
204 RealTime | 201 RealTime |
205 RealTime::operator/(int d) const | 202 RealTime::operator/(int d) const |
206 { | 203 { |
207 int secdiv = sec / d; | 204 int secdiv = sec / d; |