Another similar fix for use of an uninitialized variable.
[ardour.git] / gtk2_ardour / editor.cc
index ca51d571bebb7c9b74f250e1facca27a5de970cf..c9c309c6c545a51fd682b322aa288563ea713ac3 100644 (file)
 #include "mixer_strip.h"
 #include "editor_route_groups.h"
 #include "editor_regions.h"
+#include "editor_snapshots.h"
 
 #include "i18n.h"
 
@@ -210,50 +211,47 @@ show_me_the_size (Requisition* r, const char* what)
 }
 
 Editor::Editor ()
-       : 
          /* time display buttons */
-
-         minsec_label (_("Mins:Secs")),
-         bbt_label (_("Bars:Beats")),
-         smpte_label (_("Timecode")),
-         frame_label (_("Samples")),
-         tempo_label (_("Tempo")),
-         meter_label (_("Meter")),
-         mark_label (_("Location Markers")),
-         range_mark_label (_("Range Markers")),
-         transport_mark_label (_("Loop/Punch Ranges")),
-         cd_mark_label (_("CD Markers")),
-         edit_packer (4, 4, true),
+       : minsec_label (_("Mins:Secs"))
+       , bbt_label (_("Bars:Beats"))
+       , smpte_label (_("Timecode"))
+       , frame_label (_("Samples"))
+       , tempo_label (_("Tempo"))
+       , meter_label (_("Meter"))
+       , mark_label (_("Location Markers"))
+       , range_mark_label (_("Range Markers"))
+       , transport_mark_label (_("Loop/Punch Ranges"))
+       , cd_mark_label (_("CD Markers"))
+       , edit_packer (4, 4, true)
 
          /* the values here don't matter: layout widgets
             reset them as needed.
          */
-
-         vertical_adjustment (0.0, 0.0, 10.0, 400.0),
-         horizontal_adjustment (0.0, 0.0, 20.0, 1200.0),
-
+         
+       , vertical_adjustment (0.0, 0.0, 10.0, 400.0)
+       , horizontal_adjustment (0.0, 0.0, 20.0, 1200.0)
+         
          /* tool bar related */
 
-         edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true),
-         zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true),
+       , edit_point_clock (X_("editpoint"), false, X_("EditPointClock"), true)
+       , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, true)
          
-         toolbar_selection_clock_table (2,3),
+       , toolbar_selection_clock_table (2,3)
+         
+       , automation_mode_button (_("mode"))
+       , global_automation_button (_("automation"))
+         
+       , midi_panic_button (_("Panic"))
          
-         automation_mode_button (_("mode")),
-         global_automation_button (_("automation")),
-
-         midi_panic_button (_("Panic")),
-         midi_tools_tearoff (0),
-
 #ifdef WITH_CMT
-         image_socket_listener(0),
+       , image_socket_listener(0)
 #endif
-
+         
          /* nudge */
