Make activate/deactivate all only operate on visible
[ardour.git] / gtk2_ardour / editor.cc
index dcf97ffaa826f29dfd7bd546eedd2ae8307ba5f3..80f7feed72d34509cb9cb5b15e58d14d8eb37efa 100644 (file)
@@ -58,7 +58,6 @@
 #include "gtkmm2ext/choice.h"
 #include "gtkmm2ext/cell_renderer_pixbuf_toggle.h"
 
-#include "ardour/audio_diskstream.h"
 #include "ardour/audio_track.h"
 #include "ardour/audioplaylist.h"
 #include "ardour/audioregion.h"
 
 #include "control_protocol/control_protocol.h"
 
-#include "editor.h"
-#include "debug.h"
-#include "keyboard.h"
-#include "marker.h"
-#include "playlist_selector.h"
+#include "actions.h"
+#include "actions.h"
+#include "analysis_window.h"
+#include "audio_clock.h"
 #include "audio_region_view.h"
-#include "rgb_macros.h"
-#include "selection.h"
 #include "audio_streamview.h"
-#include "time_axis_view.h"
 #include "audio_time_axis.h"
-#include "utils.h"
-#include "crossfade_view.h"
+#include "automation_time_axis.h"
+#include "bundle_manager.h"
 #include "canvas-noevent-text.h"
-#include "editing.h"
-#include "public_editor.h"
-#include "crossfade_edit.h"
 #include "canvas_impl.h"
-#include "actions.h"
-#include "sfdb_ui.h"
-#include "gui_thread.h"
-#include "simpleline.h"
-#include "rhythm_ferret.h"
-#include "actions.h"
-#include "tempo_lines.h"
-#include "analysis_window.h"
-#include "bundle_manager.h"
-#include "global_port_matrix.h"
+#include "crossfade_edit.h"
+#include "crossfade_view.h"
+#include "debug.h"
+#include "editing.h"
+#include "editor.h"
+#include "editor_cursors.h"
 #include "editor_drag.h"
 #include "editor_group_tabs.h"
-#include "automation_time_axis.h"
-#include "editor_routes.h"
-#include "midi_time_axis.h"
-#include "mixer_strip.h"
-#include "editor_route_groups.h"
-#include "editor_regions.h"
 #include "editor_locations.h"
+#include "editor_regions.h"
+#include "editor_route_groups.h"
+#include "editor_routes.h"
 #include "editor_snapshots.h"
 #include "editor_summary.h"
-#include "region_layering_order_editor.h"
+#include "global_port_matrix.h"
+#include "gui_object.h"
+#include "gui_thread.h"
+#include "keyboard.h"
+#include "marker.h"
+#include "midi_time_axis.h"
+#include "mixer_strip.h"
+#include "mixer_ui.h"
 #include "mouse_cursors.h"
-#include "editor_cursors.h"
+#include "playlist_selector.h"
+#include "public_editor.h"
+#include "region_layering_order_editor.h"
+#include "rgb_macros.h"
+#include "rhythm_ferret.h"
+#include "selection.h"
+#include "sfdb_ui.h"
+#include "simpleline.h"
+#include "tempo_lines.h"
+#include "time_axis_view.h"
+#include "utils.h"
 
 #include "i18n.h"
 
@@ -260,15 +262,13 @@ Editor::Editor ()
 
          /* tool bar related */
 
-       , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
+       , zoom_range_clock (new AudioClock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true))
 
        , toolbar_selection_clock_table (2,3)
 
        , automation_mode_button (_("mode"))
-       , global_automation_button (_("automation"))
 
        , _toolbar_viewport (*manage (new Gtk::Adjustment (0, 0, 1e10)), *manage (new Gtk::Adjustment (0, 0, 1e10)))
-       , midi_panic_button (_("Panic"))
 
 #ifdef WITH_CMT
        , image_socket_listener(0)
@@ -276,13 +276,14 @@ Editor::Editor ()
 
          /* nudge */
 
-       , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
+       , nudge_clock (new AudioClock (X_("nudge"), false, X_("NudgeClock"), true, false, true))
        , meters_running(false)
        , _pending_locate_request (false)
        , _pending_initial_locate (false)
        , _last_cut_copy_source_track (0)
 
        , _region_selection_change_updates_region_list (true)
