Optional tabs down the LHS of the editor window to indicate edit group membership.
[ardour.git] / gtk2_ardour / editor.cc
index 3d14d9617805ea72919ef7fd56afe90005158bb4..613c91f2b81e86cf345d4786354a013a18a5db15 100644 (file)
 
 /* Note: public Editor methods are documented in public_editor.h */
 
+#define __STDC_LIMIT_MACROS 1
+#include <stdint.h>
 #include <unistd.h>
 #include <cstdlib>
 #include <cmath>
 #include <string>
 #include <algorithm>
+#include <map>
 
 #include <boost/none.hpp>
 
 #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/utils.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 <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
+
+#include "ardour/audio_diskstream.h"
+#include "ardour/audio_track.h"
+#include "ardour/audioplaylist.h"
+#include "ardour/audioregion.h"
+#include "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 "gui_thread.h"
 #include "simpleline.h"
 #include "rhythm_ferret.h"
-
-#ifdef FFT_ANALYSIS
+#include "actions.h"
+#include "tempo_lines.h"
 #include "analysis_window.h"
-#endif
+#include "bundle_manager.h"
+#include "global_port_matrix.h"
+#include "editor_drag.h"
+#include "editor_group_tabs.h"
 
 #include "i18n.h"
 
@@ -208,8 +216,7 @@ Editor::Editor ()
          range_mark_label (_("Range Markers")),
          transport_mark_label (_("Loop/Punch Ranges")),
          cd_mark_label (_("CD Markers")),
-
-         edit_packer (3, 3, true),
+         edit_packer (4, 4, true),
 
          /* the values here don't matter: layout widgets
             reset them as needed.
@@ -218,9 +225,6 @@ Editor::Editor ()
          vertical_adjustment (0.0, 0.0, 10.0, 400.0),
          horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
 
-         tempo_lines(0),
-         marker_tempo_lines(0),
-
          /* tool bar related */
 
          edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
@@ -231,6 +235,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
@@ -238,7 +245,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;
@@ -253,21 +261,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 = 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);
@@ -279,8 +282,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;
@@ -288,19 +291,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;
@@ -340,22 +338,26 @@ 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;
+       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();
@@ -363,15 +365,10 @@ 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;
-       canvas_hroizontally_scrolled_handler_id = -1;
        set_midi_edit_mode (MidiEditPencil, true);
+       _edit_point = EditAtMouse;
        set_mouse_mode (MouseObject, true);
 
-       last_visual_state.frames_per_unit = 0;
-
        frames_per_unit = 2048; /* too early to use reset_zoom () */
        reset_hscrollbar_stepping ();
        
@@ -379,119 +376,130 @@ 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::canvas_horizontally_scrolled), false);
-       vertical_adjustment.signal_value_changed().connect (mem_fun(*this, &Editor::tie_vertical_scrolling), true);
-       
-       track_canvas->set_hadjustment (horizontal_adjustment);
-       track_canvas->set_vadjustment (vertical_adjustment);
-       time_canvas->set_hadjustment (horizontal_adjustment);
-
-       track_canvas->signal_map_event().connect (mem_fun (*this, &Editor::track_canvas_map_handler));
-       time_canvas->signal_map_event().connect (mem_fun (*this, &Editor::time_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.pack_start (*time_canvas, true, true);
-       time_canvas_vbox.set_size_request (-1, (int)(timebar_height * visible_timebars) + 5);
-
        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_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));
+
+       HBox* h = manage (new HBox);
+       _group_tabs = new EditorGroupTabs (this);
+       h->pack_start (*_group_tabs, PACK_SHRINK);
+       h->pack_start (edit_controls_vbox);
+       controls_layout.add (*h);
+       
+       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);
        
-       time_button_vbox.pack_start (minsec_label, false, false);
-       time_button_vbox.pack_start (smpte_label, false, false);
-       time_button_vbox.pack_start (frame_label, false, false);
-       time_button_vbox.pack_start (bbt_label, false, false);
-       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);
+       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));
 
-       time_button_event_box.add (time_button_vbox);
-       time_button_event_box.set_name ("TimebarLabelBase");
-       time_button_frame.set_shadow_type (Gtk::SHADOW_NONE);
+       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.signal_button_release_event().connect (mem_fun(*this, &Editor::ruler_label_button_release));
+
+       time_button_event_box.add (time_button_vbox);
        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));
 
-       time_button_frame.add (time_button_event_box);
-       time_button_frame.set_name ("TimebarLabelBase");
-       time_button_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
-
        /* these enable us to have a dedicated window (for cursor setting, etc.) 
           for the canvas areas.
        */
@@ -500,46 +508,66 @@ 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,         3, 4, 1, 2,    FILL,        FILL|EXPAND, 0, 0);
-
-       edit_packer.attach (time_button_frame,       0, 2, 0, 1,    FILL,        SHRINK, 0, 0);
-       edit_packer.attach (time_canvas_event_box,   2, 4, 0, 1,    FILL|EXPAND, FILL, 0, 0);
 
