solo models work again (amazing how hard this was); remove crufty debug output; remov...
[ardour.git] / gtk2_ardour / editor.cc
index 6c276f3b0c96591c1a219afd87400e608439451c..87490a67b287d1f5b8a4b2291977f7d91b85b9f4 100644 (file)
 
 #include <sigc++/bind.h>
 
-#include <pbd/convert.h>
-#include <pbd/error.h>
-#include <pbd/enumwriter.h>
-#include <pbd/memento_command.h>
+#include "pbd/convert.h"
+#include "pbd/error.h"
+#include "pbd/enumwriter.h"
+#include "pbd/memento_command.h"
 
 #include <glibmm/miscutils.h>
 #include <gtkmm/image.h>
 #include <gtkmm2ext/window_title.h>
 #include <gtkmm2ext/choice.h>
 
-#include <ardour/audio_track.h>
-#include <ardour/audio_diskstream.h>
-#include <ardour/plugin_manager.h>
-#include <ardour/location.h>
-#include <ardour/audioplaylist.h>
-#include <ardour/audioregion.h>
-#include <ardour/midi_region.h>
-#include <ardour/session_route.h>
-#include <ardour/session_directory.h>
-#include <ardour/session_state_utils.h>
-#include <ardour/tempo.h>
-#include <ardour/utils.h>
-#include <ardour/profile.h>
-
-#include <control_protocol/control_protocol.h>
+#include "ardour/audio_diskstream.h"
+#include "ardour/audio_track.h"
+#include "ardour/audioplaylist.h"
+#include "ardour/audioregion.h"
+#include "ardour/location.h"
+#include "ardour/midi_region.h"
+#include "ardour/plugin_manager.h"
+#include "ardour/profile.h"
+#include "ardour/route_group.h"
+#include "ardour/session_directory.h"
+#include "ardour/session_route.h"
+#include "ardour/session_state_utils.h"
+#include "ardour/tempo.h"
+#include "ardour/utils.h"
+
+#include "control_protocol/control_protocol.h"
 
 #include "ardour_ui.h"
 #include "editor.h"
 #include "simpleline.h"
 #include "rhythm_ferret.h"
 #include "actions.h"
-
-#ifdef FFT_ANALYSIS
+#include "tempo_lines.h"
 #include "analysis_window.h"
-#endif
+#include "bundle_manager.h"
+#include "global_port_matrix.h"
+#include "editor_drag.h"
 
 #include "i18n.h"
 
@@ -209,7 +211,7 @@ Editor::Editor ()
          range_mark_label (_("Range Markers")),
          transport_mark_label (_("Loop/Punch Ranges")),
          cd_mark_label (_("CD Markers")),
-         edit_packer (3, 4, true),
+         edit_packer (4, 4, true),
 
          /* the values here don't matter: layout widgets
             reset them as needed.
@@ -228,6 +230,9 @@ Editor::Editor ()
          automation_mode_button (_("mode")),
          global_automation_button (_("automation")),
 
+         midi_panic_button (_("Panic")),
+         midi_tools_tearoff (0),
+
 #ifdef WITH_CMT
          image_socket_listener(0),
 #endif
@@ -235,7 +240,8 @@ Editor::Editor ()
          /* nudge */
 
          nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
-         meters_running(false)
+         meters_running(false),
+         _pending_locate_request (false)
 
 {
        constructed = false;
@@ -250,22 +256,16 @@ Editor::Editor ()
        selection = new Selection (this);
        cut_buffer = new Selection (this);
 
-       selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
-       selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
-       selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
-       selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
-       selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
-
        clicked_regionview = 0;
        clicked_axisview = 0;
        clicked_routeview = 0;
        clicked_crossfadeview = 0;
        clicked_control_point = 0;
        last_update_frame = 0;
-       drag_info.item = 0;
-       drag_info.copied_location = 0;
+       _drag = 0;
        current_mixer_strip = 0;
        current_bbt_points = 0;
+       tempo_lines = 0;
        
        snap_type_strings =  I18N (_snap_type_strings);
        snap_mode_strings =  I18N (_snap_mode_strings);
@@ -277,8 +277,8 @@ Editor::Editor ()
        
        snap_threshold = 5.0;
        bbt_beat_subdivision = 4;
-       canvas_width = 0;
-       canvas_height = 0;
+       _canvas_width = 0;
+       _canvas_height = 0;
        last_autoscroll_x = 0;
        last_autoscroll_y = 0;
        autoscroll_active = false;
@@ -286,19 +286,14 @@ Editor::Editor ()
        interthread_progress_window = 0;
        logo_item = 0;
 
-#ifdef FFT_ANALYSIS
        analysis_window = 0;
-#endif
 
        current_interthread_info = 0;
        _show_measures = true;
-       _show_waveforms = true;
        _show_waveforms_recording = true;
-       first_action_message = 0;
-       export_dialog = 0;
-       export_range_markers_dialog = 0;
        show_gain_after_trim = false;
-       ignore_route_list_reorder = false;
+       route_redisplay_does_not_sync_order_keys = false;
+       route_redisplay_does_not_reset_order_keys = false;
        no_route_list_redisplay = false;
        verbose_cursor_on = true;
        route_removal = false;
@@ -338,16 +333,18 @@ Editor::Editor ()
        _new_regionviews_show_envelope = false;
        current_timefx = 0;
        in_edit_group_row_change = false;
-       last_canvas_frame = 0;
        playhead_cursor = 0;
        button_release_can_deselect = true;
-       canvas_idle_queued = false;
        _dragging_playhead = false;
        _dragging_edit_point = false;
        _dragging_hscrollbar = false;
        select_new_marker = false;
        zoomed_to_region = false;
        rhythm_ferret = 0;
+       _bundle_manager = 0;
+       for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
+               _global_port_matrix[*i] = 0;
+       }
        allow_vertical_scroll = false;
        no_save_visual = false;
        need_resize_line = false;
@@ -356,11 +353,9 @@ Editor::Editor ()
        no_region_list_redisplay = false;
        resize_idle_id = -1;
 
-       _scrubbing = false;
        scrubbing_direction = 0;
 
        sfbrowser = 0;
-       ignore_route_order_sync = false;
 
        location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
        location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
@@ -368,10 +363,8 @@ Editor::Editor ()
        location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
        location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
 
-       range_marker_drag_rect = 0;
-       marker_drag_line = 0;
-       tempo_map_change_idle_handler_id = -1;
        set_midi_edit_mode (MidiEditPencil, true);
+       _edit_point = EditAtMouse;
        set_mouse_mode (MouseObject, true);
 
        frames_per_unit = 2048; /* too early to use reset_zoom () */
@@ -381,110 +374,122 @@ Editor::Editor ()
        set_zoom_focus (ZoomFocusLeft);
        zoom_range_clock.ValueChanged.connect (mem_fun(*this, &Editor::zoom_adjustment_changed));
 
-       initialize_rulers ();
-       initialize_canvas ();
-
-       edit_controls_vbox.set_spacing (0);
-       horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
-       vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
-       track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
-
-       controls_layout.add (edit_controls_vbox);
-       controls_layout.set_name ("EditControlsBase");
-       controls_layout.add_events (Gdk::SCROLL_MASK);
-       controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
-       
-       controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
-       controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
-       controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
-
-       edit_vscrollbar.set_adjustment (vertical_adjustment);
-       edit_hscrollbar.set_adjustment (horizontal_adjustment);
-
-       edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
-       edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
-       edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
-
-       edit_hscrollbar.set_name ("EditorHScrollbar");
-
-       build_cursors ();
-       setup_toolbar ();
-       setup_midi_toolbar ();
-
-       edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
-       
-       ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
-       ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
-                       0.0, 1.0, 100.0, 1.0));
-       pad_line_1->property_color_rgba() = 0xFF0000FF;
-       pad_line_1->show();
-       time_pad->show();
-
-       time_canvas_vbox.pack_start (*_ruler_separator, false, false);
-       time_canvas_vbox.pack_start (*minsec_ruler, false, false);
-       time_canvas_vbox.pack_start (*smpte_ruler, false, false);
-       time_canvas_vbox.pack_start (*frames_ruler, false, false);
-       time_canvas_vbox.pack_start (*bbt_ruler, false, false);
-       //time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
-       time_canvas_vbox.set_size_request (-1, -1);
        bbt_label.set_name ("EditorTimeButton");
        bbt_label.set_size_request (-1, (int)timebar_height);
        bbt_label.set_alignment (1.0, 0.5);
        bbt_label.set_padding (5,0);
+       bbt_label.hide ();
+       bbt_label.set_no_show_all();
        minsec_label.set_name ("EditorTimeButton");
        minsec_label.set_size_request (-1, (int)timebar_height);
        minsec_label.set_alignment (1.0, 0.5);
        minsec_label.set_padding (5,0);
+       minsec_label.hide ();
+       minsec_label.set_no_show_all();
        smpte_label.set_name ("EditorTimeButton");
        smpte_label.set_size_request (-1, (int)timebar_height);
        smpte_label.set_alignment (1.0, 0.5);
        smpte_label.set_padding (5,0);
+       smpte_label.hide ();
+       smpte_label.set_no_show_all();
        frame_label.set_name ("EditorTimeButton");
        frame_label.set_size_request (-1, (int)timebar_height);
        frame_label.set_alignment (1.0, 0.5);
        frame_label.set_padding (5,0);