+       , _following_mixer_selection (false)
 {
        constructed = false;
 
@@ -387,7 +388,7 @@ Editor::Editor ()
 
        zoom_focus = ZoomFocusLeft;
        set_zoom_focus (ZoomFocusLeft);
-       zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
+       zoom_range_clock->ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
 
        bbt_label.set_name ("EditorTimeButton");
        bbt_label.set_size_request (-1, (int)timebar_height);
@@ -702,6 +703,7 @@ Editor::Editor ()
        ControlProtocol::ZoomIn.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, false), gui_context());
        ControlProtocol::ZoomOut.connect (*this, invalidator (*this), boost::bind (&Editor::temporal_zoom_step, this, true), gui_context());
        ControlProtocol::ScrollTimeline.connect (*this, invalidator (*this), ui_bind (&Editor::control_scroll, this, _1), gui_context());
+       ControlProtocol::SelectByRID.connect (*this, invalidator (*this), ui_bind (&Editor::control_select, this, _1), gui_context());
        BasicUI::AccessAction.connect (*this, invalidator (*this), ui_bind (&Editor::access_action, this, _1, _2), gui_context());
 
        /* problematic: has to return a value and thus cannot be x-thread */
@@ -869,6 +871,7 @@ Editor::show_window ()
 
                if (current_mixer_strip) {
                        current_mixer_strip->hide_things ();
+                       current_mixer_strip->parameter_changed ("mixer-strip-visibility");
                }
        }
 
@@ -896,19 +899,45 @@ Editor::zoom_adjustment_changed ()
                return;
        }
 
-       double fpu = zoom_range_clock.current_duration() / _canvas_width;
+       double fpu = zoom_range_clock->current_duration() / _canvas_width;
 
        if (fpu < 1.0) {
                fpu = 1.0;
-               zoom_range_clock.set ((framepos_t) floor (fpu * _canvas_width));
+               zoom_range_clock->set ((framepos_t) floor (fpu * _canvas_width));
        } else if (fpu > _session->current_end_frame() / _canvas_width) {
                fpu = _session->current_end_frame() / _canvas_width;
-               zoom_range_clock.set ((framepos_t) floor (fpu * _canvas_width));
+               zoom_range_clock->set ((framepos_t) floor (fpu * _canvas_width));
        }
 
        temporal_zoom (fpu);
 }
 
+void
+Editor::control_select (uint32_t rid) 
+{
+       /* handles the (static) signal from the ControlProtocol class that
+        * requests setting the selected track to a given RID
+        */
+        
+       if (!_session) {
+               return;
+       }
+
+       boost::shared_ptr<Route> r = _session->route_by_remote_id (rid);
+
+       if (!r) {
+               return;
+       }
+
+       TimeAxisView* tav = axis_view_from_route (r);
+
+       if (tav) {
+               selection->set (tav);
+       } else {
+               selection->clear_tracks ();
+       }
+}
+
 void
 Editor::control_scroll (float fraction)
 {
@@ -1084,9 +1113,9 @@ Editor::set_session (Session *t)
                return;
        }
 
-       zoom_range_clock.set_session (_session);
+       zoom_range_clock->set_session (_session);
        _playlist_selector->set_session (_session);
-       nudge_clock.set_session (_session);
+       nudge_clock->set_session (_session);
        _summary->set_session (_session);
        _group_tabs->set_session (_session);
        _route_groups->set_session (_session);
@@ -1109,6 +1138,44 @@ Editor::set_session (Session *t)
 
        compute_fixed_ruler_scale ();
 
