Reinstate mouse scroll actions (audio clocks, shuttle wheel, faders), clearing select...
[ardour.git] / gtk2_ardour / editor_ops.cc
index 7ce6f4657718f95067c676ae318935ba927421d3..192269eb15bc3d6ff909d2b5b177491b918150a2 100644 (file)
@@ -60,6 +60,7 @@
 #include "sfdb_ui.h"
 #include "editing.h"
 #include "gtk-custom-hruler.h"
+#include "gui_thread.h"
 
 #include "i18n.h"
 
@@ -983,7 +984,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
@@ -1005,15 +1011,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 */
@@ -1021,6 +1033,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;
@@ -1122,6 +1136,8 @@ 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 (session->current_start_frame(), session->current_end_frame(), "zoom to session");
        }
@@ -1394,10 +1410,6 @@ Editor::set_selection_from_loop()
 void
 Editor::set_selection_from_range (Location& loc)
 {
-        if (clicked_trackview == 0) {
-               return;
-       }
-       
        begin_reversible_command (_("set selection from range"));
        selection->set (0, loc.start(), loc.end());
        commit_reversible_command ();
@@ -1408,13 +1420,8 @@ Editor::set_selection_from_range (Location& loc)
 void
 Editor::select_all_selectables_using_time_selection ()
 {
-
        list<Selectable *> touched;
 
-       if (clicked_trackview == 0) {
-               return;
-       }
-
        if (selection->time.empty()) {
                return;
        }
@@ -1432,10 +1439,10 @@ Editor::select_all_selectables_using_time_selection ()
                }
                (*iter)->get_selectables (start, end - 1, 0, DBL_MAX, touched);
        }
+
        begin_reversible_command (_("select all from range"));
        selection->set (touched);
        commit_reversible_command ();
-
 }
 
 
@@ -1491,18 +1498,51 @@ Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
        list<Selectable *> touched;
 
        if (after) {
-         begin_reversible_command (_("select all after cursor"));
-         start = cursor->current_frame ;
-         end = session->current_end_frame();
+               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;
+               }
+       }
+
+       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_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 (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 {
-         if (cursor->current_frame > 0) {
-           begin_reversible_command (_("select all before cursor"));
-           start = 0;
-           end = cursor->current_frame - 1;
-         } else {
-           return;
-         }
+               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;
@@ -2184,6 +2224,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 ()
 {