a boatload of minor and middle-sized changes to try to speed up undo. imperfect,...
[ardour.git] / gtk2_ardour / editor_selection.cc
index b4532668df25df380621ab3ae0ac0712890c4124..2b94a0561901f84525008c639192eaa23db379cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2006 Paul Davis 
+    Copyright (C) 2000-2006 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include <algorithm>
 #include <cstdlib>
 
-#include <pbd/stacktrace.h>
+#include "pbd/stacktrace.h"
 
-#include <ardour/diskstream.h>
-#include <ardour/playlist.h>
-#include <ardour/route_group.h>
-#include <ardour/profile.h>
+#include "ardour/session.h"
+#include "ardour/diskstream.h"
+#include "ardour/playlist.h"
+#include "ardour/route_group.h"
+#include "ardour/profile.h"
 
 #include "editor.h"
 #include "actions.h"
 #include "audio_streamview.h"
 #include "automation_line.h"
 #include "control_point.h"
+#include "editor_regions.h"
 
 #include "i18n.h"
 
 using namespace std;
-using namespace sigc;
 using namespace ARDOUR;
 using namespace PBD;
 using namespace Gtk;
@@ -49,7 +50,7 @@ using namespace Editing;
 struct TrackViewByPositionSorter
 {
     bool operator() (const TimeAxisView* a, const TimeAxisView *b) {
-           return a->y_position < b->y_position;
+           return a->y_position() < b->y_position();
     }
 };
 
@@ -69,10 +70,10 @@ Editor::extend_selection_to_track (TimeAxisView& view)
                } else {
                        return false;
                }
-       } 
+       }
 
        /* something is already selected, so figure out which range of things to add */
-       
+
        TrackViewList to_be_added;
        TrackViewList sorted = track_views;
        TrackViewByPositionSorter cmp;
@@ -102,18 +103,18 @@ Editor::extend_selection_to_track (TimeAxisView& view)
                        break;
                }
        }
