Fix midi region split, trim and move operations.
authornick_m <mainsbridge@gmail.com>
Mon, 6 Jun 2016 16:14:31 +0000 (02:14 +1000)
committernick_m <mainsbridge@gmail.com>
Mon, 6 Jun 2016 16:14:31 +0000 (02:14 +1000)
- there is still the problem of being unable to drag
  a trimmed region to the left when it's source
  (not it's position) would end up on a negative beat.

libs/ardour/midi_region.cc

index b1c332072eb58383110345b1cff6ff40c36b4e6a..05037d4af3032fda9345fdc8974a5648ae855cde 100644 (file)
@@ -107,11 +107,11 @@ MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, frameoffset_t
        , _start_beats (Properties::start_beats, Evoral::Beats())
        , _length_beats (Properties::length_beats, Evoral::Beats())
 {
-       BeatsFramesConverter bfc (_session.tempo_map(), _position);
+       BeatsFramesConverter bfc (_session.tempo_map(), other->_position);
        Evoral::Beats const offset_beats = bfc.from (offset);
 
-       _start_beats  = other->_start_beats.val() + offset_beats;
-       _length_beats = other->_length_beats.val() - offset_beats;
+       _start_beats = other->_start_beats.val() + offset_beats;
+       _length_beats = Evoral::Beats (_session.tempo_map().beat_at_frame (other->length() - offset));
 
        register_properties ();
 
@@ -224,6 +224,9 @@ MidiRegion::set_position_internal (framepos_t pos, bool allow_bbt_recompute)
 {
        Region::set_position_internal (pos, allow_bbt_recompute);
 
+       /* set _start to new position in tempo map */
+       _start = _position - _session.tempo_map().framepos_minus_beats (_position, _start_beats);
+
        /* leave _length_beats alone, and change _length to reflect the state of things
           at the new position (tempo map may dictate a different number of frames).
        */