From 589cc3162bb1bcae4d140f1314fc7b4138eaac98 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 13 Nov 2014 21:32:08 -0500 Subject: [PATCH] Fix crash when deleting overlapped regions. Use RegionSelection for MIDI regions as well, since the old dumb stub didn't do some things correctly. There's probably no reason to have a separate class for this at all, and some good ones for putting all regions in the same selection, so we should probably do that. For now they are still separate in the selection but use the same base class. --- gtk2_ardour/editor_drag.cc | 20 ++++++++++++++++---- gtk2_ardour/editor_ops.cc | 6 ++++-- gtk2_ardour/midi_selection.cc | 26 ++++++++------------------ gtk2_ardour/midi_selection.h | 11 ++++------- gtk2_ardour/region_view.cc | 4 +++- 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index aa37467f2c..1f400310ae 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -1967,7 +1967,10 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/) MidiRegionSelection::iterator next; next = r; ++next; - (*r)->begin_resizing (at_front); + MidiRegionView* mrv = dynamic_cast(*r); + if (mrv) { + mrv->begin_resizing (at_front); + } r = next; } } @@ -1979,7 +1982,10 @@ NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/) for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) { NoteBase* nb = reinterpret_cast (_item->get_data ("notebase")); assert (nb); - (*r)->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative); + MidiRegionView* mrv = dynamic_cast(*r); + if (mrv) { + mrv->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative); + } } } @@ -1990,7 +1996,10 @@ NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/) for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) { NoteBase* nb = reinterpret_cast (_item->get_data ("notebase")); assert (nb); - (*r)->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative); + MidiRegionView* mrv = dynamic_cast(*r); + if (mrv) { + mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative); + } } } @@ -1999,7 +2008,10 @@ NoteResizeDrag::aborted (bool) { MidiRegionSelection& ms (_editor->get_selection().midi_regions); for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) { - (*r)->abort_resizing (); + MidiRegionView* mrv = dynamic_cast(*r); + if (mrv) { + mrv->abort_resizing (); + } } } diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 1f23aa4319..6dbbb4073f 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -4000,8 +4000,10 @@ void Editor::cut_copy_midi (CutCopyOp op) { for (MidiRegionSelection::iterator i = selection->midi_regions.begin(); i != selection->midi_regions.end(); ++i) { - MidiRegionView* mrv = *i; - mrv->cut_copy_clear (op); + MidiRegionView* mrv = dynamic_cast(*i); + if (mrv) { + mrv->cut_copy_clear (op); + } } } diff --git a/gtk2_ardour/midi_selection.cc b/gtk2_ardour/midi_selection.cc index bf9b88899b..f98f696444 100644 --- a/gtk2_ardour/midi_selection.cc +++ b/gtk2_ardour/midi_selection.cc @@ -17,29 +17,19 @@ */ -#include "gtkmm2ext/gui_thread.h" -#include "midi_region_view.h" #include "midi_selection.h" -#include "region_view.h" MidiRegionSelection::MidiRegionSelection () -{ - RegionView::RegionViewGoingAway.connect (_death_connection, MISSING_INVALIDATOR, boost::bind (&MidiRegionSelection::remove_it, this, _1), gui_context()); -} + : RegionSelection () +{} -/** Copy constructor. - * @param other MidiRegionSelection to copy. - */ MidiRegionSelection::MidiRegionSelection (MidiRegionSelection const & other) - : std::list (other) -{ - RegionView::RegionViewGoingAway.connect (_death_connection, MISSING_INVALIDATOR, boost::bind (&MidiRegionSelection::remove_it, this, _1), gui_context()); -} + : RegionSelection (other) +{} - -void -MidiRegionSelection::remove_it (RegionView* rv) +MidiRegionSelection& +MidiRegionSelection::operator= (const MidiRegionSelection& other) { - MidiRegionView* mrv = dynamic_cast (rv); - remove (mrv); + RegionSelection::operator=(other); + return *this; } diff --git a/gtk2_ardour/midi_selection.h b/gtk2_ardour/midi_selection.h index f2c2d3fc60..2aa04356d7 100644 --- a/gtk2_ardour/midi_selection.h +++ b/gtk2_ardour/midi_selection.h @@ -20,22 +20,19 @@ #ifndef __ardour_gtk_midi_selection_h__ #define __ardour_gtk_midi_selection_h__ -#include -#include "pbd/signals.h" +#include "region_selection.h" class MidiRegionView; class MidiCutBuffer; class RegionView; -class MidiRegionSelection : public std::list +class MidiRegionSelection : public RegionSelection { public: MidiRegionSelection (); - MidiRegionSelection (MidiRegionSelection const &); + MidiRegionSelection (const MidiRegionSelection&); -private: - void remove_it (RegionView *); - PBD::ScopedConnection _death_connection; + MidiRegionSelection& operator= (const MidiRegionSelection&); }; struct MidiNoteSelection : std::list {}; diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index d4604b265d..fcdde48487 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -225,7 +225,9 @@ RegionView::~RegionView () bool RegionView::canvas_group_event (GdkEvent* event) { - return trackview.editor().canvas_region_view_event (event, group, this); + if (!in_destructor) { + return trackview.editor().canvas_region_view_event (event, group, this); + } } void