Region::_start should be a timepos_t not a timecnt_t

It is an offset from an *implicit* origin (the source zero), not from an explicit origin,
and this fits with the concept underlying timepos_t. A timecnt_t requires an explicit origin,
which makes no sense in this context (just as it doesn't for the timeline as a whole).
This commit is contained in:
Paul Davis 2021-03-03 10:03:54 -07:00
parent 485b74e0b9
commit 56cde042cd
11 changed files with 64 additions and 65 deletions

View file

@ -247,7 +247,7 @@ class LIBARDOUR_API AudioRegion : public Region, public AudioReadable
protected:
/* default constructor for derived (compound) types */
AudioRegion (Session& s, timecnt_t const &, timecnt_t const &, std::string name);
AudioRegion (Session& s, timepos_t const &, timecnt_t const &, std::string name);
int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
};

View file

@ -102,7 +102,7 @@ class LIBARDOUR_API MidiSource : virtual public Source
virtual timecnt_t midi_read (const Lock& lock,
Evoral::EventSink<samplepos_t>& dst,
timepos_t const & source_start,
timecnt_t const & start,
timepos_t const & start,
timecnt_t const & cnt,
Temporal::Range* loop_range,
MidiCursor& cursor,
@ -209,7 +209,7 @@ class LIBARDOUR_API MidiSource : virtual public Source
virtual timecnt_t read_unlocked (const Lock& lock,
Evoral::EventSink<samplepos_t>& dst,
timepos_t const & position,
timecnt_t const & start,
timepos_t const & start,
timecnt_t const & cnt,
Temporal::Range* loop_range,
MidiStateTracker* tracker,

View file

@ -62,12 +62,12 @@ namespace Properties {
LIBARDOUR_API extern PBD::PropertyDescriptor<bool> hidden;
LIBARDOUR_API extern PBD::PropertyDescriptor<bool> position_locked;
LIBARDOUR_API extern PBD::PropertyDescriptor<bool> valid_transients;
LIBARDOUR_API extern PBD::PropertyDescriptor<timecnt_t> start;
LIBARDOUR_API extern PBD::PropertyDescriptor<timepos_t> start;
LIBARDOUR_API extern PBD::PropertyDescriptor<timecnt_t> length;
LIBARDOUR_API extern PBD::PropertyDescriptor<timepos_t> position;
LIBARDOUR_API extern PBD::PropertyDescriptor<timecnt_t> sync_position;
LIBARDOUR_API extern PBD::PropertyDescriptor<timepos_t> sync_position;
LIBARDOUR_API extern PBD::PropertyDescriptor<layer_t> layer;
LIBARDOUR_API extern PBD::PropertyDescriptor<timecnt_t> ancestral_start;
LIBARDOUR_API extern PBD::PropertyDescriptor<timepos_t> ancestral_start;
LIBARDOUR_API extern PBD::PropertyDescriptor<timecnt_t> ancestral_length;
LIBARDOUR_API extern PBD::PropertyDescriptor<float> stretch;
LIBARDOUR_API extern PBD::PropertyDescriptor<float> shift;
@ -119,7 +119,7 @@ public:
*/
timepos_t position () const { return _length.val().position(); }
timecnt_t start () const { return _start.val(); }
timepos_t start () const { return _start.val(); }
timecnt_t length () const { return _length.val(); }
timepos_t end() const;
timepos_t nt_last() const { return end().decrement(); }
@ -146,13 +146,13 @@ public:
samplecnt_t ancestral_start_sample () const { return _ancestral_start.val().samples(); }
samplecnt_t ancestral_length_samples () const { return _ancestral_length.val().samples(); }
timecnt_t ancestral_start () const { return _ancestral_start.val(); }
timepos_t ancestral_start () const { return _ancestral_start.val(); }
timecnt_t ancestral_length () const { return _ancestral_length.val(); }
float stretch () const { return _stretch; }
float shift () const { return _shift; }
void set_ancestral_data (timecnt_t const & start, timecnt_t const & length, float stretch, float shift);
void set_ancestral_data (timepos_t const & start, timecnt_t const & length, float stretch, float shift);
timecnt_t sync_offset (int& dir) const;
timepos_t sync_position () const;
@ -241,7 +241,7 @@ public:
/* EDITING OPERATIONS */
void set_length (timecnt_t const &);
void set_start (timecnt_t const &);
void set_start (timepos_t const &);
void set_position (timepos_t const &);
void set_initial_position (timepos_t const &);
void special_set_position (timepos_t const &);
@ -439,7 +439,7 @@ protected:
Region (boost::shared_ptr<const Region>, const SourceList&);
/** Constructor for derived types only */
Region (Session& s, timecnt_t const & start, timecnt_t const & length, const std::string& name, DataType);
Region (Session& s, timepos_t const & start, timecnt_t const & length, const std::string& name, DataType);
virtual bool can_trim_start_before_source_start () const {
return false;
@ -451,8 +451,8 @@ protected:
virtual int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
virtual void set_position_internal (timepos_t const & pos);
virtual void set_length_internal (timecnt_t const &);
virtual void set_start_internal (timecnt_t const &);
bool verify_start_and_length (timecnt_t const &, timecnt_t&);
virtual void set_start_internal (timepos_t const &);
bool verify_start_and_length (timepos_t const &, timecnt_t&);
void first_edit ();
DataType _type;
@ -461,10 +461,10 @@ protected:
PBD::Property<bool> _left_of_split;
PBD::Property<bool> _right_of_split;
PBD::Property<bool> _valid_transients;
PBD::Property<timecnt_t> _start;
PBD::Property<timepos_t> _start;
PBD::Property<timecnt_t> _length;
/** Sync position relative to the start of our file */
PBD::Property<timecnt_t> _sync_position;
PBD::Property<timepos_t> _sync_position;
SourceList _sources;
/** Used when timefx are applied, so we can always use the original source */
@ -496,7 +496,7 @@ private:
void maybe_uncopy ();
bool verify_start (timecnt_t const &);
bool verify_start (timepos_t const &);
bool verify_start_mutable (timecnt_t&);
bool verify_length (timecnt_t&);
@ -513,7 +513,7 @@ private:
PBD::Property<bool> _external;
PBD::Property<bool> _hidden;
PBD::Property<bool> _position_locked;
PBD::Property<timecnt_t> _ancestral_start;
PBD::Property<timepos_t> _ancestral_start;
PBD::Property<timecnt_t> _ancestral_length;
PBD::Property<float> _stretch;
PBD::Property<float> _shift;

View file

@ -83,7 +83,7 @@ public:
Temporal::Beats _last_ev_time_beats;
samplepos_t _last_ev_time_samples;
/** end time (start + duration) of last call to read_unlocked */
mutable timecnt_t _smf_last_read_end;
mutable timepos_t _smf_last_read_end;
/** time (in SMF ticks, 1 tick per _ppqn) of the last event read by read_unlocked */
mutable timepos_t _smf_last_read_time;
@ -94,7 +94,7 @@ public:
timecnt_t read_unlocked (const Lock& lock,
Evoral::EventSink<samplepos_t>& dst,
timepos_t const & position,
timecnt_t const & start,
timepos_t const & start,
timecnt_t const & cnt,
Temporal::Range* loop_range,
MidiStateTracker* tracker,

View file

@ -242,7 +242,7 @@ AudioRegion::init ()
}
/** Constructor for use by derived types only */
AudioRegion::AudioRegion (Session& s, timecnt_t const & start, timecnt_t const & len, std::string name)
AudioRegion::AudioRegion (Session& s, timepos_t const & start, timecnt_t const & len, std::string name)
: Region (s, start, len, name, DataType::AUDIO)
, AUDIOREGION_STATE_DEFAULT
, _envelope (Properties::envelope, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter(EnvelopeAutomation), Temporal::AudioTime)))

View file

@ -1243,7 +1243,7 @@ LuaAPI::Rubberband::finalize ()
ar->set_fade_out (_region->fade_out ());
*(ar->envelope ()) = *(_region->envelope ());
ar->set_ancestral_data (timecnt_t (_read_start), timecnt_t (_read_len), _stretch_ratio, _pitch_ratio);
ar->set_ancestral_data (timepos_t (_read_start), timecnt_t (_read_len), _stretch_ratio, _pitch_ratio);
ar->set_master_sources (_region->master_sources ());
ar->set_length (ar->length () * _stretch_ratio); // XXX
if (_stretch_ratio != 1.0) {

View file

@ -490,7 +490,7 @@ MidiRegion::model_shifted (timecnt_t distance)
if (!_ignore_shift) {
PropertyChange what_changed;
_start += distance;
_start.call().operator+= (distance);
what_changed.add (Properties::start);
what_changed.add (Properties::contents);
send_change (what_changed);
@ -532,9 +532,9 @@ MidiRegion::fix_negative_start ()
{
_ignore_shift = true;
model()->insert_silence_at_start (-_start.val().beats());
model()->insert_silence_at_start (-start().beats());
_start = timecnt_t::zero (_start.val().time_domain());
_start = timepos_t::zero (start().time_domain());
}
bool

View file

@ -176,7 +176,7 @@ timecnt_t
MidiSource::midi_read (const Lock& lm,
Evoral::EventSink<samplepos_t>& dst,
timepos_t const & source_start,
timecnt_t const & start,
timepos_t const & start,
timecnt_t const & cnt,
Temporal::Range* loop_range,
MidiCursor& cursor,
@ -189,7 +189,7 @@ MidiSource::midi_read (const Lock& lm,
source_start, start, cnt, tracker, name()));
if (!_model) {
return timecnt_t (read_unlocked (lm, dst, source_start, start, cnt, loop_range, tracker, filter), start.position());
return timecnt_t (read_unlocked (lm, dst, source_start, start, cnt, loop_range, tracker, filter), start);
}
// Find appropriate model iterator

View file

@ -352,7 +352,7 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress* progress)
/* now reset ancestral data for each new region */
for (vector<boost::shared_ptr<Region> >::iterator x = results.begin (); x != results.end (); ++x) {
(*x)->set_ancestral_data (timecnt_t (read_start),
(*x)->set_ancestral_data (timepos_t (read_start),
timecnt_t (read_duration, timepos_t (read_start)),
stretch,
shift);

View file

@ -69,13 +69,13 @@ namespace ARDOUR {
PBD::PropertyDescriptor<bool> hidden;
PBD::PropertyDescriptor<bool> position_locked;
PBD::PropertyDescriptor<bool> valid_transients;
PBD::PropertyDescriptor<timecnt_t> start;
PBD::PropertyDescriptor<timepos_t> start;
PBD::PropertyDescriptor<timecnt_t> length;
PBD::PropertyDescriptor<double> beat;
PBD::PropertyDescriptor<timecnt_t> sync_position;
PBD::PropertyDescriptor<timepos_t> sync_position;
PBD::PropertyDescriptor<timepos_t> position;
PBD::PropertyDescriptor<layer_t> layer;
PBD::PropertyDescriptor<timecnt_t> ancestral_start;
PBD::PropertyDescriptor<timepos_t> ancestral_start;
PBD::PropertyDescriptor<timecnt_t> ancestral_length;
PBD::PropertyDescriptor<float> stretch;
PBD::PropertyDescriptor<float> shift;
@ -183,9 +183,9 @@ Region::register_properties ()
, _left_of_split (Properties::left_of_split, false) \
, _right_of_split (Properties::right_of_split, false) \
, _valid_transients (Properties::valid_transients, false) \
, _start (Properties::start, timecnt_t (s, _type == DataType::MIDI ? timepos_t (Temporal::Beats()) : timepos_t::from_superclock (0))) \
, _length (Properties::length, timecnt_t (l, timepos_t (s))) \
, _sync_position (Properties::sync_position, timecnt_t (s, _type == DataType::MIDI ? timepos_t (Temporal::Beats()) : timepos_t::from_superclock (0))) \
, _start (Properties::start, (s)) \
, _length (Properties::length, (l)) \
, _sync_position (Properties::sync_position, (s)) \
, _transient_user_start (0) \
, _transient_analysis_start (0) \
, _transient_analysis_end (0) \
@ -200,7 +200,7 @@ Region::register_properties ()
, _external (Properties::external, false) \
, _hidden (Properties::hidden, false) \
, _position_locked (Properties::position_locked, false) \
, _ancestral_start (Properties::ancestral_start, timecnt_t (s, _type == DataType::MIDI ? timepos_t (Temporal::Beats()) : timepos_t::from_superclock (0))) \
, _ancestral_start (Properties::ancestral_start, (s)) \
, _ancestral_length (Properties::ancestral_length, (l)) \
, _stretch (Properties::stretch, 1.0) \
, _shift (Properties::shift, 1.0) \
@ -241,10 +241,10 @@ Region::register_properties ()
, _contents (Properties::contents, other->_contents)
/* derived-from-derived constructor (no sources in constructor) */
Region::Region (Session& s, timecnt_t const & start, timecnt_t const & length, const string& name, DataType type)
Region::Region (Session& s, timepos_t const & start, timecnt_t const & length, const string& name, DataType type)
: SessionObject(s, name)
, _type(type)
, REGION_DEFAULT_STATE(start,length)
, _type (type)
, REGION_DEFAULT_STATE (start,length)
, _last_length (length)
, _first_edit (EditChangesNothing)
, _layer (0)
@ -259,7 +259,7 @@ Region::Region (Session& s, timecnt_t const & start, timecnt_t const & length, c
Region::Region (const SourceList& srcs)
: SessionObject(srcs.front()->session(), "toBeRenamed")
, _type (srcs.front()->type())
, REGION_DEFAULT_STATE(_type == DataType::MIDI ? timecnt_t (Temporal::Beats()) : timecnt_t::from_superclock (0),
, REGION_DEFAULT_STATE(_type == DataType::MIDI ? timepos_t (Temporal::Beats()) : timepos_t::from_superclock (0),
_type == DataType::MIDI ? timecnt_t (Temporal::Beats()) : timecnt_t::from_superclock (0))
, _last_length (_type == DataType::MIDI ? timecnt_t (Temporal::Beats()) : timecnt_t::from_superclock (0))
, _first_edit (EditChangesNothing)
@ -316,7 +316,7 @@ Region::Region (boost::shared_ptr<const Region> other)
if (other->sync_marked()) {
if (other->_start < other->_sync_position) {
/* sync pos was after the start point of the other region */
_sync_position = other->_sync_position - other->_start;
_sync_position = timepos_t (other->start().distance (other->_sync_position));
} else {
/* sync pos was before the start point of the other region. not possible here. */
_sync_marked = false;
@ -670,8 +670,6 @@ Region::set_position_internal (timepos_t const & pos)
_last_length.set_position (position());
if (position() != pos) {
#warning NUTEMPO is this correct? why would set position set the position of the start (duration)?
_start.call().set_position (pos);
_length.call().set_position (pos);
/* check that the new _position wouldn't make the current
@ -759,7 +757,7 @@ Region::nudge_position (timecnt_t const & n)
}
void
Region::set_ancestral_data (timecnt_t const & s, timecnt_t const & l, float st, float sh)
Region::set_ancestral_data (timepos_t const & s, timecnt_t const & l, float st, float sh)
{
_ancestral_length = l;
_ancestral_start = s;
@ -768,7 +766,7 @@ Region::set_ancestral_data (timecnt_t const & s, timecnt_t const & l, float st,
}
void
Region::set_start (timecnt_t const & pos)
Region::set_start (timepos_t const & pos)
{
if (locked() || position_locked() || video_locked()) {
return;
@ -780,7 +778,7 @@ Region::set_start (timecnt_t const & pos)
if (_start != pos) {
timecnt_t p = pos;
timepos_t p = pos;
if (!verify_start (p)) {
return;
@ -802,14 +800,15 @@ Region::move_start (timecnt_t const & distance)
return;
}
timecnt_t new_start (_start);
timepos_t new_start (_start);
timepos_t current_start (_start);
if (distance.positive()) {
if (_start > timecnt_t::max() - distance) {
new_start = timecnt_t::max(); // makes no sense
if (current_start > timepos_t::max (current_start.time_domain()).earlier (distance)) {
new_start = timecnt_t::max(current_start.time_domain()); // makes no sense
} else {
new_start = start() + distance;
new_start = current_start + distance;
}
if (!verify_start (new_start)) {
@ -818,10 +817,10 @@ Region::move_start (timecnt_t const & distance)
} else {
if (_start < -distance) {
new_start = timecnt_t (_start.val().time_domain());
if (current_start < -distance) {
new_start = timecnt_t (current_start.time_domain());
} else {
new_start = start() + distance;
new_start = current_start + distance;
}
}
@ -946,7 +945,7 @@ Region::trim_to (timepos_t const & position, timecnt_t const & length)
void
Region::trim_to_internal (timepos_t const & pos, timecnt_t const & len)
{
timecnt_t new_start (len.time_domain());
timepos_t new_start (len.time_domain());
if (locked()) {
return;
@ -957,7 +956,7 @@ Region::trim_to_internal (timepos_t const & pos, timecnt_t const & len)
if (start_shift.positive()) {
if (start() > timecnt_t::max() - start_shift) {
new_start = timecnt_t::max();
new_start = timepos_t::max (start().time_domain());
} else {
new_start = start() + start_shift;
}
@ -974,7 +973,7 @@ Region::trim_to_internal (timepos_t const & pos, timecnt_t const & len)
new_start = start();
}
timecnt_t ns = new_start;
timepos_t ns = new_start;
timecnt_t nl = len;
if (!verify_start_and_length (ns, nl)) {
@ -1103,7 +1102,7 @@ void
Region::set_sync_position (timepos_t const & absolute_pos)
{
/* position within our file */
const timecnt_t file_pos = start() + position().distance (absolute_pos);
const timepos_t file_pos = start() + position().distance (absolute_pos);
if (file_pos != _sync_position) {
_sync_marked = true;
@ -1129,21 +1128,21 @@ Region::clear_sync_position ()
}
}
/* @return the sync point relative the first sample of the region */
/* @return the sync point relative the position of the region */
timecnt_t
Region::sync_offset (int& dir) const
{
if (sync_marked()) {
if (_sync_position > _start) {
dir = 1;
return _sync_position - _start;
return start().distance (_sync_position);
} else {
dir = -1;
return _start - _sync_position;
return sync_position().distance (start());
}
} else {
dir = 0;
return timecnt_t ();
return timecnt_t::zero (start().time_domain());
}
}
@ -1681,7 +1680,7 @@ Region::verify_length (timecnt_t& len)
}
bool
Region::verify_start_and_length (timecnt_t const & new_start, timecnt_t& new_length)
Region::verify_start_and_length (timepos_t const & new_start, timecnt_t& new_length)
{
if (source() && source()->length_mutable()) {
return true;
@ -1699,7 +1698,7 @@ Region::verify_start_and_length (timecnt_t const & new_start, timecnt_t& new_len
}
bool
Region::verify_start (timecnt_t const & pos)
Region::verify_start (timepos_t const & pos)
{
if (source() && source()->length_mutable()) {
return true;
@ -1949,7 +1948,7 @@ Region::is_compound () const
}
void
Region::set_start_internal (timecnt_t const & s)
Region::set_start_internal (timepos_t const & s)
{
_start = s;
}

View file

@ -216,7 +216,7 @@ timecnt_t
SMFSource::read_unlocked (const Lock& lock,
Evoral::EventSink<samplepos_t>& destination,
timepos_t const & source_start,
timecnt_t const & start,
timepos_t const & start,
timecnt_t const & duration,
Temporal::Range* loop_range,
MidiStateTracker* tracker,
@ -244,7 +244,7 @@ SMFSource::read_unlocked (const Lock& lock,
DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("SMF read_unlocked: start in ticks %1\n", start_ticks));
if (_smf_last_read_end == 0 || start != _smf_last_read_end) {
if (_smf_last_read_end.zero() || start != _smf_last_read_end) {
DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("SMF read_unlocked: seek to %1\n", start));
Evoral::SMF::seek_to_start();
while (time < start_ticks) {