Cleanup of region drag code to be a bit more efficient and shorter. Fixes crashes...
[ardour.git] / gtk2_ardour / editor_selection.cc
index 24ee3cadcf84c4bf0d2865fed99f74b159ffc375..806efaa66ac5e555c891c18bbc4a1070d72ecd8f 100644 (file)
@@ -23,7 +23,6 @@
 #include "pbd/stacktrace.h"
 
 #include "ardour/session.h"
-#include "ardour/diskstream.h"
 #include "ardour/playlist.h"
 #include "ardour/route_group.h"
 #include "ardour/profile.h"
@@ -40,7 +39,6 @@
 #include "i18n.h"
 
 using namespace std;
-using namespace sigc;
 using namespace ARDOUR;
 using namespace PBD;
 using namespace Gtk;
@@ -172,21 +170,110 @@ Editor::select_all_tracks ()
        selection->set (visible_views);
 }
 
+/** Select clicked_axisview, 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)
+Editor::set_selected_track_as_side_effect (Selection::Operation op, bool /*force*/)
 {
-       if (!clicked_routeview) {
+       if (!clicked_axisview) {
                return;
        }
 
+#if 1
+        if (!clicked_routeview) {
+                return;
+        }
+
+        bool had_tracks = !selection->tracks.empty();
+        RouteGroup* group = clicked_routeview->route()->route_group();
+        RouteGroup& arg (_session->all_route_group());
+        
+       switch (op) {
+       case Selection::Toggle: 
+               if (selection->selected (clicked_axisview)) {
+                       if (arg.is_select() && arg.is_active()) {
+                               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
+                                        selection->remove(*i);
+                               }
+                       } else if (group && group->is_active()) {
+                               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
+                                       if ((*i)->route_group() == group)
+                                               selection->remove(*i);
+                               }
+                       } else {
+                               selection->remove (clicked_axisview);
+                        }
+               } else {
+                       if (arg.is_select() && arg.is_active()) {
+                               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
+                                               selection->add(*i);
+                               }
+                       } else if (group && group->is_active()) {
+                               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
+                                       if ( (*i)->route_group() == group)
+                                               selection->add(*i);
+                               }
+                        } else {
+                                selection->add (clicked_axisview);
+                        }
+               }
+                break;
+       
+       case Selection::Add: 
+               if (!had_tracks && arg.is_select() && arg.is_active()) {
+                        /* nothing was selected already, and all group is active etc. so use
+                           all tracks.
+                        */
+                       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
+                                       selection->add(*i);
+                       }
+               } else if (group && group->is_active()) {
+                       for (TrackViewList::iterator i  = track_views.begin(); i != track_views.end (); ++i) {
+                               if ((*i)->route_group() == group)
+                                       selection->add(*i);
+                       }
+                } else {
+                       selection->add (clicked_axisview);
+                }
+                break;
+               
+       case Selection::Set:
+                selection->clear();
+               if (!had_tracks && arg.is_select() && arg.is_active()) {
+                        /* nothing was selected already, and all group is active etc. so use
+                           all tracks.
+                        */
+                       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end (); ++i) {
+                                       selection->add(*i);
+                       }
+               } else if (group && group->is_active()) {
+                       for (TrackViewList::iterator i  = track_views.begin(); i != track_views.end (); ++i) {
+                               if ((*i)->route_group() == group)
+                                       selection->add(*i);
+                       }
+                } else {
+                       selection->set (clicked_axisview);
+                }
+                break;
+       
+       case Selection::Extend: 
+               selection->clear();
+               cerr << ("Editor::set_selected_track_as_side_effect  case  Selection::Add  not yet implemented\n");
+                break;
+       }
+
+#else // the older version
+
        if (!selection->tracks.empty()) {
-               if (!selection->selected (clicked_routeview)) {
-                       selection->add (clicked_routeview);
+               if (!selection->selected (clicked_axisview)) {
+                       selection->add (clicked_axisview);
                }
 
        } else if (force) {
-               selection->set (clicked_routeview);
+               selection->set (clicked_axisview);
        }
+#endif
 }
 
 void