-       edit_packer.attach (controls_layout,         1, 2, 1, 2,    FILL,        FILL|EXPAND, 0, 0);
-       edit_packer.attach (track_canvas_event_box,  2, 3, 1, 2,    FILL|EXPAND, FILL|EXPAND, 0, 0);
-
-       edit_packer.attach (zoom_box,                1, 2, 2, 3,    FILL,         FILL, 0, 0);
-       edit_packer.attach (edit_hscrollbar,         2, 3, 2, 3,    FILL|EXPAND,  FILL, 0, 0);
+       edit_packer.attach (zoom_vbox,               0, 1, 0, 2,    SHRINK,        FILL, 0, 0);
+       /* labels for the rulers */
+       edit_packer.attach (ruler_label_event_box,   1, 2, 0, 1,    FILL,        SHRINK, 0, 0);
+       /* labels for the marker "tracks" */
+       edit_packer.attach (time_button_event_box,   1, 2, 1, 2,    FILL,        SHRINK, 0, 0);
+       /* the rulers */
+       edit_packer.attach (time_canvas_event_box,   2, 3, 0, 1,    FILL|EXPAND, FILL, 0, 0);
+       /* track controls */
+       edit_packer.attach (controls_layout,         0, 2, 2, 3,    FILL,        FILL|EXPAND, 0, 0);
+       /* main canvas */
+       edit_packer.attach (track_canvas_event_box,  2, 3, 1, 3,    FILL|EXPAND, FILL|EXPAND, 0, 0);
 
        bottom_hbox.set_border_width (2);
        bottom_hbox.set_spacing (3);
 
+
+       CellRendererPixbufToggle* rec_col_renderer = Gtk::manage( new CellRendererPixbufToggle() );
+
+       rec_col_renderer->set_active_pixbuf(::get_icon("record_normal_red"));
+       rec_col_renderer->set_inactive_pixbuf(::get_icon("record_disabled_grey"));
+
+       rec_col_renderer->signal_toggled().connect(mem_fun(*this, &Editor::on_tv_rec_enable_toggled));
+
+       Gtk::TreeViewColumn* rec_state_column = Gtk::manage(new Gtk::TreeViewColumn("Rec", *rec_col_renderer));
+       rec_state_column->add_attribute(rec_col_renderer->property_active(), route_display_columns.rec_enabled);
+       rec_state_column->add_attribute(rec_col_renderer->property_visible(), route_display_columns.is_track);
+
        route_display_model = ListStore::create(route_display_columns);
        route_list_display.set_model (route_display_model);
+       
+       route_list_display.append_column (*rec_state_column);
        route_list_display.append_column (_("Show"), route_display_columns.visible);
        route_list_display.append_column (_("Name"), route_display_columns.text);
+       
        route_list_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
        route_list_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
+       route_list_display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
+       
        route_list_display.set_headers_visible (true);
        route_list_display.set_name ("TrackListDisplay");
-       route_list_display.get_selection()->set_mode (SELECTION_SINGLE);
+       route_list_display.get_selection()->set_mode (SELECTION_NONE);
        route_list_display.set_reorderable (true);
        route_list_display.set_size_request (100,-1);
        route_list_display.add_object_drag (route_display_columns.route.index(), "routes");
 
-       CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (0));
+       CellRendererToggle* route_list_visible_cell = dynamic_cast<CellRendererToggle*>(route_list_display.get_column_cell_renderer (1));
+       
        route_list_visible_cell->property_activatable() = true;
        route_list_visible_cell->property_radio() = false;
 
        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);
 
@@ -628,8 +656,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));
@@ -643,7 +684,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;
@@ -656,15 +697,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);
 
@@ -721,10 +766,16 @@ 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;
-       edit_pane.pack1 (edit_packer, true, true);
+
+       VPaned *editor_summary_pane = manage(new VPaned());
+       editor_summary_pane->pack1(edit_packer);
+       editor_summary_pane->pack2(*_summary);
+
+       edit_pane.pack1 (*editor_summary_pane, true, true);
        edit_pane.pack2 (the_notebook, false, true);
        
        edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
@@ -818,6 +869,7 @@ Editor::Editor ()
        ControlProtocol::ZoomIn.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), false));
        ControlProtocol::ZoomOut.connect (bind (mem_fun (*this, &Editor::temporal_zoom_step), true));
        ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll));
+       BasicUI::AccessAction.connect (mem_fun (*this, &Editor::access_action));
 
        Config->ParameterChanged.connect (mem_fun (*this, &Editor::parameter_changed));
        Route::SyncOrderKeys.connect (mem_fun (*this, &Editor::sync_order_keys));
@@ -829,8 +881,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() ;
@@ -841,17 +892,25 @@ Editor::~Editor()
        }
 #endif
 
