Merged with trunk R1304
[ardour.git] / gtk2_ardour / editor.cc
index 3c1c89f9271549e0eb00f9a710e557777530ac92..621b76a1e19b43b16a9925040f0921c81a8bb9e7 100644 (file)
@@ -901,6 +901,8 @@ Editor::instant_save ()
 void
 Editor::reposition_x_origin (nframes_t frame)
 {
+       cerr << "repsosition to " << frame << endl;
+
        if (frame != leftmost_frame) {
                leftmost_frame = frame;
                
@@ -1141,6 +1143,13 @@ Editor::connect_to_session (Session *t)
 {
        session = t;
 
+       XMLNode* node = ARDOUR_UI::instance()->editor_settings();
+       set_state (*node);
+
+       /* catch up with the playhead */
+
+       session->request_locate (playhead_cursor->current_frame);
+
        if (first_action_message) {
                first_action_message->hide();
        }
@@ -1237,27 +1246,12 @@ Editor::connect_to_session (Session *t)
                (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
        }
 
-       /* ::reposition_x_origin() doesn't work right here, since the old
-          position may be zero already, and it does nothing in such
-          circumstances.
-       */
-
-       leftmost_frame = 0;
-       
-       horizontal_adjustment.set_value (0);
-
        restore_ruler_visibility ();
        //tempo_map_changed (Change (0));
        session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
 
-       edit_cursor->set_position (0);
-       playhead_cursor->set_position (0);
-
        start_scrolling ();
 
-       XMLNode* node = ARDOUR_UI::instance()->editor_settings();
-       set_state (*node);
-
        /* don't show master bus in a new session */
 
        if (ARDOUR_UI::instance()->session_is_new ()) {
@@ -1650,7 +1644,7 @@ Editor::build_track_selection_context_menu (nframes_t ignored)
 }
 
 void
-Editor::add_crossfade_context_items (AudioStreamView* view, Crossfade* xfade, Menu_Helpers::MenuList& edit_items, bool many)
+Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
 {
        using namespace Menu_Helpers;
        Menu     *xfade_menu = manage (new Menu);
@@ -1664,8 +1658,8 @@ Editor::add_crossfade_context_items (AudioStreamView* view, Crossfade* xfade, Me
                str = _("Unmute");
        }
 
-       items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), xfade)));
-       items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), xfade)));
+       items.push_back (MenuElem (str, bind (mem_fun(*this, &Editor::toggle_xfade_active), boost::weak_ptr<Crossfade> (xfade))));
+       items.push_back (MenuElem (_("Edit"), bind (mem_fun(*this, &Editor::edit_xfade), boost::weak_ptr<Crossfade> (xfade))));
 
        if (xfade->can_follow_overlap()) {
 
@@ -2115,6 +2109,28 @@ Editor::set_state (const XMLNode& node)
        set_default_size (g.base_width, g.base_height);
        move (x, y);
 
+       if (session && (prop = node.property ("playhead"))) {
+               nframes_t pos = atol (prop->value().c_str());
+               playhead_cursor->set_position (pos);
+       } else {
+               playhead_cursor->set_position (0);
+
+               /* ::reposition_x_origin() doesn't work right here, since the old
+                  position may be zero already, and it does nothing in such
+                  circumstances.
+               */
+               
+               leftmost_frame = 0;
+               horizontal_adjustment.set_value (0);
+       }
+
+       if (session && (prop = node.property ("edit-cursor"))) {
+               nframes_t pos = atol (prop->value().c_str());
+               edit_cursor->set_position (pos);
+       } else {
+               edit_cursor->set_position (0);
+       }
+
        if ((prop = node.property ("zoom-focus"))) {
                set_zoom_focus ((ZoomFocus) atoi (prop->value()));
        }
@@ -2264,6 +2280,11 @@ Editor::get_state ()
        snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
        node->add_property ("snap-mode", buf);
 
+       snprintf (buf, sizeof (buf), "%" PRIu32, playhead_cursor->current_frame);
+       node->add_property ("playhead", buf);
+       snprintf (buf, sizeof (buf), "%" PRIu32, edit_cursor->current_frame);
+       node->add_property ("edit-cursor", buf);
+
        node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
        node->add_property ("show-waveforms-recording", _show_waveforms_recording ? "yes" : "no");
        node->add_property ("show-measures", _show_measures ? "yes" : "no");
@@ -3901,21 +3922,33 @@ Editor::set_follow_playhead (bool yn)
 }
 
 void
-Editor::toggle_xfade_active (Crossfade* xfade)
+Editor::toggle_xfade_active (boost::weak_ptr<Crossfade> wxfade)
 {
-       xfade->set_active (!xfade->active());
+       boost::shared_ptr<Crossfade> xfade (wxfade.lock());
+       if (xfade) {
+               xfade->set_active (!xfade->active());
+       }
 }
 
 void
-Editor::toggle_xfade_length (Crossfade* xfade)
+Editor::toggle_xfade_length (boost::weak_ptr<Crossfade> wxfade)
 {
-       xfade->set_follow_overlap (!xfade->following_overlap());
+       boost::shared_ptr<Crossfade> xfade (wxfade.lock());
+       if (xfade) {
+               xfade->set_follow_overlap (!xfade->following_overlap());
+       }
 }
 
 void
-Editor::edit_xfade (Crossfade* xfade)
+Editor::edit_xfade (boost::weak_ptr<Crossfade> wxfade)
 {
-       CrossfadeEditor cew (*session, *xfade, xfade->fade_in().get_min_y(), 1.0);
+       boost::shared_ptr<Crossfade> xfade (wxfade.lock());
+
+       if (!xfade) {
+               return;
+       }
+
+       CrossfadeEditor cew (*session, xfade, xfade->fade_in().get_min_y(), 1.0);
                
        ensure_float (cew);