add back-pointer to TempoMap from points, and push dirty=true into map
[ardour.git] / gtk2_ardour / time_info_box.cc
index b60d9c1594da58ca077ca9e68bec61fa1386aeed..53425f9cd9a5abd95f6d58bcc472f6a0d79b6214 100644 (file)
 #include <algorithm>
 #include "pbd/compose.h"
 
-#include "gtkmm2ext/cairocell.h"
 #include "gtkmm2ext/gui_thread.h"
 #include "gtkmm2ext/utils.h"
-#include "gtkmm2ext/stateful_button.h"
 #include "gtkmm2ext/actions.h"
 
 #include "ardour/location.h"
 #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"
 
@@ -138,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());
 }
 
@@ -158,30 +156,6 @@ TimeInfoBox::track_mouse_mode ()
        selection_changed ();
 }
 
-void
-TimeInfoBox::region_property_change (boost::shared_ptr<ARDOUR::Region> 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)
 {
@@ -256,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:
@@ -284,7 +275,7 @@ TimeInfoBox::selection_changed ()
                                        selection_length->set_off (false);
                                        selection_start->set (selection.time.start());
                                        selection_end->set (selection.time.end_frame());
-                                       selection_length->set (selection.time.length());
+                                       selection_length->set (selection.time.end_frame(), false, selection.time.start());
                                } else {
                                        selection_start->set_off (true);
                                        selection_end->set_off (true);
@@ -303,17 +294,22 @@ TimeInfoBox::selection_changed ()
                                selection_length->set_off (false);
                                selection_start->set (s);
                                selection_end->set (e);
-                               selection_length->set (e - s + 1);
+                               selection_length->set (e, false, s);
                        }
                } 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<boost::shared_ptr<ARDOUR::Playlist> > playlists;
+                       for (RegionSelection::iterator s = selection.regions.begin(); s != selection.regions.end(); ++s) {
+                               boost::shared_ptr<Playlist> pl = (*s)->region()->playlist();
+                               if (pl) {
+                                       playlists.insert (pl);
+                               }
+                       }
+                       for (std::set<boost::shared_ptr<ARDOUR::Playlist> >::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;
 
@@ -331,7 +327,7 @@ TimeInfoBox::selection_changed ()
                                selection_length->set_off (false);
                                selection_start->set (s);
                                selection_end->set (e);
-                               selection_length->set (e - s + 1);
+                               selection_length->set (e, false, s);
                        } else {
                                selection_start->set_off (true);
                                selection_end->set_off (true);
@@ -343,7 +339,7 @@ TimeInfoBox::selection_changed ()
                        selection_length->set_off (false);
                        selection_start->set (selection.time.start());
                        selection_end->set (selection.time.end_frame());
-                       selection_length->set (selection.time.length());
+                       selection_length->set (selection.time.end_frame(), false, selection.time.start());
                }
                break;