-       if (track_canvas) {
-               delete track_canvas;
-               track_canvas = 0;
-       }
+       delete track_canvas;
+       delete _drag;
+}
+
+void 
+Editor::on_tv_rec_enable_toggled(const Glib::ustring& path_string){
+
+       // Get the model row that has been toggled.
+       Gtk::TreeModel::Row row = *route_display_model->get_iter(Gtk::TreeModel::Path(path_string));
+
+       TimeAxisView *tv = row[route_display_columns.tv];
+       AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (tv);
 
-       if (time_canvas) {
-               delete time_canvas;
-               time_canvas = 0;
+       if(atv != 0 && atv->is_audio_track()){
+             atv->get_diskstream()->set_record_enabled(!atv->get_diskstream()->record_enabled());
        }
 }
 
+
 void
 Editor::add_toplevel_controls (Container& cont)
 {
@@ -866,6 +925,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;
        }
@@ -906,20 +971,27 @@ 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");
+
+               parameter_changed ("show-edit-group-tabs");
+
+               /* 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 ();
@@ -967,14 +1039,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 ((nframes_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 ((nframes_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);
@@ -994,7 +1066,7 @@ Editor::control_scroll (float fraction)
        /*
                _control_scroll_target is an optional<T>
        
-               it acts like a pointer to an nframes_t, with
+               it acts like a pointer to an nframes64_t, with
                a operator conversion to boolean to check
                that it has a value could possibly use
                playhead_cursor->current_frame to store the
@@ -1007,12 +1079,12 @@ Editor::control_scroll (float fraction)
                _dragging_playhead = true;
        }
 
-       if ((fraction < 0.0f) && (*_control_scroll_target < (nframes_t) fabs(step))) {
+       if ((fraction < 0.0f) && (*_control_scroll_target < (nframes64_t) fabs(step))) {
                *_control_scroll_target = 0;
        } else if ((fraction > 0.0f) && (max_frames - *_control_scroll_target < step)) {
                *_control_scroll_target = max_frames - (current_page_frames()*2); // allow room for slop in where the PH is on the screen
        } else {
-               *_control_scroll_target += (nframes_t) floor (step);
+               *_control_scroll_target += (nframes64_t) floor (step);
        }
 
        /* move visuals, we'll catch up with it later */
@@ -1043,7 +1115,7 @@ Editor::control_scroll (float fraction)
 }
 
 bool
-Editor::deferred_control_scroll (nframes_t target)
+Editor::deferred_control_scroll (nframes64_t target)
 {
        session->request_locate (*_control_scroll_target, session->transport_rolling());
        // reset for next stream
@@ -1052,6 +1124,25 @@ Editor::deferred_control_scroll (nframes_t target)
        return false;
 }
 
+void
+Editor::access_action (std::string action_group, std::string action_item)
+{
+       if (!session) {
+               return;
+       }
+
+       ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::access_action), action_group, action_item));
+
+       RefPtr<Action> act;
+       act = ActionManager::get_action( action_group.c_str(), action_item.c_str() );
+
+       if (act) {
+               act->activate();
+       }
+               
+
+}
+
 void
 Editor::on_realize ()
 {
@@ -1064,6 +1155,7 @@ Editor::start_scrolling ()
 {
        scroll_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect 
                (mem_fun(*this, &Editor::update_current_screen));
+
 }
 
 void
@@ -1073,7 +1165,7 @@ Editor::stop_scrolling ()
 }
 
 void
-Editor::map_position_change (nframes_t frame)
+Editor::map_position_change (nframes64_t frame)
 {
        ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::map_position_change), frame));
 
@@ -1086,9 +1178,9 @@ Editor::map_position_change (nframes_t frame)
 }      
 
 void
-Editor::center_screen (nframes_t frame)
+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.
         */
@@ -1099,12 +1191,12 @@ Editor::center_screen (nframes_t frame)
 }
 
 void
-Editor::center_screen_internal (nframes_t frame, float page)
+Editor::center_screen_internal (nframes64_t frame, float page)
 {
        page /= 2;
                
        if (frame > page) {
-               frame -= (nframes_t) page;
+               frame -= (nframes64_t) page;
        } else {
                frame = 0;
        }
@@ -1115,17 +1207,20 @@ Editor::center_screen_internal (nframes_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);
 
-       nframes_t new_end = session->get_maximum_extent() + (nframes_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);
+       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
@@ -1167,6 +1262,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);
@@ -1178,10 +1275,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));
@@ -1211,21 +1304,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);
+       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) {
@@ -1254,6 +1363,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));
        
@@ -1274,16 +1384,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 */
@@ -1325,6 +1435,9 @@ Editor::connect_to_session (Session *t)
        /* register for undo history */
        session->register_with_memento_command_factory(_id, this);
 
+       _summary->set_session (session);
+       _group_tabs->set_session (session);
+       
        start_updating ();
 }
 
@@ -1471,10 +1584,10 @@ Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* i
 }
 
 void
-Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes_t frame)
+Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, bool with_selection, nframes64_t frame)
 {
        using namespace Menu_Helpers;
-       Menu* (Editor::*build_menu_function)(nframes_t);
+       Menu* (Editor::*build_menu_function)(nframes64_t);
        Menu *menu;
 
        switch (item_type) {
@@ -1590,7 +1703,7 @@ Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type,
 }
 
 Menu*
-Editor::build_track_context_menu (nframes_t ignored)
+Editor::build_track_context_menu (nframes64_t ignored)
 {
        using namespace Menu_Helpers;
 
@@ -1602,7 +1715,7 @@ Editor::build_track_context_menu (nframes_t ignored)
 }
 
 Menu*
-Editor::build_track_bus_context_menu (nframes_t ignored)
+Editor::build_track_bus_context_menu (nframes64_t ignored)
 {
        using namespace Menu_Helpers;
 
@@ -1614,7 +1727,7 @@ Editor::build_track_bus_context_menu (nframes_t ignored)
 }
 
 Menu*
-Editor::build_track_region_context_menu (nframes_t frame)
+Editor::build_track_region_context_menu (nframes64_t frame)
 {
        using namespace Menu_Helpers;
        MenuList& edit_items  = track_region_context_menu.items();
@@ -1627,10 +1740,20 @@ Editor::build_track_region_context_menu (nframes_t frame)
                boost::shared_ptr<Playlist> pl;
                
                if ((ds = rtv->get_diskstream()) && ((pl = ds->playlist()))) {
-                       Playlist::RegionList* regions = pl->regions_at ((nframes_t) floor ( (double)frame * ds->speed()));
-                       for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
-                               add_region_context_items (rtv->view(), (*i), edit_items);
+                       Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)frame * ds->speed()));
+
+                       if (selection->regions.size() > 1) {
+                               // there's already a multiple selection: just add a 
+                               // single region context menu that will act on all 
+                               // selected regions
+                               boost::shared_ptr<Region> dummy_region; // = NULL               
+                               add_region_context_items (rtv->view(), dummy_region, edit_items);                       
+                       } else {
+                               for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
+                                       add_region_context_items (rtv->view(), (*i), edit_items);
+                               }
                        }
+
                        delete regions;
                }
        }
@@ -1641,7 +1764,7 @@ Editor::build_track_region_context_menu (nframes_t frame)
 }
 
 Menu*
-Editor::build_track_crossfade_context_menu (nframes_t frame)
+Editor::build_track_crossfade_context_menu (nframes64_t frame)
 {
        using namespace Menu_Helpers;
        MenuList& edit_items  = track_crossfade_context_menu.items();
@@ -1667,10 +1790,17 @@ Editor::build_track_crossfade_context_menu (nframes_t frame)
                                add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
                        }
 
-                       for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
-                               add_region_context_items (atv->audio_view(), (*i), edit_items);
+                       if (selection->regions.size() > 1) {
+                               // there's already a multiple selection: just add a 
+                               // single region context menu that will act on all 
+                               // selected regions
+                               boost::shared_ptr<Region> dummy_region; // = NULL               
+                               add_region_context_items (atv->audio_view(), dummy_region, edit_items);                 
+                       } else {
+                               for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
+                                       add_region_context_items (atv->audio_view(), (*i), edit_items);
+                               }
                        }
-
                        delete regions;
                }
        }
@@ -1680,7 +1810,6 @@ Editor::build_track_crossfade_context_menu (nframes_t frame)
        return &track_crossfade_context_menu;
 }
 
-#ifdef FFT_ANALYSIS
 void
 Editor::analyze_region_selection()
 {
@@ -1716,10 +1845,9 @@ Editor::analyze_range_selection()
        
        analysis_window->present();
 }
-#endif /* FFT_ANALYSIS */
 
 Menu*
-Editor::build_track_selection_context_menu (nframes_t ignored)
+Editor::build_track_selection_context_menu (nframes64_t ignored)
 {
        using namespace Menu_Helpers;
        MenuList& edit_items  = track_selection_context_menu.items();
@@ -1810,26 +1938,29 @@ 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;
 
        if (region) {
                ar = boost::dynamic_pointer_cast<AudioRegion> (region);
                mr = boost::dynamic_pointer_cast<MidiRegion> (region);
-       }
 
-       /* when this particular menu pops up, make the relevant region 
-          become selected.
-       */
+               /* when this particular menu pops up, make the relevant region 
+                  become selected.
+               */
 
-       region_menu->signal_map_event().connect (bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
+               region_menu->signal_map_event().connect (
+                       bind (mem_fun(*this, &Editor::set_selected_regionview_from_map_event), sv, boost::weak_ptr<Region>(region)));
+               
+               items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
+               items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
+       }
 
-       items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::rename_region)));
-       items.push_back (MenuElem (_("Popup region editor"), mem_fun(*this, &Editor::edit_region)));
        items.push_back (MenuElem (_("Raise to top layer"), mem_fun(*this, &Editor::raise_region_to_top)));
        items.push_back (MenuElem (_("Lower to bottom layer"), mem_fun  (*this, &Editor::lower_region_to_bottom)));
        items.push_back (SeparatorElem());
@@ -1841,27 +1972,32 @@ 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) {
+               region_to_check = region;
+       } else {
+               region_to_check = selection->regions.front()->region();
+       }
 
        items.push_back (CheckMenuElem (_("Lock")));
        CheckMenuItem* region_lock_item = static_cast<CheckMenuItem*>(&items.back());
