diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-06-03 21:27:36 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-06-03 21:27:36 +0000 |
commit | db1fa42f14c54d9a9714aafe35d669a81469f964 (patch) | |
tree | b90ae0e1ac3373306475ddc343d5f5cc1203d6a8 | |
parent | 1abbb506b84edc05d50b8d30ed27b9001885f768 (diff) |
start tracking note overlaps while moving notes
git-svn-id: svn://localhost/ardour2/branches/3.0@7228 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/editor_drag.cc | 30 | ||||
-rw-r--r-- | libs/evoral/evoral/Sequence.hpp | 6 | ||||
-rw-r--r-- | libs/evoral/src/Sequence.cpp | 16 |
3 files changed, 40 insertions, 12 deletions
diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 231946f661..7c8c192cdd 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3746,13 +3746,35 @@ NoteDrag::motion (GdkEvent*, bool) } if (dx || dy) { - region->move_selection (dx, dy); - + CanvasNoteEvent* cnote = dynamic_cast<CanvasNoteEvent*>(_item); + Evoral::MusicalTime new_time; + + if (drag_delta_x) { + nframes64_t start_frames = region->beats_to_frames(cnote->note()->time()); + if (drag_delta_x >= 0) { + start_frames += region->snap_frame_to_frame(_editor->pixel_to_frame(drag_delta_x)); + } else { + start_frames -= region->snap_frame_to_frame(_editor->pixel_to_frame(-drag_delta_x)); + } + new_time = region->frames_to_beats(start_frames); + } else { + new_time = cnote->note()->time(); + } + + boost::shared_ptr<Evoral::Note<Evoral::MusicalTime> > check_note ( + new Evoral::Note<Evoral::MusicalTime> (cnote->note()->channel(), + new_time, + cnote->note()->length(), + cnote->note()->note() + drag_delta_note, + cnote->note()->velocity())); + bool overlaps = cnote->region_view().midi_region()->model()->overlaps (check_note, cnote->note()); + + region->move_selection (dx, dy); char buf[12]; - snprintf (buf, sizeof (buf), "%s (%g)", Evoral::midi_note_name (cnote->note()->note()).c_str(), - (int) cnote->note()->note() + drag_delta_note); + snprintf (buf, sizeof (buf), "%s (%d)", Evoral::midi_note_name (cnote->note()->note()).c_str(), + (int) floor ((cnote->note()->note() + drag_delta_note))); _editor->show_verbose_canvas_cursor_with (buf); } } diff --git a/libs/evoral/evoral/Sequence.hpp b/libs/evoral/evoral/Sequence.hpp index ae9ab05104..9e1083b3fd 100644 --- a/libs/evoral/evoral/Sequence.hpp +++ b/libs/evoral/evoral/Sequence.hpp @@ -231,7 +231,8 @@ public: bool edited() const { return _edited; } void set_edited(bool yn) { _edited = yn; } - bool overlaps (const boost::shared_ptr< Note<Time> >& ev) const; + bool overlaps (const boost::shared_ptr< Note<Time> >& ev, + const boost::shared_ptr< Note<Time> >& ignore_this_note) const; bool contains (const boost::shared_ptr< Note<Time> >& ev) const; bool add_note_unlocked(const boost::shared_ptr< Note<Time> > note); @@ -254,7 +255,8 @@ private: inline Pitches& pitches(uint8_t chan) { return _pitches[chan&0xf]; } inline const Pitches& pitches(uint8_t chan) const { return _pitches[chan&0xf]; } - bool overlaps_unlocked (const boost::shared_ptr< Note<Time> >& ev) const; + bool overlaps_unlocked (const boost::shared_ptr< Note<Time> >& ev, + const boost::shared_ptr< Note<Time> >& ignore_this_note) const; bool contains_unlocked (const boost::shared_ptr< Note<Time> >& ev) const; void append_note_on_unlocked (boost::shared_ptr< Note<Time> >); diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp index 4b9fed035a..d11ec7c4fd 100644 --- a/libs/evoral/src/Sequence.cpp +++ b/libs/evoral/src/Sequence.cpp @@ -587,7 +587,7 @@ Sequence<Time>::add_note_unlocked(const boost::shared_ptr< Note<Time> > note) DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 add note %2 @ %3\n", this, (int)note->note(), note->time())); - if (!_overlapping_pitches_accepted && overlaps_unlocked (note)) { + if (!_overlapping_pitches_accepted && overlaps_unlocked (note, boost::shared_ptr<Note<Time> >())) { return false; } @@ -827,7 +827,7 @@ Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> > Sequence<Time>::contains_unlocked (const boost::shared_ptr< Note<Time> >& note) const { const Pitches& p (pitches (note->channel())); - boost::shared_ptr< Note<Time> > search_note(new Note<Time>(0, 0, 0, 0, note->note())); + boost::shared_ptr< Note<Time> > search_note(new Note<Time>(0, 0, 0, note->note())); for (typename Pitches::const_iterator i = p.lower_bound (search_note); i != p.end() && (*i)->note() == note->note(); ++i) { @@ -843,25 +843,29 @@ Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> > template<typename Time> bool - Sequence<Time>::overlaps (const boost::shared_ptr< Note<Time> >& note) const + Sequence<Time>::overlaps (const boost::shared_ptr< Note<Time> >& note, const boost::shared_ptr<Note<Time> >& without) const { ReadLock lock (read_lock()); - return overlaps_unlocked (note); + return overlaps_unlocked (note, without); } template<typename Time> bool - Sequence<Time>::overlaps_unlocked (const boost::shared_ptr< Note<Time> >& note) const + Sequence<Time>::overlaps_unlocked (const boost::shared_ptr< Note<Time> >& note, const boost::shared_ptr<Note<Time> >& without) const { Time sa = note->time(); Time ea = note->end_time(); const Pitches& p (pitches (note->channel())); - boost::shared_ptr< Note<Time> > search_note(new Note<Time>(0, 0, 0, 0, note->note())); + boost::shared_ptr< Note<Time> > search_note(new Note<Time>(0, 0, 0, note->note())); for (typename Pitches::const_iterator i = p.lower_bound (search_note); i != p.end() && (*i)->note() == note->note(); ++i) { + if (without && (**i) == *without) { + continue; + } + Time sb = (*i)->time(); Time eb = (*i)->end_time(); |