From cc07cde14255f0467fdac0f61599858b2f9a3322 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 4 Jul 2022 17:09:30 +0200 Subject: [PATCH] Simplify 86e6df15cc using a dedicated method --- libs/ardour/ardour/region.h | 5 ++++- libs/ardour/audioregion.cc | 16 +++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index 0477c762bc..3b44a3e4f3 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -129,7 +129,7 @@ public: samplepos_t position_sample () const { return position().samples(); } samplecnt_t start_sample () const { return _start.val().samples(); } - samplecnt_t length_samples () const { return _length.val().samples(); } + samplecnt_t length_samples () const { return _length.val().samples(); } layer_t layer () const { return _layer; } @@ -456,6 +456,9 @@ protected: bool verify_start_and_length (timepos_t const &, timecnt_t&); void first_edit (); + /* This is always using AudioTime. convenient for evenlopes in AudioRegion */ + timepos_t len_as_tpos () const { return timepos_t((samplepos_t)_length.val().samples()); } + DataType _type; PBD::Property _sync_marked; diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index b7789b5db4..ca41eb57e9 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -278,7 +278,7 @@ AudioRegion::AudioRegion (boost::shared_ptr other) /* As far as I can see, the _envelope's times are relative to region position, and have nothing * to do with sources (and hence _start). So when we copy the envelope, we just use the supplied offset. */ - , _envelope (Properties::envelope, boost::shared_ptr (new AutomationList (*other->_envelope.val(), timepos_t (Temporal::AudioTime), timepos_t ((samplepos_t)other->length().samples())))) + , _envelope (Properties::envelope, boost::shared_ptr (new AutomationList (*other->_envelope.val(), timepos_t (Temporal::AudioTime), other->len_as_tpos ()))) , _automatable (other->session(), Temporal::AudioTime) , _fade_in_suspended (0) , _fade_out_suspended (0) @@ -300,7 +300,7 @@ AudioRegion::AudioRegion (boost::shared_ptr other, timecnt_t /* As far as I can see, the _envelope's times are relative to region position, and have nothing to do with sources (and hence _start). So when we copy the envelope, we just use the supplied offset. */ - , _envelope (Properties::envelope, boost::shared_ptr (new AutomationList (*other->_envelope.val(), timepos_t (offset.samples()), timepos_t ((samplepos_t)other->length().samples())))) + , _envelope (Properties::envelope, boost::shared_ptr (new AutomationList (*other->_envelope.val(), timepos_t (offset.samples()), other->len_as_tpos ()))) , _automatable (other->session(), Temporal::AudioTime) , _fade_in_suspended (0) , _fade_out_suspended (0) @@ -380,7 +380,7 @@ AudioRegion::post_set (const PropertyChange& /*ignored*/) } /* If _length changed, adjust our gain envelope accordingly */ - _envelope->truncate_end (timepos_t ((samplepos_t)length ().samples ())); + _envelope->truncate_end (len_as_tpos ()); } void @@ -815,7 +815,7 @@ AudioRegion::state () const if (_envelope->size() == 2 && _envelope->front()->value == GAIN_COEFF_UNITY && _envelope->back()->value==GAIN_COEFF_UNITY) { - if (_envelope->front()->when == 0 && _envelope->back()->when == timepos_t ((samplepos_t)length ().samples ())) { + if (_envelope->front()->when == 0 && _envelope->back()->when == len_as_tpos ()) { default_env = true; } } @@ -900,7 +900,7 @@ AudioRegion::_set_state (const XMLNode& node, int version, PropertyChange& what_ set_default_envelope (); } - _envelope->truncate_end (timepos_t ((samplepos_t)length ().samples ())); + _envelope->truncate_end (len_as_tpos ()); } else if (child->name() == "FadeIn") { @@ -1294,9 +1294,7 @@ AudioRegion::set_default_envelope () * XXX this needs some thought */ - timepos_t alen ((samplepos_t)length ().samples ()); - - _envelope->fast_simple_add (alen, GAIN_COEFF_UNITY); + _envelope->fast_simple_add (len_as_tpos (), GAIN_COEFF_UNITY); _envelope->thaw (); } @@ -1308,7 +1306,7 @@ AudioRegion::recompute_at_end () */ _envelope->freeze (); - _envelope->truncate_end (timepos_t ((samplepos_t)length ().samples ())); + _envelope->truncate_end (len_as_tpos ()); _envelope->thaw (); suspend_property_changes();