diff options
author | nick_m <mainsbridge@gmail.com> | 2017-01-27 00:41:17 +1100 |
---|---|---|
committer | nick_m <mainsbridge@gmail.com> | 2017-02-04 22:57:36 +1100 |
commit | 59daffea1d78cb55b35fe19c135cc4ab472bd01d (patch) | |
tree | 45e514f2e4f5a1935e360fd4fa3e2475ec217006 /libs/ardour/midi_region.cc | |
parent | a21a414615505269bf770ad2358482e698e841af (diff) |
rework snap
snap now fills in a struct (MusicFrame) which contins a snapped frame
along with a music divisor.
this gives useful information wrt magnetic snap which may or may not
have rounded to an exact musical position.
region position may now be set musically (using quarter notes for now).
this patch fixes several problems in the current code:
- dragging a list of music-locked regions now maintains correct
musical offsets within the list.
- splitting regions using magnetic snap works correctly (#7192)
- cut drag should now work correctly with magnetic snap.
- musical length of split midi regions is no longer frame based.
Diffstat (limited to 'libs/ardour/midi_region.cc')
-rw-r--r-- | libs/ardour/midi_region.cc | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index 7511aadce8..3c885a8d99 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -102,20 +102,20 @@ MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other) } /** Create a new MidiRegion that is part of an existing one */ -MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, frameoffset_t offset, const int32_t sub_num) - : Region (other, offset, sub_num) +MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, MusicFrame offset) + : Region (other, offset) , _start_beats (Properties::start_beats, other->_start_beats) , _length_beats (Properties::length_beats, other->_length_beats) { - if (offset != 0) { - _start_beats = (_session.tempo_map().exact_qn_at_frame (other->_position + offset, sub_num) - other->_quarter_note) + other->_start_beats; - update_length_beats (sub_num); - /* we've potentially shifted _start_beats, now reset _start frames to match */ - _start = _session.tempo_map().frames_between_quarter_notes (_quarter_note - _start_beats, _quarter_note); - } register_properties (); + const double offset_quarter_note = _session.tempo_map().exact_qn_at_frame (other->_position + offset.frame, offset.division) - other->_quarter_note; + if (offset.frame != 0) { + _start_beats = other->_start_beats + offset_quarter_note; + _length_beats = other->_length_beats - offset_quarter_note; + } + assert(_name.val().find("/") == string::npos); midi_source(0)->ModelChanged.connect_same_thread (_source_connection, boost::bind (&MidiRegion::model_changed, this)); model_changed (); @@ -345,6 +345,24 @@ MidiRegion::set_position_internal (framepos_t pos, bool allow_bbt_recompute, con } } +void +MidiRegion::set_position_music_internal (double qn) +{ + Region::set_position_music_internal (qn); + /* set _start to new position in tempo map */ + _start = _session.tempo_map().frames_between_quarter_notes (quarter_note() - start_beats(), quarter_note()); + + if (position_lock_style() == AudioTime) { + _length_beats = _session.tempo_map().quarter_note_at_frame (_position + _length) - quarter_note(); + + } else { + /* 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). + */ + _length = _session.tempo_map().frames_between_quarter_notes (quarter_note(), quarter_note() + length_beats()); + } +} + framecnt_t MidiRegion::read_at (Evoral::EventSink<framepos_t>& out, framepos_t position, |