+       frame_label.hide ();
+       frame_label.set_no_show_all();
 
        tempo_label.set_name ("EditorTimeButton");
        tempo_label.set_size_request (-1, (int)timebar_height);
        tempo_label.set_alignment (1.0, 0.5);
        tempo_label.set_padding (5,0);
+       tempo_label.hide();
+       tempo_label.set_no_show_all();
        meter_label.set_name ("EditorTimeButton");
        meter_label.set_size_request (-1, (int)timebar_height);
-       meter_label.set_alignment (1.0, 0.5);
+       meter_label.set_alignment (0.0, 0.5);
        meter_label.set_padding (5,0);
+       meter_label.hide();
+       meter_label.set_no_show_all();
        mark_label.set_name ("EditorTimeButton");
        mark_label.set_size_request (-1, (int)timebar_height);
        mark_label.set_alignment (1.0, 0.5);
        mark_label.set_padding (5,0);
+       mark_label.hide();
+       mark_label.set_no_show_all();
        cd_mark_label.set_name ("EditorTimeButton");
        cd_mark_label.set_size_request (-1, (int)timebar_height);
        cd_mark_label.set_alignment (1.0, 0.5);
        cd_mark_label.set_padding (5,0);
+       cd_mark_label.hide();
+       cd_mark_label.set_no_show_all();
        range_mark_label.set_name ("EditorTimeButton");
        range_mark_label.set_size_request (-1, (int)timebar_height);
        range_mark_label.set_alignment (1.0, 0.5);
        range_mark_label.set_padding (5,0);
+       range_mark_label.hide();
+       range_mark_label.set_no_show_all();
        transport_mark_label.set_name ("EditorTimeButton");
        transport_mark_label.set_size_request (-1, (int)timebar_height);
        transport_mark_label.set_alignment (1.0, 0.5);
        transport_mark_label.set_padding (5,0);
+       transport_mark_label.hide();
+       transport_mark_label.set_no_show_all();
+
+       initialize_rulers ();
+       _summary = new EditorSummary (this);
+       initialize_canvas ();
+
+       selection->TimeChanged.connect (mem_fun(*this, &Editor::time_selection_changed));
+       selection->TracksChanged.connect (mem_fun(*this, &Editor::track_selection_changed));
+       editor_regions_selection_changed_connection = selection->RegionsChanged.connect (mem_fun(*this, &Editor::region_selection_changed));
+       selection->PointsChanged.connect (mem_fun(*this, &Editor::point_selection_changed));
+       selection->MarkersChanged.connect (mem_fun(*this, &Editor::marker_selection_changed));
+
+       edit_controls_vbox.set_spacing (0);
+       horizontal_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::scroll_canvas_horizontally), false);
+       vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
+       track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
 
-       ruler_label_vbox.pack_start (minsec_label, false, false);
-       ruler_label_vbox.pack_start (smpte_label, false, false);
-       ruler_label_vbox.pack_start (frame_label, false, false);
-       ruler_label_vbox.pack_start (bbt_label, false, false);
+       controls_layout.add (edit_controls_vbox);
+       controls_layout.set_name ("EditControlsBase");
+       controls_layout.add_events (Gdk::SCROLL_MASK);
+       controls_layout.signal_scroll_event().connect (mem_fun(*this, &Editor::control_layout_scroll), false);
        
+       controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
+       controls_layout.signal_button_release_event().connect (mem_fun(*this, &Editor::edit_controls_button_release));
+       controls_layout_size_request_connection = controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
+
+       edit_vscrollbar.set_adjustment (vertical_adjustment);
+       edit_hscrollbar.set_adjustment (horizontal_adjustment);
+
+       edit_hscrollbar.signal_button_press_event().connect (mem_fun(*this, &Editor::hscrollbar_button_press), false);
+       edit_hscrollbar.signal_button_release_event().connect (mem_fun(*this, &Editor::hscrollbar_button_release), false);
+       edit_hscrollbar.signal_size_allocate().connect (mem_fun(*this, &Editor::hscrollbar_allocate));
+
+       edit_hscrollbar.set_name ("EditorHScrollbar");
+
+       build_cursors ();
+       setup_toolbar ();
+       setup_midi_toolbar ();
+
+       edit_point_clock.ValueChanged.connect (mem_fun(*this, &Editor::edit_point_clock_changed));
+       
+       ArdourCanvas::Canvas* time_pad = manage(new ArdourCanvas::Canvas());
+       ArdourCanvas::SimpleLine* pad_line_1 = manage(new ArdourCanvas::SimpleLine(*time_pad->root(),
+                       0.0, 1.0, 100.0, 1.0));
+       pad_line_1->property_color_rgba() = 0xFF0000FF;
+       pad_line_1->show();
+       time_pad->show();
+
+       //time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 2);
+       //time_canvas_vbox.set_size_request (-1, -1);
+
        ruler_label_event_box.add (ruler_label_vbox);   
        ruler_label_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
-       ruler_label_event_box.set_name ("TimebarLabelBase");
        ruler_label_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
 
-       time_button_vbox.pack_start (meter_label, false, false);
-       time_button_vbox.pack_start (tempo_label, false, false);
-       time_button_vbox.pack_start (mark_label, false, false);
-
        time_button_event_box.add (time_button_vbox);
-       time_button_event_box.set_name ("TimebarLabelBase");
        time_button_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
        time_button_event_box.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
 
@@ -496,23 +501,22 @@ Editor::Editor ()
 
        time_canvas_event_box.add (time_canvas_vbox);
        time_canvas_event_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
-       
+
        edit_packer.set_col_spacings (0);
        edit_packer.set_row_spacings (0);
        edit_packer.set_homogeneous (false);
        edit_packer.set_border_width (0);
        edit_packer.set_name ("EditorWindow");
-       
-       edit_packer.attach (edit_vscrollbar,         0, 1, 0, 4,    FILL,        FILL|EXPAND, 0, 0);
-       edit_packer.attach (ruler_label_event_box,       1, 2, 0, 1,    FILL,        SHRINK, 0, 0);
-       edit_packer.attach (time_button_event_box,       1, 2, 1, 2,    FILL,        SHRINK, 0, 0);
+
+       edit_packer.attach (ruler_label_event_box,   1, 2, 0, 1,    FILL,        SHRINK, 0, 0);
+       edit_packer.attach (time_button_event_box,   1, 2, 1, 2,    FILL,        SHRINK, 0, 0);
+
        edit_packer.attach (time_canvas_event_box,   2, 3, 0, 1,    FILL|EXPAND, FILL, 0, 0);
 
        edit_packer.attach (controls_layout,         1, 2, 2, 3,    FILL,        FILL|EXPAND, 0, 0);
        edit_packer.attach (track_canvas_event_box,  2, 3, 1, 3,    FILL|EXPAND, FILL|EXPAND, 0, 0);
 
-       edit_packer.attach (zoom_box,                1, 2, 3, 4,    FILL,         FILL, 0, 0);
-       edit_packer.attach (edit_hscrollbar,         2, 3, 3, 4,    FILL|EXPAND,  FILL, 0, 0);
+       edit_packer.attach (*_summary,               0, 3, 3, 4,    FILL|EXPAND, SHRINK, 0, 0);
 
        bottom_hbox.set_border_width (2);
        bottom_hbox.set_spacing (3);
@@ -536,6 +540,7 @@ Editor::Editor ()
 
        route_display_model->signal_row_deleted().connect (mem_fun (*this, &Editor::route_list_delete));
        route_display_model->signal_row_changed().connect (mem_fun (*this, &Editor::route_list_change));
+       route_display_model->signal_rows_reordered().connect (mem_fun (*this, &Editor::route_list_reordered));
 
        route_list_display.signal_button_press_event().connect (mem_fun (*this, &Editor::route_list_display_button_press), false);
 
@@ -624,8 +629,21 @@ Editor::Editor ()
 
        region_list_display.set_model (region_list_model);
        region_list_display.append_column (_("Regions"), region_list_columns.name);
-       region_list_display.set_headers_visible (false);
-
+       region_list_display.append_column (_("Start"), region_list_columns.start);
+       region_list_display.append_column (_("End"), region_list_columns.end);
+       region_list_display.append_column (_("Length"), region_list_columns.length);
+       region_list_display.append_column (_("Sync"), region_list_columns.sync);
+       region_list_display.append_column (_("Fade In"), region_list_columns.fadein);
+       region_list_display.append_column (_("Fade Out"), region_list_columns.fadeout);
+       region_list_display.append_column (_("L"), region_list_columns.locked);
+       region_list_display.append_column (_("G"), region_list_columns.glued);
+       region_list_display.append_column (_("M"), region_list_columns.muted);
+       region_list_display.append_column (_("O"), region_list_columns.opaque);
+       region_list_display.append_column (_("Used"), region_list_columns.used);
+       region_list_display.append_column (_("Path"), region_list_columns.path);
+       region_list_display.set_headers_visible (true);
+       //region_list_display.set_grid_lines (TREE_VIEW_GRID_LINES_BOTH);
+       
        CellRendererText* region_name_cell = dynamic_cast<CellRendererText*>(region_list_display.get_column_cell_renderer (0));
        region_name_cell->property_editable() = true;
        region_name_cell->signal_edited().connect (mem_fun (*this, &Editor::region_name_edit));