+       /* Make sure we have auto loop and auto punch ranges */
+
+       Location* loc = _session->locations()->auto_loop_location();
+       if (loc == 0) {
+               loc = new Location (*_session, 0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
+
+               if (loc->start() == loc->end()) {
+                       loc->set_end (loc->start() + 1);
+               }
+
+               _session->locations()->add (loc, false);
+               _session->set_auto_loop_location (loc);
+       } else {
+               // force name
+               loc->set_name (_("Loop"));
+       }
+
+       loc = _session->locations()->auto_punch_location();
+
+       if (loc == 0) {
+               loc = new Location (*_session, 0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
+
+               if (loc->start() == loc->end()) {
+                       loc->set_end (loc->start() + 1);
+               }
+
+               _session->locations()->add (loc, false);
+               _session->set_auto_punch_location (loc);
+       } else {
+               // force name
+               loc->set_name (_("Punch"));
+       }
+
+       refresh_location_display ();
+
+       /* This must happen after refresh_location_display(), as (amongst other things) we restore
+          the selected Marker; this needs the LocationMarker list to be available.
+       */
        XMLNode* node = ARDOUR_UI::instance()->editor_settings();
        set_state (*node, Stateful::loading_state_version);
 
@@ -1145,52 +1212,19 @@ Editor::set_session (Session *t)
                bbt.beats = 0;
                bbt.ticks = 120;
                framepos_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
-               nudge_clock.set_mode(AudioClock::BBT);
-               nudge_clock.set (pos, true, 0, AudioClock::BBT);
+               nudge_clock->set_mode(AudioClock::BBT);
+               nudge_clock->set (pos, true, 0, AudioClock::BBT);
 
        } else {
-               nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
+               nudge_clock->set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
        }
 
        playhead_cursor->canvas_item.show ();
 
-       Location* loc = _session->locations()->auto_loop_location();
-       if (loc == 0) {
-               loc = new Location (*_session, 0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
-
-               if (loc->start() == loc->end()) {
-                       loc->set_end (loc->start() + 1);
-               }
-
-               _session->locations()->add (loc, false);
-               _session->set_auto_loop_location (loc);
-       } else {
-               // force name
-               loc->set_name (_("Loop"));
-       }
-
-       loc = _session->locations()->auto_punch_location();
-
-       if (loc == 0) {
-               loc = new Location (*_session, 0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
-
-               if (loc->start() == loc->end()) {
-                       loc->set_end (loc->start() + 1);
-               }
-
-               _session->locations()->add (loc, false);
-               _session->set_auto_punch_location (loc);
-       } else {
-               // force name
-               loc->set_name (_("Punch"));
-       }
-
        boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
        Config->map_parameters (pc);
        _session->config.map_parameters (pc);
 
-       refresh_location_display ();
-
        restore_ruler_visibility ();
        //tempo_map_changed (PropertyChange (0));
        _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
@@ -1216,7 +1250,7 @@ Editor::set_session (Session *t)
        }
 
        /* register for undo history */
-       _session->register_with_memento_command_factory(_id, this);
+       _session->register_with_memento_command_factory(id(), this);
 
        ActionManager::ui_manager->signal_pre_activate().connect (sigc::mem_fun (*this, &Editor::action_pre_activated));
 
@@ -1855,7 +1889,7 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
        edit_items.push_back (MenuElem (_("Consolidate Range With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), true, true)));
        edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
        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)));
+       edit_items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_selection)));
 }
 
 
