temporal: adjust cut buffer API to better deal with start/end "guard points"

This commit is contained in:
Paul Davis 2023-06-05 17:27:12 -06:00
parent 7789df5b1c
commit f5f87f86d4
2 changed files with 95 additions and 10 deletions

View File

@ -871,7 +871,7 @@ TempoMap::cut_copy (timepos_t const & start, timepos_t const & end, bool copy, b
TempoMetric em (metric_at (end));
timecnt_t dur = start.distance (end);
TempoMapCutBuffer* cb = new TempoMapCutBuffer (dur, sm, em);
TempoMapCutBuffer* cb = new TempoMapCutBuffer (dur);
superclock_t start_sclock = start.superclocks();
superclock_t end_sclock = end.superclocks();
@ -922,6 +922,22 @@ TempoMap::cut_copy (timepos_t const & start, timepos_t const & end, bool copy, b
}
if (cb->tempos().empty() || cb->tempos().front().sclock() != start.superclocks()) {
cb->add_start_tempo (tempo_at (start));
}
if (!cb->tempos().empty() && cb->tempos().back().sclock() != start.superclocks()) {
cb->add_end_tempo (tempo_at (start));
}
if (cb->meters().empty() || cb->meters().front().sclock() != start.superclocks()) {
cb->add_start_meter (meter_at (start));
}
if (!cb->meters().empty() && cb->meters().back().sclock() != start.superclocks()) {
cb->add_end_meter (meter_at (start));
}
return cb;
}
@ -4670,21 +4686,79 @@ DomainSwapInformation::undo ()
clear ();
}
TempoMapCutBuffer::TempoMapCutBuffer (timecnt_t const & dur, TempoMetric const & start, TempoMetric const & end)
: _start_metric (start)
, _end_metric (end)
TempoMapCutBuffer::TempoMapCutBuffer (timecnt_t const & dur)
: _start_tempo (nullptr)
, _end_tempo (nullptr)
, _start_meter (nullptr)
, _end_meter (nullptr)
, _duration (dur)
{
}
TempoMapCutBuffer::~TempoMapCutBuffer ()
{
delete _start_tempo;
delete _end_tempo;
delete _start_meter;
delete _end_meter;
}
void
TempoMapCutBuffer::add_start_tempo (Tempo const & t)
{
delete _start_tempo;
_start_tempo = new Tempo (t);
}
void
TempoMapCutBuffer::add_end_tempo (Tempo const & t)
{
delete _end_tempo;
_end_tempo = new Tempo (t);
}
void
TempoMapCutBuffer::add_start_meter (Meter const & t)
{
delete _start_meter;
_start_meter = new Meter (t);
}
void
TempoMapCutBuffer::add_end_meter (Meter const & t)
{
delete _end_meter;
_end_meter = new Meter (t);
}
void
TempoMapCutBuffer::dump (std::ostream& ostr)
{
ostr << "TempoMapCutBuffer @ " << this << std::endl;
if (_start_tempo) {
ostr << "Start Tempo: " << *_start_tempo << std::endl;
}
if (_end_tempo) {
ostr << "End Tempo: " << *_end_tempo << std::endl;
}
if (_start_meter) {
ostr << "Start Meter: " << *_start_meter << std::endl;
}
if (_end_meter) {
ostr << "End Meter: " << *_end_meter << std::endl;
}
ostr << "Tempos:\n";
for (auto const & t : _tempos) {
ostr << '\t' << &t << t << std::endl;
ostr << '\t' << &t << ' ' << t << std::endl;
}
ostr << "Meters:\n";
for (auto const & m : _meters) {
ostr << '\t' << &m << ' ' << m << std::endl;
}
}

View File

@ -1156,12 +1156,21 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
class LIBTEMPORAL_API TempoMapCutBuffer
{
public:
TempoMapCutBuffer (timecnt_t const &, TempoMetric const &, TempoMetric const &);
TempoMapCutBuffer (timecnt_t const &);
~TempoMapCutBuffer ();
timecnt_t duration() const { return _duration; }
TempoMetric const & metric_at_start () const { return _start_metric; }
TempoMetric const & metric_at_end () const { return _end_metric; }
void add_start_tempo (Tempo const & t);
void add_end_tempo (Tempo const & t);
void add_start_meter (Meter const & t);
void add_end_meter (Meter const & t);
Tempo const * tempo_at_start () const { return _start_tempo; }
Tempo const * tempo_at_end () const { return _end_tempo; }
Meter const * meter_at_start () const { return _start_meter; }
Meter const * meter_at_end () const { return _end_meter; }
typedef boost::intrusive::list<TempoPoint, boost::intrusive::base_hook<tempo_hook>> Tempos;
typedef boost::intrusive::list<MeterPoint, boost::intrusive::base_hook<meter_hook>> Meters;
@ -1182,8 +1191,10 @@ class LIBTEMPORAL_API TempoMapCutBuffer
Points const & points() const { return _points; }
private:
TempoMetric _start_metric;
TempoMetric _end_metric;
Tempo* _start_tempo;
Tempo* _end_tempo;
Meter* _start_meter;
Meter* _end_meter;
timecnt_t _duration;
Tempos _tempos;