diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index eb5e9892a9..63a3fd6b87 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -469,11 +469,19 @@ MidiRegionView::enter_internal (uint32_t state) if (frame_handle_end) { frame_handle_end->lower_to_bottom(); } + + for (Events::iterator it = _events.begin(); it != _events.end(); ++it) { + it->second->set_hide_selection (false); + } } void MidiRegionView::leave_internal() { + for (Events::iterator it = _events.begin(); it != _events.end(); ++it) { + it->second->set_hide_selection (true); + } + hide_verbose_cursor (); remove_ghost_note (); _entered_note = 0; @@ -2440,8 +2448,12 @@ MidiRegionView::add_to_selection (NoteBase* ev) } if (selection_was_empty) { - PublicEditor& editor (trackview.editor()); - editor.get_selection().add (this); + + /* first note selected in this region, force Editor region + * selection to this region. + */ + + trackview.editor().set_selected_midi_region_view (*this); } } diff --git a/gtk2_ardour/note_base.cc b/gtk2_ardour/note_base.cc index 3e6bb402da..b525b8bac9 100644 --- a/gtk2_ardour/note_base.cc +++ b/gtk2_ardour/note_base.cc @@ -68,7 +68,7 @@ NoteBase::NoteBase(MidiRegionView& region, bool with_events, const boost::shared , _state(None) , _note(note) , _with_events (with_events) - , _selected(false) + , _flags (Flags (0)) , _valid (true) , _mouse_x_fraction (-1.0) , _mouse_y_fraction (-1.0) @@ -142,10 +142,10 @@ NoteBase::on_channel_selection_change(uint16_t selection) if ( (selection & (1 << _note->channel())) == 0 ) { const Gtkmm2ext::Color inactive_ch = UIConfiguration::instance().color ("midi note inactive channel"); set_fill_color(inactive_ch); - set_outline_color(calculate_outline(inactive_ch, _selected)); + set_outline_color(calculate_outline(inactive_ch, (_flags == Selected))); } else { // set the color according to the notes selection state - set_selected(_selected); + set_selected (_flags == Selected); } // this forces the item to update..... maybe slow... _item->hide(); @@ -166,12 +166,16 @@ NoteBase::set_selected(bool selected) return; } - _selected = selected; + if (selected) { + _flags = Flags (_flags | Selected); + } else { + _flags = Flags (_flags & ~Selected); + } const uint32_t base_col = base_color(); set_fill_color (base_col); - set_outline_color(calculate_outline(base_col, _selected)); + set_outline_color(calculate_outline(base_col, (_flags == Selected))); } #define SCALE_USHORT_TO_UINT8_T(x) ((x) / 257) @@ -364,3 +368,21 @@ NoteBase::meter_style_fill_color(uint8_t vel, bool /* selected */) return velocity_color_table[vel]; } +void +NoteBase::set_hide_selection (bool yn) +{ + if (yn) { + _flags = Flags (_flags | HideSelection); + } else { + _flags = Flags (_flags & ~HideSelection); + } + + if (_flags & Selected) { + /* maybe (?) change outline color */ + set_outline_color (calculate_outline (base_color(), !yn)); + } + + /* no need to redo color if it wasn't selected and we just changed + * "hide selected" since nothing will change + */ +} diff --git a/gtk2_ardour/note_base.h b/gtk2_ardour/note_base.h index 74521f7258..c1fa77d256 100644 --- a/gtk2_ardour/note_base.h +++ b/gtk2_ardour/note_base.h @@ -55,7 +55,13 @@ namespace ArdourCanvas { */ class NoteBase : public sigc::trackable { -public: + private: + enum Flags { + Selected = 0x1, + HideSelection = 0x2, + }; + + public: typedef Evoral::Note NoteType; NoteBase (MidiRegionView& region, bool, const boost::shared_ptr note = boost::shared_ptr()); @@ -71,8 +77,9 @@ public: void invalidate (); void validate (); - bool selected() const { return _selected; } + bool selected() const { return _flags & Selected; } void set_selected(bool yn); + void set_hide_selection (bool yn); virtual void move_event(double dx, double dy) = 0; @@ -108,8 +115,8 @@ public: static Gtkmm2ext::Color meter_style_fill_color(uint8_t vel, bool selected); /// calculate outline colors from fill colors of notes - inline static uint32_t calculate_outline(uint32_t color, bool selected=false) { - if (selected) { + inline static uint32_t calculate_outline(uint32_t color, bool showing_selection = false) { + if (showing_selection) { return _selected_col; } else { return UINT_INTERPOLATE(color, 0x000000ff, 0.5); @@ -132,7 +139,7 @@ protected: const boost::shared_ptr _note; bool _with_events; bool _own_note; - bool _selected; + Flags _flags; bool _valid; float _mouse_x_fraction; float _mouse_y_fraction;