-       if (region->locked()) {
+       if (region_to_check->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()) {
+       
+       switch (region_to_check->positional_lock_style()) {
        case Region::MusicTime:
                bbt_glue_item->set_active (true);
                break;
@@ -1869,13 +2005,13 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
                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->muted()) {
+       if (region_to_check->muted()) {
                fooc.block (true);
                region_mute_item->set_active();
                fooc.block (false);
@@ -1885,15 +2021,15 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
                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()) {
+               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->at_natural_position()) {
+       if (region_to_check->at_natural_position()) {
                items.back().set_sensitive (false);
        }
        
@@ -1940,12 +2076,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());
                         
@@ -1968,7 +2110,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)));
                             
@@ -1977,6 +2127,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();
@@ -1985,7 +2139,7 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
        items.push_back (MenuElem (_("Multi-Duplicate"), (bind (mem_fun(*this, &Editor::duplicate_dialog), true))));
        items.push_back (MenuElem (_("Fill Track"), (mem_fun(*this, &Editor::region_fill_track))));
        items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_clicked_region)));
+       items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::remove_selected_regions)));
 
        /* OK, stick the region submenu at the top of the list, and then add
           the standard items.
@@ -1996,7 +2150,7 @@ Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> regi
        */
 
        string::size_type pos = 0;
-       string menu_item_name = region->name();
+       string menu_item_name = (region) ? region->name() : _("Selected regions");
 
        while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
                menu_item_name.replace (pos, 1, "__");
@@ -2014,43 +2168,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 (_("Bounce range"), mem_fun(*this, &Editor::bounce_range_selection)));
-       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)));
 }
 
        
@@ -2199,8 +2351,9 @@ Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
 
 void
 Editor::set_snap_to (SnapType st)
-{      
+{
        unsigned int snap_ind = (unsigned int)st;
+
        snap_type = st;
        
        if (snap_ind > snap_type_strings.size() - 1) {
@@ -2222,7 +2375,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;
 
@@ -2289,7 +2442,7 @@ Editor::set_edit_point_preference (EditPoint ep, bool force)
                break;
        }
 
-       const char* action;
+       const char* action=NULL;
 
        switch (_edit_point) {
        case EditAtPlayhead:
@@ -2332,30 +2485,63 @@ 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());
+               }
 
-               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_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());
+               }
+
+               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);
        move (x, y);
 
        if (session && (prop = node.property ("playhead"))) {
-               nframes_t pos = atol (prop->value().c_str());
+               nframes64_t pos = atol (prop->value().c_str());
                playhead_cursor->set_position (pos);
        } else {
                playhead_cursor->set_position (0);
@@ -2402,18 +2588,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;
@@ -2516,17 +2690,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));
 
@@ -2546,10 +2720,9 @@ Editor::get_state ()
 
        node->add_property ("edit-point", enum_2_string (_edit_point));
 
