Fix autoscroll fudge calculations. Remove some unused
[ardour.git] / gtk2_ardour / editor_routes.cc
index f58ea47868fd54f52fbfcf80c51ce97cce38d257..402681587914791a10a6c9e21418ce1c35664278 100644 (file)
@@ -115,9 +115,9 @@ EditorRoutes::EditorRoutes (Editor* e)
        // Mute enable toggle
        CellRendererPixbufMulti* mute_col_renderer = manage (new CellRendererPixbufMulti());
 
-       mute_col_renderer->set_pixbuf (0, ::get_icon("mute-disabled"));
-       mute_col_renderer->set_pixbuf (1, ::get_icon("muted-by-others"));
-       mute_col_renderer->set_pixbuf (2, ::get_icon("mute-enabled"));
+       mute_col_renderer->set_pixbuf (ActiveState(0), ::get_icon("mute-disabled"));
+       mute_col_renderer->set_pixbuf (Mid, ::get_icon("muted-by-others"));
+       mute_col_renderer->set_pixbuf (Active, ::get_icon("mute-enabled"));
        mute_col_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_mute_enable_toggled));
 
        TreeViewColumn* mute_state_column = manage (new TreeViewColumn("M", *mute_col_renderer));
@@ -131,14 +131,15 @@ EditorRoutes::EditorRoutes (Editor* e)
        // Solo enable toggle
        CellRendererPixbufMulti* solo_col_renderer = manage (new CellRendererPixbufMulti());
 
-       solo_col_renderer->set_pixbuf (0, ::get_icon("solo-disabled"));
-       solo_col_renderer->set_pixbuf (1, ::get_icon("solo-enabled"));
-       solo_col_renderer->set_pixbuf (3, ::get_icon("soloed-by-others"));
+       solo_col_renderer->set_pixbuf (ActiveState(0), ::get_icon("solo-disabled"));
+       solo_col_renderer->set_pixbuf (Active, ::get_icon("solo-enabled"));
+       solo_col_renderer->set_pixbuf (Mid, ::get_icon("soloed-by-others"));
        solo_col_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_solo_enable_toggled));
 
        TreeViewColumn* solo_state_column = manage (new TreeViewColumn("S", *solo_col_renderer));
 
        solo_state_column->add_attribute(solo_col_renderer->property_state(), _columns.solo_state);
+       solo_state_column->add_attribute(solo_col_renderer->property_visible(), _columns.solo_visible);
        solo_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
        solo_state_column->set_alignment(ALIGN_CENTER);
        solo_state_column->set_expand(false);
@@ -154,6 +155,7 @@ EditorRoutes::EditorRoutes (Editor* e)
        TreeViewColumn* solo_isolate_state_column = manage (new TreeViewColumn("SI", *solo_iso_renderer));
 
        solo_isolate_state_column->add_attribute(solo_iso_renderer->property_state(), _columns.solo_isolate_state);
+       solo_isolate_state_column->add_attribute(solo_iso_renderer->property_visible(), _columns.solo_visible);
        solo_isolate_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
        solo_isolate_state_column->set_alignment(ALIGN_CENTER);
        solo_isolate_state_column->set_expand(false);
@@ -168,6 +170,7 @@ EditorRoutes::EditorRoutes (Editor* e)
 
        TreeViewColumn* solo_safe_state_column = manage (new TreeViewColumn(_("SS"), *solo_safe_renderer));
        solo_safe_state_column->add_attribute(solo_safe_renderer->property_state(), _columns.solo_safe_state);
+       solo_safe_state_column->add_attribute(solo_safe_renderer->property_visible(), _columns.solo_visible);
        solo_safe_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
        solo_safe_state_column->set_alignment(ALIGN_CENTER);
        solo_safe_state_column->set_expand(false);
@@ -182,6 +185,7 @@ EditorRoutes::EditorRoutes (Editor* e)
 
         _name_column = _display.append_column (_("Name"), _columns.text) - 1;
        _visible_column = _display.append_column (_("V"), _columns.visible) - 1;
+       _active_column = _display.append_column (_("A"), _columns.active) - 1;
 
        _display.set_headers_visible (true);
        _display.set_name ("TrackListDisplay");