@@ -639,7 +657,7 @@ Editor::Editor ()
        
        region_list_display.get_selection()->set_mode (SELECTION_MULTIPLE);
        region_list_display.add_object_drag (region_list_columns.region.index(), "regions");
-
+       
        /* setup DnD handling */
        
        list<TargetEntry> region_list_target_table;
@@ -652,15 +670,19 @@ Editor::Editor ()
        region_list_display.signal_drag_data_received().connect (mem_fun(*this, &Editor::region_list_display_drag_data_received));
 
        region_list_scroller.add (region_list_display);
-       region_list_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
-
+       region_list_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
+       
        region_list_display.signal_key_press_event().connect (mem_fun(*this, &Editor::region_list_display_key_press));
        region_list_display.signal_key_release_event().connect (mem_fun(*this, &Editor::region_list_display_key_release));
        region_list_display.signal_button_press_event().connect (mem_fun(*this, &Editor::region_list_display_button_press), false);
        region_list_display.signal_button_release_event().connect (mem_fun(*this, &Editor::region_list_display_button_release));
-       region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
+       region_list_change_connection = region_list_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::region_list_selection_changed));
        // region_list_display.signal_popup_menu().connect (bind (mem_fun (*this, &Editor::show_region_list_display_context_menu), 1, 0));
        
+       //ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::redisplay_regions));
+       ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (mem_fun(*this, &Editor::update_all_region_rows));
+       ARDOUR::Region::RegionPropertyChanged.connect (mem_fun(*this, &Editor::update_region_row));
+       
        named_selection_scroller.add (named_selection_display);
        named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
 
@@ -717,6 +739,7 @@ Editor::Editor ()
        the_notebook.set_scrollable (true);
        the_notebook.popup_enable ();
        the_notebook.set_tab_pos (Gtk::POS_RIGHT);
+       the_notebook.show_all ();
 
        post_maximal_editor_width = 0;
        post_maximal_pane_position = 0;
@@ -826,8 +849,7 @@ Editor::Editor ()
 Editor::~Editor()
 {
 #ifdef WITH_CMT
-       if(image_socket_listener)
-       {
+       if(image_socket_listener) {
                if(image_socket_listener->is_connected())
                {
                        image_socket_listener->close_connection() ;
@@ -838,15 +860,8 @@ Editor::~Editor()
        }
 #endif
 
-       if (track_canvas) {
-               delete track_canvas;
-               track_canvas = 0;
-       }
-
-       if (track_canvas) {
-               delete track_canvas;
-               track_canvas = 0;
-       }
+       delete track_canvas;
+       delete _drag;
 }
 
 void
@@ -863,6 +878,12 @@ Editor::catch_vanishing_regionview (RegionView *rv)
           audioregionview by itself.
        */
 
+       if (_drag && rv->get_canvas_group() == _drag->item() && !_drag->ending()) {
+               _drag->end_grab (0);
+               delete _drag;
+               _drag = 0;
+       }
+
        if (clicked_regionview == rv) {
                clicked_regionview = 0;
        }
@@ -903,20 +924,25 @@ Editor::set_entered_track (TimeAxisView* tav)
 void
 Editor::show_window ()
 {
-       show_all_children ();
-       
-       /* re-hide editor list if necessary */
-       editor_list_button_toggled ();
+       if (! is_visible ()) {
+               show_all ();
 
-       /* now reset all audio_time_axis heights, because widgets might need
-          to be re-hidden
-       */
-       
-       TimeAxisView *tv;
+               /* re-hide editor list if necessary */
+               editor_list_button_toggled ();
+
+               /* re-hide summary widget if necessary */
+               parameter_changed ("show-summary");
+
+               /* now reset all audio_time_axis heights, because widgets might need
+                  to be re-hidden
+               */
+
+               TimeAxisView *tv;
        
-       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-               tv = (static_cast<TimeAxisView*>(*i));
-               tv->reset_height ();
+               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+                       tv = (static_cast<TimeAxisView*>(*i));
+                       tv->reset_height ();
+               }
        }
 
        present ();
@@ -964,14 +990,14 @@ 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 ((nframes64_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 ((nframes64_t) floor (fpu * canvas_width));
+               zoom_range_clock.set ((nframes64_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 ((nframes64_t) floor (fpu * _canvas_width));
        }
        
        temporal_zoom (fpu);
@@ -1058,8 +1084,6 @@ Editor::access_action (std::string action_group, std::string action_item)
 
        ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
 
-       cout<< "OSC: Recieved: "<< action_item << endl;
-
        RefPtr<Action> act;
        act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
 
@@ -1107,7 +1131,7 @@ Editor::map_position_change (nframes64_t frame)
 void
 Editor::center_screen (nframes64_t frame)
 {
-       double page = canvas_width * frames_per_unit;
+       double page = _canvas_width * frames_per_unit;
 
        /* if we're off the page, then scroll.
         */
@@ -1134,18 +1158,20 @@ Editor::center_screen_internal (nframes64_t frame, float page)
 void
 Editor::handle_new_duration ()
 {
+       if (!session) {
+               return;
+       }
+
        ENSURE_GUI_THREAD (mem_fun (*this, &Editor::handle_new_duration));
+       nframes64_t new_end = session->current_end_frame() + (nframes64_t) floorf (current_page_frames() * 0.10f);
 
-       nframes64_t new_end = session->get_maximum_extent() + (nframes64_t) floorf (current_page_frames() * 0.10f);
-                                 
-       if (new_end > last_canvas_frame) {
-               last_canvas_frame = new_end;
-               horizontal_adjustment.set_upper (last_canvas_frame / frames_per_unit);
-               //reset_scrolling_region ();
-       }
+       horizontal_adjustment.set_upper (new_end / frames_per_unit);
+       horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
 
-       horizontal_adjustment.set_value (leftmost_frame/frames_per_unit);
-       //cerr << "Editor::handle_new_duration () called ha v:l:u:ps:lcf = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << last_canvas_frame << endl;//DEBUG
+       if (horizontal_adjustment.get_value() + _canvas_width > horizontal_adjustment.get_upper()) {
+               horizontal_adjustment.set_value (horizontal_adjustment.get_upper() - _canvas_width);
+       }
+       //cerr << "Editor::handle_new_duration () called ha v:l:u:ps:lcf = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << endl;//DEBUG
 }
 
 void
@@ -1187,6 +1213,8 @@ Editor::connect_to_session (Session *t)
 {
        session = t;
 
+       compute_fixed_ruler_scale ();
+
        /* there are never any selected regions at startup */
 
        sensitize_the_right_region_actions (false);
@@ -1198,10 +1226,6 @@ Editor::connect_to_session (Session *t)
 
        session->request_locate (playhead_cursor->current_frame);
 
-       if (first_action_message) {
-               first_action_message->hide();
-       }
-
        update_title ();
 
        session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away));
@@ -1231,22 +1255,37 @@ Editor::connect_to_session (Session *t)
 
        session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
 
+       session_connections.push_back (session->Located.connect (mem_fun (*this, &Editor::located)));
+       session_connections.push_back (session->config.ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed)));
+
        edit_groups_changed ();
 
+       edit_point_clock.set_mode(AudioClock::BBT);
        edit_point_clock.set_session (session);
        zoom_range_clock.set_session (session);
        _playlist_selector->set_session (session);
        nudge_clock.set_session (session);
-       nudge_clock.set (session->frame_rate() * 5); // default of 5 seconds
+       if (Profile->get_sae()) {
+               BBT_Time bbt;
+               bbt.bars = 0;
+               bbt.beats = 0;
+               bbt.ticks = 120;
+               nframes_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);
+               
+       } else {
+               nudge_clock.set (session->frame_rate() * 5, true, 0, AudioClock::SMPTE); // default of 5 seconds
+       }
+
+       playhead_cursor->canvas_item.show ();
 
        if (rhythm_ferret) {
                rhythm_ferret->set_session (session);
        }
 
-#ifdef FFT_ANALYSIS
        if (analysis_window != 0)
                analysis_window->set_session (session);
-#endif
 
        Location* loc = session->locations()->auto_loop_location();
        if (loc == 0) {
@@ -1275,6 +1314,7 @@ Editor::connect_to_session (Session *t)
        }
 
        Config->map_parameters (mem_fun (*this, &Editor::parameter_changed));
+       session->config.map_parameters (mem_fun (*this, &Editor::parameter_changed));
        
        session->StateSaved.connect (mem_fun(*this, &Editor::session_state_saved));
        
@@ -1295,16 +1335,16 @@ Editor::connect_to_session (Session *t)
        redisplay_named_selections ();
        redisplay_snapshots ();
 
+       restore_ruler_visibility ();
+       //tempo_map_changed (Change (0));
+       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
+
        initial_route_list_display ();
 
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
        }
 
-       restore_ruler_visibility ();
-       //tempo_map_changed (Change (0));
-       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
-
        start_scrolling ();
 
        /* don't show master bus in a new session */
@@ -1346,6 +1386,8 @@ Editor::connect_to_session (Session *t)
        /* register for undo history */
        session->register_with_memento_command_factory(_id, this);
 
+       _summary->set_session (session);
+       
        start_updating ();
 }
 
@@ -1718,7 +1760,6 @@ Editor::build_track_crossfade_context_menu (nframes64_t frame)
        return &track_crossfade_context_menu;
 }
 
-#ifdef FFT_ANALYSIS
 void
 Editor::analyze_region_selection()
 {
@@ -1754,7 +1795,6 @@ Editor::analyze_range_selection()
        
        analysis_window->present();
 }
