From 4217a6885281056e42b2c37dd194a0a1637ebf10 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Sun, 3 Sep 2023 14:17:53 -0500 Subject: [PATCH] Arranger: implement bi-directional selection --- gtk2_ardour/editor_sections.cc | 31 +++++++++++++++++++++++++++++-- gtk2_ardour/editor_sections.h | 7 ++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/editor_sections.cc b/gtk2_ardour/editor_sections.cc index c4dd52bbe9..501a3c22c7 100644 --- a/gtk2_ardour/editor_sections.cc +++ b/gtk2_ardour/editor_sections.cc @@ -86,7 +86,7 @@ EditorSections::EditorSections () ARDOUR_UI::instance ()->primary_clock->mode_changed.connect (sigc::mem_fun (*this, &EditorSections::clock_format_changed)); - _selection_change = PublicEditor::instance ().get_selection ().TimeChanged.connect (sigc::mem_fun (*this, &EditorSections::clear_selection)); + _selection_change = PublicEditor::instance ().get_selection ().TimeChanged.connect (sigc::mem_fun (*this, &EditorSections::update_time_selection)); } void @@ -116,6 +116,7 @@ EditorSections::redisplay () } _view.set_model (Glib::RefPtr ()); _model->clear (); + _location_row_map.clear (); if (_session == 0) { return; @@ -135,6 +136,8 @@ EditorSections::redisplay () newrow[_columns.location] = l; newrow[_columns.start] = start; newrow[_columns.end] = end; + + _location_row_map.insert (pair (l, newrow)); } } while (l); @@ -189,9 +192,29 @@ EditorSections::scroll_row_timeout () } void -EditorSections::clear_selection () +EditorSections::update_time_selection () { _view.get_selection ()->unselect_all (); + + Selection& selection (PublicEditor::instance ().get_selection ()); + + if (selection.time.empty ()) { + return; + } + + Locations* loc = _session->locations (); + Location* l = NULL; + do { + timepos_t start, end; + l = loc->next_section (l, start, end); + if (l) { + if (start == selection.time.start_time () && end == selection.time.end_time ()) { + LocationRowMap::iterator map_it = _location_row_map.find (l); + TreeModel::iterator j = map_it->second; + _view.get_selection ()->select (*j); + } + } + } while (l); } void @@ -208,6 +231,7 @@ EditorSections::selection_changed () _selection_change.block (); Selection& s (PublicEditor::instance ().get_selection ()); + s.clear (); s.set (start, end); _selection_change.unblock (); } @@ -390,6 +414,9 @@ EditorSections::delete_selected_section () _session->cut_copy_section (start, end, timepos_t (0), DeleteSection); } redisplay (); + + PublicEditor::instance ().get_selection ().clear (); + return true; } diff --git a/gtk2_ardour/editor_sections.h b/gtk2_ardour/editor_sections.h index 5b0163d4fb..2a158d88e8 100644 --- a/gtk2_ardour/editor_sections.h +++ b/gtk2_ardour/editor_sections.h @@ -19,6 +19,8 @@ #ifndef _gtk_ardour_editor_sections_h_ #define _gtk_ardour_editor_sections_h_ +#include + #include "ardour/location.h" #include "ardour/session_handle.h" @@ -44,7 +46,7 @@ private: bool delete_selected_section (); bool rename_selected_section (); - void clear_selection (); + void update_time_selection (); void selection_changed (); void clock_format_changed (); bool scroll_row_timeout (); @@ -101,11 +103,14 @@ private: Gtk::TreeModelColumn end; }; + typedef boost::unordered_map LocationRowMap; + Columns _columns; Glib::RefPtr _model; Gtk::TreeView _view; Gtk::ScrolledWindow _scroller; + LocationRowMap _location_row_map; bool _no_redisplay; sigc::connection _scroll_timeout; sigc::connection _selection_change;