Mostly Cosmetic/Design changes to bring trunk and midi branch closer
[ardour.git] / gtk2_ardour / editor_ops.cc
index 7191b81b7bc2dbdc72fde755bc734cf57aee0fab..af366e18d0e2efd73d8aeb0dad29ede2f93d3719 100644 (file)
@@ -25,8 +25,6 @@
 #include <string>
 #include <map>
 
-#include <sndfile.h>
-
 #include <pbd/error.h>
 #include <pbd/basename.h>
 #include <pbd/pthread_utils.h>
@@ -38,9 +36,7 @@
 #include <ardour/session.h>
 #include <ardour/audioplaylist.h>
 #include <ardour/audioregion.h>
-#include <ardour/diskstream.h>
-#include <ardour/filesource.h>
-#include <ardour/sndfilesource.h>
+#include <ardour/audio_diskstream.h>
 #include <ardour/utils.h>
 #include <ardour/location.h>
 #include <ardour/named_selection.h>
 #include "audio_time_axis.h"
 #include "automation_time_axis.h"
 #include "streamview.h"
-#include "regionview.h"
+#include "audio_region_view.h"
 #include "rgb_macros.h"
 #include "selection_templates.h"
 #include "selection.h"
 #include "sfdb_ui.h"
 #include "editing.h"
 #include "gtk-custom-hruler.h"
+#include "gui_thread.h"
 
 #include "i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
+using namespace PBD;
 using namespace sigc;
 using namespace Gtk;
 using namespace Editing;
@@ -94,14 +92,78 @@ Editor::redo (uint32_t n)
 void
 Editor::set_meter_hold (int32_t cnt)
 {
+       Config->set_meter_hold_off(false);
+       Config->set_meter_hold_short(false);
+       Config->set_meter_hold_medium(false);
+       Config->set_meter_hold_long(false);
+
+       switch (cnt)
+       {
+               case 0:
+                Config->set_meter_hold_off(true);
+                break;
+               case 40:
+                Config->set_meter_hold_short(true);
+                break;
+               case 100:
+                Config->set_meter_hold_medium(true);
+                break;
+               case 200:
+                Config->set_meter_hold_long(true);
+                break;
+       }
+                
        if (session) {
                session->set_meter_hold (cnt);
        }
 }
 
 void