-#endif /* FFT_ANALYSIS */
 
 Menu*
 Editor::build_track_selection_context_menu (nframes64_t ignored)
@@ -1848,10 +1888,11 @@ void
 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
 {
        using namespace Menu_Helpers;
+       Gtk::MenuItem* foo_item;
        Menu     *region_menu = manage (new Menu);
        MenuList& items       = region_menu->items();
        region_menu->set_name ("ArdourContextMenu");
-       
+
        boost::shared_ptr<AudioRegion> ar;
        boost::shared_ptr<MidiRegion>  mr;
 
@@ -1881,71 +1922,64 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
        items.push_back (MenuElem (_("Export"), mem_fun(*this, &Editor::export_region)));
        items.push_back (MenuElem (_("Bounce"), mem_fun(*this, &Editor::bounce_region_selection)));
 
-#ifdef FFT_ANALYSIS
        if (ar) {
                items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_region_selection)));
        }
-#endif
 
        items.push_back (SeparatorElem());
 
        sigc::connection fooc;
+       boost::shared_ptr<Region> region_to_check;
 
        if (region) {
-               items.push_back (CheckMenuElem (_("Lock")));
-               CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
-               if (region->locked()) {
-                       region_lock_item->set_active();
-               }
-               region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
-
-               items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
-               CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
-
-               switch (region->positional_lock_style()) {
-               case Region::MusicTime:
-                       bbt_glue_item->set_active (true);
-                       break;
-               default:
-                       bbt_glue_item->set_active (false);
-                       break;
-               }
-
-               bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
+               region_to_check = region;
+       } else {
+               region_to_check = selection->regions.front()->region();
+       }
 
-               items.push_back (CheckMenuElem (_("Mute")));
-               CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
-               fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
-               if (region->muted()) {
-                       fooc.block (true);
-                       region_mute_item->set_active();
-                       fooc.block (false);
-               }
+       items.push_back (CheckMenuElem (_("Lock")));
+       CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
+       if (region_to_check->locked()) {
+               region_lock_item->set_active();
+       }
+       region_lock_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_lock));
        
-               if (!Profile->get_sae()) {
-                       items.push_back (CheckMenuElem (_("Opaque")));
-                       CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
-                       fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
-                       if (region->opaque()) {
-                               fooc.block (true);
-                               region_opaque_item->set_active();
-                               fooc.block (false);
-                       }
-               }
-       } else {
-               // multiple regions selected
-               // how should these act? 
-               // here they toggle the property of all selected regions
+       items.push_back (CheckMenuElem (_("Glue to Bars&Beats")));
+       CheckMenuItem* bbt_glue_item = static_cast<CheckMenuItem*>(&items.back());
        
-               items.push_back (MenuElem (_("Lock"), mem_fun(*this, &Editor::toggle_region_lock)));
-               items.push_back (MenuElem (_("Mute"), mem_fun(*this, &Editor::toggle_region_mute)));
-               if (!Profile->get_sae()) {
-                       items.push_back (MenuElem (_("Opaque"), mem_fun(*this, &Editor::toggle_region_opaque)));
+       switch (region_to_check->positional_lock_style()) {
+       case Region::MusicTime:
+               bbt_glue_item->set_active (true);
+               break;
+       default:
+               bbt_glue_item->set_active (false);
+               break;
+       }
+       
+       bbt_glue_item->signal_activate().connect (bind (mem_fun (*this, &Editor::set_region_lock_style), Region::MusicTime));
+       
+       items.push_back (CheckMenuElem (_("Mute")));
+       CheckMenuItem* region_mute_item = static_cast<CheckMenuItem*>(&items.back());
+       fooc = region_mute_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_mute));
+       if (region_to_check->muted()) {
+               fooc.block (true);
+               region_mute_item->set_active();
+               fooc.block (false);
+       }
+       
+       if (!Profile->get_sae()) {
+               items.push_back (CheckMenuElem (_("Opaque")));
+               CheckMenuItem* region_opaque_item = static_cast<CheckMenuItem*>(&items.back());
+               fooc = region_opaque_item->signal_activate().connect (mem_fun(*this, &Editor::toggle_region_opaque));
+               if (region_to_check->opaque()) {
+                       fooc.block (true);
+                       region_opaque_item->set_active();
+                       fooc.block (false);
                }
        }
-
+       
        items.push_back (CheckMenuElem (_("Original position"), mem_fun(*this, &Editor::naturalize)));
-       if (region && region->at_natural_position()) {
+       if (region_to_check->at_natural_position()) {
                items.back().set_sensitive (false);
        }
        
@@ -1992,12 +2026,18 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
                items.push_back (SeparatorElem());
        }
 
+       items.push_back (MenuElem (_("Strip silence..."), mem_fun (*this, &Editor::strip_region_silence)));
        items.push_back (MenuElem (_("Reverse"), mem_fun(*this, &Editor::reverse_region)));
        items.push_back (SeparatorElem());
 
        /* range related stuff */
 
-       items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_audio_region)));
+       items.push_back (MenuElem (_("Add Single Range"), mem_fun (*this, &Editor::add_location_from_audio_region)));
+       items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_locations_from_audio_region)));
+       if (selection->regions.size() < 2) {
+               items.back().set_sensitive (false);
+       }
+
        items.push_back (MenuElem (_("Set Range Selection"), mem_fun (*this, &Editor::set_selection_from_region)));
        items.push_back (SeparatorElem());
                         
@@ -2020,7 +2060,15 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
        trim_menu->set_name ("ArdourContextMenu");
        
        trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
+       foo_item = &trim_items.back();
+       if (_edit_point == EditAtMouse) {
+               foo_item->set_sensitive (false);
+       }
        trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
+       foo_item = &trim_items.back();
+       if (_edit_point == EditAtMouse) {
+               foo_item->set_sensitive (false);
+       }
        trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
        trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
                             
@@ -2029,6 +2077,10 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
 
        items.push_back (MenuElem (_("Split"), (mem_fun(*this, &Editor::split_region))));
        region_edit_menu_split_item = &items.back();
+       
+       if (_edit_point == EditAtMouse) {
+               region_edit_menu_split_item->set_sensitive (false);
+       }
 
        items.push_back (MenuElem (_("Make mono regions"), (mem_fun(*this, &Editor::split_multichannel_region))));
        region_edit_menu_split_multichannel_item = &items.back();
@@ -2066,44 +2118,41 @@ void
 Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
 {
        using namespace Menu_Helpers;
-       Menu     *selection_menu = manage (new Menu);
-       MenuList& items       = selection_menu->items();
-       selection_menu->set_name ("ArdourContextMenu");
 
-       items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
-       items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
+       edit_items.push_back (MenuElem (_("Play range"), mem_fun(*this, &Editor::play_selection)));
+       edit_items.push_back (MenuElem (_("Loop range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), true)));
 
-#ifdef FFT_ANALYSIS
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
-#endif
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
        
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
-       items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
+       edit_items.push_back (MenuElem (_("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
 
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
-       items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Convert to region in-place"), mem_fun(*this, &Editor::separate_region_from_selection)));
+       edit_items.push_back (MenuElem (_("Convert to region in region list"), mem_fun(*this, &Editor::new_region_from_selection)));
        
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
 
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
-       items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Set loop from selection"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
+       edit_items.push_back (MenuElem (_("Set punch from selection"), mem_fun(*this, &Editor::set_punch_from_selection)));
        
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
-       items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
-       items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
-       items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
-       items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true)));
-       items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false)));
-       items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_selection)));
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Add Range Markers"), mem_fun (*this, &Editor::add_location_from_selection)));
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Crop region to range"), mem_fun(*this, &Editor::crop_region_to_selection)));
+       edit_items.push_back (MenuElem (_("Fill range with region"), mem_fun(*this, &Editor::region_fill_selection)));
+       edit_items.push_back (MenuElem (_("Duplicate range"), bind (mem_fun(*this, &Editor::duplicate_dialog), false)));
+       edit_items.push_back (MenuElem (_("Create chunk from range"), mem_fun(*this, &Editor::create_named_selection)));
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Consolidate range"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, false)));
+       edit_items.push_back (MenuElem (_("Consolidate range with processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), true, true)));
+       edit_items.push_back (MenuElem (_("Bounce range to region list"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, false)));
+       edit_items.push_back (MenuElem (_("Bounce range to region list with processing"), bind (mem_fun(*this, &Editor::bounce_range_selection), false, true)));
+       edit_items.push_back (MenuElem (_("Export range"), mem_fun(*this, &Editor::export_range)));
 }
 
        
@@ -2276,7 +2325,7 @@ Editor::set_snap_to (SnapType st)
        case SnapToAEighthBeat:
        case SnapToAQuarterBeat:
        case SnapToAThirdBeat:
-               compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + (nframes_t)(edit_packer.get_width() * frames_per_unit));
+               compute_bbt_ruler_scale (leftmost_frame, leftmost_frame + current_page_frames());
                update_tempo_based_rulers ();
                break;
 
@@ -2343,7 +2392,7 @@ Editor::set_edit_point_preference (EditPoint ep, bool force)
                break;
        }
 
-       const char* action;
+       const char* action=NULL;
 
        switch (_edit_point) {
        case EditAtPlayhead:
@@ -2386,23 +2435,56 @@ Editor::set_state (const XMLNode& node)
                _id = prop->value ();
        }
 