-
-         nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true),
-         meters_running(false),
-         _pending_locate_request (false)
+         
+       , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, true)
+       , meters_running(false)
+       , _pending_locate_request (false)
 
 {
        constructed = false;
@@ -327,8 +325,6 @@ Editor::Editor ()
        region_edit_menu_split_item = 0;
        temp_location = 0;
        leftmost_frame = 0;
-       ignore_mouse_mode_toggle = false;
-       ignore_midi_edit_mode_toggle = false;
        current_stepping_trackview = 0;
        entered_track = 0;
        entered_regionview = 0;
@@ -362,9 +358,9 @@ Editor::Editor ()
        location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
        location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
 
-       set_midi_edit_mode (MidiEditPencil, true);
        _edit_point = EditAtMouse;
-       set_mouse_mode (MouseObject, true);
+       _internal_editing = false;
+       current_canvas_cursor = 0;
 
        frames_per_unit = 2048; /* too early to use reset_zoom () */
        reset_hscrollbar_stepping ();
@@ -530,6 +526,7 @@ Editor::Editor ()
        _route_groups = new EditorRouteGroups (this);
        _routes = new EditorRoutes (this);
        _regions = new EditorRegions (this);
+       _snapshots = new EditorSnapshots (this);
 
        named_selection_scroller.add (named_selection_display);
        named_selection_scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
@@ -547,21 +544,6 @@ Editor::Editor ()
        named_selection_display.signal_key_release_event().connect (mem_fun(*this, &Editor::named_selection_display_key_release), false);
        named_selection_display.get_selection()->signal_changed().connect (mem_fun (*this, &Editor::named_selection_display_selection_changed));
 
-       /* SNAPSHOTS */
-
-       snapshot_display_model = ListStore::create (snapshot_display_columns);
-       snapshot_display.set_model (snapshot_display_model);
-       snapshot_display.append_column (X_("snapshot"), snapshot_display_columns.visible_name);
-       snapshot_display.set_name ("SnapshotDisplay");
-       snapshot_display.set_size_request (75, -1);
-       snapshot_display.set_headers_visible (false);
-       snapshot_display.set_reorderable (false);
-       snapshot_display_scroller.add (snapshot_display);
-       snapshot_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
-
-       snapshot_display.get_selection()->signal_changed().connect (mem_fun(*this, &Editor::snapshot_display_selection_changed));
-       snapshot_display.signal_button_press_event().connect (mem_fun (*this, &Editor::snapshot_display_button_press), false);
-
        Gtk::Label* nlabel;
 
        nlabel = manage (new Label (_("Regions")));
@@ -572,7 +554,7 @@ Editor::Editor ()
        the_notebook.append_page (_routes->widget (), *nlabel);
        nlabel = manage (new Label (_("Snapshots")));
        nlabel->set_angle (-90);
-       the_notebook.append_page (snapshot_display_scroller, *nlabel);
+       the_notebook.append_page (_snapshots->widget (), *nlabel);
        nlabel = manage (new Label (_("Route Groups")));
        nlabel->set_angle (-90);
        the_notebook.append_page (_route_groups->widget (), *nlabel);
@@ -602,7 +584,6 @@ Editor::Editor ()
        edit_pane.signal_size_allocate().connect (bind (mem_fun(*this, &Editor::pane_allocation_handler), static_cast<Paned*> (&edit_pane)));
 
        top_hbox.pack_start (toolbar_frame, false, true);
-       top_hbox.pack_start (midi_toolbar_frame, false, true);
 
        HBox *hbox = manage (new HBox);
        hbox->pack_start (edit_pane, true, true);
@@ -628,6 +609,7 @@ Editor::Editor ()
        set_snap_to (snap_type);
        snap_mode = SnapOff;
        set_snap_mode (snap_mode);
+       set_mouse_mode (MouseObject, true);
        set_edit_point_preference (EditAtMouse, true);
 
        XMLNode* node = ARDOUR_UI::instance()->editor_settings();
@@ -924,7 +906,7 @@ Editor::control_scroll (float fraction)
 }
 
 bool
-Editor::deferred_control_scroll (nframes64_t target)
+Editor::deferred_control_scroll (nframes64_t /*target*/)
 {
        session->request_locate (*_control_scroll_target, session->transport_rolling());
        // reset for next stream
@@ -1183,14 +1165,11 @@ Editor::connect_to_session (Session *t)
        handle_new_duration ();
 
        redisplay_named_selections ();
-       redisplay_snapshots ();
 
        restore_ruler_visibility ();
        //tempo_map_changed (Change (0));
        session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
 
-       _routes->initial_display ();
-
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                (static_cast<TimeAxisView*>(*i))->set_samples_per_unit (frames_per_unit);
        }
@@ -1216,6 +1195,8 @@ Editor::connect_to_session (Session *t)
        _group_tabs->connect_to_session (session);
        _route_groups->connect_to_session (session);
        _regions->connect_to_session (session);
+       _snapshots->connect_to_session (session);
+       _routes->connect_to_session (session);
        
        start_updating ();
 }