@@ -2129,19 +2163,15 @@ Editor::set_state (const XMLNode& node, int /*version*/)
 {
        const XMLProperty* prop;
        XMLNode* geometry;
-       int x, y, xoff, yoff;
+       int x, y;
        Gdk::Geometry g;
 
-       if ((prop = node.property ("id")) != 0) {
-               _id = prop->value ();
-       }
+       set_id (node);
 
        g.base_width = default_width;
        g.base_height = default_height;
        x = 1;
        y = 1;
-       xoff = 0;
-       yoff = 21;
 
        if ((geometry = find_named_node (node, "geometry")) != 0) {
 
@@ -2173,19 +2203,6 @@ Editor::set_state (const XMLNode& node, int /*version*/)
                if (prop) {
                        y = atoi (prop->value());
                }
-
-               if ((prop = geometry->property ("x_off")) == 0) {
-                       prop = geometry->property ("x-off");
-               }
-               if (prop) {
-                       xoff = atoi (prop->value());
-               }
-               if ((prop = geometry->property ("y_off")) == 0) {
-                       prop = geometry->property ("y-off");
-               }
-               if (prop) {
-                       yoff = atoi (prop->value());
-               }
        }
 
        set_default_size (g.base_width, g.base_height);
@@ -2282,7 +2299,7 @@ Editor::set_state (const XMLNode& node, int /*version*/)
        }
 
        if ((prop = node.property ("stationary-playhead"))) {
-               bool yn = (prop->value() == "yes");
+               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) {
@@ -2361,15 +2378,14 @@ Editor::get_state ()
        XMLNode* node = new XMLNode ("Editor");
        char buf[32];
 
-       _id.print (buf, sizeof (buf));
+       id().print (buf, sizeof (buf));
        node->add_property ("id", buf);
 
        if (is_realized()) {
                Glib::RefPtr<Gdk::Window> win = get_window();
 
-               int x, y, xoff, yoff, width, height;
+               int x, y, width, height;
                win->get_root_origin(x, y);
-               win->get_position(xoff, yoff);
                win->get_size(width, height);
 
                XMLNode* geometry = new XMLNode ("geometry");
@@ -2382,10 +2398,6 @@ Editor::get_state ()
                geometry->add_property("x-pos", string(buf));
                snprintf(buf, sizeof(buf), "%d", y);
                geometry->add_property("y-pos", string(buf));
-               snprintf(buf, sizeof(buf), "%d", xoff);
-               geometry->add_property("x-off", string(buf));
-               snprintf(buf, sizeof(buf), "%d", yoff);
-               geometry->add_property("y-off", string(buf));
                snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
                geometry->add_property("edit-horizontal-pane-pos", string(buf));
                geometry->add_property("notebook-shrunk", _notebook_shrunk ? "1" : "0");
@@ -2748,6 +2760,7 @@ Editor::setup_toolbar ()
        /* table containing mode buttons */
 
        HBox* mouse_mode_button_box = manage (new HBox ());
+       mouse_mode_button_box->set_spacing (2);
 
        if (Profile->get_sae()) {
                mouse_mode_button_box->pack_start (mouse_move_button);
@@ -2797,48 +2810,30 @@ Editor::setup_toolbar ()
        _mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
                                                          &_mouse_mode_tearoff->tearoff_window(), 1));
 
-       mouse_move_button.set_mode (false);
-       mouse_select_button.set_mode (false);
-       mouse_gain_button.set_mode (false);
-       mouse_zoom_button.set_mode (false);
-       mouse_timefx_button.set_mode (false);
-       mouse_audition_button.set_mode (false);
-       join_object_range_button.set_mode (false);
-
-       mouse_move_button.set_name ("MouseModeButton");
-       mouse_select_button.set_name ("MouseModeButton");
-       mouse_gain_button.set_name ("MouseModeButton");
-       mouse_zoom_button.set_name ("MouseModeButton");
-       mouse_timefx_button.set_name ("MouseModeButton");
-       mouse_audition_button.set_name ("MouseModeButton");
-       internal_edit_button.set_name ("MouseModeButton");
-       join_object_range_button.set_name ("MouseModeButton");
-
-       mouse_move_button.unset_flags (CAN_FOCUS);
-       mouse_select_button.unset_flags (CAN_FOCUS);
-       mouse_gain_button.unset_flags (CAN_FOCUS);
-       mouse_zoom_button.unset_flags (CAN_FOCUS);
-       mouse_timefx_button.unset_flags (CAN_FOCUS);
-       mouse_audition_button.unset_flags (CAN_FOCUS);
-       internal_edit_button.unset_flags (CAN_FOCUS);
-       join_object_range_button.unset_flags (CAN_FOCUS);
-
        /* Zoom */
 
-       _zoom_box.set_spacing (1);
-       _zoom_box.set_border_width (0);
+       _zoom_box.set_spacing (2);
+       _zoom_box.set_border_width (2);
+
+       RefPtr<Action> act;
 
-       zoom_in_button.set_name ("EditorTimeButton");
-       zoom_in_button.set_image (*(manage (new Image (::get_icon ("zoom_in")))));
-       zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
+       zoom_in_button.set_name ("zoom button");
+       zoom_in_button.set_image (::get_icon ("zoom_in"));
+       zoom_in_button.set_tweaks (ArdourButton::ShowClick);
+       act = ActionManager::get_action (X_("Editor"), X_("temporal-zoom-in"));
+       zoom_in_button.set_related_action (act);
 
-       zoom_out_button.set_name ("EditorTimeButton");
-       zoom_out_button.set_image (*(manage (new Image (::get_icon ("zoom_out")))));
-       zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
+       zoom_out_button.set_name ("zoom button");
+       zoom_out_button.set_image (::get_icon ("zoom_out"));
+       zoom_out_button.set_tweaks (ArdourButton::ShowClick);
+       act = ActionManager::get_action (X_("Editor"), X_("temporal-zoom-out"));
+       zoom_out_button.set_related_action (act);
 
-       zoom_out_full_button.set_name ("EditorTimeButton");
-       zoom_out_full_button.set_image (*(manage (new Image (::get_icon ("zoom_full")))));
-       zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
+       zoom_out_full_button.set_name ("zoom button");
+       zoom_out_full_button.set_image (::get_icon ("zoom_full"));
+       zoom_out_full_button.set_tweaks (ArdourButton::ShowClick);
+       act = ActionManager::get_action (X_("Editor"), X_("zoom-to-session"));
+       zoom_out_full_button.set_related_action (act);
 
        zoom_focus_selector.set_name ("ZoomFocusSelector");
        set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
@@ -2854,7 +2849,7 @@ Editor::setup_toolbar ()
        tav_expand_button.set_name ("TrackHeightButton");
        tav_expand_button.set_size_request (-1, 20);
        tav_expand_button.add (*(manage (new Image (::get_icon ("tav_exp")))));
-       RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("expand-tracks"));
+       act = ActionManager::get_action (X_("Editor"), X_("expand-tracks"));
        act->connect_proxy (tav_expand_button);
 
        tav_shrink_button.set_name ("TrackHeightButton");