@@ -222,6 +226,18 @@ EditorRoutes::EditorRoutes (Editor* e)
        visible_col->set_fixed_width(30);
        visible_col->set_alignment(ALIGN_CENTER);
 
+       CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*> (_display.get_column_cell_renderer (_active_column));
+
+       active_cell->property_activatable() = true;
+       active_cell->property_radio() = false;
+       active_cell->signal_toggled().connect (sigc::mem_fun (*this, &EditorRoutes::active_changed));
+
+       TreeViewColumn* active_col = dynamic_cast<TreeViewColumn*> (_display.get_column (_active_column));
+       active_col->set_expand (false);
+       active_col->set_sizing (TREE_VIEW_COLUMN_FIXED);
+       active_col->set_fixed_width (30);
+       active_col->set_alignment (ALIGN_CENTER);
+       
        _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRoutes::route_deleted));
        _model->signal_rows_reordered().connect (sigc::mem_fun (*this, &EditorRoutes::reordered));
 
@@ -450,9 +466,18 @@ EditorRoutes::redisplay ()
        TreeModel::Children rows = _model->children();
        TreeModel::Children::iterator i;
        uint32_t position;
+
+       /* n will be the count of tracks plus children (updated by TimeAxisView::show_at),
+          so we will use that to know where to put things.
+       */
        int n;
 