@@ -1482,7 +1463,7 @@ Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type,
 }
 
 Menu*
-Editor::build_track_context_menu (nframes64_t ignored)
+Editor::build_track_context_menu (nframes64_t)
 {
        using namespace Menu_Helpers;
 
@@ -1494,7 +1475,7 @@ Editor::build_track_context_menu (nframes64_t ignored)
 }
 
 Menu*
-Editor::build_track_bus_context_menu (nframes64_t ignored)
+Editor::build_track_bus_context_menu (nframes64_t)
 {
        using namespace Menu_Helpers;
 
@@ -1626,7 +1607,7 @@ Editor::analyze_range_selection()
 }
 
 Menu*
-Editor::build_track_selection_context_menu (nframes64_t ignored)
+Editor::build_track_selection_context_menu (nframes64_t)
 {
        using namespace Menu_Helpers;
        MenuList& edit_items  = track_selection_context_menu.items();
@@ -1643,7 +1624,7 @@ Editor::build_track_selection_context_menu (nframes64_t ignored)
  * @param edit_items List to add the items to.
  */
 void
-Editor::add_crossfade_context_items (AudioStreamView* view, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
+Editor::add_crossfade_context_items (AudioStreamView* /*view*/, boost::shared_ptr<Crossfade> xfade, Menu_Helpers::MenuList& edit_items, bool many)
 {
        using namespace Menu_Helpers;
        Menu     *xfade_menu = manage (new Menu);
@@ -1699,20 +1680,6 @@ Editor::xfade_edit_right_region ()
        }
 }
 
-/** Add an element to a menu, settings its sensitivity.
- * @param m Menu to add to.
- * @param e Element to add.
- * @param s true to make sensitive, false to make insensitive
- */
-void
-Editor::add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s) const
-{
-       m.push_back (e);
-       if (!s) {
-               m.back().set_sensitive (false);
-       }
-}
-
 void
 Editor::add_region_context_items (StreamView* sv, boost::shared_ptr<Region> region, Menu_Helpers::MenuList& edit_items)
 {
@@ -1948,40 +1915,44 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
 {
        using namespace Menu_Helpers;
 
-       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)));
+       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)));
 
        edit_items.push_back (SeparatorElem());
        edit_items.push_back (MenuElem (_("Spectral Analysis"), mem_fun(*this, &Editor::analyze_range_selection)));
-       
-       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)));
+
+       if (!selection->regions.empty()) {
+               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)));
+       }
 
        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)));
+       edit_items.push_back (MenuElem (_("Silence Range"), 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)));
        
        edit_items.push_back (SeparatorElem());
-       edit_items.push_back (MenuElem (_("Select all in range"), mem_fun(*this, &Editor::select_all_selectables_using_time_selection)));
+       edit_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 (_("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)));
+       edit_items.push_back (MenuElem (_("Set Loop from Range"), bind (mem_fun(*this, &Editor::set_loop_from_selection), false)));
+       edit_items.push_back (MenuElem (_("Set Punch from Range"), mem_fun(*this, &Editor::set_punch_from_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 (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)));
+       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)));
 }
 
        
@@ -2354,10 +2325,6 @@ Editor::set_state (const XMLNode& node)
                set_snap_mode ((SnapMode) atoi (prop->value()));
        }
 
-       if ((prop = node.property ("edit-point"))) {
-               set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
-       }
-
        if ((prop = node.property ("mouse-mode"))) {
                MouseMode m = str2mousemode(prop->value());
                mouse_mode = MouseMode ((int) m + 1); /* lie, force mode switch */
@@ -2367,6 +2334,10 @@ Editor::set_state (const XMLNode& node)
                set_mouse_mode (MouseObject, true);
        }
 
