mp4chaps Lua script: don't clutter global environment
[ardour.git] / gtk2_ardour / editor_selection.cc
index c9e2ba49fdcc1f6f4d9c8aa3ac27aa043f6594e3..b5a0be1c7869aa3e19c71a5a83c8ef282ac08bdb 100644 (file)
 #include "pbd/stacktrace.h"
 #include "pbd/unwind.h"
 
+#include "ardour/control_protocol_manager.h"
 #include "ardour/midi_region.h"
 #include "ardour/playlist.h"
 #include "ardour/profile.h"
 #include "ardour/route_group.h"
 #include "ardour/selection.h"
 #include "ardour/session.h"
-
-#include "control_protocol/control_protocol.h"
+#include "ardour/vca.h"
 
 #include "editor.h"
 #include "editor_drag.h"
@@ -1001,14 +1001,22 @@ struct SelectionOrderSorter {
 void
 Editor::presentation_info_changed (PropertyChange const & what_changed)
 {
+       uint32_t n_tracks = 0;
+       uint32_t n_busses = 0;
+       uint32_t n_vcas = 0;
+       uint32_t n_routes = 0;
+       uint32_t n_stripables = 0;
+
        /* We cannot ensure ordering of the handlers for
         * PresentationInfo::Changed, so we have to do everything in order
         * here, as a single handler.
         */
 
-       for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
-               (*i)->set_selected (false);
-               (*i)->hide_selection ();
+       if (what_changed.contains (Properties::selected)) {
+               for (TrackViewList::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+                       (*i)->set_selected (false);
+                       (*i)->hide_selection ();
+               }
        }
 
        /* STEP 1: set the GUI selection state (in which TimeAxisViews for the
@@ -1020,10 +1028,6 @@ Editor::presentation_info_changed (PropertyChange const & what_changed)
        /* STEP 2: update TimeAxisView's knowledge of their selected state
         */
 
-
-       PropertyChange pc;
-       pc.add (Properties::selected);
-
        if (what_changed.contains (Properties::selected)) {
 
                StripableNotificationListPtr stripables (new StripableNotificationList);
@@ -1050,9 +1054,22 @@ Editor::presentation_info_changed (PropertyChange const & what_changed)
                                continue;
                        }
 
+                       n_stripables++;
+
+                       if (boost::dynamic_pointer_cast<Track> ((*i).stripable)) {
+                               n_tracks++;
+                               n_routes++;
+                       } else if (boost::dynamic_pointer_cast<Route> ((*i).stripable)) {
+                               n_busses++;
+                               n_routes++;
+                       } else if (boost::dynamic_pointer_cast<VCA> ((*i).stripable)) {
+                               n_vcas++;
+                       }
+
                        TimeAxisView* tav = dynamic_cast<TimeAxisView*> (av);
 
                        if (!tav) {
+                               assert (0);
                                continue; /* impossible */
                        }
 
@@ -1084,13 +1101,17 @@ Editor::presentation_info_changed (PropertyChange const & what_changed)
                        stripables->push_back ((*i).stripable);
                }
 
-               ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, !selection->tracks.empty());
+               ActionManager::set_sensitive (ActionManager::stripable_selection_sensitive_actions, (n_stripables > 0));
+               ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, (n_tracks > 0));
+               ActionManager::set_sensitive (ActionManager::bus_selection_sensitive_actions, (n_busses > 0));
+               ActionManager::set_sensitive (ActionManager::route_selection_sensitive_actions, (n_routes > 0));
+               ActionManager::set_sensitive (ActionManager::vca_selection_sensitive_actions, (n_vcas > 0));
 
                sensitize_the_right_region_actions (false);
 
                /* STEP 4: notify control protocols */
 
-               ControlProtocol::StripableSelectionChanged (stripables);
+               ControlProtocolManager::instance().stripable_selection_changed (stripables);
 
                if (sfbrowser && _session && !_session->deletion_in_progress()) {
                        uint32_t audio_track_cnt = 0;