-Editor::set_meter_falloff (float val)
+Editor::set_meter_falloff (int intval)
 {
+       float val = 0.0f; /* off */
+       std::string str;
+
+       Config->set_meter_falloff_off(false);
+       Config->set_meter_falloff_slowest(false);
+       Config->set_meter_falloff_slow(false);
+       Config->set_meter_falloff_medium(false);
+       Config->set_meter_falloff_fast(false);
+       Config->set_meter_falloff_faster(false);
+       Config->set_meter_falloff_fastest(false);
+       
+       switch (intval)
+       {
+               case 0:
+                val = 0.0f;
+                Config->set_meter_falloff_off(true);
+                break;
+               case 1:
+                val = 0.266f;
+                Config->set_meter_falloff_slowest(true);
+                break;
+               case 2:
+                val = 0.342f;
+                Config->set_meter_falloff_slow(true);
+                break;
+               case 3:
+                val = 0.7f;
+                Config->set_meter_falloff_medium(true);
+                break;
+               case 4:
+                val = 1.1f;
+                Config->set_meter_falloff_fast(true);
+                break;
+               case 5:
+                val = 1.5f;
+                Config->set_meter_falloff_faster(true);
+                break;
+               case 6:
+                val = 2.5f;
+                Config->set_meter_falloff_fastest(true);
+                break;
+       }
+       
        if (session) {
                session->set_meter_falloff (val);
        }
@@ -124,29 +186,31 @@ Editor::split_region ()
 void
 Editor::split_region_at (jack_nframes_t where)
 {
-       split_regions_at (where, selection->audio_regions);
+       split_regions_at (where, selection->regions);
 }
 
 void
-Editor::split_regions_at (jack_nframes_t where, AudioRegionSelection& regions)
+Editor::split_regions_at (jack_nframes_t where, RegionSelection& regions)
 {
        begin_reversible_command (_("split"));
 
        snap_to (where);
-       for (AudioRegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
+       for (RegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
 
-               AudioRegionSelection::iterator tmp;
+               RegionSelection::iterator tmp;
                
                tmp = a;
                ++tmp;
 
-               Playlist* pl = (*a)->region.playlist();
+               Playlist* pl = (*a)->region().playlist();
 
-               _new_regionviews_show_envelope = (*a)->envelope_visible();
+               AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*a);
+               if (arv)
+                       _new_regionviews_show_envelope = arv->envelope_visible();
                
                if (pl) {
                        session->add_undo (pl->get_memento());
-                       pl->split_region ((*a)->region, where);
+                       pl->split_region ((*a)->region(), where);
                        session->add_redo_no_execute (pl->get_memento());
                }
 
@@ -168,7 +232,7 @@ Editor::remove_clicked_region ()
        
        begin_reversible_command (_("remove region"));
        session->add_undo (playlist->get_memento());
-       playlist->remove_region (&clicked_regionview->region);
+       playlist->remove_region (&clicked_regionview->region());
        session->add_redo_no_execute (playlist->get_memento());
        commit_reversible_command ();
 }
@@ -176,7 +240,7 @@ Editor::remove_clicked_region ()
 void
 Editor::destroy_clicked_region ()
 {
-       int32_t selected = selection->audio_regions.size();
+       int32_t selected = selection->regions.size();
 
        if (!session || clicked_regionview == 0 && selected == 0) {
                return;
@@ -191,51 +255,46 @@ Do you really want to destroy %1 ?"),
                           (selected > 1 ? 
                            _("these regions") : _("this region")));
 
+       choices.push_back (_("No, do nothing."));
+
        if (selected > 1) {
                choices.push_back (_("Yes, destroy them."));
        } else {
                choices.push_back (_("Yes, destroy it."));
        }
 
-       choices.push_back (_("No, do nothing."));
-
        Gtkmm2ext::Choice prompter (prompt, choices);
-
-       prompter.chosen.connect (ptr_fun (Main::quit));
-       prompter.show_all ();
-
-       Main::run ();
-               
-       if (prompter.get_choice() != 0) {
+       
+       if (prompter.run() == 0) { /* first choice */
                return;
        }
 
        if (selected > 0) {
                list<Region*> r;
 
-               for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-                       r.push_back (&(*i)->region);
+               for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+                       r.push_back (&(*i)->region());
                }
 
                session->destroy_regions (r);
 
        } else if (clicked_regionview) {
-               session->destroy_region (&clicked_regionview->region);
+               session->destroy_region (&clicked_regionview->region());
        } 
 }
 
-AudioRegion *
+Region *
 Editor::select_region_for_operation (int dir, TimeAxisView **tv)
 {
-       AudioRegionView* rv;
-       AudioRegion *region;
+       RegionView* rv;
+       Region *region;
        jack_nframes_t start = 0;
 
        if (selection->time.start () == selection->time.end_frame ()) {
                
                /* no current selection-> is there a selected regionview? */
 
-               if (selection->audio_regions.empty()) {
+               if (selection->regions.empty()) {
                        return 0;
                }
 
@@ -243,26 +302,26 @@ Editor::select_region_for_operation (int dir, TimeAxisView **tv)
 
        region = 0;
 
-       if (!selection->audio_regions.empty()) {
+       if (!selection->regions.empty()) {
 
-               rv = *(selection->audio_regions.begin());
+               rv = *(selection->regions.begin());
                (*tv) = &rv->get_time_axis_view();
-               region = &rv->region;
+               region = &rv->region();
 
        } else if (!selection->tracks.empty()) {
 
                (*tv) = selection->tracks.front();
 
-               AudioTimeAxisView* atv;
+               RouteTimeAxisView* rtv;
 
-               if ((atv = dynamic_cast<AudioTimeAxisView*> (*tv)) != 0) {
+               if ((rtv = dynamic_cast<RouteTimeAxisView*> (*tv)) != 0) {
                        Playlist *pl;
                        
-                       if ((pl = atv->playlist()) == 0) {
+                       if ((pl = rtv->playlist()) == 0) {
                                return 0;
                        }
                        
-                       region = dynamic_cast<AudioRegion*> (pl->top_region_at (start));
+                       region = pl->top_region_at (start);
                }
        } 
        
@@ -334,12 +393,12 @@ Editor::nudge_forward (bool next)
 
        if (!session) return;
        
-       if (!selection->audio_regions.empty()) {
+       if (!selection->regions.empty()) {
 
                begin_reversible_command (_("nudge forward"));
 
-               for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-                       AudioRegion& r ((*i)->region);
+               for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+                       Region& r ((*i)->region());
                        
                        distance = get_nudge_distance (r.position(), next_distance);
 
@@ -368,12 +427,12 @@ Editor::nudge_backward (bool next)
 
        if (!session) return;
        
-       if (!selection->audio_regions.empty()) {
+       if (!selection->regions.empty()) {
 
                begin_reversible_command (_("nudge forward"));
 
-               for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-                       AudioRegion& r ((*i)->region);
+               for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+                       Region& r ((*i)->region());
 
                        distance = get_nudge_distance (r.position(), next_distance);
                        
@@ -400,7 +459,7 @@ Editor::nudge_backward (bool next)
                if (playhead_cursor->current_frame > distance) {
                        session->request_locate (playhead_cursor->current_frame - distance);
                } else {
-                       session->request_locate (0);
+                       session->goto_start();
                }
        }
 }
@@ -412,14 +471,14 @@ Editor::nudge_forward_capture_offset ()
 
        if (!session) return;
        
-       if (!selection->audio_regions.empty()) {
+       if (!selection->regions.empty()) {
 
                begin_reversible_command (_("nudge forward"));
 
                distance = session->worst_output_latency();
 
-               for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-                       AudioRegion& r ((*i)->region);
+               for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+                       Region& r ((*i)->region());
                        
                        session->add_undo (r.playlist()->get_memento());
                        r.set_position (r.position() + distance, this);
@@ -438,14 +497,14 @@ Editor::nudge_backward_capture_offset ()
 
        if (!session) return;
        
-       if (!selection->audio_regions.empty()) {
+       if (!selection->regions.empty()) {
 
                begin_reversible_command (_("nudge forward"));
 
                distance = session->worst_output_latency();
 
-               for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-                       AudioRegion& r ((*i)->region);
+               for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+                       Region& r ((*i)->region());
 
                        session->add_undo (r.playlist()->get_memento());
                        
@@ -466,7 +525,7 @@ Editor::nudge_backward_capture_offset ()
 void
 Editor::move_to_start ()
 {
-       session->request_locate (0);
+       session->goto_start ();
 }
 
 void
@@ -725,8 +784,8 @@ Editor::cursor_to_selection_start (Cursor *cursor)
        jack_nframes_t pos = 0;
        switch (mouse_mode) {
        case MouseObject:
-               if (!selection->audio_regions.empty()) {
-                       pos = selection->audio_regions.start();
+               if (!selection->regions.empty()) {
+                       pos = selection->regions.start();
                }
                break;
 
@@ -754,8 +813,8 @@ Editor::cursor_to_selection_end (Cursor *cursor)
 
        switch (mouse_mode) {
        case MouseObject:
-               if (!selection->audio_regions.empty()) {
-                       pos = selection->audio_regions.end_frame();
+               if (!selection->regions.empty()) {
+                       pos = selection->regions.end_frame();
                }
                break;
 
@@ -990,7 +1049,12 @@ Editor::scroll_tracks_down ()
                cnt = (int) floor (prefix);
        }
 
-       vertical_adjustment.set_value (vertical_adjustment.get_value() + (cnt * vertical_adjustment.get_page_size()));
+       double vert_value = vertical_adjustment.get_value() + (cnt *
+               vertical_adjustment.get_page_size());
+       if (vert_value > vertical_adjustment.get_upper() - canvas_height) {
+               vert_value = vertical_adjustment.get_upper() - canvas_height;
+       }
+       vertical_adjustment.set_value (vert_value);
 }
 
 void
@@ -1012,15 +1076,21 @@ Editor::scroll_tracks_up ()
 void
 Editor::scroll_tracks_down_line ()
 {
+
         Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
-       adj->set_value (adj->get_value() + 10);
+       double vert_value = adj->get_value() + 20;
+
+       if (vert_value>adj->get_upper() - canvas_height) {
+               vert_value = adj->get_upper() - canvas_height;
+       }
+       adj->set_value (vert_value);
 }
 
 void
 Editor::scroll_tracks_up_line ()
 {
         Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
-       adj->set_value (adj->get_value() - 10);
+       adj->set_value (adj->get_value() - 20);
 }
 
 /* ZOOM */
@@ -1028,6 +1098,8 @@ Editor::scroll_tracks_up_line ()
 void
 Editor::temporal_zoom_step (bool coarser)
 {
+       ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::temporal_zoom_step), coarser));
+
        double nfpu;
 
        nfpu = frames_per_unit;
@@ -1129,8 +1201,10 @@ Editor::temporal_zoom_selection ()
 void
 Editor::temporal_zoom_session ()
 {
+       ENSURE_GUI_THREAD (mem_fun (*this, &Editor::temporal_zoom_session));
+
        if (session) {
-               temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
+               temporal_zoom_by_frame (session->current_start_frame(), session->current_end_frame(), "zoom to session");
        }
 }
 
@@ -1200,7 +1274,61 @@ Editor::temporal_zoom_to_frame (bool coarser, jack_nframes_t frame)
 }
 
 void
-Editor::select_all_in_track (bool add)
+Editor::add_location_from_selection ()
+{
+       if (selection->time.empty()) {
+               return;
+       }
+
+       if (session == 0 || clicked_trackview == 0) {
+               return;
+       }
+
+       jack_nframes_t start = selection->time[clicked_selection].start;
+       jack_nframes_t end = selection->time[clicked_selection].end;
+
+       Location *location = new Location (start, end, "selection");
+
+       session->begin_reversible_command (_("add marker"));
+       session->add_undo (session->locations()->get_memento());
+       session->locations()->add (location, true);
+       session->add_redo_no_execute (session->locations()->get_memento());
+       session->commit_reversible_command ();
+}
+
+void
+Editor::add_location_from_playhead_cursor ()
+{
+       jack_nframes_t where = session->audible_frame();
+       
+       Location *location = new Location (where, where, "mark", Location::IsMark);
+       session->begin_reversible_command (_("add marker"));
+       session->add_undo (session->locations()->get_memento());
+       session->locations()->add (location, true);
+       session->add_redo_no_execute (session->locations()->get_memento());
+       session->commit_reversible_command ();
+}
+
+void
+Editor::add_location_from_audio_region ()
+{
+       if (selection->regions.empty()) {
+               return;
+       }
+
+       RegionView* rv = *(selection->regions.begin());
+       Region& region = rv->region();
+       
+       Location *location = new Location (region.position(), region.last_frame(), region.name());
+       session->begin_reversible_command (_("add marker"));
+       session->add_undo (session->locations()->get_memento());
+       session->locations()->add (location, true);
+       session->add_redo_no_execute (session->locations()->get_memento());
+       session->commit_reversible_command ();
+}
+
+void
+Editor::select_all_in_track (Selection::Operation op)
 {
        list<Selectable *> touched;
 
@@ -1210,15 +1338,21 @@ Editor::select_all_in_track (bool add)
        
        clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
 
-       if (add) {
+       switch (op) {
+       case Selection::Toggle:
                selection->add (touched);
-       } else {
+               break;
+       case Selection::Set:
                selection->set (touched);
+               break;
+       case Selection::Extend:
+               /* not defined yet */
+               break;
        }
 }
 
 void
-Editor::select_all (bool add)
+Editor::select_all (Selection::Operation op)
 {
        list<Selectable *> touched;
        
@@ -1228,13 +1362,19 @@ Editor::select_all (bool add)
                }
                (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
        }
-
-       if (add) {
+       begin_reversible_command (_("select all"));
+       switch (op) {
+       case Selection::Toggle:
                selection->add (touched);
-       } else {
+               break;
+       case Selection::Set:
                selection->set (touched);
+               break;
+       case Selection::Extend:
+               /* not defined yet */
+               break;
        }
-
+       commit_reversible_command ();
 }
 
 void
@@ -1266,7 +1406,7 @@ Editor::invert_selection ()
 }
 
 bool
-Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
+Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, Selection::Operation op)
 {
        list<Selectable *> touched;
        
@@ -1276,16 +1416,48 @@ Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top,
                }
                (*iter)->get_selectables (start, end, top, bot, touched);
        }
+
+       cerr << "select all within found " << touched.size() << endl;
+
        begin_reversible_command (_("select all within"));
-       if (add) {
+       switch (op) {
+       case Selection::Toggle:
+               cerr << "toggle\n";
                selection->add (touched);
-       } else {
+               break;
+       case Selection::Set:
+               cerr << "set\n";
                selection->set (touched);
+               break;
+       case Selection::Extend:
+               cerr << "extend\n";
+               /* not defined yet */
+               break;
        }
+
+       cerr << "selection now has " << selection->points.size() << endl;
+
        commit_reversible_command ();
        return !touched.empty();
 }
 
+void
+Editor::set_selection_from_audio_region ()
+{
+       if (selection->regions.empty()) {
+               return;
+       }
+
+       RegionView* rv = *(selection->regions.begin());
+       Region& region = rv->region();
+       
+       begin_reversible_command (_("set selection from region"));
+       selection->set (0, region.position(), region.last_frame());
+       commit_reversible_command ();
+
+       set_mouse_mode (Editing::MouseRange, false);
+}
+
 void
 Editor::set_selection_from_punch()
 {
@@ -1310,11 +1482,51 @@ Editor::set_selection_from_loop()
 }
 
 void
-Editor::select_all_from_punch()
+Editor::set_selection_from_range (Location& loc)
+{
+       begin_reversible_command (_("set selection from range"));
+       selection->set (0, loc.start(), loc.end());
+       commit_reversible_command ();
+
+       set_mouse_mode (Editing::MouseRange, false);
+}
+
+void
+Editor::select_all_selectables_using_time_selection ()
 {
-       Location* location;
        list<Selectable *> touched;
-       if ((location = session->locations()->auto_punch_location()) == 0)  {
+
+       if (selection->time.empty()) {
+               return;
+       }
+
+       jack_nframes_t start = selection->time[clicked_selection].start;
+       jack_nframes_t end = selection->time[clicked_selection].end;
+
+       if (end - start < 1)  {
+               return;
+       }
+
+       for (TrackViewList::iterator iter = selection->tracks.begin(); iter != selection->tracks.end(); ++iter) {
+               if ((*iter)->hidden()) {
+                       continue;
+               }
+               (*iter)->get_selectables (start, end - 1, 0, DBL_MAX, touched);
+       }
+
+       begin_reversible_command (_("select all from range"));
+       selection->set (touched);
+       commit_reversible_command ();
+}
+
+
+void
+Editor::select_all_selectables_using_punch()
+{
+       Location* location = session->locations()->auto_punch_location();
+       list<Selectable *> touched;
+
+       if (location == 0 || (location->end() - location->start() <= 1))  {
                return;
        }
 
@@ -1322,7 +1534,7 @@ Editor::select_all_from_punch()
                if ((*iter)->hidden()) {
                        continue;
                }
-               (*iter)->get_selectables (location->start(), location->end(), 0, DBL_MAX, touched);
+               (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched);
        }
        begin_reversible_command (_("select all from punch"));
        selection->set (touched);
@@ -1331,19 +1543,20 @@ Editor::select_all_from_punch()
 }
 
 void
-Editor::select_all_from_loop()
+Editor::select_all_selectables_using_loop()
 {
-       Location* location;
+       Location* location = session->locations()->auto_loop_location();
        list<Selectable *> touched;
 
-       if ((location = session->locations()->auto_loop_location()) == 0)  {
+       if (location == 0 || (location->end() - location->start() <= 1))  {
                return;
        }
+
        for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
                if ((*iter)->hidden()) {
                        continue;
                }
-               (*iter)->get_selectables (location->start(), location->end(), 0, DBL_MAX, touched);
+               (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched);
        }
        begin_reversible_command (_("select all from loop"));
        selection->set (touched);
@@ -1352,33 +1565,58 @@ Editor::select_all_from_loop()
 }
 
 void
-Editor::set_selection_from_range (Location& range)
+Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
 {
-       if (clicked_trackview == 0) {
-               return;
+        jack_nframes_t start;
+       jack_nframes_t end;
+       list<Selectable *> touched;
+
+       if (after) {
+               begin_reversible_command (_("select all after cursor"));
+               start = cursor->current_frame ;
+               end = session->current_end_frame();
+       } else {
+               if (cursor->current_frame > 0) {
+                       begin_reversible_command (_("select all before cursor"));
+                       start = 0;
+                       end = cursor->current_frame - 1;
+               } else {
+                       return;
+               }
        }
-       
-       begin_reversible_command (_("set selection from range"));
-       selection->set (0, range.start(), range.end());
+
+       for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+               if ((*iter)->hidden()) {
+                       continue;
+               }
+               (*iter)->get_selectables (start, end, 0, DBL_MAX, touched);
+       }
+       selection->set (touched);
        commit_reversible_command ();
 }
 
 void
-Editor::select_all_after_cursor (Cursor *cursor, bool after)
+Editor::select_all_selectables_between_cursors (Cursor *cursor, Cursor *other_cursor)
 {
         jack_nframes_t start;
        jack_nframes_t end;
        list<Selectable *> touched;
+       bool  other_cursor_is_first = cursor->current_frame > other_cursor->current_frame;
 
-       if (after) {
-         begin_reversible_command (_("select all after cursor"));
-         start = cursor->current_frame ;
-         end = session->current_end_frame();
+       if (cursor->current_frame == other_cursor->current_frame) {
+               return;
+       }
+
+       begin_reversible_command (_("select all between cursors"));
+       if (other_cursor_is_first) {
+               start = other_cursor->current_frame;
+               end = cursor->current_frame - 1;
+               
        } else {
-         begin_reversible_command (_("select all before cursor"));
-         start = 0;
-         end = cursor->current_frame ;
+               start = cursor->current_frame;
+               end = other_cursor->current_frame - 1;
        }
+       
        for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
                if ((*iter)->hidden()) {
                        continue;
@@ -1472,7 +1710,7 @@ Editor::jump_backward_to_mark ()
        if (location) {
                session->request_locate (location->start(), session->transport_rolling());
        } else {
-               session->request_locate (0);
+               session->goto_start ();
        }
 }
 
@@ -1591,13 +1829,13 @@ Editor::insert_region_list_drag (AudioRegion& region, int x, int y)
 void
 Editor::insert_region_list_selection (float times)
 {
-       AudioTimeAxisView *tv = 0;
+       RouteTimeAxisView *tv = 0;
        Playlist *playlist;
 
        if (clicked_audio_trackview != 0) {
                tv = clicked_audio_trackview;
        } else if (!selection->tracks.empty()) {
-               if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
+               if ((tv = dynamic_cast<RouteTimeAxisView*>(selection->tracks.front())) == 0) {
                        return;
                }
        } else {
@@ -1676,7 +1914,7 @@ Editor::toggle_playback (bool with_abort)
 void
 Editor::play_from_start ()
 {
-       session->request_locate (0, true);
+       session->request_locate (session->current_start_frame(), true);
 }
 
 void
@@ -1692,23 +1930,23 @@ Editor::play_selection ()
 void
 Editor::play_selected_region ()
 {
-       if (!selection->audio_regions.empty()) {
-               AudioRegionView *rv = *(selection->audio_regions.begin());
+       if (!selection->regions.empty()) {
+               RegionView *rv = *(selection->regions.begin());
 
-               session->request_bounded_roll (rv->region.position(), rv->region.last_frame()); 
+               session->request_bounded_roll (rv->region().position(), rv->region().last_frame());     
        }
 }
 
 void
 Editor::loop_selected_region ()
 {
-       if (!selection->audio_regions.empty()) {
-               AudioRegionView *rv = *(selection->audio_regions.begin());
+       if (!selection->regions.empty()) {
+               RegionView *rv = *(selection->regions.begin());
                Location* tll;
 
                if ((tll = transport_loop_location()) != 0)  {
 
-                       tll->set (rv->region.position(), rv->region.last_frame());
+                       tll->set (rv->region().position(), rv->region().last_frame());
                        
                        // enable looping, reposition and start rolling
 
@@ -1751,10 +1989,10 @@ void
 Editor::toggle_region_mute ()
 {
        if (clicked_regionview) {
-               clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
-       } else if (!selection->audio_regions.empty()) {
-               bool yn = ! (*selection->audio_regions.begin())->region.muted();
-               selection->foreach_audio_region (&AudioRegion::set_muted, yn);
+               clicked_regionview->region().set_muted (!clicked_regionview->region().muted());
+       } else if (!selection->regions.empty()) {
+               bool yn = ! (*selection->regions.begin())->region().muted();
+               selection->foreach_region (&Region::set_muted, yn);
        }
 }
 
@@ -1762,35 +2000,35 @@ void
 Editor::toggle_region_opaque ()
 {
        if (clicked_regionview) {
-               clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
-       } else if (!selection->audio_regions.empty()) {
-               bool yn = ! (*selection->audio_regions.begin())->region.opaque();
-               selection->foreach_audio_region (&Region::set_opaque, yn);
+               clicked_regionview->region().set_opaque (!clicked_regionview->region().opaque());
+       } else if (!selection->regions.empty()) {
+               bool yn = ! (*selection->regions.begin())->region().opaque();
+               selection->foreach_region (&Region::set_opaque, yn);
        }
 }
 
 void
 Editor::raise_region ()
 {
-       selection->foreach_audio_region (&Region::raise);
+       selection->foreach_region (&Region::raise);
 }
 
 void
 Editor::raise_region_to_top ()
 {
-       selection->foreach_audio_region (&Region::raise_to_top);
+       selection->foreach_region (&Region::raise_to_top);
 }
 
 void
 Editor::lower_region ()
 {
-       selection->foreach_audio_region (&Region::lower);
+       selection->foreach_region (&Region::lower);
 }
 
 void
 Editor::lower_region_to_bottom ()
 {
-       selection->foreach_audio_region (&Region::lower_to_bottom);
+       selection->foreach_region (&Region::lower_to_bottom);
 }
 
 void
@@ -1811,7 +2049,7 @@ Editor::rename_region ()
        Button ok_button (_("OK"));
        Button cancel_button (_("Cancel"));
 
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                return;
        }
 
@@ -1842,7 +2080,7 @@ Editor::rename_region ()
        Main::run ();
 
        if (region_renamed) {
-               (*selection->audio_regions.begin())->region.set_name (entry.get_text());
+               (*selection->regions.begin())->region().set_name (entry.get_text());
                redisplay_regions ();
        }
 }
@@ -1856,7 +2094,7 @@ Editor::rename_region_finished (bool status)
 }
 
 void
-Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
+Editor::audition_playlist_region_via_route (Region& region, Route& route)
 {
        if (session->is_auditioning()) {
                session->cancel_audition ();
@@ -1877,14 +2115,14 @@ Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
 void
 Editor::audition_selected_region ()
 {
-       if (!selection->audio_regions.empty()) {
-               AudioRegionView* rv = *(selection->audio_regions.begin());
-               session->audition_region (rv->region);
+       if (!selection->regions.empty()) {
+               RegionView* rv = *(selection->regions.begin());
+               session->audition_region (rv->region());
        }
 }
 
 void
-Editor::audition_playlist_region_standalone (AudioRegion& region)
+Editor::audition_playlist_region_standalone (Region& region)
 {
        session->audition_region (region);
 }
@@ -1917,497 +2155,6 @@ Editor::interthread_cancel_clicked ()
        }
 }
 
-void *
-Editor::_import_thread (void *arg)
-{
-       PBD::ThreadCreated (pthread_self(), X_("Import"));
-
-       Editor *ed = (Editor *) arg;
-       return ed->import_thread ();
-}
-
-void *
-Editor::import_thread ()
-{
-       session->import_audiofile (import_status);
-       return 0;
-}
-
-gint
-Editor::import_progress_timeout (void *arg)
-{
-       interthread_progress_label.set_text (import_status.doing_what);
-
-       if (import_status.freeze) {
-               interthread_cancel_button.set_sensitive(false);
-       } else {
-               interthread_cancel_button.set_sensitive(true);
-       }
-
-       if (import_status.doing_what == "building peak files") {
-               interthread_progress_bar.pulse ();
-               return FALSE;
-       } else {
-               interthread_progress_bar.set_fraction (import_status.progress/100);
-       }
-
-       return !(import_status.done || import_status.cancel);
-}
-
-void
-Editor::import_audio (bool as_tracks)
-{
-       if (session == 0) {
-               warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
-               return;
-       }
-
-       string str;
-
-       if (as_tracks) {
-               str =_("Import selected as tracks");
-       } else {
-               str = _("Import selected to region list");
-       }
-
-       SoundFileOmega sfdb (str);
-       sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks));
-
-       sfdb.run();
-}
-
-void
-Editor::catch_new_audio_region (AudioRegion* ar)
-{
-       last_audio_region = ar;
-}
-
-void
-Editor::do_import (vector<string> paths, bool split, bool as_tracks)
-{
-       sigc::connection c;
-       
-       /* SFDB sets "multichan" to true to indicate "split channels"
-          so reverse the setting to match the way libardour
-          interprets it.
-       */
-       
-       import_status.multichan = !split;
-
-       if (interthread_progress_window == 0) {
-               build_interthread_progress_window ();
-       }
-       
-       interthread_progress_window->set_title (_("ardour: audio import in progress"));
-       interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
-       interthread_progress_window->show_all ();
-       interthread_progress_bar.set_fraction (0.0f);
-       interthread_cancel_label.set_text (_("Cancel Import"));
-       current_interthread_info = &import_status;
-
-       c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
-
-       for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
-
-               interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
-       
-               import_status.pathname = (*i);
-               import_status.done = false;
-               import_status.cancel = false;
-               import_status.freeze = false;
-               import_status.done = 0.0;
-               
-               interthread_progress_connection = 
-                 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
-               
-               last_audio_region = 0;
-               
-               pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
-               pthread_detach (import_status.thread);
-               
-               while (!(import_status.done || import_status.cancel)) {
-                       gtk_main_iteration ();
-               }
-               
-               import_status.done = true;
-               interthread_progress_connection.disconnect ();
-
-               if (as_tracks && last_audio_region != 0) {
-                       uint32_t channels = last_audio_region->n_channels();
-
-                       AudioTrack* at = session->new_audio_track (channels, channels);
-                       AudioRegion* copy = new AudioRegion (*last_audio_region);
-                       at->disk_stream().playlist()->add_region (*copy, 0);
-               }
-       }
-
-       c.disconnect ();
-       interthread_progress_window->hide_all ();
-}
-
-int
-Editor::reject_because_rate_differs (const string & path, SF_INFO& finfo, const string & action, bool multiple_pending)
-{
-       if (!session) {
-               return 1;
-       }
-
-       if (finfo.samplerate != (int) session->frame_rate()) {
-               vector<string> choices;
-
-               choices.push_back (string_compose (_("%1 it anyway"), action));
-
-               if (multiple_pending) {
-                       /* XXX assumptions about sentence structure
-                          here for translators. Sorry.
-                       */
-                       choices.push_back (string_compose (_("Don't %1 it"), action));
-                       choices.push_back (string_compose (_("%1 all without questions"), action));
-                       choices.push_back (_("Cancel entire import"));
-               } else {
-                       choices.push_back (_("Cancel"));
-               }
-
-               Gtkmm2ext::Choice rate_choice (
-                       string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
-                       choices);
-
-               rate_choice.chosen.connect (ptr_fun (Main::quit));
-               rate_choice.show_all ();
-
-               Main::run ();
-
-               switch (rate_choice.get_choice()) {
-               case 0: /* do it anyway */
-                       return 0;
-               case 1: /* don't import this one */
-                       return 1;
-               case 2: /* do the rest without asking */
-                       return -1;
-               case 3: /* stop a multi-file import */
-               default:
-                       return -2;
-               }
-       }
-
-       return 0;
-}
-
-void 
-Editor::embed_audio ()
-{
-       if (session == 0) {
-               warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
-               return;
-       }
-
-       SoundFileOmega sfdb (_("Add to External Region list"));
-       sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
-
-       sfdb.run ();
-}
-
-void
-Editor::do_embed_sndfiles (vector<string> paths, bool split)
-{
-       bool multiple_files = paths.size() > 1;
-       bool check_sample_rate = true;
-
-       for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
-               embed_sndfile (*i, split, multiple_files, check_sample_rate);
-       }
-
-       session->save_state ("");
-}
-
-void
-Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
-{
-       SndFileSource *source = 0; /* keep g++ quiet */
-       AudioRegion::SourceList sources;
-       string idspec;
-       string linked_path;
-       SNDFILE *sf;
-       SF_INFO finfo;
-
-       /* lets see if we can link it into the session */
-       
-       linked_path = session->sound_dir();
-       linked_path += PBD::basename (path);
-
-       if (link (path.c_str(), linked_path.c_str()) == 0) {
-
-               /* there are many reasons why link(2) might have failed.
-                  but if it succeeds, we now have a link in the
-                  session sound dir that will protect against
-                  unlinking of the original path. nice.
-               */
-
-               path = linked_path;
-       }
-
-       memset (&finfo, 0, sizeof(finfo));
-
-       /* note that we temporarily truncated _id at the colon */
-       
-       if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
-               char errbuf[256];
-               sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-               error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
-               return;
-       }
-       sf_close (sf);
-       sf = 0;
-       
-       if (check_sample_rate) {
-               switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
-               case 0:
-                       break;
-               case 1:
-                       return;
-               case -1:
-                       check_sample_rate = false;
-                       break;
-                       
-               case -2:
-               default:
-                       return;
-               }
-       }
-
-       track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
-       ARDOUR_UI::instance()->flush_pending ();
-
-       /* make the proper number of channels in the region */
-
-       for (int n=0; n < finfo.channels; ++n)
-       {
-               idspec = path;
-               idspec += string_compose(":%1", n);
-               
-               try {
-                       source = new SndFileSource (idspec.c_str());
-                       sources.push_back(source);
-               } 
-
-               catch (failed_constructor& err) {
-                       error << string_compose(_("could not open %1"), path) << endmsg;
-                       goto out;
-               }
-
-               ARDOUR_UI::instance()->flush_pending ();
-       }
-
-       if (sources.size() > 0) {
-
-               string region_name = PBD::basename_nosuffix (path);
-               region_name += "-0";
-
-               /* The created region isn't dropped.  It emits a signal
-                  that is picked up by the session. 
-               */
-
-               new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
-                                Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
-               
-               /* make sure we can see it in the list */
-
-                /* its the second node, always */
-
-               // GTK2FIX ?? is it still always the 2nd node
-
-               TreeModel::Path path ("2");
-               region_list_display.expand_row (path, true);
-
-               ARDOUR_UI::instance()->flush_pending ();
-       }
-
-  out:
-       track_canvas.get_window()->set_cursor (*current_canvas_cursor);
-}
-
-void
-Editor::insert_sndfile (bool as_tracks)
-{
-//     SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
-       sigc::connection c;
-       string str;
-
-       if (as_tracks) {
-
-//             c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
-               str = _("Insert selected as new tracks");
-
-       } else {
-
-               jack_nframes_t pos;
-
-               if (clicked_audio_trackview == 0) {
-                       return;
-               }
-
-               if (ensure_cursor (&pos)) {
-                       return;
-               }
-
-//             c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
-               str = _("Insert selected");
-       }
-
-//     sfdb.run (str, false);
-//     c.disconnect ();
-}
-
-void
-Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
-{
-       SNDFILE *sf;
-       SF_INFO finfo;
-       bool multiple_files;
-       bool check_sample_rate = true;
-
-       multiple_files = paths.size() > 1;      
-
-       for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
-               
-               memset (&finfo, 0, sizeof(finfo));
-               
-               if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
-                       char errbuf[256];
-                       sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-                       error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
-                       continue;
-               }
-               
-               sf_close (sf);
-               sf = 0;
-               
-               /* add a new track */
-               
-               if (check_sample_rate) {
-                       switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
-                       case 0:
-                               break;
-                       case 1:
-                               continue;
-                       case -1:
-                               check_sample_rate = false;
-                               break;
-                               
-                       case -2:
-                               return;
-                       }
-               }
-               
-               uint32_t input_chan = finfo.channels;
-               uint32_t output_chan;
-               
-               if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
-                       output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
-               } else {
-                       output_chan = input_chan;
-               }
-               
-               (void) session->new_audio_track (input_chan, output_chan);
-
-
-               /* get the last (most recently added) track view */
-       
-               AudioTimeAxisView* tv;
-       
-               if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
-                       fatal << _("programming error: ")
-                             << X_("last trackview after new_audio_track is not an audio track!")
-                             << endmsg;
-                       /*NOTREACHED*/
-               }
-               
-               jack_nframes_t pos = 0;
-               insert_sndfile_into (*p, true, tv, pos, false);
-       }
-}
-
-void
-Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
-{
-       for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
-               insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
-       }
-}
-
-void
-Editor::insert_sndfile_into (const string & path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
-{
-       SndFileSource *source = 0; /* keep g++ quiet */
-       AudioRegion::SourceList sources;
-       string idspec;
-       SNDFILE *sf;
-       SF_INFO finfo;
-
-       memset (&finfo, 0, sizeof(finfo));
-
-       /* note that we temporarily truncated _id at the colon */
-       
-       if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
-               char errbuf[256];
-               sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-               error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
-               return;
-       }
-       sf_close (sf);
-       sf = 0;
-       
-       if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
-               return;
-       }
-
-       track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
-       ARDOUR_UI::instance()->flush_pending ();
-
-       /* make the proper number of channels in the region */
-
-       for (int n=0; n < finfo.channels; ++n)
-       {
-               idspec = path;
-               idspec += string_compose(":%1", n);
-
-               try {
-                       source = new SndFileSource (idspec.c_str());
-                       sources.push_back(source);
-               } 
-
-               catch (failed_constructor& err) {
-                       error << string_compose(_("could not open %1"), path) << endmsg;
-                       goto out;
-               }
-
-               ARDOUR_UI::instance()->flush_pending ();
-       }
-
-       if (sources.size() > 0) {
-
-               string region_name = region_name_from_path (PBD::basename (path));
-               
-               AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name, 
-                                                      0, /* irrelevant these days */
-                                                      Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
-
-               begin_reversible_command (_("insert sndfile"));
-               session->add_undo (tv->playlist()->get_memento());
-               tv->playlist()->add_region (*region, pos);
-               session->add_redo_no_execute (tv->playlist()->get_memento());
-               commit_reversible_command ();
-               
-               pos += sources[0]->length();
-
-               ARDOUR_UI::instance()->flush_pending ();
-       }
-
-  out:
-       track_canvas.get_window()->set_cursor (*current_canvas_cursor);
-       return;
-}
-
 void
 Editor::region_from_selection ()
 {
@@ -2442,7 +2189,9 @@ Editor::region_from_selection ()
                        continue;
                }
 
-               if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
+               current = dynamic_cast<AudioRegion*> (current_r);
+               assert(current); // FIXME
+               if (current != 0) {
                        internal_start = start - current->position();
                        session->region_name (new_name, current->name(), true);
                        region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
@@ -2492,11 +2241,13 @@ Editor::split_multichannel_region ()
 {
        vector<AudioRegion*> v;
 
-       if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
+       AudioRegionView* clicked_arv = dynamic_cast<AudioRegionView*>(clicked_regionview);
+       
+       if (!clicked_arv || clicked_arv->audio_region().n_channels() < 2) {
                return;
        }
 
-       clicked_regionview->region.separate_by_channel (*session, v);
+       clicked_arv->audio_region().separate_by_channel (*session, v);
 
        /* nothing else to do, really */
 }
@@ -2551,6 +2302,53 @@ Editor::separate_region_from_selection ()
        if (doing_undo) commit_reversible_command ();
 }
 
+void
+Editor::separate_regions_using_location (Location& loc)
+{
+       bool doing_undo = false;
+
+       if (loc.is_mark()) {
+               return;
+       }
+
+       Playlist *playlist;
+
+       /* XXX i'm unsure as to whether this should operate on selected tracks only 
+          or the entire enchillada. uncomment the below line to correct the behaviour 
+          (currently set for all tracks)
+       */
+
+       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {    
+       //for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+
+               AudioTimeAxisView* atv;
+
+               if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
+
+                       if (atv->is_audio_track()) {
+                                       
+                               if ((playlist = atv->playlist()) != 0) {
+                                       if (!doing_undo) {
+                                               begin_reversible_command (_("separate"));
+                                               doing_undo = true;
+                                       }
+                                       if (doing_undo) session->add_undo ((playlist)->get_memento());
+                       
+                                       /* XXX need to consider musical time selections here at some point */
+
+                                       double speed = atv->get_diskstream()->speed();
+
+
+                                       playlist->partition ((jack_nframes_t)(loc.start() * speed), (jack_nframes_t)(loc.end() * speed), true);
+                                       if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
+                               }
+                       }
+               }
+       }
+
+       if (doing_undo) commit_reversible_command ();
+}
+
 void
 Editor::crop_region_to_selection ()
 {
@@ -2627,7 +2425,7 @@ Editor::region_fill_track ()
 {
        jack_nframes_t end;
 
-       if (!session || selection->audio_regions.empty()) {
+       if (!session || selection->regions.empty()) {
                return;
        }
 
@@ -2635,9 +2433,15 @@ Editor::region_fill_track ()
 
        begin_reversible_command (_("region fill"));
 
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+
+               Region& region ((*i)->region());
+               
+               // FIXME
+               AudioRegion* const ar = dynamic_cast<AudioRegion*>(&region);
+               if (!ar)
+                       continue;
 
-               AudioRegion& region ((*i)->region);
                Playlist* pl = region.playlist();
 
                if (end <= region.last_frame()) {
@@ -2651,7 +2455,7 @@ Editor::region_fill_track ()
                }
 
                session->add_undo (pl->get_memento());
-               pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
+               pl->add_region (*(new AudioRegion (*ar)), ar->last_frame(), times);
                session->add_redo_no_execute (pl->get_memento());
        }
 
@@ -2730,12 +2534,12 @@ Editor::set_region_sync_from_edit_cursor ()
                return;
        }
 
-       if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
+       if (!clicked_regionview->region().covers (edit_cursor->current_frame)) {
                error << _("Place the edit cursor at the desired sync point") << endmsg;
                return;
        }
 
-       Region& region (clicked_regionview->region);
+       Region& region (clicked_regionview->region());
        begin_reversible_command (_("set sync from edit cursor"));
        session->add_undo (region.playlist()->get_memento());
        region.set_sync_position (edit_cursor->current_frame);
@@ -2747,7 +2551,7 @@ void
 Editor::remove_region_sync ()
 {
        if (clicked_regionview) {
-               Region& region (clicked_regionview->region);
+               Region& region (clicked_regionview->region());
                begin_reversible_command (_("remove sync"));
                session->add_undo (region.playlist()->get_memento());
                region.clear_sync_position ();
@@ -2759,14 +2563,14 @@ Editor::remove_region_sync ()
 void
 Editor::naturalize ()
 {
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                return;
        }
        begin_reversible_command (_("naturalize"));
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-               session->add_undo ((*i)->region.get_memento());
-               (*i)->region.move_to_natural_position (this);
-               session->add_redo_no_execute ((*i)->region.get_memento());
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               session->add_undo ((*i)->region().get_memento());
+               (*i)->region().move_to_natural_position (this);
+               session->add_redo_no_execute ((*i)->region().get_memento());
        }
        commit_reversible_command ();
 }
@@ -2785,14 +2589,14 @@ Editor::align_relative (RegionPoint what)
 
 struct RegionSortByTime {
     bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
-           return a->region.position() < b->region.position();
+           return a->region().position() < b->region().position();
     }
 };
 
 void
 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
 {
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                return;
        }
 
@@ -2800,9 +2604,9 @@ Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
        jack_nframes_t pos = 0;
        int dir;
 
-       list<AudioRegionView*> sorted;
-       selection->audio_regions.by_position (sorted);
-       Region& r ((*sorted.begin())->region);
+       list<RegionView*> sorted;
+       selection->regions.by_position (sorted);
+       Region& r ((*sorted.begin())->region());
 
        switch (point) {
        case Start:
@@ -2828,9 +2632,9 @@ Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
 
        begin_reversible_command (_("align selection (relative)"));
 
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
 
-               Region& region ((*i)->region);
+               Region& region ((*i)->region());
 
                session->add_undo (region.playlist()->get_memento());
                
@@ -2850,14 +2654,14 @@ Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
 void
 Editor::align_selection (RegionPoint point, jack_nframes_t position)
 {
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                return;
        }
 
        begin_reversible_command (_("align selection"));
 
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-               align_region_internal ((*i)->region, point, position);
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               align_region_internal ((*i)->region(), point, position);
        }
 
        commit_reversible_command ();
@@ -2902,7 +2706,7 @@ Editor::trim_region_to_edit_cursor ()
                return;
        }
 
-       Region& region (clicked_regionview->region);
+       Region& region (clicked_regionview->region());
 
        float speed = 1.0f;
        AudioTimeAxisView *atav;
@@ -2927,7 +2731,7 @@ Editor::trim_region_from_edit_cursor ()
                return;
        }
 
-       Region& region (clicked_regionview->region);
+       Region& region (clicked_regionview->region());
 
        float speed = 1.0f;
        AudioTimeAxisView *atav;
@@ -3098,16 +2902,16 @@ Editor::cut_copy (CutCopyOp op)
 
        switch (current_mouse_mode()) {
        case MouseObject: 
-               if (!selection->audio_regions.empty() || !selection->points.empty()) {
+               if (!selection->regions.empty() || !selection->points.empty()) {
 
                        begin_reversible_command (opname + _(" objects"));
 
-                       if (!selection->audio_regions.empty()) {
+                       if (!selection->regions.empty()) {
                                
                                cut_copy_regions (op);
                                
                                if (op == Cut) {
-                                       selection->clear_audio_regions ();
+                                       selection->clear_regions ();
                                }
                        }
 
@@ -3164,11 +2968,11 @@ Editor::cut_copy_regions (CutCopyOp op)
        set<Playlist*> freezelist;
        pair<set<Playlist*>::iterator,bool> insert_result;
 
-       for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
-               first_position = min ((*x)->region.position(), first_position);
+       for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) {
+               first_position = min ((*x)->region().position(), first_position);
 
                if (op == Cut || op == Clear) {
-                       AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
+                       AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region().playlist());
                        if (pl) {
                                insert_result = freezelist.insert (pl);
                                if (insert_result.second) {
@@ -3179,11 +2983,11 @@ Editor::cut_copy_regions (CutCopyOp op)
                }
        }
 
-       for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
+       for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ) {
 
-               AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
+               AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region().playlist());
                AudioPlaylist* npl;
-               AudioRegionSelection::iterator tmp;
+               RegionSelection::iterator tmp;
                
                tmp = x;
                ++tmp;
@@ -3200,18 +3004,24 @@ Editor::cut_copy_regions (CutCopyOp op)
                                npl = pi->second;
                        }
 
+                       // FIXME
+                       AudioRegion* const ar = dynamic_cast<AudioRegion*>(&(*x)->region());
                        switch (op) {
                        case Cut:
-                               npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
-                               pl->remove_region (&((*x)->region));
+                               if (!ar) break;
+
+                               npl->add_region (*(new AudioRegion (*ar)), (*x)->region().position() - first_position);
+                               pl->remove_region (&((*x)->region()));
                                break;
 
                        case Copy:
-                               npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
+                               if (!ar) break;
+
+                               npl->add_region (*(new AudioRegion (*ar)), (*x)->region().position() - first_position);
                                break;
 
                        case Clear:
-                               pl->remove_region (&((*x)->region));
+                               pl->remove_region (&((*x)->region()));
                                break;
                        }
                }
@@ -3357,24 +3167,24 @@ Editor::paste_named_selection (float times)
 }
 
 void
-Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
+Editor::duplicate_some_regions (RegionSelection& regions, float times)
 {
        Playlist *playlist; 
-       AudioRegionSelection sel = regions; // clear (below) will clear the argument list
+       RegionSelection sel = regions; // clear (below) will clear the argument list
                
        begin_reversible_command (_("duplicate region"));
 
-       selection->clear_audio_regions ();
+       selection->clear_regions ();
 
-       for (AudioRegionSelection::iterator i = sel.begin(); i != sel.end(); ++i) {
+       for (RegionSelection::iterator i = sel.begin(); i != sel.end(); ++i) {
 
-               Region& r ((*i)->region);
+               Region& r ((*i)->region());
 
                TimeAxisView& tv = (*i)->get_time_axis_view();
                AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
-               sigc::connection c = atv->view->AudioRegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
+               sigc::connection c = atv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
                
-               playlist = (*i)->region.playlist();
+               playlist = (*i)->region().playlist();
                session->add_undo (playlist->get_memento());
                playlist->duplicate (r, r.last_frame(), times);
                session->add_redo_no_execute (playlist->get_memento());
@@ -3428,6 +3238,23 @@ Editor::duplicate_selection (float times)
        commit_reversible_command ();
 }
 
+void
+Editor::reset_point_selection ()
+{
+       /* reset all selected points to the relevant default value */
+
+       cerr << "point selection has " << selection->points.size() << " entries\n";
+       
+       for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
+               
+               AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
+               
+               if (atv) {
+                       atv->reset_objects (selection->points);
+               } 
+       }
+}
+
 void
 Editor::center_playhead ()
 {
@@ -3492,26 +3319,6 @@ Editor::nudge_track (bool use_edit_cursor, bool forwards)
        commit_reversible_command ();                   
 }
 
-void
-Editor::toggle_xfades_active ()
-{
-       if (session) {
-               session->set_crossfades_active (!session->get_crossfades_active());
-       }
-}
-
-void
-Editor::set_xfade_visibility (bool yn)
-{
-       
-}
-
-void
-Editor::toggle_xfade_visibility ()
-{
-       set_xfade_visibility (!xfade_visibility());
-}
-
 void
 Editor::remove_last_capture ()
 {
@@ -3526,16 +3333,12 @@ Editor::remove_last_capture ()
                prompt  = _("Do you really want to destroy the last capture?"
                            "\n(This is destructive and cannot be undone)");
 
-               choices.push_back (_("Yes, destroy it."));
                choices.push_back (_("No, do nothing."));
+               choices.push_back (_("Yes, destroy it."));
                
                Gtkmm2ext::Choice prompter (prompt, choices);
-               prompter.chosen.connect (ptr_fun (Main::quit));
-               prompter.show_all ();
-
-               Main::run ();
                
-               if (prompter.get_choice() == 0) {
+               if (prompter.run () == 1) {
                        session->remove_last_capture ();
                }
 
@@ -3551,7 +3354,7 @@ Editor::normalize_region ()
                return;
        }
 
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                return;
        }
 
@@ -3560,10 +3363,13 @@ Editor::normalize_region ()
        track_canvas.get_window()->set_cursor (*wait_cursor);
        gdk_flush ();
 
-       for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
-               session->add_undo ((*r)->region.get_memento());
-               (*r)->region.normalize_to (0.0f);
-               session->add_redo_no_execute ((*r)->region.get_memento());
+       for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ++r) {
+               AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*r);
+               if (!arv)
+                       continue;
+               session->add_undo (arv->region().get_memento());
+               arv->audio_region().normalize_to (0.0f);
+               session->add_redo_no_execute (arv->region().get_memento());
        }
 
        commit_reversible_command ();
@@ -3578,16 +3384,19 @@ Editor::denormalize_region ()
                return;
        }
 
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                return;
        }
 
        begin_reversible_command ("denormalize");
 
