Move control surface options into RC prefs editor. Remove Options menu.
[ardour.git] / gtk2_ardour / editor_route_list.cc
index 6e368716f71e41459ff1d509ab8549fee0829544..00b4a3656d400327a2f6f1b03e8a8701bfa2f9f8 100644 (file)
 #include "gui_thread.h"
 #include "actions.h"
 
-#include <pbd/unknown_type.h>
+#include "pbd/unknown_type.h"
 
-#include <ardour/route.h>
+#include "ardour/route.h"
 
 #include "i18n.h"
 
+using namespace std;
 using namespace sigc;
 using namespace ARDOUR;
 using namespace PBD;
@@ -48,7 +49,7 @@ using namespace Glib;
 const char* _order_key = N_("editor");
 
 void
-Editor::handle_new_route (Session::RouteList& routes)
+Editor::handle_new_route (RouteList& routes)
 {
        ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes));
        
@@ -60,7 +61,7 @@ Editor::handle_new_route (Session::RouteList& routes)
        route_redisplay_does_not_sync_order_keys = true;
        no_route_list_redisplay = true;
 
-       for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
+       for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
                boost::shared_ptr<Route> route = (*x);
 
                if (route->is_hidden()) {
@@ -169,6 +170,8 @@ Editor::remove_route (TimeAxisView *tv)
        TrackViewList::iterator i;
        TreeModel::Children rows = route_display_model->children();
        TreeModel::Children::iterator ri;
+       boost::shared_ptr<Route> route;
+       TimeAxisView* next_tv;
 
        if (tv == entered_track) {
                entered_track = 0;
@@ -182,6 +185,7 @@ Editor::remove_route (TimeAxisView *tv)
 
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                if ((*ri)[route_display_columns.tv] == tv) {
+                       route = (*ri)[route_display_columns.route];
                        route_display_model->erase (ri);
                        break;
                }
@@ -190,14 +194,30 @@ Editor::remove_route (TimeAxisView *tv)
        route_redisplay_does_not_sync_order_keys = false;
 
        if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
-               track_views.erase (i);
+
+               i = track_views.erase (i);
+
+               if (track_views.empty()) {
+                       next_tv = 0;
+               } else if (i == track_views.end()) {
+                       next_tv = track_views.front();
+               } else {
+                      next_tv = (*i);
+               }
        }
+       
+       if (current_mixer_strip && current_mixer_strip->route() == route) {
 
-       /* since the editor mixer goes away when you remove a route, set the
-        * button to inactive and untick the menu option
-        */
+               if (next_tv) {
+                       set_selected_mixer_strip (*next_tv);
+               } else {
+                       /* make the editor mixer strip go away setting the
+                        * button to inactive (which also unticks the menu option)
+                        */
 
-       ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
+                       ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
+               }
+       } 
 }
 
 void
@@ -320,14 +340,13 @@ Editor::redisplay_route_list ()
        TreeModel::Children rows = route_display_model->children();
        TreeModel::Children::iterator i;
        uint32_t position;
-       uint32_t order;
        int n;
 
        if (no_route_list_redisplay) {
                return;
        }
 
-       for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
+       for (n = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
                TimeAxisView *tv = (*i)[route_display_columns.tv];
                boost::shared_ptr<Route> route = (*i)[route_display_columns.route];
 
@@ -342,11 +361,12 @@ Editor::redisplay_route_list ()
                           to tracks.
                        */
                        
-                       route->set_order_key (_order_key, order);
+                       route->set_order_key (_order_key, n);
                }
 
                bool visible = (*i)[route_display_columns.visible];
 
+               /* show or hide the TimeAxisView */
                if (visible) {
                        tv->set_marked_for_display (true);
                        position += tv->show_at (position, n, &edit_controls_vbox);
@@ -360,6 +380,13 @@ Editor::redisplay_route_list ()
                
        }
 
+       /* whenever we go idle, update the track view list to reflect the new order.
+          we can't do this here, because we could mess up something that is traversing
+          the track order and has caused a redisplay of the list.
+       */
+
+       Glib::signal_idle().connect (mem_fun (*this, &Editor::sync_track_view_list_and_route_list));
+       
        full_canvas_height = position + canvas_timebars_vsize;
        vertical_adjustment.set_upper (full_canvas_height);
        if ((vertical_adjustment.get_value() + canvas_height) > vertical_adjustment.get_upper()) {
@@ -375,6 +402,22 @@ Editor::redisplay_route_list ()
        }
 }
 
+bool
+Editor::sync_track_view_list_and_route_list ()
+{
+       TreeModel::Children rows = route_display_model->children();
+       TreeModel::Children::iterator i;
+
+       track_views.clear ();
+
+       for (i = rows.begin(); i != rows.end(); ++i) {
+               TimeAxisView *tv = (*i)[route_display_columns.tv];
+               track_views.push_back (tv);
+       }
+
+       return false; // do not call again (until needed)
+}
+
 void
 Editor::hide_all_tracks (bool with_select)
 {
@@ -591,8 +634,8 @@ struct EditorOrderRouteSorter {
 void
 Editor::initial_route_list_display ()
 {
-       boost::shared_ptr<Session::RouteList> routes = session->get_routes();
-       Session::RouteList r (*routes);
+       boost::shared_ptr<RouteList> routes = session->get_routes();
+       RouteList r (*routes);
        EditorOrderRouteSorter sorter;
 
        r.sort (sorter);