-       if ((geometry = find_named_node (node, "geometry")) == 0) {
+       g.base_width = default_width;
+       g.base_height = default_height;
+       x = 1;
+       y = 1;
+       xoff = 0;
+       yoff = 21;
 
-               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) {
 
-       } else {
+               XMLProperty* prop;
+
+               if ((prop = geometry->property("x_size")) == 0) {
+                       prop = geometry->property ("x-size");
+               }
+               if (prop) {
+                       g.base_width = atoi(prop->value());
+               }
+               if ((prop = geometry->property("y_size")) == 0) {
+                       prop = geometry->property ("y-size");
+               }
+               if (prop) {
+                       g.base_height = atoi(prop->value());
+               }
+
+               if ((prop = geometry->property ("x_pos")) == 0) {
+                       prop = geometry->property ("x-pos");
+               }
+               if (prop) {
+                       x = atoi (prop->value());
+
+               }
+               if ((prop = geometry->property ("y_pos")) == 0) {
+                       prop = geometry->property ("y-pos");
+               }
+               if (prop) {
+                       y = atoi (prop->value());
+               }
 
-               g.base_width = atoi(geometry->property("x_size")->value());
-               g.base_height = atoi(geometry->property("y_size")->value());
-               x = atoi(geometry->property("x_pos")->value());
-               y = atoi(geometry->property("y_pos")->value());
-               xoff = atoi(geometry->property("x_off")->value());
-               yoff = atoi(geometry->property("y_off")->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);
@@ -2456,18 +2538,6 @@ Editor::set_state (const XMLNode& node)
                set_mouse_mode (MouseObject, true);
        }
 
-       if ((prop = node.property ("show-waveforms"))) {
-               bool yn = (prop->value() == "yes");
-               _show_waveforms = !yn;
-               RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-waveform-visible"));
-               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 ("show-waveforms-recording"))) {
                bool yn = (prop->value() == "yes");
                _show_waveforms_recording = !yn;
@@ -2570,17 +2640,17 @@ Editor::get_state ()
                XMLNode* geometry = new XMLNode ("geometry");
 
                snprintf(buf, sizeof(buf), "%d", width);
-               geometry->add_property("x_size", string(buf));
+               geometry->add_property("x-size", string(buf));
                snprintf(buf, sizeof(buf), "%d", height);
-               geometry->add_property("y_size", string(buf));
+               geometry->add_property("y-size", string(buf));
                snprintf(buf, sizeof(buf), "%d", x);
-               geometry->add_property("x_pos", string(buf));
+               geometry->add_property("x-pos", string(buf));
                snprintf(buf, sizeof(buf), "%d", y);
-               geometry->add_property("y_pos", string(buf));
+               geometry->add_property("y-pos", string(buf));
                snprintf(buf, sizeof(buf), "%d", xoff);
-               geometry->add_property("x_off", string(buf));
+               geometry->add_property("x-off", string(buf));
                snprintf(buf, sizeof(buf), "%d", yoff);
-               geometry->add_property("y_off", string(buf));
+               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_pane_pos", string(buf));
 
@@ -2603,7 +2673,6 @@ Editor::get_state ()
        snprintf (buf, sizeof (buf), "%" PRIi64, playhead_cursor->current_frame);
        node->add_property ("playhead", 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");
        node->add_property ("follow-playhead", _follow_playhead ? "yes" : "no");
@@ -2628,19 +2697,23 @@ Editor::get_state ()
 
 
 
-TimeAxisView *
+/** @param y y offset from the top of all trackviews.
+ *  @return pair: TimeAxisView that y is over, layer index.
+ *  TimeAxisView may be 0.  Layer index is the layer number if the TimeAxisView is valid and is
+ *  in stacked region display mode, otherwise 0.
+ */
+std::pair<TimeAxisView *, layer_t>
 Editor::trackview_by_y_position (double y)
 {
        for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
 
-               TimeAxisView *tv;
-
-               if ((tv = (*iter)->covers_y_position (y)) != 0) {
-                       return tv;
+               std::pair<TimeAxisView*, int> const r = (*iter)->covers_y_position (y);
+               if (r.first) {
+                       return r;
                }
        }
 
-       return 0;
+       return std::make_pair ( (TimeAxisView *) 0, 0);
 }
 
 void
@@ -2675,7 +2748,7 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
                break;
 
        case SnapToSMPTEFrame:
-               if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
+               if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
                        start = (nframes64_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
                } else {
                        start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) *  session->frames_per_smpte_frame());
@@ -2906,12 +2979,6 @@ Editor::setup_toolbar ()
 {
        string pixmap_path;
 
-#ifdef GTKOSX
-       const guint32 FUDGE = 38; // Combo's are stupid - they steal space from the entry for the button
-#else
-       const guint32 FUDGE = 18; // Combo's are stupid - they steal space from the entry for the button
-#endif
-
        /* Mode Buttons (tool selection) */
 
        vector<ToggleButton *> mouse_mode_buttons;
@@ -2964,12 +3031,13 @@ Editor::setup_toolbar ()
 
        vector<string> edit_mode_strings;
        edit_mode_strings.push_back (edit_mode_to_string (Slide));
-       edit_mode_strings.push_back (edit_mode_to_string (Splice));
+       if (!Profile->get_sae()) {
+               edit_mode_strings.push_back (edit_mode_to_string (Splice));
+       }
        edit_mode_strings.push_back (edit_mode_to_string (Lock));
 
        edit_mode_selector.set_name ("EditModeSelector");
-       Gtkmm2ext::set_size_request_to_display_given_text (edit_mode_selector, longest (edit_mode_strings).c_str(), 2+FUDGE, 10);
-       set_popdown_strings (edit_mode_selector, edit_mode_strings);
+       set_popdown_strings (edit_mode_selector, edit_mode_strings, true);
        edit_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_mode_selection_done));
 
        mode_box->pack_start(edit_mode_selector);
@@ -2978,6 +3046,10 @@ Editor::setup_toolbar ()
        mouse_mode_tearoff = manage (new TearOff (*mode_box));
        mouse_mode_tearoff->set_name ("MouseModeBase");
 
+       if (Profile->get_sae()) {
+               mouse_mode_tearoff->set_can_be_torn_off (false);
+       }
+
        mouse_mode_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox), 
                                                  &mouse_mode_tearoff->tearoff_window()));
        mouse_mode_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox), 
@@ -3048,34 +3120,34 @@ Editor::setup_toolbar ()
        ARDOUR_UI::instance()->tooltips().set_tip (zoom_out_full_button, _("Zoom to Session"));
 
        zoom_focus_selector.set_name ("ZoomFocusSelector");
-       Gtkmm2ext::set_size_request_to_display_given_text (zoom_focus_selector, _("Playhead"), FUDGE, 0);
-       set_popdown_strings (zoom_focus_selector, zoom_focus_strings);
+       set_popdown_strings (zoom_focus_selector, zoom_focus_strings, true);
        zoom_focus_selector.signal_changed().connect (mem_fun(*this, &Editor::zoom_focus_selection_done));
        ARDOUR_UI::instance()->tooltips().set_tip (zoom_focus_selector, _("Zoom focus"));
 
-       zoom_box.pack_start (zoom_focus_selector, true, true);
        zoom_box.pack_start (zoom_out_button, false, false);
        zoom_box.pack_start (zoom_in_button, false, false);
        zoom_box.pack_start (zoom_out_full_button, false, false);
 
+       HBox* zbc = manage (new HBox);
+       zbc->pack_start (zoom_focus_selector, false, false);
+       zoom_vbox.pack_start (*zbc, false, false);
+       zoom_vbox.pack_start (zoom_box, false, false);
+
        snap_box.set_spacing (1);
        snap_box.set_border_width (2);
 
        snap_type_selector.set_name ("SnapTypeSelector");
-       Gtkmm2ext::set_size_request_to_display_given_text (snap_type_selector, _("SMPTE Seconds"), 2+FUDGE, 10);
-       set_popdown_strings (snap_type_selector, snap_type_strings);
+       set_popdown_strings (snap_type_selector, snap_type_strings, true);
        snap_type_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_type_selection_done));
        ARDOUR_UI::instance()->tooltips().set_tip (snap_type_selector, _("Snap/Grid Units"));
 
        snap_mode_selector.set_name ("SnapModeSelector");
-       Gtkmm2ext::set_size_request_to_display_given_text (snap_mode_selector, _("Magnetic Snap"), 2+FUDGE, 10);
-       set_popdown_strings (snap_mode_selector, snap_mode_strings);
+       set_popdown_strings (snap_mode_selector, snap_mode_strings, true);
        snap_mode_selector.signal_changed().connect (mem_fun(*this, &Editor::snap_mode_selection_done));
        ARDOUR_UI::instance()->tooltips().set_tip (snap_mode_selector, _("Snap/Grid Mode"));
 
-       edit_point_selector.set_name ("SnapModeSelector");
-       Gtkmm2ext::set_size_request_to_display_given_text (edit_point_selector, _("Playhead"), 2+FUDGE, 10);
-       set_popdown_strings (edit_point_selector, edit_point_strings);
+       edit_point_selector.set_name ("EditPointSelector");
+       set_popdown_strings (edit_point_selector, edit_point_strings, true);
        edit_point_selector.signal_changed().connect (mem_fun(*this, &Editor::edit_point_selection_done));
        ARDOUR_UI::instance()->tooltips().set_tip (edit_point_selector, _("Edit point"));
 
