13
0

libtemporal: fix/improve/correct parsing of timecnt_t from string

This commit is contained in:
Paul Davis 2020-12-28 18:11:25 -07:00
parent d165c492af
commit 016aada4df

View File

@ -154,14 +154,17 @@ bool
timecnt_t::string_to (std::string const & str) timecnt_t::string_to (std::string const & str)
{ {
superclock_t s; superclock_t s;
samplecnt_t sm;
int64_t ticks;
Beats beats; Beats beats;
char sep; char sep;
if (isdigit (str[0])) { if (isdigit (str[0])) {
/* old school position format: we assume samples */ /* old school position format: we assume samples */
std::stringstream ss (str); std::stringstream ss (str);
ss >> s; ss >> sm;
_distance = s; _distance = int62_t (false, samples_to_superclock (sm, TEMPORAL_SAMPLE_RATE));
_position = timepos_t (AudioTime);
std::cerr << "deserialized timecnt from older " << str << " as " << *this << std::endl; std::cerr << "deserialized timecnt from older " << str << " as " << *this << std::endl;
return true; return true;
} }
@ -174,8 +177,8 @@ timecnt_t::string_to (std::string const & str)
_distance = int62_t (false, s); _distance = int62_t (false, s);
break; break;
case 'b': case 'b':
ss >> beats; ss >> ticks;
_distance = int62_t (true, beats.to_ticks()); _distance = int62_t (true, ticks);
break; break;
} }