+       if ((prop = node.property ("edit-point"))) {
+               set_edit_point_preference ((EditPoint) string_2_enum (prop->value(), _edit_point), true);
+       }
+
        if ((prop = node.property ("show-waveforms-recording"))) {
                bool yn = (prop->value() == "yes");
                _show_waveforms_recording = !yn;
@@ -2809,36 +2780,13 @@ Editor::setup_toolbar ()
 
        /* Mode Buttons (tool selection) */
 
-       vector<ToggleButton *> mouse_mode_buttons;
-
-       mouse_move_button.add (*(manage (new Image (::get_icon("tool_object")))));
        mouse_move_button.set_relief(Gtk::RELIEF_NONE);
-       mouse_mode_buttons.push_back (&mouse_move_button);
-
-       if (!Profile->get_sae()) {
-               mouse_select_button.add (*(manage (new Image (get_xpm("tool_range.xpm")))));
-               mouse_select_button.set_relief(Gtk::RELIEF_NONE);
-               mouse_mode_buttons.push_back (&mouse_select_button);
-
-               mouse_gain_button.add (*(manage (new Image (::get_icon("tool_gain")))));
-               mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
-               mouse_mode_buttons.push_back (&mouse_gain_button);
-       }
-
-       mouse_zoom_button.add (*(manage (new Image (::get_icon("tool_zoom")))));
+       mouse_select_button.set_relief(Gtk::RELIEF_NONE);
+       mouse_gain_button.set_relief(Gtk::RELIEF_NONE);
        mouse_zoom_button.set_relief(Gtk::RELIEF_NONE);
-       mouse_mode_buttons.push_back (&mouse_zoom_button);
-       mouse_timefx_button.add (*(manage (new Image (::get_icon("tool_stretch")))));
        mouse_timefx_button.set_relief(Gtk::RELIEF_NONE);
-       mouse_mode_buttons.push_back (&mouse_timefx_button);
-       mouse_audition_button.add (*(manage (new Image (::get_icon("tool_audition")))));
        mouse_audition_button.set_relief(Gtk::RELIEF_NONE);
-       mouse_note_button.add (*(manage (new Image (::get_icon("tool_note")))));
-       mouse_note_button.set_relief(Gtk::RELIEF_NONE);
-       mouse_mode_buttons.push_back (&mouse_note_button);
-       mouse_mode_buttons.push_back (&mouse_audition_button);
-       
-       mouse_mode_button_set = new GroupedButtons (mouse_mode_buttons);
+       // internal_edit_button.set_relief(Gtk::RELIEF_NONE);
 
        HBox* mode_box = manage(new HBox);
        mode_box->set_border_width (2);
@@ -2854,7 +2802,7 @@ Editor::setup_toolbar ()
        }
        mouse_mode_button_box.pack_start(mouse_timefx_button, true, true);
        mouse_mode_button_box.pack_start(mouse_audition_button, true, true);
-       mouse_mode_button_box.pack_start(mouse_note_button, true, true);
+       mouse_mode_button_box.pack_start(internal_edit_button, true, true);
        mouse_mode_button_box.set_homogeneous(true);
 
        vector<string> edit_mode_strings;
@@ -2887,21 +2835,21 @@ Editor::setup_toolbar ()
        mouse_mode_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox), 
                                                   &mouse_mode_tearoff->tearoff_window(), 1));
 
+       mouse_move_button.set_mode (false);
+       mouse_select_button.set_mode (false);
+       mouse_gain_button.set_mode (false);
+       mouse_zoom_button.set_mode (false);
+       mouse_timefx_button.set_mode (false);
+       mouse_audition_button.set_mode (false);
+
        mouse_move_button.set_name ("MouseModeButton");
        mouse_select_button.set_name ("MouseModeButton");
        mouse_gain_button.set_name ("MouseModeButton");
        mouse_zoom_button.set_name ("MouseModeButton");
        mouse_timefx_button.set_name ("MouseModeButton");
        mouse_audition_button.set_name ("MouseModeButton");
-       mouse_note_button.set_name ("MouseModeButton");
 