@@ -239,18 +326,23 @@ Editor::set_selected_control_point_from_click (Selection::Operation op, bool /*n
        if (!clicked_control_point) {
                return false;
        }
+       
+       switch (op) {
+       case Selection::Set:
+               selection->set (clicked_control_point);
+               break;
+       case Selection::Add:
+               selection->add (clicked_control_point);
+               break;
+       case Selection::Toggle:
+               selection->toggle (clicked_control_point);
+               break;
+       case Selection::Extend:
+               /* XXX */
+               break;
+       }
 
-       /* select this point and any others that it represents */
-
-       double y1, y2;
-       nframes64_t x1, x2;
-
-       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;
-
-       return select_all_within (x1, x2, y1, y2, selection->tracks, op);
+       return true;
 }
 
 void
@@ -263,48 +355,6 @@ Editor::get_onscreen_tracks (TrackViewList& tvl)
        }
 }
 
-/** Given a track, find any other tracks that are in the same active route group with a given property.
- *  @param basis Base track.
- *  @param equivs Filled with the base track and the found tracks.
- *  @param prop Property to look for in route groups.
- */
-
-void
-Editor::get_equivalent_tracks (RouteTimeAxisView* basis, set<RouteTimeAxisView*> & equivs, RouteGroup::Property prop) const
-{
-       equivs.insert (basis);
-
-       RouteGroup* group = 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 */
-
-               for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) {
-                       RouteTimeAxisView* v = dynamic_cast<RouteTimeAxisView*> (*i);
-                       if (v && v->route()->route_group() == group) {
-                               equivs.insert (v);
-                       }
-               }
-       }
-}
-
-/** Find tracks that are selected, and also those that are in the same `selection'-enabled route
- *  group as one that is selected.
- *  @param relevant_tracks set to add tracks to.
- */
-
-void
-Editor::get_relevant_tracks (set<RouteTimeAxisView*>& relevant_tracks) const
-{
-       for (TrackSelection::iterator ti = selection->tracks.begin(); ti != selection->tracks.end(); ++ti) {
-               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*ti);
-               if (rtv) {
-                       get_equivalent_tracks (rtv, relevant_tracks, RouteGroup::Select);
-               }
-       }
-}
-
 /** 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.
  *
@@ -314,18 +364,35 @@ Editor::get_relevant_tracks (set<RouteTimeAxisView*>& relevant_tracks) const
  */
 
 void
-Editor::mapover_tracks (slot<void, RouteTimeAxisView&, uint32_t> sl, TimeAxisView* basis, RouteGroup::Property prop) const
+Editor::mapover_tracks (sigc::slot<void, RouteTimeAxisView&, uint32_t> sl, TimeAxisView* basis, PBD::PropertyID prop) const
 {
        RouteTimeAxisView* route_basis = dynamic_cast<RouteTimeAxisView*> (basis);
+
        if (route_basis == 0) {
                return;
        }
 
        set<RouteTimeAxisView*> tracks;
-       get_equivalent_tracks (route_basis, tracks, prop);
+       tracks.insert (route_basis);
+
+       RouteGroup* group = route_basis->route()->route_group();
+
+       if (group && group->enabled_property(prop) && group->enabled_property (Properties::active.property_id) ) {
+
+               /* the basis is a member of an active route group, with the appropriate
+                  properties; 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()->route_group() == group) {
+                               tracks.insert (v);
+                       }
+               }
+       }
 
        /* call the slots */
        uint32_t const sz = tracks.size ();
+       
        for (set<RouteTimeAxisView*>::iterator i = tracks.begin(); i != tracks.end(); ++i) {
                sl (**i, sz);
        }
@@ -337,9 +404,9 @@ Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t, RegionVi
        boost::shared_ptr<Playlist> pl;
        vector<boost::shared_ptr<Region> > results;
        RegionView* marv;
-       boost::shared_ptr<Diskstream> ds;
+       boost::shared_ptr<Track> tr;
 
-       if ((ds = tv.get_diskstream()) == 0) {
+       if ((tr = tv.track()) == 0) {
                /* bus */
                return;
        }
@@ -349,7 +416,7 @@ Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t, RegionVi
                return;
        }
 
-       if ((pl = ds->playlist()) != 0) {
+       if ((pl = tr->playlist()) != 0) {
                pl->get_equivalent_regions (basis->region(), results);
        }
 
@@ -361,9 +428,9 @@ Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t, RegionVi
 }
 
 void
-Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivalent_regions, RouteGroup::Property prop) const
+Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivalent_regions, PBD::PropertyID property) const
 {
-       mapover_tracks (bind (mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions), &basis->get_trackview(), prop);
+       mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions), &basis->get_time_axis_view(), property);
 
        /* add clicked regionview since we skipped all other regions in the same track as the one it was in */
 