-       for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
-               session->add_undo ((*r)->region.get_memento());
-               (*r)->region.set_scale_amplitude (1.0f);
-               session->add_redo_no_execute ((*r)->region.get_memento());
+       for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ++r) {
+               AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*r);
+               if (!arv)
+                       continue;
+               session->add_undo (arv->region().get_memento());
+               arv->audio_region().set_scale_amplitude (1.0f);
+               session->add_redo_no_execute (arv->region().get_memento());
        }
 
        commit_reversible_command ();
@@ -3608,7 +3417,7 @@ Editor::reverse_region ()
 void
 Editor::apply_filter (AudioFilter& filter, string command)
 {
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                return;
        }
 
@@ -3617,20 +3426,22 @@ Editor::apply_filter (AudioFilter& filter, string command)
        track_canvas.get_window()->set_cursor (*wait_cursor);
        gdk_flush ();
 
-       for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
+       for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ) {
+               AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*r);
+               if (!arv)
+                       continue;
 
-               AudioRegion& region ((*r)->region);
-               Playlist* playlist = region.playlist();
+               Playlist* playlist = arv->region().playlist();
 
-               AudioRegionSelection::iterator tmp;
+               RegionSelection::iterator tmp;
                
                tmp = r;
                ++tmp;
 
-               if (region.apply (filter) == 0) {
+               if (arv->audio_region().apply (filter) == 0) {
 
                        session->add_undo (playlist->get_memento());
-                       playlist->replace_region (region, *(filter.results.front()), region.position());
+                       playlist->replace_region (arv->region(), *(filter.results.front()), arv->region().position());
                        session->add_redo_no_execute (playlist->get_memento());
                } else {
                        goto out;
@@ -3640,7 +3451,7 @@ Editor::apply_filter (AudioFilter& filter, string command)
        }
 
        commit_reversible_command ();
-       selection->audio_regions.clear ();
+       selection->regions.clear ();
 
   out:
        track_canvas.get_window()->set_cursor (*current_canvas_cursor);
@@ -3649,8 +3460,8 @@ Editor::apply_filter (AudioFilter& filter, string command)
 void
 Editor::region_selection_op (void (Region::*pmf)(void))
 {
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-               ((*i)->region.*pmf)();
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               ((*i)->region().*pmf)();
        }
 }
 
