merge fix for tempo branch
[ardour.git] / gtk2_ardour / editor.cc
index 231bb088d187eff88a8f82d6ccb740b07dfcb2cc..09d70e40d62bc5480501fa054c1946be00360f51 100644 (file)
@@ -68,6 +68,7 @@
 #include "ardour/audio_track.h"
 #include "ardour/audioengine.h"
 #include "ardour/audioregion.h"
+#include "ardour/lmath.h"
 #include "ardour/location.h"
 #include "ardour/profile.h"
 #include "ardour/route_group.h"
@@ -403,7 +404,7 @@ Editor::Editor ()
        location_loop_color = ARDOUR_UI::config()->color ("location loop");
        location_punch_color = ARDOUR_UI::config()->color ("location punch");
 
-       zoom_focus = ZoomFocusLeft;
+       zoom_focus = ZoomFocusPlayhead;
        _edit_point = EditAtMouse;
        _visible_track_count = -1;
 
@@ -1878,7 +1879,7 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
        edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
        edit_items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_selection)));
        if (ARDOUR_UI::instance()->video_timeline->get_duration() > 0) {
-               edit_items.push_back (MenuElem (_("Export Video Range..."), sigc::bind (sigc::mem_fun(*this, &Editor::export_video), true)));
+               edit_items.push_back (MenuElem (_("Export Video Range..."), sigc::bind (sigc::mem_fun(*(ARDOUR_UI::instance()), &ARDOUR_UI::export_video), true)));
        }
 }
 
@@ -2321,37 +2322,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 +2407,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 +3785,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 +4477,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 ();
                }
        }
@@ -5221,6 +5238,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);
@@ -5243,6 +5262,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 ();
 
@@ -5255,6 +5275,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);
        }