-       ARDOUR_UI::instance()->tooltips().set_tip (mouse_move_button, _("Select/Move Objects"));
-       ARDOUR_UI::instance()->tooltips().set_tip (mouse_select_button, _("Select/Move Ranges"));
-       ARDOUR_UI::instance()->tooltips().set_tip (mouse_gain_button, _("Draw Gain Automation"));
-       ARDOUR_UI::instance()->tooltips().set_tip (mouse_zoom_button, _("Select Zoom Range"));
-       ARDOUR_UI::instance()->tooltips().set_tip (mouse_timefx_button, _("Stretch/Shrink Regions"));
-       ARDOUR_UI::instance()->tooltips().set_tip (mouse_audition_button, _("Listen to Specific Regions"));
-       ARDOUR_UI::instance()->tooltips().set_tip (mouse_note_button, _("Edit MIDI Notes"));
+       internal_edit_button.set_name ("MouseModeButton");
 
        mouse_move_button.unset_flags (CAN_FOCUS);
        mouse_select_button.unset_flags (CAN_FOCUS);
@@ -2909,20 +2857,7 @@ Editor::setup_toolbar ()
        mouse_zoom_button.unset_flags (CAN_FOCUS);
        mouse_timefx_button.unset_flags (CAN_FOCUS);
        mouse_audition_button.unset_flags (CAN_FOCUS);
-       mouse_note_button.unset_flags (CAN_FOCUS);
-
-       mouse_select_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
-       mouse_select_button.signal_button_release_event().connect (mem_fun(*this, &Editor::mouse_select_button_release));
-
-       mouse_move_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
-       mouse_gain_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseGain));
-       mouse_zoom_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseZoom));
-       mouse_timefx_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
-       mouse_audition_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
-       mouse_note_button.signal_toggled().connect (bind (mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseNote));
-
-       // mouse_move_button.set_active (true);
-       
+       internal_edit_button.unset_flags (CAN_FOCUS);
 
        /* Zoom */
        
@@ -3024,11 +2959,10 @@ Editor::setup_toolbar ()
 
        toolbar_hbox.pack_start (*mouse_mode_tearoff, false, false);
        toolbar_hbox.pack_start (*tools_tearoff, false, false);
-
        
        hbox->pack_start (snap_box, false, false);
-       // hbox->pack_start (zoom_box, false, false); 
        hbox->pack_start (*nudge_box, false, false);
+       hbox->pack_start (panic_box, false, false);
 
        hbox->show_all ();
        
