13
0

start tracking note overlaps while moving notes

git-svn-id: svn://localhost/ardour2/branches/3.0@7228 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-06-03 21:27:36 +00:00
parent 1abbb506b8
commit db1fa42f14
3 changed files with 40 additions and 12 deletions

View File

@ -3746,13 +3746,35 @@ NoteDrag::motion (GdkEvent*, bool)
}
if (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);
CanvasNoteEvent* cnote = dynamic_cast<CanvasNoteEvent*>(_item);
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);
}
}

View File

@ -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> >);

View File

@ -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();