@@ -371,7 +438,7 @@ Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivale
 }
 
 RegionSelection
-Editor::get_equivalent_regions (RegionSelection & basis, RouteGroup::Property prop) const
+Editor::get_equivalent_regions (RegionSelection & basis, PBD::PropertyID prop) const
 {
        RegionSelection equivalent;
 
@@ -380,8 +447,8 @@ Editor::get_equivalent_regions (RegionSelection & basis, RouteGroup::Property pr
                vector<RegionView*> eq;
 
                mapover_tracks (
-                       bind (mem_fun (*this, &Editor::mapped_get_equivalent_regions), *i, &eq),
-                       &(*i)->get_trackview(), prop
+                       sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), *i, &eq),
+                       &(*i)->get_time_axis_view(), prop
                        );
 
                for (vector<RegionView*>::iterator j = eq.begin(); j != eq.end(); ++j) {
@@ -409,14 +476,14 @@ Editor::get_regionview_count_from_region_list (boost::shared_ptr<Region> region)
                        boost::shared_ptr<Playlist> pl;
                        vector<boost::shared_ptr<Region> > results;
                        RegionView* marv;
-                       boost::shared_ptr<Diskstream> ds;
+                       boost::shared_ptr<Track> tr;
 
-                       if ((ds = tatv->get_diskstream()) == 0) {
+                       if ((tr = tatv->track()) == 0) {
                                /* bus */
                                continue;
                        }
 
-                       if ((pl = (ds->playlist())) != 0) {
+                       if ((pl = (tr->playlist())) != 0) {
                                pl->get_region_list_equivalent_regions (region, results);
                        }
 
@@ -484,15 +551,13 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
                                if (press) {
 
                                        if (selection->selected (clicked_routeview)) {
-                                               get_equivalent_regions (clicked_regionview, all_equivalent_regions, RouteGroup::Select);
+                                               get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::select.property_id);
                                        } 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;
                                        }
@@ -504,7 +569,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op,
 
                case Selection::Set:
                        if (!selection->selected (clicked_regionview)) {
-                               get_equivalent_regions (clicked_regionview, all_equivalent_regions, RouteGroup::Select);
+                               get_equivalent_regions (clicked_regionview, all_equivalent_regions, ARDOUR::Properties::select.property_id);
                                selection->set (all_equivalent_regions);
                                commit = true;
                        } else {
@@ -612,16 +677,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)) {
@@ -655,7 +727,6 @@ 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;
@@ -710,8 +781,6 @@ 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);
                }
@@ -805,7 +874,7 @@ Editor::set_selected_regionview_from_map_event (GdkEventAny* /*ev*/, StreamView*
 void
 Editor::track_selection_changed ()
 {
-       switch (selection->tracks.size()){
+       switch (selection->tracks.size()) {
        case 0:
                break;
        default:
@@ -814,12 +883,24 @@ Editor::track_selection_changed ()
        }
 
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-               if (find (selection->tracks.begin(), selection->tracks.end(), *i) != selection->tracks.end()) {
-                       (*i)->set_selected (true);
-               } else {
-                       (*i)->set_selected (false);
-               }
-       }
+
+                bool yn = (find (selection->tracks.begin(), selection->tracks.end(), *i) != selection->tracks.end());
+                
+                (*i)->set_selected (yn);
+                
+                TimeAxisView::Children c = (*i)->get_child_list ();
+                for (TimeAxisView::Children::iterator j = c.begin(); j != c.end(); ++j) {
+                        (*j)->set_selected (find (selection->tracks.begin(), selection->tracks.end(), j->get()) != selection->tracks.end());
+                }
+
+                if (yn && 
+                    ((mouse_mode == MouseRange) || 
+                     ((mouse_mode == MouseObject) && (_join_object_range_state == JOIN_OBJECT_RANGE_OBJECT)))) {
+                        (*i)->reshow_selection (selection->time);
+                } else {
+                        (*i)->hide_selection ();
+                }
+        }
 
        ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, !selection->tracks.empty());
 }
@@ -835,14 +916,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()) {
@@ -850,7 +925,6 @@ Editor::time_selection_changed ()
        } else {
                ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, true);
        }
-
 }
 
 void