-                       
+
        passed_clicked = false;
 
        if (forwards) {
 
                for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) {
-                                       
+
                        if ((*i) == &view) {
                                passed_clicked = true;
                                continue;
                        }
-                                       
+
                        if (passed_clicked) {
                                if ((*i)->hidden()) {
                                        continue;
@@ -129,18 +130,18 @@ Editor::extend_selection_to_track (TimeAxisView& view)
        } else {
 
                for (TrackViewList::reverse_iterator r = sorted.rbegin(); r != sorted.rend(); ++r) {
-                                       
+
                        if ((*r) == &view) {
                                passed_clicked = true;
                                continue;
                        }
-                                       
+
                        if (passed_clicked) {
-                                               
+
                                if ((*r)->hidden()) {
                                        continue;
                                }
-                                               
+
                                if (selection->selected (*r)) {
                                        break;
                                } else if (!(*r)->hidden()) {
@@ -149,12 +150,12 @@ Editor::extend_selection_to_track (TimeAxisView& view)
                        }
                }
        }
-                       
+
        if (!to_be_added.empty()) {
                selection->add (to_be_added);
                return true;
        }
-       
+
        return false;
 }
 
@@ -170,6 +171,9 @@ Editor::select_all_tracks ()
        selection->set (visible_views);
 }
 
+/** Select clicked_routeview, unless there are no currently selected
+ *  tracks, in which case nothing will happen unless `force' is true.
+ */
 void
 Editor::set_selected_track_as_side_effect (bool force)
 {
@@ -210,7 +214,7 @@ Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no
        case Selection::Set:
                selection->set (&view);
                break;
-               
+
        case Selection::Extend:
                extend_selection_to_track (view);
                break;
@@ -223,7 +227,7 @@ Editor::set_selected_track_from_click (bool press, Selection::Operation op, bool
        if (!clicked_routeview) {
                return;
        }
-       
+
        if (!press) {
                return;
        }
@@ -232,91 +236,81 @@ Editor::set_selected_track_from_click (bool press, Selection::Operation op, bool
 }
 
 bool
-Editor::set_selected_control_point_from_click (Selection::Operation op, bool no_remove)
+Editor::set_selected_control_point_from_click (Selection::Operation op, bool /*no_remove*/)
 {
        if (!clicked_control_point) {
                return false;
        }
 
-       /* select this point and any others that it represents */
-
-       double y1, y2;
-       nframes64_t x1, x2;
+       if (clicked_control_point->selected()) {
+               /* the clicked control point is already selected; others may be as well, so
+                  don't change the selection.
+               */
+               return true;
+       }
 
-       x1 = pixel_to_frame (clicked_control_point->get_x() - 10);
-       x2 = pixel_to_frame (clicked_control_point->get_x() + 10);
-       y1 = clicked_control_point->get_x() - 10;
-       y2 = clicked_control_point->get_y() + 10;
+       /* We know the ControlPoint that was clicked, but (as discussed in automation_selectable.h)
+        * selected automation data are described by areas on the AutomationLine.  A ControlPoint
+        * represents any model points in the space that it takes up, so the AutomationSelectable
+        * needs to be the size of the ControlPoint.
+        */
 
-       return select_all_within (x1, x2, y1, y2, selection->tracks, op);
+       double const size = clicked_control_point->size ();
+       
+       nframes64_t const x1 = pixel_to_frame (clicked_control_point->get_x() - size / 2);
+       nframes64_t const x2 = pixel_to_frame (clicked_control_point->get_x() + size / 2);
+       double y1 = clicked_control_point->get_y() - size / 2;
+       double y2 = clicked_control_point->get_y() + size / 2;
+
+       /* convert the y values to trackview space */
+       double dummy = 0;
+       clicked_control_point->line().parent_group().i2w (dummy, y1);
+       clicked_control_point->line().parent_group().i2w (dummy, y2);
+       _trackview_group->w2i (dummy, y1);
+       _trackview_group->w2i (dummy, y2);
+
+       /* and set up the selection */
+       return select_all_within (x1, x2, y1, y2, selection->tracks, Selection::Set);
 }
 
 void
-Editor::get_relevant_tracks (set<RouteTimeAxisView*>& relevant_tracks)
+Editor::get_onscreen_tracks (TrackViewList& tvl)
 {
-       /* step one: get all selected tracks and all tracks in the relevant edit groups */
-
-       for (TrackSelection::iterator ti = selection->tracks.begin(); ti != selection->tracks.end(); ++ti) {
-
-               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*ti);
-
-               if (!rtv) {
-                       continue;
-               }
-
-               RouteGroup* group = rtv->route()->edit_group();
-
-               if (group && group->is_active()) {
-                       
-                       /* active group for this track, loop over all tracks and get every member of the group */
-
-                       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-                               
-                               RouteTimeAxisView* trtv;
-                               
-                               if ((trtv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
-                                       
-                                       if (trtv->route()->edit_group() == group) {
-                                               relevant_tracks.insert (trtv);
-                                       }
-                               }
-                       }
-               } else {
-                       relevant_tracks.insert (rtv);
-               }
-       }
+       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+               if ((*i)->y_position() < _canvas_height) {
+                       tvl.push_back (*i);
+               }
+       }
 }
 
-/**
- *  Call a slot for a given `basis' track and also for any track that is in the same
- *  active edit group.
+/** Call a slot for a given `basis' track and also for any track that is in the same
+ *  active route group with a particular set of properties.
+ *
  *  @param sl Slot to call.
  *  @param basis Basis track.
+ *  @param prop Properties that active edit groups must share to be included in the map.
  */
 
 void
-Editor::mapover_tracks (slot<void, RouteTimeAxisView&, uint32_t> sl, TimeAxisView* basis) const
+Editor::mapover_tracks (sigc::slot<void, RouteTimeAxisView&, uint32_t> sl, TimeAxisView* basis, RouteGroup::Property prop) const
 {
        RouteTimeAxisView* route_basis = dynamic_cast<RouteTimeAxisView*> (basis);
        if (route_basis == 0) {
                return;
        }
 
-       /* work out the tracks that we will call the slot for; use
-          a set here as it will disallow possible duplicates of the
-          basis track */
        set<RouteTimeAxisView*> tracks;
-
-       /* always call for the basis */
        tracks.insert (route_basis);
 
-       RouteGroup* group = route_basis->route()->edit_group();
-       if (group && group->is_active()) {
+       RouteGroup* group = route_basis->route()->route_group();
+       if (group && group->active_property (prop)) {
+
+               /* the basis is a member of an active route group, with the appropriate
+                  properties; find other members */
 
-               /* the basis is a member of an active edit group; find other members */
                for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) {
                        RouteTimeAxisView* v = dynamic_cast<RouteTimeAxisView*> (*i);
-                       if (v && v->route()->edit_group() == group) {
+                       if (v && v->route()->route_group() == group) {
                                tracks.insert (v);
                        }
                }
@@ -330,7 +324,7 @@ Editor::mapover_tracks (slot<void, RouteTimeAxisView&, uint32_t> sl, TimeAxisVie
 }
 
 void
-Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t ignored, RegionView* basis, vector<RegionView*>* all_equivs) const
+Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t, RegionView * basis, vector<RegionView*>* all_equivs) const
 {
        boost::shared_ptr<Playlist> pl;
        vector<boost::shared_ptr<Region> > results;
@@ -359,55 +353,80 @@ Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t ignored,
 }
 
 void
-Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivalent_regions) const
+Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivalent_regions, RouteGroup::Property prop) const
 {
-       mapover_tracks (bind (mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions), &basis->get_trackview());
-       
+       mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions), &basis->get_trackview(), prop);
+
        /* add clicked regionview since we skipped all other regions in the same track as the one it was in */
