From af4ba1cc01f3517846f933396e88c00b09f4f436 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 21 Mar 2021 21:12:04 -0600 Subject: [PATCH] fix start, length/position for recorded MIDI regions Note that we should really set the position value as part of the length, but then Playlist::add_region() would need to drop its second argument (position). Maybe in a future commit --- libs/ardour/track.cc | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/libs/ardour/track.cc b/libs/ardour/track.cc index 027391f1b3..5b749f3b99 100644 --- a/libs/ardour/track.cc +++ b/libs/ardour/track.cc @@ -983,9 +983,25 @@ Track::use_captured_midi_sources (SourceList& srcs, CaptureInfos const & capture /* start of this region is the offset between the start of its capture and the start of the whole pass */ samplecnt_t start_off = (*ci)->start - initial_capture + (*ci)->loop_offset; -#warning NUTEMPO thinkme MIDI region with start & length in samples - plist.add (Properties::start, timecnt_t (start_off, timepos_t::zero (false))); - plist.add (Properties::length, timecnt_t ((*ci)->samples, timepos_t::zero (false))); + timepos_t s; + timecnt_t l; + + if (time_domain() == Temporal::BeatTime) { + + const timepos_t ss (start_off); + const timecnt_t ll ((*ci)->samples, ss); + + s = timepos_t (ss.beats()); + l = timecnt_t (ll.beats(), s); + + } else { + + s = timepos_t (start_off); + l = timecnt_t ((*ci)->samples, s); + } + + plist.add (Properties::start, s); + plist.add (Properties::length, l); plist.add (Properties::name, region_name); boost::shared_ptr rx (RegionFactory::create (srcs, plist)); @@ -996,15 +1012,16 @@ Track::use_captured_midi_sources (SourceList& srcs, CaptureInfos const & capture } catch (failed_constructor& err) { - error << _("MidiDiskstream: could not create region for captured midi!") << endmsg; + error << string_compose (_("%1: could not create region for captured data!"), name()) << endmsg; continue; /* XXX is this OK? */ } -#ifndef NDEBUG - cerr << "add new region, len = " << (*ci)->samples << " @ " << (*ci)->start << endl; -#endif - - pl->add_region (midi_region, timepos_t ((*ci)->start + preroll_off), 1, _session.config.get_layered_record_mode ()); + if (time_domain() == Temporal::BeatTime) { + const timepos_t b ((*ci)->start + preroll_off); + pl->add_region (midi_region, timepos_t (b.beats()), 1, _session.config.get_layered_record_mode ()); + } else { + pl->add_region (midi_region, timepos_t ((*ci)->start + preroll_off), 1, _session.config.get_layered_record_mode ()); + } } pl->thaw ();