From b3a127d31864ded7c629f96b4f1928765ba8f36f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 May 2023 17:09:19 -0600 Subject: [PATCH] temporal: TempoMap::paste(), TempoMapCutBuffer::dump() and cut/copy fixes --- libs/temporal/tempo.cc | 74 +++++++++++++++++++++++++++++++--- libs/temporal/temporal/tempo.h | 3 +- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 1ad6547f7c..0f4f59e324 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -876,7 +876,7 @@ TempoMap::cut_copy (timepos_t const & start, timepos_t const & end, bool copy) superclock_t start_sclock = start.superclocks(); superclock_t end_sclock = end.superclocks(); bool removed = false; - + for (auto const & p : _points) { /* XXX might to check time domain of start/end, and use beat @@ -922,8 +922,41 @@ TempoMap::cut_copy (timepos_t const & start, timepos_t const & end, bool copy) } void -TempoMap::paste (TempoMapCutBuffer& cb, timepos_t const & position) +TempoMap::paste (TempoMapCutBuffer const & cb, timepos_t const & position, bool ripple) { + if (ripple) { + + + } + + bool replaced_ignored; + + /* iterate over _points since they are already in sclock order, and we + * won't need to post-sort the way we would if we handled tempos, + * meters, bartimes separately. + */ + + for (auto const & p : cb.points()) { + TempoPoint const * tp; + MeterPoint const * mp; + MusicTimePoint const * mtp; + + if ((mtp = dynamic_cast (&p))) { + MusicTimePoint *ntp = new MusicTimePoint (*mtp); + ntp->set (ntp->sclock() + position.superclocks(), ntp->beats() + position.beats(), ntp->bbt()); + core_add_bartime (ntp, replaced_ignored); + } else { + if ((tp = dynamic_cast (&p))) { + TempoPoint *ntp = new TempoPoint (*tp); + ntp->set (ntp->sclock() + position.superclocks(), ntp->beats() + position.beats(), ntp->bbt()); + core_add_tempo (ntp, replaced_ignored); + } else if ((mp = dynamic_cast (&p))) { + MeterPoint *ntp = new MeterPoint (*mp); + ntp->set (ntp->sclock() + position.superclocks(), ntp->beats() + position.beats(), ntp->bbt()); + core_add_meter (ntp, replaced_ignored); + } + } + } } MeterPoint* @@ -2410,7 +2443,7 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u DEBUG_TRACE (DEBUG::Grid, "\tthat was that\n"); } - } + } /* reset the metric to use the most recent tempo & meter */ @@ -4601,12 +4634,29 @@ TempoMapCutBuffer::TempoMapCutBuffer (timecnt_t const & dur, TempoMetric const & { } +void +TempoMapCutBuffer::dump (std::ostream& ostr) +{ + ostr << "TempoMapCutBuffer @ " << this << std::endl; + ostr << "Tempos:\n"; + + for (auto const & t : _tempos) { + ostr << '\t' << &t << t << std::endl; + } +} + void TempoMapCutBuffer::add (TempoPoint const & tp) { TempoPoint* ntp = new TempoPoint (tp); - ntp->set (tp.sclock() - _duration.position().superclocks(), tp.beats(), tp.bbt()); + /* We must reset the audio and beat time position, but we can't do + * anything useful with the BBT time designation. + */ + + ntp->set (ntp->sclock() - _duration.position().superclocks(), + ntp->beats() - _duration.position().beats(), + ntp->bbt()); _tempos.push_back (*ntp); _points.push_back (*ntp); @@ -4617,7 +4667,13 @@ TempoMapCutBuffer::add (MeterPoint const & mp) { MeterPoint* ntp = new MeterPoint (mp); - ntp->set (mp.sclock() - _duration.position().superclocks(), mp.beats(), mp.bbt()); + /* We must reset the audio and beat time position, but we can't do + * anything useful with the BBT time designation. + */ + + ntp->set (ntp->sclock() - _duration.position().superclocks(), + ntp->beats() - _duration.position().beats(), + ntp->bbt()); _meters.push_back (*ntp); _points.push_back (*ntp); @@ -4628,7 +4684,13 @@ TempoMapCutBuffer::add (MusicTimePoint const & mtp) { MusicTimePoint* ntp = new MusicTimePoint (mtp); - ntp->set (mtp.sclock() - _duration.position().superclocks(), mtp.beats(), mtp.bbt()); + /* We must reset the audio and beat time position, but we can't do + * anything useful with the BBT time designation. + */ + + ntp->set (ntp->sclock() - _duration.position().superclocks(), + ntp->beats() - _duration.position().beats(), + ntp->bbt()); _bartimes.push_back (*ntp); _tempos.push_back (*ntp); diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 367f696567..49de625dc6 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -820,7 +820,7 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible LIBTEMPORAL_API TempoMapCutBuffer* cut (timepos_t const & start, timepos_t const & end); LIBTEMPORAL_API TempoMapCutBuffer* copy (timepos_t const & start, timepos_t const & end); - LIBTEMPORAL_API void paste (TempoMapCutBuffer&, timepos_t const & position); + LIBTEMPORAL_API void paste (TempoMapCutBuffer const &, timepos_t const & position, bool ripple); private: template TempoPoint const & _tempo_at (TimeType when, Comparator cmp) const { @@ -1173,6 +1173,7 @@ class LIBTEMPORAL_API TempoMapCutBuffer void add (Point const &); void clear (); + void dump (std::ostream&); Tempos const & tempos() const { return _tempos; } Meters const & meters() const { return _meters; }