@@ -3106,6 +3178,10 @@ Editor::setup_toolbar ()
        tools_tearoff = manage (new TearOff (*hbox));
        tools_tearoff->set_name ("MouseModeBase");
 
+       if (Profile->get_sae()) {
+               tools_tearoff->set_can_be_torn_off (false);
+       }
+
        tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox), 
                                             &tools_tearoff->tearoff_window()));
        tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox), 
@@ -3136,6 +3212,13 @@ Editor::setup_toolbar ()
        toolbar_frame.add (toolbar_base);
 }
 
+void
+Editor::midi_panic_button_pressed ()
+{
+       if (session) {
+               session->midi_panic();
+       }
+}
 
 void
 Editor::setup_midi_toolbar ()
@@ -3168,18 +3251,18 @@ Editor::setup_midi_toolbar ()
        midi_tool_button_box.pack_start(midi_tool_pencil_button, true, true);
        midi_tool_button_box.pack_start(midi_tool_select_button, true, true);
        midi_tool_button_box.pack_start(midi_tool_resize_button, true, true);
-       midi_tool_button_box.pack_start(midi_tool_erase_button, true, true);
+       midi_tool_button_box.pack_start(midi_tool_erase_button , true, true);
        midi_tool_button_box.set_homogeneous(true);
 
        midi_tool_pencil_button.set_name ("MouseModeButton");
        midi_tool_select_button.set_name ("MouseModeButton");
        midi_tool_resize_button.set_name ("MouseModeButton");
-       midi_tool_erase_button.set_name ("MouseModeButton");
+       midi_tool_erase_button .set_name ("MouseModeButton");
 
        ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_pencil_button, _("Add/Move/Stretch Notes"));
        ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_select_button, _("Select/Move Notes"));
        ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_resize_button, _("Resize Notes"));
-       ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button, _("Erase Notes"));
+       ARDOUR_UI::instance()->tooltips().set_tip (midi_tool_erase_button,  _("Erase Notes"));
 
        midi_tool_pencil_button.unset_flags (CAN_FOCUS);
        midi_tool_select_button.unset_flags (CAN_FOCUS);
@@ -3194,6 +3277,22 @@ Editor::setup_midi_toolbar ()
                                &Editor::midi_edit_mode_toggled), Editing::MidiEditResize));
        midi_tool_erase_button.signal_toggled().connect (bind (mem_fun(*this,
                                &Editor::midi_edit_mode_toggled), Editing::MidiEditErase));
+
+       
+       /* Midi sound notes */
+       midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
+       midi_sound_notes.set_relief(Gtk::RELIEF_NONE);
+       ARDOUR_UI::instance()->tooltips().set_tip (midi_sound_notes, _("Sound Notes"));
+       midi_sound_notes.unset_flags (CAN_FOCUS);
+       
+       /* Panic */
+       
+       HBox* panic_box = manage (new HBox);
+       midi_panic_button.set_name("MidiPanicButton");
+       midi_panic_button.signal_pressed().connect (
+                       mem_fun(this, &Editor::midi_panic_button_pressed));
+       panic_box->pack_start (midi_sound_notes , true, true);
+       panic_box->pack_start (midi_panic_button, true, true);
        
        /* Pack everything in... */
 
@@ -3215,6 +3314,8 @@ Editor::setup_midi_toolbar ()
        midi_toolbar_hbox.set_border_width (1);
 
        midi_toolbar_hbox.pack_start (*midi_tools_tearoff, false, true);
+       
+       midi_toolbar_hbox.pack_start(*panic_box, false, true, 4);
 
        midi_tool_button_box.show_all ();
        midi_toolbar_hbox.show_all();
@@ -3229,14 +3330,14 @@ Editor::setup_midi_toolbar ()
 }
 
 int
-Editor::convert_drop_to_paths (vector<ustring>& paths, 
-                              const RefPtr<Gdk::DragContext>& context,
-                              gint                x,
-                              gint                y,
-                              const SelectionData& data,
-                              guint               info,
-                              guint               time)                               
-
+Editor::convert_drop_to_paths (
+               vector<ustring>&                paths, 
+               const RefPtr<Gdk::DragContext>& context,
+               gint                            x,
+               gint                            y,
+               const SelectionData&            data,
+               guint                           info,
+               guint                           time)
 {      
        if (session == 0) {
                return -1;
@@ -3255,12 +3356,19 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                }
   
                /* Parse the "uri-list" format that Nautilus provides, 
-                  where each pathname is delimited by \r\n
+                  where each pathname is delimited by \r\n.
+
+                  THERE MAY BE NO NULL TERMINATING CHAR!!!
                */
-       
-               const char* p = data.get_text().c_str();
+
+               ustring txt = data.get_text();
+               const char* p;
                const char* q;
 
+               p = (const char *) malloc (txt.length() + 1);
+               txt.copy ((char *) p, txt.length(), 0);
+               ((char*)p)[txt.length()] = '\0';
+
                while (p)
                {
                        if (*p != '#')
@@ -3269,8 +3377,9 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                                        p++;
                                
                                q = p;
-                               while (*q && (*q != '\n') && (*q != '\r'))
+                               while (*q && (*q != '\n') && (*q != '\r')) {
                                        q++;
+                               }
                                
                                if (q > p)
                                {
@@ -3289,6 +3398,8 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                                p++;
                }
 
+               free ((void*)p);
+               
                if (uris.empty()) {
                        return -1;
                }
@@ -3299,7 +3410,7 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                if ((*i).substr (0,7) == "file://") {
                        
                        ustring p = *i;
-                        PBD::url_decode (p);
+                       PBD::url_decode (p);
 
                        // scan forward past three slashes
                        
@@ -3359,15 +3470,6 @@ Editor::State::~State ()
        delete selection;
 }
 
-UndoAction
-Editor::get_memento () const
-{
-       State *state = new State (this);
-
-       store_state (*state);
-       return bind (mem_fun (*(const_cast<Editor*>(this)), &Editor::restore_state), state);
-}
-
 void
 Editor::store_state (State& state) const
 {
@@ -3383,7 +3485,7 @@ Editor::restore_state (State *state)
 
        *selection = *state->selection;
        time_selection_changed ();
-       region_selection_changed ();   
+       region_selection_changed ();
 
        /* XXX other selection change handlers? */
 }
@@ -3392,7 +3494,7 @@ void
 Editor::begin_reversible_command (string name)
 {
        if (session) {
-                before = &get_state();
+               before = &get_state();
                session->begin_reversible_command (name);
        }
 }
@@ -3545,7 +3647,7 @@ Editor::clamp_verbose_cursor_x (double x)
        if (x < 0) {
                x = 0;
        } else {
-               x = min (canvas_width - 200.0, x);
+               x = min (_canvas_width - 200.0, x);
        }
        return x;
 }
@@ -3556,7 +3658,7 @@ Editor::clamp_verbose_cursor_y (double y)
        if (y < canvas_timebars_vsize) {
                y = canvas_timebars_vsize;
        } else {
-               y = min (canvas_height - 50, y);
+               y = min (_canvas_height - 50, y);
        }
        return y;
 }