-       snprintf (buf, sizeof (buf), "%" PRIu32, playhead_cursor->current_frame);
+       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");
@@ -2574,19 +2747,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
@@ -2614,17 +2791,17 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
        switch (snap_type) {
        case SnapToCDFrame:
                if (((direction == 0) && (start % (one_second/75) > (one_second/75) / 2)) || (direction > 0)) {
-                       start = (nframes_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
+                       start = (nframes64_t) ceil ((double) start / (one_second / 75)) * (one_second / 75);
                } else {
-                       start = (nframes_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
+                       start = (nframes64_t) floor ((double) start / (one_second / 75)) * (one_second / 75);
                }
                break;
 
        case SnapToSMPTEFrame:
-               if (((direction == 0) && (fmod((double)start, (double)session->frames_per_smpte_frame()) > (session->frames_per_smpte_frame() / 2))) || (direction > 0)) {
-                       start = (nframes_t) (ceil ((double) start / session->frames_per_smpte_frame()) * session->frames_per_smpte_frame());
+               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 = (nframes_t) (floor ((double) start / session->frames_per_smpte_frame()) *  session->frames_per_smpte_frame());
+                       start = (nframes64_t) (floor ((double) start / session->frames_per_smpte_frame()) *  session->frames_per_smpte_frame());
                }
                break;
 
@@ -2636,9 +2813,9 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
                        start -= session->smpte_offset ();
                }    
                if (((direction == 0) && (start % one_smpte_second > one_smpte_second / 2)) || direction > 0) {
-                       start = (nframes_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
+                       start = (nframes64_t) ceil ((double) start / one_smpte_second) * one_smpte_second;
                } else {
-                       start = (nframes_t) floor ((double) start / one_smpte_second) * one_smpte_second;
+                       start = (nframes64_t) floor ((double) start / one_smpte_second) * one_smpte_second;
                }
                
                if (session->smpte_offset_negative())
@@ -2657,9 +2834,9 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
                        start -= session->smpte_offset ();
                }
                if (((direction == 0) && (start % one_smpte_minute > one_smpte_minute / 2)) || direction > 0) {
-                       start = (nframes_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
+                       start = (nframes64_t) ceil ((double) start / one_smpte_minute) * one_smpte_minute;
                } else {
-                       start = (nframes_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
+                       start = (nframes64_t) floor ((double) start / one_smpte_minute) * one_smpte_minute;
                }
                if (session->smpte_offset_negative())
                {
@@ -2671,17 +2848,17 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
                
        case SnapToSeconds:
                if (((direction == 0) && (start % one_second > one_second / 2)) || (direction > 0)) {
-                       start = (nframes_t) ceil ((double) start / one_second) * one_second;
+                       start = (nframes64_t) ceil ((double) start / one_second) * one_second;
                } else {
-                       start = (nframes_t) floor ((double) start / one_second) * one_second;
+                       start = (nframes64_t) floor ((double) start / one_second) * one_second;
                }
                break;
                
        case SnapToMinutes:
                if (((direction == 0) && (start % one_minute > one_minute / 2)) || (direction > 0)) {
-                       start = (nframes_t) ceil ((double) start / one_minute) * one_minute;
+                       start = (nframes64_t) ceil ((double) start / one_minute) * one_minute;
                } else {
-                       start = (nframes_t) floor ((double) start / one_minute) * one_minute;
+                       start = (nframes64_t) floor ((double) start / one_minute) * one_minute;
                }
                break;
 
@@ -2758,7 +2935,7 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
        case SnapToRegionSync:
        case SnapToRegionBoundary:
                if (!region_boundary_cache.empty()) {
-                       vector<nframes_t>::iterator i;
+                       vector<nframes64_t>::iterator i;
 
                        if (direction > 0) {
                                i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
@@ -2808,7 +2985,7 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
 }
 
 double
-Editor::snap_length_beats (nframes_t start)
+Editor::snap_length_beats (nframes64_t start)
 {
        if (!session) {
                return 1.0;
@@ -2852,12 +3029,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;
@@ -2910,12 +3081,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);
@@ -2924,6 +3096,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), 
@@ -2994,34 +3170,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, PACK_SHRINK);
+       zoom_vbox.pack_start (*zbc, PACK_SHRINK);
+       zoom_vbox.pack_start (zoom_box, PACK_SHRINK);
+
        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"));
 
@@ -3052,6 +3228,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), 
@@ -3082,6 +3262,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 ()
@@ -3114,18 +3301,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);
@@ -3140,6 +3327,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... */
 
@@ -3161,6 +3364,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();
@@ -3175,14 +3380,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;
@@ -3201,12 +3406,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 != '#')
@@ -3215,8 +3427,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)
                                {
@@ -3235,6 +3448,8 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                                p++;
                }
 
+               free ((void*)p);
+               
                if (uris.empty()) {
                        return -1;
                }
@@ -3245,7 +3460,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
                        
@@ -3305,15 +3520,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
 {
@@ -3329,7 +3535,7 @@ Editor::restore_state (State *state)
 
        *selection = *state->selection;
        time_selection_changed ();
-       region_selection_changed ();   
+       region_selection_changed ();
 
        /* XXX other selection change handlers? */
 }
@@ -3338,7 +3544,7 @@ void
 Editor::begin_reversible_command (string name)
 {
        if (session) {
-                before = &get_state();
+               before = &get_state();
                session->begin_reversible_command (name);
        }
 }
@@ -3488,13 +3694,23 @@ Editor::hide_verbose_canvas_cursor ()
 double
 Editor::clamp_verbose_cursor_x (double x)
 {
-       return min (horizontal_adjustment.get_value() + canvas_width - 75.0, x);
+       if (x < 0) {
+               x = 0;
+       } else {
+               x = min (_canvas_width - 200.0, x);
+       }
+       return x;
 }
 
 double
 Editor::clamp_verbose_cursor_y (double y)
 {
-       return min (vertical_adjustment.get_value() + canvas_height - 50.0, y);
+       if (y < canvas_timebars_vsize) {
+               y = canvas_timebars_vsize;
+       } else {
+               y = min (_canvas_height - 50, y);
+       }
+       return y;
 }
 
 void
@@ -3503,7 +3719,7 @@ Editor::set_verbose_canvas_cursor (const string & txt, double x, double y)
        verbose_canvas_cursor->property_text() = txt.c_str();
        /* don't get too close to the edge */
        verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (x);
-       verbose_canvas_cursor->property_y() = clamp_verbose_cursor_x (y);
+       verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (y);
 }
 
 void
@@ -3523,7 +3739,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);
@@ -3685,6 +3905,8 @@ Editor::zoom_focus_selection_done ()
                focus_type = ZoomFocusEdit;
        } else if (choice == _("Active Mark")) {
                focus_type = ZoomFocusEdit;
+       } else if (choice == _("Active Mark")) {
+               focus_type = ZoomFocusEdit;
        } else {
                focus_type = ZoomFocusMouse;
        } 
@@ -3794,12 +4016,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)) {
@@ -3808,14 +4041,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;
@@ -3847,6 +4080,8 @@ Editor::set_show_measures (bool yn)
                hide_measures ();
 
                if ((_show_measures = yn) == true) {
+                       if (tempo_lines)
+                               tempo_lines->show();
                        draw_measures ();
                }
                instant_save ();
@@ -3923,10 +4158,10 @@ Editor::playlist_selector () const
        return *_playlist_selector;
 }
 