-       for (n = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
+       /* Order keys must not take children into account, so use a separate counter
+          for that.
+       */
+       int order_key;
+
+       for (n = 0, order_key = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
                TimeAxisView *tv = (*i)[_columns.tv];
                boost::shared_ptr<Route> route = (*i)[_columns.route];
 
@@ -465,7 +490,7 @@ EditorRoutes::redisplay ()
                        /* this reorder is caused by user action, so reassign sort order keys
                           to tracks.
                        */
-                       route->set_order_key (N_ ("editor"), n);
+                       route->set_order_key (N_ ("editor"), order_key);
                }
 
                bool visible = tv->marked_for_display ();
@@ -474,10 +499,12 @@ EditorRoutes::redisplay ()
                if (visible) {
                        position += tv->show_at (position, n, &_editor->edit_controls_vbox);
                        tv->clip_to_viewport ();
-                       n++;
                } else {
                        tv->hide ();
                }
+
+               n++;
+               order_key++;
        }
 
        /* whenever we go idle, update the track view list to reflect the new order.
@@ -543,6 +570,19 @@ EditorRoutes::visible_changed (std::string const & path)
        }
 }
 
+void
+EditorRoutes::active_changed (std::string const & path)
+{
+       if (_session && _session->deletion_in_progress ()) {
+               return;
+       }
+
+       Gtk::TreeModel::Row row = *_model->get_iter (path);
+       boost::shared_ptr<Route> route = row[_columns.route];
+       bool const active = row[_columns.active];
+       route->set_active (!active, this);
+}
+
 void
 EditorRoutes::routes_added (list<RouteTimeAxisView*> routes)
 {
@@ -559,6 +599,7 @@ EditorRoutes::routes_added (list<RouteTimeAxisView*> routes)
 
                row[_columns.text] = (*x)->route()->name();
                row[_columns.visible] = (*x)->marked_for_display();
+               row[_columns.active] = (*x)->route()->active ();
                row[_columns.tv] = *x;
                row[_columns.route] = (*x)->route ();
                row[_columns.is_track] = (boost::dynamic_pointer_cast<Track> ((*x)->route()) != 0);
@@ -571,8 +612,9 @@ EditorRoutes::routes_added (list<RouteTimeAxisView*> routes)
                        row[_columns.is_midi] = false;
                }
 
-               row[_columns.mute_state] = (*x)->route()->muted();
-               row[_columns.solo_state] = RouteUI::solo_visual_state ((*x)->route());
+               row[_columns.mute_state] = (*x)->route()->muted() ? Active : ActiveState (0);
+               row[_columns.solo_state] = RouteUI::solo_active_state ((*x)->route());
+               row[_columns.solo_visible] = !(*x)->route()->is_master ();
                row[_columns.solo_isolate_state] = (*x)->route()->solo_isolated();
                row[_columns.solo_safe_state] = (*x)->route()->solo_safe();
                row[_columns.name_editable] = true;
@@ -607,6 +649,7 @@ EditorRoutes::routes_added (list<RouteTimeAxisView*> routes)
                (*x)->route()->listen_changed.connect (*this, MISSING_INVALIDATOR, ui_bind (&EditorRoutes::update_solo_display, this, _1), gui_context());
                (*x)->route()->solo_isolated_changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_solo_isolate_display, this), gui_context());
                (*x)->route()->solo_safe_changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_solo_safe_display, this), gui_context());
+               (*x)->route()->active_changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_active_display, this), gui_context ());
        }
 
        update_rec_display ();
@@ -615,6 +658,7 @@ EditorRoutes::routes_added (list<RouteTimeAxisView*> routes)
        update_solo_isolate_display ();
        update_solo_safe_display ();
        update_input_active_display ();
+       update_active_display ();
        resume_redisplay ();
        _redisplay_does_not_sync_order_keys = false;
 }
@@ -688,6 +732,18 @@ EditorRoutes::route_property_changed (const PropertyChange& what_changed, boost:
        }
 }
 
+void
+EditorRoutes::update_active_display ()
+{
+       TreeModel::Children rows = _model->children();
+       TreeModel::Children::iterator i;
+
+       for (i = rows.begin(); i != rows.end(); ++i) {
+               boost::shared_ptr<Route> route = (*i)[_columns.route];
+               (*i)[_columns.active] = route->active ();
+       }
+}
+
 void
 EditorRoutes::update_visibility ()
 {
@@ -782,6 +838,8 @@ EditorRoutes::sync_order_keys (string const & src)
                        co.push_back (i->second);
                }
 
+               assert (co.size() == _model->children().size ());
+
                _model->reorder (co);
                _redisplay_does_not_reset_order_keys = false;
        }
@@ -1279,9 +1337,15 @@ EditorRoutes::move_selected_tracks (bool up)
                neworder.push_back (leading->second->order_key (N_ ("editor")));
        }
 
+#ifndef NDEBUG
+       for (vector<int>::iterator i = neworder.begin(); i != neworder.end(); ++i) {
+               assert (*i < (int) neworder.size ());
+       }
+#endif 
+
        _model->reorder (neworder);
 
-       _session->sync_order_keys (N_ ("editor"));
+       _session->sync_order_keys (N_ ("editor"));
 }
 
 void
@@ -1340,7 +1404,7 @@ EditorRoutes::update_mute_display ()
 
        for (i = rows.begin(); i != rows.end(); ++i) {
                boost::shared_ptr<Route> route = (*i)[_columns.route];
-               (*i)[_columns.mute_state] = RouteUI::mute_visual_state (_session, route);
+               (*i)[_columns.mute_state] = RouteUI::mute_active_state (_session, route);
        }
 }
 
@@ -1352,7 +1416,7 @@ EditorRoutes::update_solo_display (bool /* selfsoloed */)
 
        for (i = rows.begin(); i != rows.end(); ++i) {
                boost::shared_ptr<Route> route = (*i)[_columns.route];
-               (*i)[_columns.solo_state] = RouteUI::solo_visual_state (route);
+               (*i)[_columns.solo_state] = RouteUI::solo_active_state (route);
        }
 }
 
@@ -1364,7 +1428,7 @@ EditorRoutes::update_solo_isolate_display ()
 
        for (i = rows.begin(); i != rows.end(); ++i) {
                boost::shared_ptr<Route> route = (*i)[_columns.route];
-               (*i)[_columns.solo_isolate_state] = RouteUI::solo_isolate_visual_state (route) > 0 ? 1 : 0;
+               (*i)[_columns.solo_isolate_state] = RouteUI::solo_isolate_active_state (route) ? 1 : 0;
        }
 }
 
@@ -1376,7 +1440,7 @@ EditorRoutes::update_solo_safe_display ()
 
        for (i = rows.begin(); i != rows.end(); ++i) {
                boost::shared_ptr<Route> route = (*i)[_columns.route];
-               (*i)[_columns.solo_safe_state] = RouteUI::solo_safe_visual_state (route) > 0 ? 1 : 0;
+               (*i)[_columns.solo_safe_state] = RouteUI::solo_safe_active_state (route) ? 1 : 0;
        }
 }