Move control surface options into RC prefs editor. Remove Options menu.
[ardour.git] / gtk2_ardour / editor_route_list.cc
index db3c4918c21c4f47ec2006aa96ede215bac6b401..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()) {
@@ -147,7 +148,7 @@ void
 Editor::handle_gui_changes (const string & what, void *src)
 {
        ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
-       
+
        if (what == "track_height") {
                /* Optional :make tracks change height while it happens, instead 
                   of on first-idle
@@ -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);
@@ -643,14 +686,10 @@ Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& c
                                                const SelectionData& data,
                                                guint info, guint time)
 {
-       cerr << "RouteLD::dddr target = " << data.get_target() << endl;
-       
        if (data.get_target() == "GTK_TREE_MODEL_ROW") {
-               cerr << "Delete drag data drop to treeview\n";
                route_list_display.on_drag_data_received (context, x, y, data, info, time);
                return;
        }
-       cerr << "some other kind of drag\n";
        context->drag_finish (true, false, time);
 }
 
@@ -786,114 +825,6 @@ Editor::move_selected_tracks (bool up)
        }
 
        route_display_model->reorder (neworder);
-}
-
-#if 0
-       vector<boost::shared_ptr<Route> > selected_block;
-       boost::shared_ptr<Route> target_unselected_route;
-       bool last_track_was_selected = false;
-       vector<int> neworder;
-       TreeModel::Children rows = route_display_model->children();
-       TreeModel::Children::iterator ri;
-       uint32_t old_key;
-       uint32_t new_key;
-       int n;
-
-       /* preload "neworder" with the current order */
-       
-       for (n = 0, ri = rows.begin(); ri != rows.end(); ++ri, ++n) {
-               neworder.push_back (n);
-       }
-
-       for (ri = rows.begin(); ri != rows.end(); ++ri) {
-
-               TimeAxisView* tv = (*ri)[route_display_columns.tv];
-               boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
-
-               if (selection->selected (tv)) {
-
-                       selected_block.push_back (route);
-                       cerr << "--SAVE as SELECTED " << route->name() << endl;
-                       last_track_was_selected = true;
-                       continue;
 
-               } else {
-
-                       if (!last_track_was_selected) {
-                               /* keep moving through unselected tracks, but save this
-                                  one in case we need it later as the one that will
-                                  move *down* as the selected block moves up.
-                               */
-                               target_unselected_route = route;
-                               cerr << "--pre-SAVE as UNSELECTED " << route->name() << endl;
-                               continue;
-                       }
-
-                       last_track_was_selected = false;
-
-                       if (!up) {
-                               /* this is the track immediately after a selected block,
-                                  and this is the one that will move *up* as 
-                                  the selected block moves down.
-                               */
-
-                               target_unselected_route = route;
-                               cerr << "--post-SAVE as UNSELECTED " << route->name() << endl;
-                       } else {
-                               cerr << "--(up) plan to use existing unselected target\n";
-                       }
-               }
-
-               cerr << "TRANSITION: sel = " << selected_block.size() << " unsel = " << target_unselected_route << endl;
-
-               /* transitioned between selected/not-selected */
-               
-               uint32_t distance;
-               
-               for (vector<boost::shared_ptr<Route> >::iterator x = selected_block.begin(); x != selected_block.end(); ++x) {
-                       old_key = (*x)->order_key (_order_key);
-                       new_key = compute_new_key (old_key, up, 1, rows.size());
-                       neworder[new_key] = old_key;
-                       cerr << "--SELECTED, reorder from " << old_key << " => " << new_key << endl;
-               }
-
-               /* now move the unselected tracks in the opposite direction */
-               
-               if (!selected_block.empty() && target_unselected_route) {
-                       distance = selected_block.size();
-                       old_key = target_unselected_route->order_key (_order_key);
-                       new_key = compute_new_key (old_key, !up, distance, rows.size());
-                       neworder[new_key] = old_key;
-                       cerr << "--UNSELECTED, reorder from " << old_key << " => " << new_key << endl;
-               }
-
-               selected_block.clear ();
-               target_unselected_route.reset ();
-       }
-
-       cerr << "when done ... sel = " << selected_block.size() << " unsel = " << target_unselected_route << endl;
-       
-       if (!selected_block.empty() || target_unselected_route) {
-               
-               /* left over blocks */
-               
-               uint32_t distance;
-               
-               for (vector<boost::shared_ptr<Route> >::iterator x = selected_block.begin(); x != selected_block.end(); ++x) {
-                       old_key = (*x)->order_key (_order_key);
-                       new_key = compute_new_key (old_key, up, 1, rows.size());
-                       neworder[new_key] = old_key;
-                       cerr << "--SELECTED, reorder from " << old_key << " => " << new_key << endl;
-               }
-
-               if (!selected_block.empty() && target_unselected_route) {
-                       distance = selected_block.size();
-                       old_key = target_unselected_route->order_key (_order_key);
-                       new_key = compute_new_key (old_key, !up, distance, rows.size());
-                       neworder[new_key] = old_key;
-                       cerr << "--UNSELECTED, reorder from " << old_key << " => " << new_key << endl;
-               }
-       }
-
-       route_display_model->reorder (neworder);
-#endif
+       session->sync_order_keys (_order_key);
+}