@@ -3587,7 +3689,11 @@ Editor::cycle_edit_mode ()
 {
        switch (Config->get_edit_mode()) {
        case Slide:
-               Config->set_edit_mode (Splice);
+               if (Profile->get_sae()) {
+                       Config->set_edit_mode (Lock);
+               } else {
+                       Config->set_edit_mode (Splice);
+               }
                break;
        case Splice:
                Config->set_edit_mode (Lock);
@@ -3860,12 +3966,23 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
        static int32_t done;
        XMLNode* geometry;
 
-       if ((geometry = find_named_node (*node, "geometry")) == 0) {
-               width = default_width;
-               height = default_height;
-       } else {
-               width = atoi(geometry->property("x_size")->value());
-               height = atoi(geometry->property("y_size")->value());
+       width = default_width;
+       height = default_height;
+
+       if ((geometry = find_named_node (*node, "geometry")) != 0) {
+
+               if ((prop = geometry->property ("x_size")) == 0) {
+                       prop = geometry->property ("x-size");
+               }
+               if (prop) {
+                       width = atoi (prop->value());
+               }
+               if ((prop = geometry->property ("y_size")) == 0) {
+                       prop = geometry->property ("y-size");
+               }
+               if (prop) {
+                       height = atoi (prop->value());
+               }
        }
 
        if (which == static_cast<Paned*> (&edit_pane)) {
@@ -3874,14 +3991,14 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
                        return;
                }
 
-               if (!geometry || (prop = geometry->property ("edit_pane_pos")) == 0) {
+               if (!geometry || (prop = geometry->property ("edit-pane-pos")) == 0) {
                        /* initial allocation is 90% to canvas, 10% to notebook */
                        pos = (int) floor (alloc.get_width() * 0.90f);
                        snprintf (buf, sizeof(buf), "%d", pos);
                } else {
                        pos = atoi (prop->value());
                }
-               
+
                if ((done = GTK_WIDGET(edit_pane.gobj())->allocation.width > pos)) {
                        edit_pane.set_position (pos);
                        pre_maximal_pane_position = pos;
@@ -3913,6 +4030,8 @@ Editor::set_show_measures (bool yn)
                hide_measures ();
 
                if ((_show_measures = yn) == true) {
+                       if (tempo_lines)
+                               tempo_lines->show();
                        draw_measures ();
                }
                instant_save ();
@@ -4005,7 +4124,8 @@ Editor::end_location_changed (Location* location)
 {
        ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
        //reset_scrolling_region ();
-       horizontal_adjustment.set_upper ( location->start());
+       nframes64_t session_span = location->start() + (nframes64_t) floorf (current_page_frames() * 0.10f);
+       horizontal_adjustment.set_upper (session_span / frames_per_unit);
 }
 
 int
@@ -4202,7 +4322,7 @@ Editor::rename_snapshot (Glib::ustring old_name)
                prompter.get_result (new_name);
                if (new_name.length()) {
                        session->rename_state (old_name, new_name);
-                       redisplay_snapshots ();
+                       redisplay_snapshots ();
                }
        }
 }
@@ -4276,8 +4396,6 @@ Editor::session_state_saved (string snap_name)
 void
 Editor::maximise_editing_space ()
 {
-       initial_ruler_update_required = true;
-
        mouse_mode_tearoff->set_visible (false);
        tools_tearoff->set_visible (false);
 
@@ -4301,9 +4419,8 @@ Editor::maximise_editing_space ()
 void
 Editor::restore_editing_space ()
 {
-       initial_ruler_update_required = true;
-
        // user changed width of pane during fullscreen
+
        if(post_maximal_pane_position != edit_pane.get_position()) {
                post_maximal_pane_position = edit_pane.get_position();
        }
@@ -4314,10 +4431,7 @@ Editor::restore_editing_space ()
        tools_tearoff->set_visible (true);
        post_maximal_editor_width = this->get_width();
 
-
-       edit_pane.set_position (
-               pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width)
-       );
+       edit_pane.set_position (pre_maximal_pane_position + abs(this->get_width() - pre_maximal_editor_width));
 }
 
 /**
@@ -4330,7 +4444,9 @@ void
 Editor::new_playlists (TimeAxisView* v)
 {
        begin_reversible_command (_("new playlists"));
-       mapover_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v);
+       vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
+       session->get_playlists(playlists);
+       mapover_tracks ( bind(mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v );
        commit_reversible_command ();
 }
 
@@ -4344,7 +4460,9 @@ void
 Editor::copy_playlists (TimeAxisView* v)
 {
        begin_reversible_command (_("copy playlists"));
-       mapover_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v);
+       vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
+       session->get_playlists(playlists);
+       mapover_tracks ( bind(mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v );
        commit_reversible_command ();
 }
 
@@ -4358,20 +4476,22 @@ void
 Editor::clear_playlists (TimeAxisView* v)
 {
        begin_reversible_command (_("clear playlists"));
-       mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v);
+       vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
+       session->get_playlists(playlists);
+       mapover_tracks ( mem_fun (*this, &Editor::mapped_clear_playlist), v );
        commit_reversible_command ();
 }
 
 void 
-Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz)
+Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
 {
-       atv.use_new_playlist (sz > 1 ? false : true);
+       atv.use_new_playlist (sz > 1 ? false : true, playlists);
 }
 
 void
-Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz)
+Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
 {
-       atv.use_copy_playlist (sz > 1 ? false : true);
+       atv.use_copy_playlist (sz > 1 ? false : true, playlists);
 }
 
 void 
@@ -4400,6 +4520,12 @@ Editor::reset_x_origin (nframes64_t frame)
        queue_visual_change (frame);
 }
 
+void
+Editor::reset_y_origin (double y)
+{
+       queue_visual_change_y (y);
+}
+
 void
 Editor::reset_zoom (double fpu)
 {
@@ -4477,12 +4603,14 @@ void
 Editor::use_visual_state (VisualState& vs)
 {
        no_save_visual = true;
+       no_route_list_redisplay = true;
 
        vertical_adjustment.set_value (vs.y_position);
 
        set_zoom_focus (vs.zoom_focus);
        reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
-
+       zoomed_to_region = vs.zoomed_to_region;
+       
        for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
                TrackViewList::iterator t;
 
@@ -4493,10 +4621,14 @@ Editor::use_visual_state (VisualState& vs)
                }
        }
 
+
        if (!vs.track_states.empty()) {
                update_route_visibility ();
        } 
-       
+
+       no_route_list_redisplay = false;
+       redisplay_route_list ();
+
        no_save_visual = false;
 }
 
@@ -4523,6 +4655,9 @@ Editor::set_frames_per_unit (double fpu)
        if (max_frames / fpu < 800.0) {
                return;
        }
+       
+       if (tempo_lines)
+               tempo_lines->tempo_map_changed();
 
        frames_per_unit = fpu;
        post_zoom ();
@@ -4531,9 +4666,11 @@ Editor::set_frames_per_unit (double fpu)
 void
 Editor::post_zoom ()
 {
+       nframes64_t cef = 0;
+
        // convert fpu to frame count
 
-       nframes64_t frames = (nframes64_t) floor (frames_per_unit * canvas_width);
+       nframes64_t frames = (nframes64_t) floor (frames_per_unit * _canvas_width);
 
        if (frames_per_unit != zoom_range_clock.current_duration()) {
                zoom_range_clock.set (frames);
@@ -4551,41 +4688,71 @@ Editor::post_zoom ()
                }
        }
 
+       leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
+
        ZoomChanged (); /* EMIT_SIGNAL */
 
        reset_hscrollbar_stepping ();
+
+       if (session) {
+               cef = session->current_end_frame() + (current_page_frames() / 10);// Add a little extra so we can see the end marker
+       }
+       horizontal_adjustment.set_upper (cef / frames_per_unit);
+
        //reset_scrolling_region ();
 
        if (playhead_cursor) {
                playhead_cursor->set_position (playhead_cursor->current_frame);
        }
 
+       _summary->set_overlays_dirty ();
+
        instant_save ();
 }
 
 void
 Editor::queue_visual_change (nframes64_t where)
 {
-//     pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
-//     pending_visual_change.time_origin = where;
-
-       if (pending_visual_change.idle_handler_id < 0) {
-               pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
-               pending_visual_change.time_origin = where;
-               pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
+       pending_visual_change.add (VisualChange::TimeOrigin);
+       
+       /* if we're moving beyond the end, make sure the upper limit of the horizontal adjustment
+          can reach.
+       */
+       
+       if (where > session->current_end_frame()) {
+               horizontal_adjustment.set_upper ((where + current_page_frames()) / frames_per_unit);
        }
+       
+       pending_visual_change.time_origin = where;
+       
+       ensure_visual_change_idle_handler ();
 }
 
 void
 Editor::queue_visual_change (double fpu)
 {
-       pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
+       pending_visual_change.add (VisualChange::ZoomLevel);
        pending_visual_change.frames_per_unit = fpu;
 
+       ensure_visual_change_idle_handler ();
+       
+}
+
+void
+Editor::queue_visual_change_y (double y)
+{
+       pending_visual_change.add (VisualChange::YOrigin);
+       pending_visual_change.y_origin = y;
+
+       ensure_visual_change_idle_handler ();
+}
+
+void
+Editor::ensure_visual_change_idle_handler ()
+{
        if (pending_visual_change.idle_handler_id < 0) {
-               pending_visual_change.idle_handler_id = g_idle_add ( _idle_visual_changer, this);
+               pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
        }
-       
 }
 
 int
@@ -4600,37 +4767,54 @@ Editor::idle_visual_changer ()
        VisualChange::Type p = pending_visual_change.pending;
        pending_visual_change.pending = (VisualChange::Type) 0;
 
+#ifdef FIX_THIS_FOR_V3
+       double last_time_origin = horizontal_adjustment.get_value();
+#endif
+
        if (p & VisualChange::ZoomLevel) {
                set_frames_per_unit (pending_visual_change.frames_per_unit);
 
                compute_fixed_ruler_scale ();
-               compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + (nframes_t)(edit_packer.get_width() * pending_visual_change.frames_per_unit));
-               compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + (nframes_t)(edit_packer.get_width() * pending_visual_change.frames_per_unit));
+               compute_current_bbt_points(pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
+               compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_frames());
                update_tempo_based_rulers ();
        }
        if (p & VisualChange::TimeOrigin) {
+               horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
+       }
+       if (p & VisualChange::YOrigin) {
+               vertical_adjustment.set_value (pending_visual_change.y_origin);
+       }
+       
+       nframes64_t csf=0, cef=0;
+       nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
+       
+       if (session) {
+               csf = session->current_start_frame();
+               cef = session->current_end_frame();
+       }
+       
+       /* if we seek beyond the current end of the canvas, move the end */
 
-               nframes64_t csf, cef;
-               nframes64_t current_time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
-
-               if (session) {
-                       csf = session->current_start_frame();
-                       cef = session->current_end_frame() + (current_page_frames() / 24);// Add a little extra so we can see the end marker
-               }
-
-               /* if we seek beyond the current end of the canvas, move the end */
-
-               if (current_time_origin != pending_visual_change.time_origin) {
-                       //if (horizontal_adjustment.get_upper() < pending_visual_change.time_origin) {
-                       last_canvas_frame = (cef > (pending_visual_change.time_origin + current_page_frames())) ? cef : pending_visual_change.time_origin + current_page_frames();
-                       horizontal_adjustment.set_upper ((cef - csf) / frames_per_unit);
-                       //}
-                       horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
-               } else {
-                       update_fixed_rulers();
-                       redisplay_tempo (true);
-               }
+#ifdef FIX_THIS_FOR_V3
+       if (last_time_origin == horizontal_adjustment.get_value() ) {
+               /* changed signal not emitted */
+               update_fixed_rulers ();
+               redisplay_tempo (true);
        }
+#endif
+       
+       if (current_time_origin != pending_visual_change.time_origin) {
+               cef += current_page_frames() / 10; // Add a little extra so we can see the end marker
+               horizontal_adjustment.set_upper (cef / frames_per_unit);
+               horizontal_adjustment.set_value (pending_visual_change.time_origin / frames_per_unit);
+       } else {
+               update_fixed_rulers();
+               redisplay_tempo (true);
+       }
+
+       _summary->set_overlays_dirty ();
+       
        //cerr << "Editor::idle_visual_changer () called ha v:l:u:ps:fpu = " << horizontal_adjustment.get_value() << ":" << horizontal_adjustment.get_lower() << ":" << horizontal_adjustment.get_upper() << ":" << horizontal_adjustment.get_page_size() << ":" << frames_per_unit << endl;//DEBUG
        pending_visual_change.idle_handler_id = -1;
        return 0; /* this is always a one-shot call */
@@ -4638,7 +4822,7 @@ Editor::idle_visual_changer ()
 
 struct EditorOrderTimeAxisSorter {
     bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
-           return a->order < b->order;
+           return a->order () < b->order ();
     }
 };
        