-nframes_t
-Editor::get_nudge_distance (nframes_t pos, nframes_t& next)
+nframes64_t
+Editor::get_nudge_distance (nframes64_t pos, nframes64_t& next)
 {
-       nframes_t ret;
+       nframes64_t ret;
 
        ret = nudge_clock.current_duration (pos);
        next = ret + 1; /* XXXX fix me */
@@ -3938,7 +4173,9 @@ void
 Editor::end_location_changed (Location* location)
 {
        ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::end_location_changed), location));
-       reset_scrolling_region ();
+       //reset_scrolling_region ();
+       nframes64_t session_span = location->start() + (nframes64_t) floorf (current_page_frames() * 0.10f);
+       horizontal_adjustment.set_upper (session_span / frames_per_unit);
 }
 
 int
@@ -3978,7 +4215,7 @@ Editor::playlist_deletion_dialog (boost::shared_ptr<Playlist> pl)
 }
 
 bool
-Editor::audio_region_selection_covers (nframes_t where)
+Editor::audio_region_selection_covers (nframes64_t where)
 {
        for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) {
                if ((*a)->region()->covers (where)) {
@@ -3997,6 +4234,15 @@ Editor::prepare_for_cleanup ()
 
        selection->clear_regions ();
        selection->clear_playlists ();
+
+       no_region_list_redisplay = true;
+}
+
+void
+Editor::finish_cleanup ()
+{
+       no_region_list_redisplay = false;
+       redisplay_regions ();
 }
 
 Location*
@@ -4126,7 +4372,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 ();
                }
        }
 }
@@ -4200,8 +4446,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);
 
@@ -4212,8 +4456,8 @@ Editor::maximise_editing_space ()
                post_maximal_pane_position = edit_pane.get_width();
        }
 
-
        fullscreen();
+
        if(post_maximal_editor_width) {
                edit_pane.set_position (post_maximal_pane_position - 
                        abs(post_maximal_editor_width - pre_maximal_editor_width));
@@ -4225,9 +4469,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();
        }
@@ -4238,10 +4481,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));
 }
 
 /**
@@ -4254,7 +4494,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 ();
 }
 
@@ -4268,7 +4510,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 ();
 }
 
@@ -4282,20 +4526,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 
@@ -4318,11 +4564,18 @@ Editor::on_key_release_event (GdkEventKey* ev)
 }
 
 void
-Editor::reset_x_origin (nframes_t frame)
+Editor::reset_x_origin (nframes64_t frame)
 {
+       //cerr << "resetting x origin" << endl;
        queue_visual_change (frame);
 }
 
+void
+Editor::reset_y_origin (double y)
+{
+       queue_visual_change_y (y);
+}
+
 void
 Editor::reset_zoom (double fpu)
 {
@@ -4330,28 +4583,103 @@ Editor::reset_zoom (double fpu)
 }
 
 void
-Editor::reposition_and_zoom (nframes_t frame, double fpu)
+Editor::reposition_and_zoom (nframes64_t frame, double fpu)
 {
+       //cerr << "Editor::reposition_and_zoom () 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
        reset_x_origin (frame);
        reset_zoom (fpu);
+
+       if (!no_save_visual) {
+               undo_visual_stack.push_back (current_visual_state(false));
+       }
+}
+
+Editor::VisualState*
+Editor::current_visual_state (bool with_tracks)
+{
+       VisualState* vs = new VisualState;
+       vs->y_position = vertical_adjustment.get_value();
+       vs->frames_per_unit = frames_per_unit;
+       vs->leftmost_frame = leftmost_frame;
+       vs->zoom_focus = zoom_focus;
+       vs->zoomed_to_region = zoomed_to_region;
+
+       if (with_tracks) {
+               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+                       vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
+               }
+       }
+       
+       return vs;
 }
 
 void
-Editor::swap_visual_state ()
+Editor::undo_visual_state ()
 {
-       if (last_visual_state.frames_per_unit == 0) {
-               // never set
+       if (undo_visual_stack.empty()) {
                return;
        }
 
-       /* note: the correct functionality here is very dependent on the ordering of 
-          setting zoom focus, horizontal position and finally zoom. this is because
-          it is set_frames_per_unit() that overwrites last_visual_state.
-       */
+       VisualState* vs = undo_visual_stack.back();
+       undo_visual_stack.pop_back();
+       use_visual_state (*vs);
+       redo_visual_stack.push_back (vs);
+}
 