@@ -886,12 +960,11 @@ Editor::region_selection_changed ()
        _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);
-
        }
 
+       _regions->set_selected (selection->regions);
+
        sensitize_the_right_region_actions (!selection->regions.empty());
 
        _regions->block_change_connection (false);
@@ -989,59 +1062,54 @@ Editor::invert_selection ()
        selection->set (touched);
 }
 
+/** @param start Start time in session frames.
+ *  @param end End time in session frames.
+ *  @param top Top (lower) y limit in trackview coordinates (ie 0 at the top of the track view)
+ *  @param bottom Bottom (higher) y limit in trackview coordinates (ie 0 at the top of the track view)
+ *  @param preserve_if_selected true to leave the current selection alone if we're adding to the selection and all of the selectables
+ *  within the region are already selected.
+ */
 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 (
+       framepos_t start, framepos_t end, double top, double bot, const TrackViewList& tracklist, Selection::Operation op, bool preserve_if_selected
+       )
 {
-       list<Selectable*> touched;
-       list<Selectable*>::size_type n = 0;
-       TrackViewList touched_tracks;
+       list<Selectable*> found;
 
        for (TrackViewList::const_iterator iter = tracklist.begin(); iter != tracklist.end(); ++iter) {
+               
                if ((*iter)->hidden()) {
                        continue;
                }
 
-               n = touched.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 (touched.empty()) {
+       if (found.empty()) {
                return false;
        }
 
-       if (!touched_tracks.empty()) {
+       if (preserve_if_selected && op != Selection::Toggle) {
+               list<Selectable*>::iterator i = found.begin();
+               while (i != found.end() && (*i)->get_selected()) {
+                       ++i;
+               }
 
-               switch (op) {
-               case Selection::Add:
-                       selection->add (touched_tracks);
-                       break;
-               case Selection::Toggle:
-                       selection->toggle (touched_tracks);
-                       break;
-               case Selection::Set:
-                       selection->set (touched_tracks);
-                       break;
-               case Selection::Extend:
-                       /* not defined yet */
-                       break;
+               if (i == found.end()) {
+                       return false;
                }
        }
 
        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 */
@@ -1050,7 +1118,7 @@ Editor::select_all_within (nframes64_t start, nframes64_t end, double top, doubl
 
        commit_reversible_command ();
 
-       return !touched.empty();
+       return !found.empty();
 }
 
 void
@@ -1060,7 +1128,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);
        }
@@ -1071,7 +1139,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;
        }
 
@@ -1083,7 +1151,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);
@@ -1093,7 +1161,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()) {
@@ -1117,7 +1185,7 @@ Editor::select_all_selectables_using_time_selection ()
                return;
        }
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1141,7 +1209,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))  {
@@ -1149,7 +1217,7 @@ Editor::select_all_selectables_using_punch()
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1172,7 +1240,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))  {
@@ -1180,7 +1248,7 @@ Editor::select_all_selectables_using_loop()
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1210,7 +1278,7 @@ Editor::select_all_selectables_using_cursor (EditorCursor *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"));
@@ -1222,7 +1290,7 @@ Editor::select_all_selectables_using_cursor (EditorCursor *cursor, bool after)
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1250,7 +1318,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"));
@@ -1262,7 +1330,7 @@ Editor::select_all_selectables_using_edit (bool after)
        }
 
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1291,7 +1359,7 @@ Editor::select_all_selectables_between (bool /*within*/)
                return;
        }
 
-       TrackSelection* ts;
+       TrackViewList* ts;
 
        if (selection->tracks.empty()) {
                ts = &track_views;
@@ -1315,12 +1383,16 @@ Editor::select_range_between ()
         nframes64_t start;
        nframes64_t end;
 
+        if (mouse_mode == MouseRange && !selection->time.empty()) {
+                selection->clear_time ();
+        }
+
        if (!get_edit_op_range (start, end)) {
                return;
        }
 
        set_mouse_mode (MouseRange);
-       selection->set ((TimeAxisView*) 0, start, end);
+       selection->set (start, end);
 }
 
 bool
@@ -1348,7 +1420,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 {
 
@@ -1357,10 +1429,10 @@ 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;
@@ -1369,7 +1441,7 @@ Editor::get_edit_op_range (nframes64_t& start, nframes64_t& end) const
                        /* 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;
@@ -1426,4 +1498,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());
+}