@@ -4713,17 +4897,17 @@ Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
 
        if ((tll = transport_loop_location()) == 0) {
                Location* loc = new Location (start, end, _("Loop"),  Location::IsAutoLoop);
-                XMLNode &before = session->locations()->get_state();
+               XMLNode &before = session->locations()->get_state();
                session->locations()->add (loc, true);
                session->set_auto_loop_location (loc);
-                XMLNode &after = session->locations()->get_state();
+               XMLNode &after = session->locations()->get_state();
                session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
        } else {
-                XMLNode &before = tll->get_state();
+               XMLNode &before = tll->get_state();
                tll->set_hidden (false, this);
                tll->set (start, end);
-                XMLNode &after = tll->get_state();
-                session->add_command (new MementoCommand<Location>(*tll, &before, &after));
+               XMLNode &after = tll->get_state();
+               session->add_command (new MementoCommand<Location>(*tll, &before, &after));
        }
        
        commit_reversible_command ();
@@ -4740,18 +4924,18 @@ Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
 
        if ((tpl = transport_punch_location()) == 0) {
                Location* loc = new Location (start, end, _("Loop"),  Location::IsAutoPunch);
-                XMLNode &before = session->locations()->get_state();
+               XMLNode &before = session->locations()->get_state();
                session->locations()->add (loc, true);
                session->set_auto_loop_location (loc);
-                XMLNode &after = session->locations()->get_state();
+               XMLNode &after = session->locations()->get_state();
                session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
        }
        else {
-                XMLNode &before = tpl->get_state();
+               XMLNode &before = tpl->get_state();
                tpl->set_hidden (false, this);
                tpl->set (start, end);
-                XMLNode &after = tpl->get_state();
-                session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
+               XMLNode &after = tpl->get_state();
+               session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
        }
        
        commit_reversible_command ();
@@ -4769,21 +4953,18 @@ Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelec
        }
 
        for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
-       
-               AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
-
-               if (atv) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
+               if (rtv) {
                        boost::shared_ptr<Diskstream> ds;
                        boost::shared_ptr<Playlist> pl;
                        
-                       if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
+                       if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
 
-                               Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)where * ds->speed()));
+                               Playlist::RegionList* regions = pl->regions_at (
+                                               (nframes64_t) floor ( (double)where * ds->speed()));
 
                                for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
-
-                                       RegionView* rv = atv->audio_view()->find_view (*i);
-
+                                       RegionView* rv = rtv->view()->find_view (*i);
                                        if (rv) {
                                                rs.add (rv);
                                        }
@@ -4807,20 +4988,19 @@ Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSe
        }
 
        for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
-       
-               AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
-
-               if (atv) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*t);
+               if (rtv) {
                        boost::shared_ptr<Diskstream> ds;
                        boost::shared_ptr<Playlist> pl;
                        
-                       if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
+                       if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
 
-                               Playlist::RegionList* regions = pl->regions_touched ((nframes64_t) floor ( (double)where * ds->speed()), max_frames);
+                               Playlist::RegionList* regions = pl->regions_touched (
+                                               (nframes64_t) floor ( (double)where * ds->speed()), max_frames);
 
                                for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
 
-                                       RegionView* rv = atv->audio_view()->find_view (*i);
+                                       RegionView* rv = rtv->view()->find_view (*i);
 
                                        if (rv) {
                                                rs.push_back (rv);
@@ -4937,6 +5117,26 @@ Editor::show_rhythm_ferret ()
        rhythm_ferret->present ();
 }
 
+void
+Editor::show_bundle_manager ()
+{
+       if (_bundle_manager == 0) {
+               _bundle_manager = new BundleManager (*session);
+       }
+
+       _bundle_manager->show ();
+}
+
+void
+Editor::show_global_port_matrix (ARDOUR::DataType t)
+{
+       if (_global_port_matrix[t] == 0) {
+               _global_port_matrix[t] = new GlobalPortMatrixWindow (*session, t);
+       }
+
+       _global_port_matrix[t]->show ();
+}
+
 void
 Editor::first_idle ()
 {
@@ -4955,10 +5155,11 @@ Editor::first_idle ()
        for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
                (*t)->first_idle();
        }
+
+       // first idle adds route children (automation tracks), so we need to redisplay here
+       redisplay_route_list();
        
-       if (dialog) {
-               delete dialog;
-       }
+       delete dialog;
 
        _have_idled = true;
 }
@@ -4980,7 +5181,7 @@ Editor::end_resize_line_ops ()
        need_resize_line = false;
 
        if (old_resize_line_y >= 0) {
-               Gdk::Rectangle r (0, old_resize_line_y, (int) canvas_width, 3);
+               Gdk::Rectangle r (0, old_resize_line_y, (int) _canvas_width, 3);
                Glib::RefPtr<Gdk::Window> win = get_window();
                cerr << "Final invalidation at " << old_resize_line_y << endl;
                win->invalidate_rect (r, false);
@@ -4996,7 +5197,7 @@ Editor::queue_draw_resize_line (int at)
 
        resize_line_y = at;
 
-       if (win && canvas_width) {
+       if (win && _canvas_width) {
 
                int controls_width = controls_layout.get_width();
                int xroot, discard;
@@ -5008,15 +5209,15 @@ Editor::queue_draw_resize_line (int at)
                        /* redraw where it used to be */
                        
                        
-                       Gdk::Rectangle r (0, old_resize_line_y - 1, controls_width + (int) canvas_width, 3);
+                       Gdk::Rectangle r (0, old_resize_line_y - 1, controls_width + (int) _canvas_width, 3);
                        win->invalidate_rect (r, true);
                        cerr << "invalidate " << xroot << "," << old_resize_line_y - 1 << ' ' 
-                            << controls_width + canvas_width << " x 3\n";
+                            << controls_width + _canvas_width << " x 3\n";
                }
 
                /* draw where it is */
 
-               Gdk::Rectangle r (0, at - 1, controls_width + (int) canvas_width, 3);
+               Gdk::Rectangle r (0, at - 1, controls_width + (int) _canvas_width, 3);
                win->invalidate_rect (r, true);
        }
 #endif
@@ -5053,7 +5254,7 @@ Editor::on_expose_event (GdkEventExpose* ev)
 
                lr.x = 0;
                lr.y = resize_line_y;
-               lr.width = controls_width + (int) canvas_width;
+               lr.width = controls_width + (int) _canvas_width;
                lr.height = 3;
 
                if (gdk_rectangle_intersect (&lr, &ev->area, &intersection)) {
@@ -5074,11 +5275,11 @@ Editor::on_expose_event (GdkEventExpose* ev)
                        gdk_draw_line (win, gc->gobj(), 
                                       0,
                                       resize_line_y, 
-                                      (int) canvas_width + controls_width,
+                                      (int) _canvas_width + controls_width,
                                       resize_line_y);
 #if 0
                        cerr << "drew line @ " << xroot << ", " << yroot + resize_line_y 
-                            << " to " << xroot + (int) canvas_width + controls_width
+                            << " to " << xroot + (int) _canvas_width + controls_width
                             << ", " << yroot + resize_line_y
                             << endl;
 #endif
@@ -5110,7 +5311,7 @@ Editor::add_to_idle_resize (TimeAxisView* view, uint32_t h)
 {
        if (resize_idle_id < 0) {
                resize_idle_id = g_idle_add (_idle_resizer, this);
-       }
+       } 
 
        resize_idle_target = h;
 
@@ -5128,6 +5329,27 @@ Editor::idle_resize ()
                (*i)->idle_resize (resize_idle_target);
        }
        pending_resizes.clear();
+       flush_canvas ();
        resize_idle_id = -1;
        return false;
 }
+
+void
+Editor::located ()
+{
+       ENSURE_GUI_THREAD (mem_fun (*this, &Editor::located));
+
+       _pending_locate_request = false;
+}
+
+void
+Editor::region_view_added (RegionView *)
+{
+       _summary->set_dirty ();
+}
+
+void
+Editor::streamview_height_changed ()
+{
+       _summary->set_dirty ();
+}