From fb761a6fa7719fbd532dec08564142336316d92c Mon Sep 17 00:00:00 2001 From: nick_m Date: Sat, 17 Jun 2017 04:08:56 +1000 Subject: [PATCH] Rework time info box updates on region selection change Should provide better performance as we now only listen for changes in the selected regions. Testing every changed region to see if its in the selection was not working very well under some circumstances. --- gtk2_ardour/time_info_box.cc | 70 ++++++++++++++++++------------------ gtk2_ardour/time_info_box.h | 2 +- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/gtk2_ardour/time_info_box.cc b/gtk2_ardour/time_info_box.cc index 968e3ba9de..2c316c05a9 100644 --- a/gtk2_ardour/time_info_box.cc +++ b/gtk2_ardour/time_info_box.cc @@ -28,11 +28,12 @@ #include "ardour/profile.h" #include "ardour/session.h" -#include "time_info_box.h" #include "audio_clock.h" -#include "editor.h" -#include "control_point.h" #include "automation_line.h" +#include "control_point.h" +#include "editor.h" +#include "region_view.h" +#include "time_info_box.h" #include "pbd/i18n.h" @@ -136,7 +137,6 @@ TimeInfoBox::TimeInfoBox (std::string state_node_name, bool with_punch) Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed)); Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed)); - Region::RegionPropertyChanged.connect (region_property_connections, invalidator (*this), boost::bind (&TimeInfoBox::region_property_change, this, _1, _2), gui_context()); Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context()); } @@ -156,30 +156,6 @@ TimeInfoBox::track_mouse_mode () selection_changed (); } -void -TimeInfoBox::region_property_change (boost::shared_ptr r, const PBD::PropertyChange& what_changed) -{ - Selection& selection (Editor::instance().get_selection()); - - if (selection.regions.empty()) { - return; - } - - PBD::PropertyChange our_interests; - - our_interests.add (ARDOUR::Properties::position); - our_interests.add (ARDOUR::Properties::length); - our_interests.add (ARDOUR::Properties::start); - - if (!what_changed.contains (our_interests)) { - return; - } - - if (selection.regions.contains (r)) { - selection_changed (); - } -} - bool TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src) { @@ -254,12 +230,29 @@ TimeInfoBox::set_session (Session* s) } } +void +TimeInfoBox::region_selection_changed () +{ + framepos_t s, e; + Selection& selection (Editor::instance().get_selection()); + s = selection.regions.start(); + e = selection.regions.end_frame(); + selection_start->set_off (false); + selection_end->set_off (false); + selection_length->set_off (false); + selection_start->set (s); + selection_end->set (e); + selection_length->set (e, false, s); +} + void TimeInfoBox::selection_changed () { framepos_t s, e; Selection& selection (Editor::instance().get_selection()); + region_property_connections.drop_connections(); + switch (Editor::instance().current_mouse_mode()) { case Editing::MouseContent: @@ -304,14 +297,19 @@ TimeInfoBox::selection_changed () selection_length->set (e - s + 1); } } else { - s = selection.regions.start(); - e = selection.regions.end_frame(); - selection_start->set_off (false); - selection_end->set_off (false); - selection_length->set_off (false); - selection_start->set (s); - selection_end->set (e); - selection_length->set (e - s + 1); + /* this is more efficient than tracking changes per region in large selections */ + std::set > playlists; + for (RegionSelection::iterator s = selection.regions.begin(); s != selection.regions.end(); ++s) { + boost::shared_ptr pl = (*s)->region()->playlist(); + if (pl) { + playlists.insert (pl); + } + } + for (std::set >::iterator ps = playlists.begin(); ps != playlists.end(); ++ps) { + (*ps)->ContentsChanged.connect (region_property_connections, invalidator (*this), + boost::bind (&TimeInfoBox::region_selection_changed, this), gui_context()); + } + region_selection_changed (); } break; diff --git a/gtk2_ardour/time_info_box.h b/gtk2_ardour/time_info_box.h index cf06b404c9..0ffd00a2be 100644 --- a/gtk2_ardour/time_info_box.h +++ b/gtk2_ardour/time_info_box.h @@ -70,13 +70,13 @@ private: PBD::ScopedConnectionList region_property_connections; void selection_changed (); + void region_selection_changed (); void sync_selection_mode (AudioClock*); void sync_punch_mode (AudioClock*); bool clock_button_release_event (GdkEventButton* ev, AudioClock* src); void track_mouse_mode (); - void region_property_change (boost::shared_ptr r, const PBD::PropertyChange& what_changed); }; #endif /* __time_info_box_h__ */