-       set_zoom_focus (last_visual_state.zoom_focus);
-       reposition_and_zoom (last_visual_state.leftmost_frame, last_visual_state.frames_per_unit);
-       zoomed_to_region = false;
+void
+Editor::redo_visual_state ()
+{
+       if (redo_visual_stack.empty()) {
+               return;
+       }
+
+       VisualState* vs = redo_visual_stack.back();
+       redo_visual_stack.pop_back();
+       use_visual_state (*vs);
+       undo_visual_stack.push_back (vs);
+}
+
+void
+Editor::swap_visual_state ()
+{
+       if (undo_visual_stack.empty()) {
+               redo_visual_state ();
+       } else {
+               undo_visual_state ();
+       }
+}
+
+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;
+
+               /* check if the track still exists - it could have been deleted */
+
+               if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
+                       (*t)->set_state (*(i->second));
+               }
+       }
+
+
+       if (!vs.track_states.empty()) {
+               update_route_visibility ();
+       } 
+
+       no_route_list_redisplay = false;
+       redisplay_route_list ();
+
+       no_save_visual = false;
 }
 
 void
@@ -4377,14 +4705,9 @@ Editor::set_frames_per_unit (double fpu)
        if (max_frames / fpu < 800.0) {
                return;
        }
-
-       if (fpu == frames_per_unit) {
-               return;
-       }
        
-       last_visual_state.frames_per_unit = frames_per_unit;
-       last_visual_state.leftmost_frame = leftmost_frame;
-       last_visual_state.zoom_focus = zoom_focus;
+       if (tempo_lines)
+               tempo_lines->tempo_map_changed();
 
        frames_per_unit = fpu;
        post_zoom ();
@@ -4393,9 +4716,11 @@ Editor::set_frames_per_unit (double fpu)
 void
 Editor::post_zoom ()
 {
+       nframes64_t cef = 0;
+
        // convert fpu to frame count
 
-       nframes_t frames = (nframes_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);
@@ -4413,37 +4738,71 @@ Editor::post_zoom ()
                }
        }
 
+       leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
+
        ZoomChanged (); /* EMIT_SIGNAL */
 
        reset_hscrollbar_stepping ();
-       reset_scrolling_region ();
 
-       if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
+       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 (nframes_t where)
+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;
+       pending_visual_change.add (VisualChange::TimeOrigin);
        
-       if (pending_visual_change.idle_handler_id < 0) {
-               pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
+       /* 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
@@ -4456,36 +4815,64 @@ int
 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) {
-               
-               nframes_t time_origin = (nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
+               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 */
 
-               if (time_origin != pending_visual_change.time_origin) {
-                       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);
        }
-       pending_visual_change.idle_handler_id = -1;
 
+       _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 */
 }
 
 struct EditorOrderTimeAxisSorter {
     bool operator() (const TimeAxisView* a, const TimeAxisView* b) const {
-           return a->order < b->order;
+           return a->order () < b->order ();
     }
 };
        
@@ -4550,7 +4937,7 @@ Editor::get_preferred_edit_position (bool ignore_playhead)
 }
 
 void
-Editor::set_loop_range (nframes_t start, nframes_t end, string cmd)
+Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
 {
        if (!session) return;
 
@@ -4560,24 +4947,24 @@ Editor::set_loop_range (nframes_t start, nframes_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 ();
 }
 
 void
-Editor::set_punch_range (nframes_t start, nframes_t end, string cmd)
+Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
 {
        if (!session) return;
 
@@ -4587,18 +4974,18 @@ Editor::set_punch_range (nframes_t start, nframes_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 ();
@@ -4616,23 +5003,20 @@ 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 ((nframes_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.push_back (rv);
+                                               rs.add (rv);
                                        }
                                }
 
@@ -4654,20 +5038,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 ((nframes_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);
@@ -4784,6 +5167,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 ()
 {
@@ -4802,10 +5205,85 @@ 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;
 }
+
+static gboolean
+_idle_resizer (gpointer arg)
+{
+       return ((Editor*)arg)->idle_resize ();
+}
+
+void
+Editor::add_to_idle_resize (TimeAxisView* view, int32_t h)
+{
+       if (resize_idle_id < 0) {
+               resize_idle_id = g_idle_add (_idle_resizer, this);
+               _pending_resize_amount = 0;
+       }
+
+       /* make a note of the smallest resulting height, so that we can clamp the
+          lower limit at TimeAxisView::hSmall */
+
+       int32_t min_resulting = INT32_MAX;
+
+       _pending_resize_amount += h;
+       _pending_resize_view = view;
+
+       min_resulting = min (min_resulting, int32_t (_pending_resize_view->current_height()) + _pending_resize_amount);
+
+       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+               min_resulting = min (min_resulting, int32_t ((*i)->current_height()) + _pending_resize_amount);
+       }
+
+       if (min_resulting < 0) {
+               min_resulting = 0;
+       }
+
+       /* clamp */
+       if (uint32_t (min_resulting) < TimeAxisView::hSmall) {
+               _pending_resize_amount += TimeAxisView::hSmall - min_resulting;
+       }
+}
+
+/** Handle pending resizing of tracks */
+bool
+Editor::idle_resize ()
+{
+       _pending_resize_view->idle_resize (_pending_resize_view->current_height() + _pending_resize_amount);
+       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+               if (*i != _pending_resize_view) {
+                       (*i)->idle_resize ((*i)->current_height() + _pending_resize_amount);
+               }
+                       
+       }
+       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 ();
+}