13
0

triggerbox: basic stretch test using assumption that slot holds s 4 bar region

This commit is contained in:
Paul Davis 2021-10-05 16:01:52 -06:00
parent bbbfadb832
commit 0199a4e561
2 changed files with 14 additions and 6 deletions

View File

@ -77,7 +77,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
virtual void set_start (timepos_t const &) = 0;
virtual void set_end (timepos_t const &) = 0;
/* this accepts timepos_t because the origin is assumed to be the start */
virtual void set_length (timepos_t const &) = 0;
virtual void set_length (timecnt_t const &) = 0;
virtual double position_as_fraction() const = 0;
@ -206,7 +206,7 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
void set_legato_offset (timepos_t const &);
timepos_t current_pos() const;
/* this accepts timepos_t because the origin is assumed to be the start */
void set_length (timepos_t const &);
void set_length (timecnt_t const &);
timepos_t start_offset () const { return timepos_t (_start_offset); } /* offset from start of data */
timepos_t end() const; /* offset from start of data */
timepos_t current_length() const; /* offset from start of data */

View File

@ -483,7 +483,7 @@ AudioTrigger::set_start (timepos_t const & s)
void
AudioTrigger::set_end (timepos_t const & e)
{
set_length (timepos_t (e.samples() - _start_offset));
set_length (timecnt_t (e.samples() - _start_offset, timepos_t (_start_offset)));
}
void
@ -505,7 +505,7 @@ AudioTrigger::end() const
}
void
AudioTrigger::set_length (timepos_t const & newlen)
AudioTrigger::set_length (timecnt_t const & newlen)
{
using namespace RubberBand;
using namespace Temporal;
@ -520,7 +520,7 @@ AudioTrigger::set_length (timepos_t const & newlen)
load_data (ar);
if (newlen == timepos_t (_region->length_samples())) {
if (newlen == _region->length()) {
/* no stretch required */
return;
}
@ -540,6 +540,7 @@ AudioTrigger::set_length (timepos_t const & newlen)
if (newlen.time_domain() == AudioTime) {
new_ratio = (double) newlen.samples() / data_length;
cerr << "gonna stretch, ratio is " << new_ratio << endl;
} else {
/* XXX what to use for position ??? */
timecnt_t l (newlen, timepos_t (AudioTime));
@ -547,6 +548,8 @@ AudioTrigger::set_length (timepos_t const & newlen)
new_ratio = (double) dur.samples() / data_length;
}
stretcher.setTimeRatio (new_ratio);
const samplecnt_t expected_length = ceil (data_length * new_ratio) + 16; /* extra space for safety */
@ -685,6 +688,8 @@ AudioTrigger::natural_length() const
int
AudioTrigger::set_region (boost::shared_ptr<Region> r)
{
using namespace Temporal;
boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (r);
if (!ar) {
@ -695,7 +700,10 @@ AudioTrigger::set_region (boost::shared_ptr<Region> r)
/* this will load data, but won't stretch it for now */
set_length (timepos_t::from_superclock (r->length ().magnitude()));
TempoMap::SharedPtr tm (TempoMap::use());
timecnt_t two_bars = tm->bbt_duration_at (timepos_t (AudioTime), BBT_Offset (4, 0, 0));
set_length (two_bars);
PropertyChanged (ARDOUR::Properties::name);