@@ -3051,12 +2985,7 @@ Editor::midi_panic_button_pressed ()
 void
 Editor::setup_midi_toolbar ()
 {
-       string pixmap_path;
-
-       /* Mode Buttons (tool selection) */
-
-       vector<ToggleButton *> midi_tool_buttons;
-
+#if 0
        midi_tool_pencil_button.add (*(manage (new Image (::get_icon("midi_tool_pencil")))));
        midi_tool_pencil_button.set_relief(Gtk::RELIEF_NONE);
        midi_tool_buttons.push_back (&midi_tool_pencil_button);
@@ -3070,42 +2999,11 @@ Editor::setup_midi_toolbar ()
        midi_tool_erase_button.set_relief(Gtk::RELIEF_NONE);
        midi_tool_buttons.push_back (&midi_tool_erase_button);
 
-       midi_tool_pencil_button.set_active(true);
-       
-       midi_tool_button_set = new GroupedButtons (midi_tool_buttons);
-
-       midi_tool_button_box.set_border_width (2);
-       midi_tool_button_box.set_spacing(1);
-       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.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");
-
        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"));
-
-       midi_tool_pencil_button.unset_flags (CAN_FOCUS);
-       midi_tool_select_button.unset_flags (CAN_FOCUS);
-       midi_tool_resize_button.unset_flags (CAN_FOCUS);
-       midi_tool_erase_button.unset_flags (CAN_FOCUS);
-       
-       midi_tool_pencil_button.signal_toggled().connect (bind (mem_fun(*this,
-                               &Editor::midi_edit_mode_toggled), Editing::MidiEditPencil));
-       midi_tool_select_button.signal_toggled().connect (bind (mem_fun(*this,
-                               &Editor::midi_edit_mode_toggled), Editing::MidiEditSelect));
-       midi_tool_resize_button.signal_toggled().connect (bind (mem_fun(*this,
-                               &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));
-
+#endif
        
        /* Midi sound notes */
        midi_sound_notes.add (*(manage (new Image (::get_icon("midi_sound_notes")))));
@@ -3115,57 +3013,22 @@ Editor::setup_midi_toolbar ()
        
        /* 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... */
+       midi_panic_button.signal_pressed().connect (mem_fun(this, &Editor::midi_panic_button_pressed));
 
-       midi_tools_tearoff = manage (new TearOff (midi_tool_button_box));
-       midi_tools_tearoff->set_name ("MouseModeBase");
-
-       /*
-       midi_tools_tearoff->Detach.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox), 
-                                            &midi_tools_tearoff->tearoff_window()));
-       midi_tools_tearoff->Attach.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox), 
-                                            &midi_tools_tearoff->tearoff_window(), 0));
-       midi_tools_tearoff->Hidden.connect (bind (mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&midi_toolbar_hbox), 
-                                            &midi_tools_tearoff->tearoff_window()));
-       midi_tools_tearoff->Visible.connect (bind (mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&midi_toolbar_hbox), 
-                                             &midi_tools_tearoff->tearoff_window(), 0));
-       */
-
-       midi_toolbar_hbox.set_spacing (10);
-       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();
-       midi_tools_tearoff->show_all();
-       
-       midi_toolbar_base.set_name ("ToolBarBase");
-       midi_toolbar_base.add (midi_toolbar_hbox);
-
-       midi_toolbar_frame.set_shadow_type (SHADOW_OUT);
-       midi_toolbar_frame.set_name ("BaseFrame");
-       midi_toolbar_frame.add (midi_toolbar_base);
+       panic_box.pack_start (midi_sound_notes , true, true);
+       panic_box.pack_start (midi_panic_button, true, true);
 }
 
 int
 Editor::convert_drop_to_paths (
                vector<ustring>&                paths, 
-               const RefPtr<Gdk::DragContext>& context,
-               gint                            x,
-               gint                            y,
+               const RefPtr<Gdk::DragContext>& /*context*/,
+               gint                            /*x*/,
+               gint                            /*y*/,
                const SelectionData&            data,
-               guint                           info,
-               guint                           time)
+               guint                           /*info*/,
+               guint                           /*time*/)
 {      
        if (session == 0) {
                return -1;
@@ -3834,8 +3697,10 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
 }
 
 void
-Editor::detach_tearoff (Box* b, Window* w)
+Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
 {
+       cerr << "remove tearoff\n";
+
        if (tools_tearoff->torn_off() && 
            mouse_mode_tearoff->torn_off()) {
                top_hbox.remove (toolbar_frame);
@@ -3843,8 +3708,9 @@ Editor::detach_tearoff (Box* b, Window* w)
 }
 
 void
-Editor::reattach_tearoff (Box* b, Window* w, int32_t n)
+Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
 {
+       cerr << "reattach tearoff\n";
        if (toolbar_frame.get_parent() == 0) {
                top_hbox.pack_end (toolbar_frame);
        }
@@ -4062,161 +3928,12 @@ Editor::control_layout_scroll (GdkEventScroll* ev)
        return false;
 }
 
-
-/** A new snapshot has been selected.
- */
-void
-Editor::snapshot_display_selection_changed ()
-{
-       if (snapshot_display.get_selection()->count_selected_rows() > 0) {
-
-               TreeModel::iterator i = snapshot_display.get_selection()->get_selected();
-               
-               Glib::ustring snap_name = (*i)[snapshot_display_columns.real_name];
-
-               if (snap_name.length() == 0) {
-                       return;
-               }
-               
-               if (session->snap_name() == snap_name) {
-                       return;
-               }
-               
-               ARDOUR_UI::instance()->load_session(session->path(), string (snap_name));
-       }
-}
-
-bool
-Editor::snapshot_display_button_press (GdkEventButton* ev)
-{
-       if (ev->button == 3) {
-               /* Right-click on the snapshot list. Work out which snapshot it
-                  was over. */
-               Gtk::TreeModel::Path path;
-               Gtk::TreeViewColumn* col;
-               int cx;
-               int cy;
-               snapshot_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, col, cx, cy);
-               Gtk::TreeModel::iterator iter = snapshot_display_model->get_iter (path);
-               if (iter) {
-                       Gtk::TreeModel::Row row = *iter;
-                       popup_snapshot_context_menu (ev->button, ev->time, row[snapshot_display_columns.real_name]);
-               }
-               return true;
-       }
-
-       return false;
-}
-
-
-/** Pop up the snapshot display context menu.
- * @param button Button used to open the menu.
- * @param time Menu open time.
- * @snapshot_name Name of the snapshot that the menu click was over.
- */
-
-void
-Editor::popup_snapshot_context_menu (int button, int32_t time, Glib::ustring snapshot_name)
-{
-       using namespace Menu_Helpers;
-
-       MenuList& items (snapshot_context_menu.items());
-       items.clear ();
-
-       const bool modification_allowed = (session->snap_name() != snapshot_name && session->name() != snapshot_name);
-
-       add_item_with_sensitivity (items, MenuElem (_("Remove"), bind (mem_fun (*this, &Editor::remove_snapshot), snapshot_name)), modification_allowed);
-
-       add_item_with_sensitivity (items, MenuElem (_("Rename"), bind (mem_fun (*this, &Editor::rename_snapshot), snapshot_name)), modification_allowed);
-
-       snapshot_context_menu.popup (button, time);
-}
-
-void
-Editor::rename_snapshot (Glib::ustring old_name)
-{
-       ArdourPrompter prompter(true);
-
-       string new_name;
-
-       prompter.set_name ("Prompter");
-       prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
-       prompter.set_prompt (_("New name of snapshot"));
-       prompter.set_initial_text (old_name);
-       
-       if (prompter.run() == RESPONSE_ACCEPT) {
-               prompter.get_result (new_name);
-               if (new_name.length()) {
-                       session->rename_state (old_name, new_name);
-                       redisplay_snapshots ();
-               }
-       }
-}
-
-
-void
-Editor::remove_snapshot (Glib::ustring name)
-{
-       vector<string> choices;
-
-       std::string prompt  = string_compose (_("Do you really want to remove snapshot \"%1\" ?\n(cannot be undone)"), name);
-
-       choices.push_back (_("No, do nothing."));
-       choices.push_back (_("Yes, remove it."));
-
-       Gtkmm2ext::Choice prompter (prompt, choices);
-
-       if (prompter.run () == 1) {
-               session->remove_state (name);
-               redisplay_snapshots ();
-       }
-}
-
-void
-Editor::redisplay_snapshots ()
-{
-       if (session == 0) {
-               return;
-       }
-
-       vector<sys::path> state_file_paths;
-
-       get_state_files_in_directory (session->session_directory().root_path(),
-                       state_file_paths);
-
-       if (state_file_paths.empty()) return;
-
-       vector<string> state_file_names(get_file_names_no_extension(state_file_paths));
-
-       snapshot_display_model->clear ();
-
-       for (vector<string>::iterator i = state_file_names.begin();
-                       i != state_file_names.end(); ++i)
-       {
-               string statename = (*i);
-               TreeModel::Row row = *(snapshot_display_model->append());
-               
-               /* this lingers on in case we ever want to change the visible
-                  name of the snapshot.
-               */
-               
-               string display_name;
-               display_name = statename;
-
-               if (statename == session->snap_name()) {
-                       snapshot_display.get_selection()->select(row);
-               } 
-               
-               row[snapshot_display_columns.visible_name] = display_name;
-               row[snapshot_display_columns.real_name] = statename;
-       }
-}
-
 void
 Editor::session_state_saved (string snap_name)
 {
        ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::session_state_saved), snap_name));