@@ -3658,16 +3469,16 @@ Editor::region_selection_op (void (Region::*pmf)(void))
 void
 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
 {
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-               ((*i)->region.*pmf)(arg);
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               ((*i)->region().*pmf)(arg);
        }
 }
 
 void
 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
 {
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-               ((*i)->region.*pmf)(yn);
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               ((*i)->region().*pmf)(yn);
        }
 }
 
@@ -3684,20 +3495,20 @@ Editor::external_edit_region ()
 void
 Editor::brush (jack_nframes_t pos)
 {
-       AudioRegionSelection sel;
+       RegionSelection sel;
        snap_to (pos);
 
-       if (selection->audio_regions.empty()) {
+       if (selection->regions.empty()) {
                /* XXX get selection from region list */
        } else { 
-               sel = selection->audio_regions;
+               sel = selection->regions;
        }
 
        if (sel.empty()) {
                return;
        }
 
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
                mouse_brush_insert_region ((*i), pos);
        }
 }
@@ -3705,18 +3516,19 @@ Editor::brush (jack_nframes_t pos)
 void
 Editor::toggle_gain_envelope_visibility ()
 {
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-               (*i)->set_envelope_visible (!(*i)->envelope_visible());
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
+               if (arv)
+                       arv->set_envelope_visible (!arv->envelope_visible());
        }
 }
 
 void
 Editor::toggle_gain_envelope_active ()
 {
-       for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
-               AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
-               if (ar) {
-                       ar->set_envelope_active (true);
-               }
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
+               if (arv)
+                       arv->audio_region().set_envelope_active (true);
        }
 }