From 472e8a0d7bda2c7d9f0d9254f221bd1fc2dfc31c Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Sun, 12 Jul 2020 11:18:11 -0500 Subject: [PATCH] When copying a Range of MIDI, special-case the midi start+end in beats. This will likely get cleaner after nutempo. --- libs/ardour/playlist.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 2d89e9f44d..d9953e7e49 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -42,6 +42,7 @@ #include "ardour/playlist_factory.h" #include "ardour/playlist_source.h" #include "ardour/region.h" +#include "ardour/midi_region.h" #include "ardour/region_factory.h" #include "ardour/region_sorters.h" #include "ardour/session.h" @@ -256,6 +257,21 @@ Playlist::Playlist (boost::shared_ptr other, samplepos_t start, PropertyList plist; + if (_type == DataType::MIDI) { + boost::shared_ptr mregion = boost::dynamic_pointer_cast (region); + if ( mregion && offset ) { + int32_t division = 1; /*magic value that ignores the meter (right?)*/ + const double start_quarter_note =_session.tempo_map().exact_qn_at_sample (start, division ); + const double start_offset_quarter_note = start_quarter_note - region->quarter_note(); + const double end_samples = (overlap == Evoral::OverlapStart ? + end : /*end the new region at the end of the selection*/ + region->position() + region->length() -1); /*use the region's end*/ + const double length_quarter_note = _session.tempo_map().exact_qn_at_sample ( end_samples, division ) - start_quarter_note; + plist.add (Properties::start_beats, mregion->start_beats() + start_offset_quarter_note); + plist.add (Properties::length_beats, length_quarter_note); + } + } + plist.add (Properties::start, region->start() + offset); plist.add (Properties::length, len); plist.add (Properties::name, new_name);