@@ -2899,7 +2894,7 @@ Editor::setup_toolbar ()
        /* Nudge */
 
        HBox *nudge_box = manage (new HBox);
-       nudge_box->set_spacing(1);
+       nudge_box->set_spacing (2);
        nudge_box->set_border_width (2);
 
        nudge_forward_button.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::nudge_forward_release), false);
@@ -2907,7 +2902,7 @@ Editor::setup_toolbar ()
 
        nudge_box->pack_start (nudge_backward_button, false, false);
        nudge_box->pack_start (nudge_forward_button, false, false);
-       nudge_box->pack_start (nudge_clock, false, false);
+       nudge_box->pack_start (*nudge_clock, false, false);
 
 
        /* Pack everything in... */
@@ -2986,19 +2981,9 @@ Editor::setup_tooltips ()
        ARDOUR_UI::instance()->set_tip (snap_mode_selector, _("Snap/Grid Mode"));
        ARDOUR_UI::instance()->set_tip (edit_point_selector, _("Edit point"));
        ARDOUR_UI::instance()->set_tip (midi_sound_notes, _("Sound Notes"));
-       ARDOUR_UI::instance()->set_tip (midi_panic_button, _("Send note off and reset controller messages on all MIDI channels"));
        ARDOUR_UI::instance()->set_tip (edit_mode_selector, _("Edit Mode"));
 }
 
-void
-Editor::midi_panic ()
-{
-       cerr << "MIDI panic\n";
-
-       if (_session) {
-               _session->midi_panic();
-       }
-}
 
 void
 Editor::setup_midi_toolbar ()
@@ -3008,15 +2993,12 @@ Editor::setup_midi_toolbar ()
        /* Midi sound notes */
        midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
        midi_sound_notes.unset_flags (CAN_FOCUS);
+       midi_sound_notes.set_name (X_("MidiSoundNotesButton"));
 
        /* Panic */
 
-       act = ActionManager::get_action (X_("MIDI"), X_("panic"));
-       midi_panic_button.set_name("MidiPanicButton");
-       act->connect_proxy (midi_panic_button);
-
        panic_box.pack_start (midi_sound_notes , true, true);
-       panic_box.pack_start (midi_panic_button, true, true);
+       // panic_box.pack_start (midi_panic_button, true, true);
 }
 
 int