-       
+
        equivalent_regions.push_back (basis);
 }
 
+RegionSelection
+Editor::get_equivalent_regions (RegionSelection & basis, RouteGroup::Property prop) const
+{
+       RegionSelection equivalent;
+
+       for (RegionSelection::const_iterator i = basis.begin(); i != basis.end(); ++i) {
+
+               vector<RegionView*> eq;
+
+               mapover_tracks (
+                       sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), *i, &eq),
+                       &(*i)->get_trackview(), prop
+                       );
+
+               for (vector<RegionView*>::iterator j = eq.begin(); j != eq.end(); ++j) {
+                       equivalent.add (*j);
+               }
+
+               equivalent.add (*i);
+       }
+
+       return equivalent;
+}
+
+
 int
 Editor::get_regionview_count_from_region_list (boost::shared_ptr<Region> region)
 {
        int region_count = 0;
-       
+
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-               
+
                RouteTimeAxisView* tatv;
-               
+
                if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
-                       
+
                        boost::shared_ptr<Playlist> pl;
                        vector<boost::shared_ptr<Region> > results;
                        RegionView* marv;
                        boost::shared_ptr<Diskstream> ds;
-                       
+
                        if ((ds = tatv->get_diskstream()) == 0) {
                                /* bus */
                                continue;
                        }
-                       
+
                        if ((pl = (ds->playlist())) != 0) {
                                pl->get_region_list_equivalent_regions (region, results);
                        }
-                       
+
                        for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
                                if ((marv = tatv->view()->find_view (*ir)) != 0) {
                                        region_count++;
                                }
                        }
-                       
+
                }
        }
-       
+
        return region_count;
 }
 
 
 bool
-Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool no_track_remove)
+Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool /*no_track_remove*/)
 {
        vector<RegionView*> all_equivalent_regions;
        bool commit = false;
@@ -418,14 +437,14 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
 
        if (press) {
                button_release_can_deselect = false;
-       } 
+       }
 
        if (op == Selection::Toggle || op == Selection::Set) {
 
 
                switch (op) {
                case Selection::Toggle:
-                       
+
                        if (selection->selected (clicked_regionview)) {
                                if (press) {
 
@@ -450,34 +469,33 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
 
                                                button_release_can_deselect = false;
                                        }
-                               } 
+                               }
 
                        } else {
 
                                if (press) {
 
                                        if (selection->selected (clicked_routeview)) {
-                                               get_equivalent_regions (clicked_regionview, all_equivalent_regions);
+                                               get_equivalent_regions (clicked_regionview, all_equivalent_regions, RouteGroup::Select);
                                        } else {
                                                all_equivalent_regions.push_back (clicked_regionview);
                                        }
 
                                        /* add all the equivalent regions, but only on button press */
-                                       
-
 
                                        if (!all_equivalent_regions.empty()) {
                                                commit = true;
                                        }
 
                                        selection->add (all_equivalent_regions);
-                               } 
+                               }
                        }
                        break;