-       redisplay_snapshots ();
+       
+       _snapshots->redisplay ();
 }
 
 void
@@ -4320,7 +4037,7 @@ Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<bo
 }
 
 void 
-Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t sz)
+Editor::mapped_clear_playlist (RouteTimeAxisView& atv, uint32_t /*sz*/)
 {
        atv.clear_playlist ();
 }
@@ -4767,6 +4484,11 @@ Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
        commit_reversible_command ();
 }
 
+/** Find regions which exist at a given time, and optionally on a given list of tracks.
+ *  @param rs List to which found regions are added.
+ *  @param where Time to look at.
+ *  @param ts Tracks to look on; if this is empty, all tracks are examined.
+ */
 void
 Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
 {
@@ -4839,11 +4561,21 @@ Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSe
        }
 }
 
+/** Find all regions which are either:
+ *      - selected or
+ *      - the entered_regionview (if allow_entered == true) or
+ *      - under the preferred edit position AND on a selected track, or on a track
+ *        which is in the same active edit-enable route group as a selected region.
+ *  @param rs Returned region list.
+ *  @param allow_entered true to include the entered_regionview in the list.
+ */
 void
 Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
 {
+       /* Start with selected regions */
        rs = selection->regions;
 
+       /* Add the entered_regionview, if requested */
        if (allow_entered && entered_regionview) {
                rs.add (entered_regionview);
        }
@@ -4852,13 +4584,19 @@ Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
 
        RegionSelection to_map = rs;
 
+       /* tracks is currently the set of selected tracks; add any other tracks that
+        * have regions that are in the same edit-activated route group as one of
+        * our regions */
        for (RegionSelection::iterator i = to_map.begin (); i != to_map.end(); ++i) {
 
                RouteGroup* g = (*i)->get_time_axis_view().route_group ();
                if (g && g->active_property (RouteGroup::Edit)) {
                        tracks.add (axis_views_from_routes (g->route_list()));
                }
+       }
 
+       /* now find regions that are at the edit position on those tracks */
+       for (RegionSelection::iterator i = to_map.begin (); i != to_map.end(); ++i) {
                nframes64_t const where = get_preferred_edit_position ();
                get_regions_at (rs, where, tracks);
        }
@@ -4867,7 +4605,6 @@ Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
 void
 Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
 {
-
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                
                RouteTimeAxisView* tatv;
@@ -5040,19 +4777,31 @@ Editor::streamview_height_changed ()
        _summary->set_dirty ();
 }
 
+TimeAxisView*
+Editor::axis_view_from_route (Route* r) const
+{
+       TrackViewList::const_iterator j = track_views.begin ();
+       while (j != track_views.end()) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
+               if (rtv && rtv->route().get() == r) {
+                       return rtv;
+               }
+               ++j;
+       }
+
+       return 0;
+}
+
+
 TrackSelection
 Editor::axis_views_from_routes (list<Route*> r) const
 {
        TrackSelection t;
        
        for (list<Route*>::const_iterator i = r.begin(); i != r.end(); ++i) {
-               TrackViewList::const_iterator j = track_views.begin ();
-               while (j != track_views.end()) {
-                       RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*j);
-                       if (rtv && rtv->route().get() == *i) {
-                               t.push_back (rtv);
-                       }
-                       ++j;
+               TimeAxisView* tv = axis_view_from_route (*i);
+               if (tv) {
+                       t.push_back (tv);
                }
        }
 
@@ -5148,7 +4897,7 @@ Editor::remove_route (TimeAxisView *tv)
 }
 
 void
-Editor::hide_track_in_display (TimeAxisView& tv, bool temponly)
+Editor::hide_track_in_display (TimeAxisView& tv, bool /*temponly*/)
 {
        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);