properly apply default state
[ardour.git] / gtk2_ardour / editor.cc
index 1b00ba96526ecb336c7bf98e2435052593ab3e78..a6d36ee7992ae2ddcb367595f0d0a071dc2ef234 100644 (file)
@@ -2321,37 +2321,16 @@ Editor::set_state (const XMLNode& node, int /*version*/)
        if ((prop = node.property ("show-measures"))) {
                bool yn = string_is_affirmative (prop->value());
                _show_measures = yn;
-               RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
-               if (act) {
-                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-                       /* do it twice to force the change */
-                       tact->set_active (!yn);
-                       tact->set_active (yn);
-               }
        }
 
        if ((prop = node.property ("follow-playhead"))) {
                bool yn = string_is_affirmative (prop->value());
                set_follow_playhead (yn);
-               RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
-               if (act) {
-                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-                       if (tact->get_active() != yn) {
-                               tact->set_active (yn);
-                       }
-               }
        }
 
        if ((prop = node.property ("stationary-playhead"))) {
                bool yn = string_is_affirmative (prop->value());
                set_stationary_playhead (yn);
-               RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
-               if (act) {
-                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-                       if (tact->get_active() != yn) {
-                               tact->set_active (yn);
-                       }
-               }
        }
 
        if ((prop = node.property ("region-list-sort-type"))) {
@@ -2427,6 +2406,42 @@ Editor::set_state (const XMLNode& node, int /*version*/)
                nudge_clock->set (_session->frame_rate() * 5, true);
        }
 
+       {
+               /* apply state
+                * Not all properties may have been in XML, but
+                * those that are linked to a private variable may need changing
+                */
+               RefPtr<Action> act;
+               bool yn;
+
+               act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
+               if (act) {
+                       yn = _show_measures;
+                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
+                       /* do it twice to force the change */
+                       tact->set_active (!yn);
+                       tact->set_active (yn);
+               }
+
+               act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
+               yn = _follow_playhead;
+               if (act) {
+                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
+                       if (tact->get_active() != yn) {
+                               tact->set_active (yn);
+                       }
+               }
+
+               act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
+               yn = _stationary_playhead;
+               if (act) {
+                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
+                       if (tact->get_active() != yn) {
+                               tact->set_active (yn);
+                       }
+               }
+       }
+
        return 0;
 }
 
@@ -3769,7 +3784,7 @@ Editor::set_visible_track_count (int32_t n)
        }
 
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-               (*i)->set_height (h);
+               (*i)->set_height (h, TimeAxisView::HeightPerLane);
        }
        
        if (str != visible_tracks_selector.get_text()) {
@@ -4461,6 +4476,7 @@ Editor::use_visual_state (VisualState& vs)
                *ARDOUR_UI::instance()->gui_object_state = *vs.gui_state;
                
                for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {    
+                       (*i)->clear_property_cache();
                        (*i)->reset_visual_state ();
                }
        }
@@ -5220,6 +5236,8 @@ Editor::add_routes (RouteList& routes)
 
        RouteTimeAxisView *rtv;
        list<RouteTimeAxisView*> new_views;
+       TrackViewList new_selection;
+       bool from_scratch = (track_views.size() == 0);
 
        for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
                boost::shared_ptr<Route> route = (*x);
@@ -5242,6 +5260,7 @@ Editor::add_routes (RouteList& routes)
 
                new_views.push_back (rtv);
                track_views.push_back (rtv);
+               new_selection.push_back (rtv);
 
                rtv->effective_gain_display ();
 
@@ -5254,6 +5273,12 @@ Editor::add_routes (RouteList& routes)
                _summary->routes_added (new_views);
        }
 
+       if (!from_scratch) {
+               selection->tracks.clear();
+               selection->add (new_selection);
+               begin_selection_op_history();
+       }
+
        if (show_editor_mixer_when_tracks_arrive) {
                show_editor_mixer (true);
        }