diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index fd2278172a..075a7396a4 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -749,3 +749,37 @@ MidiRegionView::drag_group () const { return get_canvas_group (); } + +void +MidiRegionView::select_self (bool add) +{ + if (add) { + _editing_context.get_selection().add (this); + } else { + _editing_context.get_selection().set (this); + } +} + +void +MidiRegionView::unselect_self () +{ + _editing_context.get_selection().remove (this); +} + +void +MidiRegionView::begin_drag_edit (std::string const & why) +{ + if (!_selected) { + /* unclear why gcc can't understand which version of + select_self() to use here, but so be it. + */ + MidiView::select_self (); + } + // start_note_diff_command (why); +} + +void +MidiRegionView::select_self_uniquely () +{ + _editing_context.set_selected_midi_region_view (*this); +} diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index e0960dec71..0cb09831a6 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -126,6 +126,10 @@ public: void redisplay (bool); ArdourCanvas::Item* drag_group() const; + void select_self (bool add); + void unselect_self (); + void select_self_uniquely (); + void begin_drag_edit (std::string const & why); protected: void reset_width_dependent_items (double pixel_width); diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index c86c488ab5..b1909d2d50 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -113,9 +113,9 @@ MidiView::MidiView (std::shared_ptr mt, : _midi_track (mt) , _editing_context (ec) , _midi_context (bg) - , _active_notes(0) + , _active_notes (0) , _note_group (new ArdourCanvas::Container (&parent)) - , _note_diff_command (0) + , _note_diff_command (nullptr) , _ghost_note(0) , _step_edit_cursor (0) , _step_edit_cursor_width (1, 0) @@ -123,7 +123,7 @@ MidiView::MidiView (std::shared_ptr mt, , _mouse_state(None) , _pressed_button(0) , _optimization_iterator (_events.end()) - , _list_editor (0) + , _list_editor (nullptr) , _no_sound_notes (false) , _last_display_zoom (0) , _last_event_x (0) @@ -2066,7 +2066,7 @@ void MidiView::clear_note_selection () { clear_selection_internal (); - // XXXX _editing_context.get_selection().remove (this); + unselect_self (); } void @@ -2403,7 +2403,7 @@ MidiView::remove_from_selection (NoteBase* ev) ghost_sync_selection (ev); if (_selection.empty()) { - // XXXX _editing_context.get_selection().remove (this); + unselect_self (); } } @@ -2428,7 +2428,7 @@ MidiView::add_to_selection (NoteBase* ev) * only apply to notes anyway, not regions. */ - // XXX _editing_context.set_selected_midi_region_view (*this); + select_self_uniquely (); } if (_selection.insert (ev).second == true) { @@ -3173,8 +3173,6 @@ MidiView::change_note_length (NoteBase* event, Temporal::Beats t) void MidiView::begin_drag_edit (std::string const & why) { - // XXXX _editing_context.get_selection().set (this, true); - start_note_diff_command (why); } void @@ -4079,7 +4077,7 @@ MidiView::maybe_select_by_position (GdkEventButton* ev, double /*x*/, double y) } if (add_mrv_selection) { - // XXXXX _editing_context.get_selection().add (this); + select_self (true); } } diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index 842711bc7e..61f3895508 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -173,7 +173,7 @@ class MidiView : public virtual sigc::trackable void end_write(); void extend_active_notes(); - void begin_drag_edit (std::string const & why); + virtual void begin_drag_edit (std::string const & why); void end_drag_edit (); void display_model(std::shared_ptr model); @@ -332,6 +332,11 @@ class MidiView : public virtual sigc::trackable EditingContext& editing_context() const { return _editing_context; } MidiViewBackground& midi_context() const { return _midi_context; } + virtual void select_self (bool add) {} + virtual void unselect_self () {} + void select_self () { select_self (false); } + virtual void select_self_uniquely () {} + protected: void init (); virtual void region_resized (const PBD::PropertyChange&); diff --git a/gtk2_ardour/selection.cc b/gtk2_ardour/selection.cc index cd75dd1289..5febec0274 100644 --- a/gtk2_ardour/selection.cc +++ b/gtk2_ardour/selection.cc @@ -1622,8 +1622,8 @@ Selection::midi_regions () { MidiRegionSelection ms; - for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) { - MidiRegionView* mrv = dynamic_cast(*i); + for (auto & r : regions) { + MidiRegionView* mrv = dynamic_cast(r); if (mrv) { ms.add (mrv); }