temporal: fix construction of timepos_t and timecnt_t with max_sample{pos,cnt}
max_samplepos and max_samplecnt and both INT64_MAX which is (a) too large to fit into a signed 62 bit integer and (b) definitely too large to be represented in a signed 62 bit superclock value. Move the constructors that use samplepos_t into the .cc file, and treat these two values as special cases that mean "as large/late/huge/long as possible".
This commit is contained in:
@@ -52,7 +52,7 @@ class LIBTEMPORAL_API timepos_t : public int62_t {
|
||||
|
||||
/* for now (Sept2020) do not allow implicit type conversions */
|
||||
|
||||
explicit timepos_t (samplepos_t s) : int62_t (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE)) {}
|
||||
explicit timepos_t (samplepos_t s);
|
||||
explicit timepos_t (Temporal::Beats const & b) : int62_t (true, b.to_ticks()) {}
|
||||
|
||||
explicit timepos_t (timecnt_t const &); /* will throw() if val is negative */
|
||||
@@ -292,8 +292,8 @@ class LIBTEMPORAL_API timecnt_t {
|
||||
timecnt_t (timecnt_t const &other) : _distance (other.distance()), _position (other.position()) {}
|
||||
|
||||
/* construct from sample count (position doesn't matter due to linear nature * of audio time */
|
||||
explicit timecnt_t (samplepos_t s, timepos_t const & pos) : _distance (int62_t (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE))), _position (pos) {}
|
||||
explicit timecnt_t (samplepos_t s) : _distance (int62_t (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE))), _position (AudioTime) {}
|
||||
explicit timecnt_t (samplepos_t s, timepos_t const & pos);
|
||||
explicit timecnt_t (samplepos_t s);
|
||||
|
||||
/* construct from timeline types */
|
||||
explicit timecnt_t (timepos_t const & d) : _distance (d), _position (timepos_t::zero (d.flagged())) {}
|
||||
|
||||
@@ -82,6 +82,27 @@ timecnt_t::timecnt_t (timecnt_t const & tc, timepos_t const & pos)
|
||||
_distance = tc.distance();
|
||||
}
|
||||
|
||||
timecnt_t::timecnt_t (samplepos_t s, timepos_t const & pos)
|
||||
: _position (pos)
|
||||
{
|
||||
assert (_position.time_domain() == AudioTime);
|
||||
|
||||
if (s == max_samplepos) {
|
||||
_distance = int62_t (false, int62_t::max);
|
||||
} else {
|
||||
_distance = int62_t (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE));
|
||||
}
|
||||
}
|
||||
|
||||
timecnt_t::timecnt_t (samplepos_t s)
|
||||
: _position (AudioTime)
|
||||
{
|
||||
if (s == max_samplepos) {
|
||||
_distance = int62_t (false, int62_t::max);
|
||||
} else {
|
||||
_distance = int62_t (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE));
|
||||
}
|
||||
}
|
||||
|
||||
timepos_t
|
||||
timecnt_t::end (TimeDomain return_domain) const
|
||||
@@ -449,6 +470,15 @@ timepos_t::timepos_t (timecnt_t const & t)
|
||||
v = build (t.distance().flagged(), t.distance ().val());
|
||||
}
|
||||
|
||||
timepos_t::timepos_t (samplepos_t s)
|
||||
{
|
||||
if (s == max_samplepos) {
|
||||
v = build (false, int62_t::max);
|
||||
} else {
|
||||
v = build (false, samples_to_superclock (s, TEMPORAL_SAMPLE_RATE));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
timepos_t::set_time_domain (TimeDomain td)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user