-                       
+
                case Selection::Set:
                        if (!selection->selected (clicked_regionview)) {
-                               selection->set (clicked_regionview);
+                               get_equivalent_regions (clicked_regionview, all_equivalent_regions, RouteGroup::Select);
+                               selection->set (all_equivalent_regions);
                                commit = true;
                        } else {
                                /* no commit necessary: clicked on an already selected region */
@@ -520,7 +538,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                if (same_track) {
 
                        /* 2. figure out the boundaries for our search for new objects */
-                       
+
                        switch (clicked_regionview->region()->coverage (first_frame, last_frame)) {
                        case OverlapNone:
                                if (last_frame < clicked_regionview->region()->first_frame()) {
@@ -531,7 +549,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                                        first_frame = clicked_regionview->region()->first_frame();
                                }
                                break;
-                               
+
                        case OverlapExternal:
                                if (last_frame < clicked_regionview->region()->first_frame()) {
                                        first_frame = last_frame;
@@ -541,7 +559,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                                        first_frame = clicked_regionview->region()->first_frame();
                                }
                                break;
-                               
+
                        case OverlapInternal:
                                if (last_frame < clicked_regionview->region()->first_frame()) {
                                        first_frame = last_frame;
@@ -551,7 +569,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                                        first_frame = clicked_regionview->region()->first_frame();
                                }
                                break;
-                               
+
                        case OverlapStart:
                        case OverlapEnd:
                                /* nothing to do except add clicked region to selection, since it
@@ -566,11 +584,11 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                           to pick out all regions that are defined by the existing selection
                           plus this one.
                        */
-                       
-                       
+
+
                        first_frame = entered_regionview->region()->position();
                        last_frame = entered_regionview->region()->last_frame();
-                       
+
                        for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
                                if ((*i)->region()->position() < first_frame) {
                                        first_frame = (*i)->region()->position();
@@ -584,16 +602,23 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                /* 2. find all the tracks we should select in */
 
                set<RouteTimeAxisView*> relevant_tracks;
-               set<RouteTimeAxisView*> already_in_selection;
 
-               get_relevant_tracks (relevant_tracks);
+               for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+                       RouteTimeAxisView* r = dynamic_cast<RouteTimeAxisView*> (*i);
+                       if (r) {
+                               relevant_tracks.insert (r);
+                       }
+               }
+               
+               set<RouteTimeAxisView*> already_in_selection;
 
                if (relevant_tracks.empty()) {
 
-                       /* no relevant tracks -> no tracks selected .. thus .. if
-                          the regionview we're in isn't selected (i.e. we're
-                          about to extend to it), then find all tracks between
-                          the this one and any selected ones.
+                       /* no tracks selected .. thus .. if the
+                          regionview we're in isn't selected
+                          (i.e. we're about to extend to it), then
+                          find all tracks between the this one and
+                          any selected ones.
                        */
 
                        if (!selection->selected (entered_regionview)) {
@@ -626,12 +651,11 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
 
                                                        if (result.second) {
                                                                /* newly added to already_in_selection */
-                                                       
 
                                                                int d = artv->route()->order_key ("editor");
-                                                               
+
                                                                d -= key;
-                                                               
+
                                                                if (abs (d) < distance) {
                                                                        distance = abs (d);
                                                                        closest = artv;
@@ -639,17 +663,17 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                                                        }
                                                }
                                        }
-                                       
+
                                        if (closest) {
 
                                                /* now add all tracks between that one and this one */
-                                               
+
                                                int okey = closest->route()->order_key ("editor");
-                                               
+
                                                if (okey > key) {
                                                        swap (okey, key);
                                                }
-                                               
+
                                                for (TrackViewList::iterator x = track_views.begin(); x != track_views.end(); ++x) {
                                                        RouteTimeAxisView* artv = dynamic_cast<RouteTimeAxisView*>(*x);
                                                        if (artv && artv != rtv) {
@@ -682,16 +706,14 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                           one that was clicked.
                */
 
-               get_relevant_tracks (relevant_tracks);
-
                for (set<RouteTimeAxisView*>::iterator t = relevant_tracks.begin(); t != relevant_tracks.end(); ++t) {
                        (*t)->get_selectables (first_frame, last_frame, -1.0, -1.0, results);
                }
-               
+
                /* 4. convert to a vector of regions */
 
                vector<RegionView*> regions;
-               
+
                for (list<Selectable*>::iterator x = results.begin(); x != results.end(); ++x) {
                        RegionView* arv;
 
@@ -723,7 +745,7 @@ Editor::set_selected_regionview_from_region_list (boost::shared_ptr<Region> regi
        }
 
        begin_reversible_command (_("set selected regions"));
-       
+
        switch (op) {
        case Selection::Toggle:
                /* XXX this is not correct */
@@ -744,7 +766,7 @@ Editor::set_selected_regionview_from_region_list (boost::shared_ptr<Region> regi
 }
 
 bool
-Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, boost::weak_ptr<Region> weak_r)
+Editor::set_selected_regionview_from_map_event (GdkEventAny* /*ev*/, StreamView* sv, boost::weak_ptr<Region> weak_r)
 {
        RegionView* rv;
        boost::shared_ptr<Region> r (weak_r.lock());
@@ -757,16 +779,16 @@ Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv,
                return true;
        }
 
-       /* don't reset the selection if its something other than 
+       /* don't reset the selection if its something other than
           a single other region.
        */
 
        if (selection->regions.size() > 1) {
                return true;
        }
-       
+
        begin_reversible_command (_("set selected regions"));
-       
+
        selection->set (rv);
 
        commit_reversible_command () ;
@@ -807,14 +829,8 @@ Editor::time_selection_changed ()
                (*i)->hide_selection ();
        }
 
-       if (selection->tracks.empty()) {
-               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-                       (*i)->show_selection (selection->time);
-               }
-       } else {
-               for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
-                       (*i)->show_selection (selection->time);
-               }
+       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+               (*i)->show_selection (selection->time);
        }
 
        if (selection->time.empty()) {
@@ -822,7 +838,6 @@ Editor::time_selection_changed ()
        } else {
                ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, true);
        }
-
 }
 
 void
@@ -852,13 +867,21 @@ Editor::sensitize_the_right_region_actions (bool have_selected_regions)
 void
 Editor::region_selection_changed ()
 {
+       _regions->block_change_connection (true);
+       editor_regions_selection_changed_connection.block(true);
+
+       _regions->unselect_all ();
+
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                (*i)->set_selected_regionviews (selection->regions);
        }
-       
+
+       _regions->set_selected (selection->regions);
+
        sensitize_the_right_region_actions (!selection->regions.empty());
 
-       zoomed_to_region = false;
+       _regions->block_change_connection (false);
+       editor_regions_selection_changed_connection.block(false);
 }
 
 void
@@ -877,7 +900,7 @@ Editor::select_all_in_track (Selection::Operation op)
        if (!clicked_routeview) {
                return;
        }
-       
+
        clicked_routeview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
 
        switch (op) {
@@ -932,7 +955,7 @@ Editor::invert_selection_in_track ()
        if (!clicked_routeview) {
                return;
        }
-       
+
        clicked_routeview->get_inverted_selectables (*selection, touched);
        selection->set (touched);
 }
@@ -941,7 +964,7 @@ void
 Editor::invert_selection ()
 {
        list<Selectable *> touched;
-       
+
        for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
                if ((*iter)->hidden()) {
                        continue;
@@ -952,42 +975,47 @@ Editor::invert_selection ()
        selection->set (touched);
 }
 
+/** @param top Top (lower) y limit in trackview coordinates.
+ *  @param bottom Bottom (higher) y limit in trackview coordinates.
+ */
 bool
-Editor::select_all_within (nframes64_t start, nframes64_t end, double top, double bot, const TrackViewList& tracklist, Selection::Operation op)
+Editor::select_all_within (
+       nframes64_t start, nframes64_t end, double top, double bot, const TrackViewList& tracklist, Selection::Operation op
+       )
 {
-       list<Selectable*> touched;
-       list<Selectable*>::size_type n = 0;
-       TrackViewList touched_tracks;
+       list<Selectable*> found;
+       TrackViewList tracks;
 
        for (TrackViewList::const_iterator iter = tracklist.begin(); iter != tracklist.end(); ++iter) {
+               
                if ((*iter)->hidden()) {
                        continue;
                }
 
-               n = touched.size();
+               list<Selectable*>::size_type const n = found.size ();
 
-               (*iter)->get_selectables (start, end, top, bot, touched);
-               
-               if (n != touched.size()) {
-                       touched_tracks.push_back (*iter);
+               (*iter)->get_selectables (start, end, top, bot, found);
+
+               if (n != found.size()) {
+                       tracks.push_back (*iter);
                }
        }
-
-       if (touched.empty()) {
+       
+       if (found.empty()) {
                return false;
        }
 
-       if (!touched_tracks.empty()) {
+       if (!tracks.empty()) {
 
                switch (op) {
                case Selection::Add:
-                       selection->add (touched_tracks);
+                       selection->add (tracks);
                        break;
                case Selection::Toggle:
-                       selection->toggle (touched_tracks);
+                       selection->toggle (tracks);
                        break;
                case Selection::Set:
-                       selection->set (touched_tracks);
+                       selection->set (tracks);
                        break;
                case Selection::Extend:
                        /* not defined yet */
@@ -998,22 +1026,22 @@ Editor::select_all_within (nframes64_t start, nframes64_t end, double top, doubl
        begin_reversible_command (_("select all within"));
        switch (op) {
        case Selection::Add:
-               selection->add (touched);
+               selection->add (found);
                break;
        case Selection::Toggle:
-               selection->toggle (touched);
+               selection->toggle (found);
                break;
        case Selection::Set:
-               selection->set (touched);
+               selection->set (found);
                break;
        case Selection::Extend:
                /* not defined yet */
                break;
        }
-       
+
        commit_reversible_command ();
 
-       return !touched.empty();
+       return !found.empty();
 }
 
 void
@@ -1023,7 +1051,7 @@ Editor::set_selection_from_region ()
                return;
        }
 
-       selection->set (0, selection->regions.start(), selection->regions.end_frame());
+       selection->set (selection->regions.start(), selection->regions.end_frame());
        if (!Profile->get_sae()) {
                set_mouse_mode (Editing::MouseRange, false);
        }
@@ -1034,7 +1062,7 @@ Editor::set_selection_from_punch()
 {
        Location* location;
 
-       if ((location = session->locations()->auto_punch_location()) == 0)  {
+       if ((location = _session->locations()->auto_punch_location()) == 0)  {
                return;
        }
 
@@ -1046,7 +1074,7 @@ Editor::set_selection_from_loop()
 {
        Location* location;
 
-       if ((location = session->locations()->auto_loop_location()) == 0)  {
+       if ((location = _session->locations()->auto_loop_location()) == 0)  {
                return;
        }
        set_selection_from_range (*location);
@@ -1056,7 +1084,7 @@ void
 Editor::set_selection_from_range (Location& loc)
 {
        begin_reversible_command (_("set selection from range"));
-       selection->set (0, loc.start(), loc.end());
+       selection->set (loc.start(), loc.end());
        commit_reversible_command ();
 
        if (!Profile->get_sae()) {
@@ -1080,7 +1108,7 @@ Editor::select_all_selectables_using_time_selection ()
                return;
        }
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1104,7 +1132,7 @@ Editor::select_all_selectables_using_time_selection ()
 void
 Editor::select_all_selectables_using_punch()
 {
-       Location* location = session->locations()->auto_punch_location();
+       Location* location = _session->locations()->auto_punch_location();
        list<Selectable *> touched;
 
        if (location == 0 || (location->end() - location->start() <= 1))  {
@@ -1112,7 +1140,7 @@ Editor::select_all_selectables_using_punch()
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1135,7 +1163,7 @@ Editor::select_all_selectables_using_punch()
 void
 Editor::select_all_selectables_using_loop()
 {
-       Location* location = session->locations()->auto_loop_location();
+       Location* location = _session->locations()->auto_loop_location();
        list<Selectable *> touched;
 
        if (location == 0 || (location->end() - location->start() <= 1))  {
@@ -1143,7 +1171,7 @@ Editor::select_all_selectables_using_loop()
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1164,7 +1192,7 @@ Editor::select_all_selectables_using_loop()
 }
 
 void
-Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
+Editor::select_all_selectables_using_cursor (EditorCursor *cursor, bool after)
 {
         nframes64_t start;
        nframes64_t end;
@@ -1173,7 +1201,7 @@ Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
        if (after) {
                begin_reversible_command (_("select all after cursor"));
                start = cursor->current_frame ;
-               end = session->current_end_frame();
+               end = _session->current_end_frame();
        } else {
                if (cursor->current_frame > 0) {
                        begin_reversible_command (_("select all before cursor"));
@@ -1185,7 +1213,7 @@ Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1213,7 +1241,7 @@ Editor::select_all_selectables_using_edit (bool after)
        if (after) {
                begin_reversible_command (_("select all after edit"));
                start = get_preferred_edit_position();
-               end = session->current_end_frame();
+               end = _session->current_end_frame();
        } else {
                if ((end = get_preferred_edit_position()) > 1) {
                        begin_reversible_command (_("select all before edit"));
@@ -1225,7 +1253,7 @@ Editor::select_all_selectables_using_edit (bool after)
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1244,7 +1272,7 @@ Editor::select_all_selectables_using_edit (bool after)
 }
 
 void
-Editor::select_all_selectables_between (bool within)
+Editor::select_all_selectables_between (bool /*within*/)
 {
         nframes64_t start;
        nframes64_t end;
@@ -1254,7 +1282,7 @@ Editor::select_all_selectables_between (bool within)
                return;
        }
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1277,13 +1305,13 @@ Editor::select_range_between ()
 {
         nframes64_t start;
        nframes64_t end;
-       
+
        if (!get_edit_op_range (start, end)) {
                return;
        }
 
        set_mouse_mode (MouseRange);
-       selection->set ((TimeAxisView*) 0, start, end);
+       selection->set (start, end);
 }
 
 bool
@@ -1311,7 +1339,7 @@ Editor::get_edit_op_range (nframes64_t& start, nframes64_t& end) const
                }
 
                start = selection->markers.front()->position();
-               end = session->audible_frame();
+               end = _session->audible_frame();
 
        } else {
 
@@ -1320,29 +1348,29 @@ Editor::get_edit_op_range (nframes64_t& start, nframes64_t& end) const
                        if (selection->markers.empty()) {
                                /* use mouse + playhead */
                                start = m;
-                               end = session->audible_frame();
+                               end = _session->audible_frame();
                        } else {
                                /* use playhead + selected marker */
-                               start = session->audible_frame();
+                               start = _session->audible_frame();
                                end = selection->markers.front()->position();
                        }
                        break;
-                       
+
                case EditAtMouse:
                        /* use mouse + selected marker */
                        if (selection->markers.empty()) {
                                start = m;
-                               end = session->audible_frame();
+                               end = _session->audible_frame();
                        } else {
                                start = selection->markers.front()->position();
                                end = m;
                        }
                        break;
-                       
+
                case EditAtSelectedMarker:
                        /* use mouse + selected marker */
                        if (selection->markers.empty()) {
-                               
+
                                MessageDialog win (_("No edit range defined"),
                                                   false,
                                                   MESSAGE_INFO,
@@ -1350,14 +1378,14 @@ Editor::get_edit_op_range (nframes64_t& start, nframes64_t& end) const
 
                                win.set_secondary_text (
                                        _("the edit point is Selected Marker\nbut there is no selected marker."));
-                               
+
 
                                win.set_default_response (RESPONSE_CLOSE);
                                win.set_position (Gtk::WIN_POS_MOUSE);
                                win.show_all();
-                               
+
                                win.run ();
-                               
+
                                return false; // NO RANGE
                        }
                        start = selection->markers.front()->position();
@@ -1389,4 +1417,14 @@ Editor::deselect_all ()
        selection->clear ();
 }
 
-
+long
+Editor::select_range_around_region (RegionView* rv)
+{
+       assert (rv);
+       
+       selection->set (&rv->get_time_axis_view());
+       
+       selection->time.clear ();
+       boost::shared_ptr<Region> r = rv->region ();
+       return selection->set (r->position(), r->position() + r->length());
+}