@@ -3526,7 +3508,6 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
        XMLProperty* prop;
        char buf[32];
        XMLNode* node = ARDOUR_UI::instance()->editor_settings();
-       int width, height;
 
        enum Pane {
                Horizontal = 0x1,
@@ -3535,22 +3516,7 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
 
        static Pane done;
 
-       XMLNode* geometry;
-
-       width = default_width;
-       height = default_height;
-
-       if ((geometry = find_named_node (*node, "geometry")) != 0) {
-
-               prop = geometry->property ("x-size");
-               if (prop) {
-                       width = atoi (prop->value());
-               }
-               prop = geometry->property ("y-size");
-               if (prop) {
-                       height = atoi (prop->value());
-               }
-       }
+       XMLNode* geometry = find_named_node (*node, "geometry");
 
        if (which == static_cast<Paned*> (&edit_pane)) {
 
@@ -3821,7 +3787,7 @@ Editor::get_nudge_distance (framepos_t pos, framecnt_t& next)
 {
        framecnt_t ret;
 
-       ret = nudge_clock.current_duration (pos);
+       ret = nudge_clock->current_duration (pos);
        next = ret + 1; /* XXXX fix me */
 
        return ret;
@@ -3974,12 +3940,16 @@ Editor::maximise_editing_space ()
                edit_pane.set_position (post_maximal_horizontal_pane_position);
        }
 
-       if (post_maximal_editor_height) {
-               editor_summary_pane.set_position (post_maximal_vertical_pane_position -
-                       abs(post_maximal_editor_height - pre_maximal_editor_height));
-       } else {
-               editor_summary_pane.set_position (post_maximal_vertical_pane_position);
-       }
+       /* Hack: we must do this in an idle handler for it to work; see comment in
+          restore_editing_space()
+       */
+          
+       Glib::signal_idle().connect (
+               sigc::bind (
+                       sigc::mem_fun (*this, &Editor::idle_reset_vertical_pane_position),
+                       post_maximal_vertical_pane_position
+                       )
+               );
 
        if (Config->get_keep_tearoffs()) {
                _mouse_mode_tearoff->set_visible (true);
@@ -3991,6 +3961,13 @@ Editor::maximise_editing_space ()
 
 }
 
+bool
+Editor::idle_reset_vertical_pane_position (int p)
+{
+       editor_summary_pane.set_position (p);
+       return false;
+}
+
 void
 Editor::restore_editing_space ()
 {
@@ -4015,7 +3992,17 @@ Editor::restore_editing_space ()
        post_maximal_editor_height = this->get_height();
 
        edit_pane.set_position (pre_maximal_horizontal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
-       editor_summary_pane.set_position (pre_maximal_vertical_pane_position + abs(this->get_height() - pre_maximal_editor_height));
+
+       /* This is a bit of a hack, but it seems that if you set the vertical pane position
+          here it gets reset to some wrong value after this method has finished.  Doing
+          the setup in an idle callback seems to work.
+       */
+       Glib::signal_idle().connect (
+               sigc::bind (
+                       sigc::mem_fun (*this, &Editor::idle_reset_vertical_pane_position),
+                       pre_maximal_vertical_pane_position
+                       )
+               );
 }
 
 /**
@@ -4128,6 +4115,16 @@ Editor::reposition_and_zoom (framepos_t frame, double fpu)
        }
 }
 
+Editor::VisualState::VisualState ()
+       : gui_state (new GUIObjectState)
+{
+}
+
+Editor::VisualState::~VisualState ()
+{
+       delete gui_state;
+}
+
 Editor::VisualState*
 Editor::current_visual_state (bool with_tracks)
 {
@@ -4137,10 +4134,8 @@ Editor::current_visual_state (bool with_tracks)
        vs->leftmost_frame = leftmost_frame;
        vs->zoom_focus = zoom_focus;
 
-       if (with_tracks) {
-               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-                       vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
-               }
+       if (with_tracks) {      
+               *(vs->gui_state) = *ARDOUR_UI::instance()->gui_object_state;
        }
 
        return vs;
@@ -4195,22 +4190,14 @@ Editor::use_visual_state (VisualState& vs)
 
        set_zoom_focus (vs.zoom_focus);
        reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
+       
+       *ARDOUR_UI::instance()->gui_object_state = *vs.gui_state;
 
-       for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
-               TrackViewList::iterator t;
-
-               /* check if the track still exists - it could have been deleted */
-
-               if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
-                       (*t)->set_state (*(i->second), Stateful::loading_state_version);
-               }
-       }
-
-
-       if (!vs.track_states.empty()) {
-               _routes->update_visibility ();
+       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {    
+               (*i)->reset_visual_state ();
        }
 
+       _routes->update_visibility ();
        _routes->resume_redisplay ();
 
        no_save_visual = false;
@@ -4254,8 +4241,8 @@ Editor::post_zoom ()
 
        framepos_t frames = (framepos_t) floor (frames_per_unit * _canvas_width);
 
-       if (frames_per_unit != zoom_range_clock.current_duration()) {
-               zoom_range_clock.set (frames);
+       if (frames_per_unit != zoom_range_clock->current_duration()) {
+               zoom_range_clock->set (frames);
        }
 
        if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
@@ -4712,13 +4699,13 @@ void
 Editor::first_idle ()
 {
        MessageDialog* dialog = 0;
-
+       
        if (track_views.size() > 1) {
-               dialog = new MessageDialog (*this,
-                                           string_compose (_("Please wait while %1 loads visual data"), PROGRAM_NAME),
-                                           true,
-                                           Gtk::MESSAGE_INFO,
-                                           Gtk::BUTTONS_NONE);
+               dialog = new MessageDialog (
+                       *this,
+                       string_compose (_("Please wait while %1 loads visual data."), PROGRAM_NAME),
+                       true
+                       );
                dialog->present ();
                ARDOUR_UI::instance()->flush_pending ();
        }
@@ -4731,7 +4718,6 @@ Editor::first_idle ()
        _routes->redisplay ();
 
        delete dialog;
-
        _have_idled = true;
 }
 
@@ -4875,9 +4861,11 @@ Editor::handle_new_route (RouteList& routes)
                DataType dt = route->input()->default_type();
 
                if (dt == ARDOUR::DataType::AUDIO) {
-                       rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
+                       rtv = new AudioTimeAxisView (*this, _session, *track_canvas);
+                       rtv->set_route (route);
                } else if (dt == ARDOUR::DataType::MIDI) {
-                       rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
+                       rtv = new MidiTimeAxisView (*this, _session, *track_canvas);
+                       rtv->set_route (route);
                } else {
                        throw unknown_type();
                }
@@ -5019,7 +5007,7 @@ Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
 
 /** Find a RouteTimeAxisView by the ID of its route */
 RouteTimeAxisView*
-Editor::get_route_view_by_route_id (PBD::ID& id) const
+Editor::get_route_view_by_route_id (const PBD::ID& id) const
 {
        RouteTimeAxisView* v;
 
@@ -5349,8 +5337,8 @@ Editor::session_going_away ()
        }
        track_views.clear ();
 
-       zoom_range_clock.set_session (0);
-       nudge_clock.set_session (0);
+       zoom_range_clock->set_session (0);
+       nudge_clock->set_session (0);
 
        editor_list_button.set_active(false);
        editor_list_button.set_sensitive(false);
@@ -5497,3 +5485,20 @@ Editor::notebook_tab_clicked (GdkEventButton* ev, Gtk::Widget* page)
        return true;
 }
 
+void
+Editor::popup_control_point_context_menu (ArdourCanvas::Item* item, GdkEvent* event)
+{
+       using namespace Menu_Helpers;
+       
+       MenuList& items = _control_point_context_menu.items ();
+       items.clear ();
+       
+       items.push_back (MenuElem (_("Edit..."), sigc::bind (sigc::mem_fun (*this, &Editor::edit_control_point), item)));
+       items.push_back (MenuElem (_("Delete"), sigc::bind (sigc::mem_fun (*this, &Editor::remove_control_point), item)));
+       if (!can_remove_control_point (item)) {
+               items.back().set_sensitive (false);
+       }
+
+       _control_point_context_menu.popup (event->button.button, event->button.time);
+}
+