Re-work main right-click context menu to operate on the selection, and remove some...
[ardour.git] / gtk2_ardour / editor_selection.cc
1 /*
2     Copyright (C) 2000-2006 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <pbd/stacktrace.h>
21
22 #include <ardour/diskstream.h>
23 #include <ardour/playlist.h>
24 #include <ardour/route_group.h>
25
26 #include "editor.h"
27 #include "actions.h"
28 #include "audio_time_axis.h"
29 #include "audio_region_view.h"
30 #include "audio_streamview.h"
31 #include "automation_line.h"
32
33 #include "i18n.h"
34
35 using namespace std;
36 using namespace sigc;
37 using namespace ARDOUR;
38 using namespace PBD;
39 using namespace Gtk;
40 using namespace Glib;
41 using namespace Gtkmm2ext;
42 using namespace Editing;
43
44 struct TrackViewByPositionSorter
45 {
46     bool operator() (const TimeAxisView* a, const TimeAxisView *b) {
47             return a->y_position < b->y_position;
48     }
49 };
50
51 bool
52 Editor::extend_selection_to_track (TimeAxisView& view)
53 {
54         if (selection->selected (&view)) {
55                 /* already selected, do nothing */
56                 return false;
57         }
58
59         if (selection->tracks.empty()) {
60
61                 if (!selection->selected (&view)) {
62                         selection->set (&view);
63                         return true;
64                 } else {
65                         return false;
66                 }
67         } 
68
69         /* something is already selected, so figure out which range of things to add */
70         
71         TrackViewList to_be_added;
72         TrackViewList sorted = track_views;
73         TrackViewByPositionSorter cmp;
74         bool passed_clicked = false;
75         bool forwards = true;
76
77         sorted.sort (cmp);
78
79         if (!selection->selected (&view)) {
80                 to_be_added.push_back (&view);
81         }
82
83         /* figure out if we should go forward or backwards */
84
85         for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) {
86
87                 if ((*i) == &view) {
88                         passed_clicked = true;
89                 }
90
91                 if (selection->selected (*i)) {
92                         if (passed_clicked) {
93                                 forwards = true;
94                         } else {
95                                 forwards = false;
96                         }
97                         break;
98                 }
99         }
100                         
101         passed_clicked = false;
102
103         if (forwards) {
104
105                 for (TrackViewList::iterator i = sorted.begin(); i != sorted.end(); ++i) {
106                                         
107                         if ((*i) == &view) {
108                                 passed_clicked = true;
109                                 continue;
110                         }
111                                         
112                         if (passed_clicked) {
113                                 if ((*i)->hidden()) {
114                                         continue;
115                                 }
116                                 if (selection->selected (*i)) {
117                                         break;
118                                 } else if (!(*i)->hidden()) {
119                                         to_be_added.push_back (*i);
120                                 }
121                         }
122                 }
123
124         } else {
125
126                 for (TrackViewList::reverse_iterator r = sorted.rbegin(); r != sorted.rend(); ++r) {
127                                         
128                         if ((*r) == &view) {
129                                 passed_clicked = true;
130                                 continue;
131                         }
132                                         
133                         if (passed_clicked) {
134                                                 
135                                 if ((*r)->hidden()) {
136                                         continue;
137                                 }
138                                                 
139                                 if (selection->selected (*r)) {
140                                         break;
141                                 } else if (!(*r)->hidden()) {
142                                         to_be_added.push_back (*r);
143                                 }
144                         }
145                 }
146         }
147                         
148         if (!to_be_added.empty()) {
149                 selection->add (to_be_added);
150                 return true;
151         }
152         
153         return false;
154 }
155
156 void
157 Editor::select_all_tracks ()
158 {
159         selection->set (track_views);
160 }
161
162 bool
163 Editor::set_selected_track (TimeAxisView& view, Selection::Operation op, bool no_remove)
164 {
165         bool commit = false;
166
167         switch (op) {
168         case Selection::Toggle:
169                 if (selection->selected (&view)) {
170                         if (!no_remove) {
171                                 selection->remove (&view);
172                                 commit = true;
173                         }
174                 } else {
175                         selection->add (&view);
176                         commit = false;
177                 }
178                 break;
179
180         case Selection::Add:
181                 if (!selection->selected (&view)) {
182                         selection->add (&view);
183                         commit = true;
184                 }
185                 break;
186
187         case Selection::Set:
188                 if (selection->selected (&view) && selection->tracks.size() == 1) {
189                         /* no commit necessary */
190                 } else {
191                         
192                         /* reset track selection if there is only 1 other track
193                            selected OR if no_remove is not set (its there to 
194                            prevent deselecting a multi-track selection
195                            when clicking on an already selected track
196                            for some reason.
197                         */
198
199                         if (selection->tracks.empty()) {
200                                 selection->set (&view);
201                                 commit = true;
202                         } else if (selection->tracks.size() == 1 || !no_remove) {
203                                 selection->set (&view);
204                                 commit = true;
205                         }
206                 }
207                 break;
208                 
209         case Selection::Extend:
210                 commit = extend_selection_to_track (view);
211                 break;
212         }
213
214         return commit;
215 }
216
217 bool
218 Editor::set_selected_track_from_click (bool press, Selection::Operation op, bool no_remove)
219 {
220         if (!clicked_routeview) {
221                 return false;
222         }
223         
224         if (!press) {
225                 return false;
226         }
227
228         return set_selected_track (*clicked_routeview, op, no_remove);
229 }
230
231 bool
232 Editor::set_selected_control_point_from_click (Selection::Operation op, bool no_remove)
233 {
234         if (!clicked_control_point) {
235                 return false;
236         }
237
238         /* select this point and any others that it represents */
239
240         double y1, y2;
241         nframes_t x1, x2;
242
243         x1 = pixel_to_frame (clicked_control_point->get_x() - 10);
244         x2 = pixel_to_frame (clicked_control_point->get_x() + 10);
245         y1 = clicked_control_point->get_x() - 10;
246         y2 = clicked_control_point->get_y() + 10;
247
248         return select_all_within (x1, x2, y1, y2, selection->tracks, op);
249 }
250
251 void
252 Editor::get_relevant_tracks (set<RouteTimeAxisView*>& relevant_tracks)
253 {
254         /* step one: get all selected tracks and all tracks in the relevant edit groups */
255
256         for (TrackSelection::iterator ti = selection->tracks.begin(); ti != selection->tracks.end(); ++ti) {
257
258                 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*ti);
259
260                 if (!rtv) {
261                         continue;
262                 }
263
264                 RouteGroup* group = rtv->route()->edit_group();
265
266                 if (group && group->is_active()) {
267                         
268                         /* active group for this track, loop over all tracks and get every member of the group */
269
270                         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
271                                 
272                                 RouteTimeAxisView* trtv;
273                                 
274                                 if ((trtv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
275                                         
276                                         if (trtv->route()->edit_group() == group) {
277                                                 relevant_tracks.insert (trtv);
278                                         }
279                                 }
280                         }
281                 } else {
282                         relevant_tracks.insert (rtv);
283                 }
284         }
285 }
286
287 void
288 Editor::mapover_tracks (slot<void,RouteTimeAxisView&,uint32_t> sl)
289 {
290         set<RouteTimeAxisView*> relevant_tracks;
291
292         get_relevant_tracks (relevant_tracks);
293
294         uint32_t sz = relevant_tracks.size();
295
296         for (set<RouteTimeAxisView*>::iterator rti = relevant_tracks.begin(); rti != relevant_tracks.end(); ++rti) {
297                 sl (**rti, sz);
298         }
299 }
300
301 void
302 Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t ignored, RegionView* basis, vector<RegionView*>* all_equivs)
303 {
304         boost::shared_ptr<Playlist> pl;
305         vector<boost::shared_ptr<Region> > results;
306         RegionView* marv;
307         boost::shared_ptr<Diskstream> ds;
308
309         if ((ds = tv.get_diskstream()) == 0) {
310                 /* bus */
311                 return;
312         }
313
314         if (&tv == &basis->get_time_axis_view()) {
315                 /* looking in same track as the original */
316                 return;
317         }
318
319         if ((pl = ds->playlist()) != 0) {
320                 pl->get_equivalent_regions (basis->region(), results);
321         }
322
323         for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
324                 if ((marv = tv.view()->find_view (*ir)) != 0) {
325                         all_equivs->push_back (marv);
326                 }
327         }
328 }
329
330 void
331 Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivalent_regions)
332 {
333         mapover_tracks (bind (mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions));
334         
335         /* add clicked regionview since we skipped all other regions in the same track as the one it was in */
336         
337         equivalent_regions.push_back (basis);
338 }
339
340 bool
341 Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, bool no_track_remove)
342 {
343         vector<RegionView*> all_equivalent_regions;
344         bool commit = false;
345
346         if (!clicked_regionview || !clicked_routeview) {
347                 return false;
348         }
349
350         if (press) {
351                 button_release_can_deselect = false;
352         } 
353
354         if (op == Selection::Toggle || op == Selection::Set) {
355
356
357                 switch (op) {
358                 case Selection::Toggle:
359                         
360                         if (clicked_regionview->get_selected()) {
361                                 if (press) {
362
363                                         /* whatever was clicked was selected already; do nothing here but allow
364                                            the button release to deselect it
365                                         */
366
367                                         button_release_can_deselect = true;
368
369                                 } else {
370
371                                         if (button_release_can_deselect) {
372
373                                                 /* just remove this one region, but only on a permitted button release */
374
375                                                 selection->remove (clicked_regionview);
376                                                 commit = true;
377
378                                                 /* no more deselect action on button release till a new press
379                                                    finds an already selected object.
380                                                 */
381
382                                                 button_release_can_deselect = false;
383                                         }
384                                 } 
385
386                         } else {
387
388                                 if (press) {
389
390                                         if (selection->selected (clicked_routeview)) {
391                                                 get_equivalent_regions (clicked_regionview, all_equivalent_regions);
392                                         } else {
393                                                 all_equivalent_regions.push_back (clicked_regionview);
394                                         }
395
396                                         /* add all the equivalent regions, but only on button press */
397                                         
398
399
400                                         if (!all_equivalent_regions.empty()) {
401                                                 commit = true;
402                                         }
403
404                                         selection->add (all_equivalent_regions);
405                                 } 
406                         }
407                         break;
408                         
409                 case Selection::Set:
410                         if (!clicked_regionview->get_selected()) {
411
412                                 if (selection->selected (clicked_routeview)) {
413                                         get_equivalent_regions (clicked_regionview, all_equivalent_regions);
414                                 } else {
415                                         all_equivalent_regions.push_back (clicked_regionview);
416                                 }
417
418                                 selection->set (all_equivalent_regions);
419                                 commit = true;
420                         } else {
421                                 /* no commit necessary: clicked on an already selected region */
422                                 goto out;
423                         }
424                         break;
425
426                 default:
427                         /* silly compiler */
428                         break;
429                 }
430
431         } else if (op == Selection::Extend) {
432
433                 list<Selectable*> results;
434                 nframes_t last_frame;
435                 nframes_t first_frame;
436
437                 /* 1. find the last selected regionview in the track that was clicked in */
438
439                 last_frame = 0;
440                 first_frame = max_frames;
441
442                 for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) {
443                         if (&(*x)->get_time_axis_view() == &clicked_regionview->get_time_axis_view()) {
444
445                                 if ((*x)->region()->last_frame() > last_frame) {
446                                         last_frame = (*x)->region()->last_frame();
447                                 }
448
449                                 if ((*x)->region()->first_frame() < first_frame) {
450                                         first_frame = (*x)->region()->first_frame();
451                                 }
452                         }
453                 }
454
455                 /* 2. figure out the boundaries for our search for new objects */
456
457                 switch (clicked_regionview->region()->coverage (first_frame, last_frame)) {
458                 case OverlapNone:
459                         if (last_frame < clicked_regionview->region()->first_frame()) {
460                                 first_frame = last_frame;
461                                 last_frame = clicked_regionview->region()->last_frame();
462                         } else {
463                                 last_frame = first_frame;
464                                 first_frame = clicked_regionview->region()->first_frame();
465                         }
466                         break;
467
468                 case OverlapExternal:
469                         if (last_frame < clicked_regionview->region()->first_frame()) {
470                                 first_frame = last_frame;
471                                 last_frame = clicked_regionview->region()->last_frame();
472                         } else {
473                                 last_frame = first_frame;
474                                 first_frame = clicked_regionview->region()->first_frame();
475                         }
476                         break;
477
478                 case OverlapInternal:
479                         if (last_frame < clicked_regionview->region()->first_frame()) {
480                                 first_frame = last_frame;
481                                 last_frame = clicked_regionview->region()->last_frame();
482                         } else {
483                                 last_frame = first_frame;
484                                 first_frame = clicked_regionview->region()->first_frame();
485                         }
486                         break;
487
488                 case OverlapStart:
489                 case OverlapEnd:
490                         /* nothing to do except add clicked region to selection, since it
491                            overlaps with the existing selection in this track.
492                         */
493                         break;
494                 }
495
496                 /* 2. find all selectable objects (regionviews in this case) between that one and the end of the
497                       one that was clicked.
498                 */
499
500                 set<RouteTimeAxisView*> relevant_tracks;
501                 
502                 get_relevant_tracks (relevant_tracks);
503
504                 for (set<RouteTimeAxisView*>::iterator t = relevant_tracks.begin(); t != relevant_tracks.end(); ++t) {
505                         (*t)->get_selectables (first_frame, last_frame, -1.0, -1.0, results);
506                 }
507                 
508                 /* 3. convert to a vector of audio regions */
509
510                 vector<RegionView*> regions;
511                 
512                 for (list<Selectable*>::iterator x = results.begin(); x != results.end(); ++x) {
513                         RegionView* arv;
514
515                         if ((arv = dynamic_cast<RegionView*>(*x)) != 0) {
516                                 regions.push_back (arv);
517                         }
518                 }
519
520                 if (!regions.empty()) {
521                         selection->add (regions);
522                         commit = true;
523                 }
524         }
525
526   out:
527         return commit;
528 }
529
530 void
531 Editor::set_selected_regionview_from_region_list (boost::shared_ptr<Region> region, Selection::Operation op)
532 {
533         vector<RegionView*> all_equivalent_regions;
534
535         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
536                 
537                 RouteTimeAxisView* tatv;
538                 
539                 if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
540                         
541                         boost::shared_ptr<Playlist> pl;
542                         vector<boost::shared_ptr<Region> > results;
543                         RegionView* marv;
544                         boost::shared_ptr<Diskstream> ds;
545                         
546                         if ((ds = tatv->get_diskstream()) == 0) {
547                                 /* bus */
548                                 continue;
549                         }
550                         
551                         if ((pl = (ds->playlist())) != 0) {
552                                 pl->get_region_list_equivalent_regions (region, results);
553                         }
554                         
555                         for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
556                                 if ((marv = tatv->view()->find_view (*ir)) != 0) {
557                                         all_equivalent_regions.push_back (marv);
558                                 }
559                         }
560                         
561                 }
562         }
563         
564         begin_reversible_command (_("set selected regions"));
565         
566         switch (op) {
567         case Selection::Toggle:
568                 /* XXX this is not correct */
569                 selection->toggle (all_equivalent_regions);
570                 break;
571         case Selection::Set:
572                 selection->set (all_equivalent_regions);
573                 break;
574         case Selection::Extend:
575                 selection->add (all_equivalent_regions);
576                 break;
577         case Selection::Add:
578                 selection->add (all_equivalent_regions);
579                 break;
580         }
581
582         commit_reversible_command () ;
583 }
584
585 void
586 Editor::track_selection_changed ()
587 {
588         switch (selection->tracks.size()){
589         case 0:
590                 break;
591         default:
592                 set_selected_mixer_strip (*(selection->tracks.front()));
593                 break;
594         }
595
596         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
597                 (*i)->set_selected (false);
598                 if (mouse_mode == MouseRange) {
599                         (*i)->hide_selection ();
600                 }
601         }
602
603         for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
604                 (*i)->set_selected (true);
605                 if (mouse_mode == MouseRange) {
606                         (*i)->show_selection (selection->time);
607                 }
608         }
609 }
610
611 void
612 Editor::time_selection_changed ()
613 {
614         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
615                 (*i)->hide_selection ();
616         }
617
618         if (selection->tracks.empty()) {
619                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
620                         (*i)->show_selection (selection->time);
621                 }
622         } else {
623                 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
624                         (*i)->show_selection (selection->time);
625                 }
626         }
627
628         if (selection->time.empty()) {
629                 ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, false);
630         } else {
631                 ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, true);
632         }
633 }
634
635 void
636 Editor::region_selection_changed ()
637 {
638         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
639                 (*i)->set_selected_regionviews (selection->regions);
640         }
641 }
642
643 void
644 Editor::point_selection_changed ()
645 {
646         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
647                 (*i)->set_selected_points (selection->points);
648         }
649 }
650
651 /** Select everything in the selected tracks
652  * @param Selection operation to apply.
653  */
654 void
655 Editor::select_all_in_selected_tracks (Selection::Operation op)
656 {
657         list<Selectable *> touched;
658
659         for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
660                 (*i)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
661         }
662
663         switch (op) {
664         case Selection::Toggle:
665                 selection->add (touched);
666                 break;
667         case Selection::Set:
668                 selection->set (touched);
669                 break;
670         case Selection::Extend:
671                 /* meaningless, because we're selecting everything */
672                 break;
673         case Selection::Add:
674                 selection->add (touched);
675                 break;
676         }
677 }
678
679 void
680 Editor::select_all (Selection::Operation op)
681 {
682         list<Selectable *> touched;
683         
684         for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
685                 if ((*iter)->hidden()) {
686                         continue;
687                 }
688                 (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
689         }
690         begin_reversible_command (_("select all"));
691         switch (op) {
692         case Selection::Add:
693                 selection->add (touched);
694                 break;
695         case Selection::Toggle:
696                 selection->add (touched);
697                 break;
698         case Selection::Set:
699                 selection->set (touched);
700                 break;
701         case Selection::Extend:
702                 /* meaningless, because we're selecting everything */
703                 break;
704         }
705         commit_reversible_command ();
706 }
707
708 /** Invert the selection in the selected tracks */
709 void
710 Editor::invert_selection_in_selected_tracks ()
711 {
712         list<Selectable *> touched;
713
714         for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
715                 (*i)->get_inverted_selectables (*selection, touched);
716         }
717         
718         selection->set (touched);
719 }
720
721 void
722 Editor::invert_selection ()
723 {
724         list<Selectable *> touched;
725         
726         for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
727                 if ((*iter)->hidden()) {
728                         continue;
729                 }
730                 (*iter)->get_inverted_selectables (*selection, touched);
731         }
732
733         selection->set (touched);
734 }
735
736 bool
737 Editor::select_all_within (nframes_t start, nframes_t end, double top, double bot, const TrackViewList& tracklist, Selection::Operation op)
738 {
739         list<Selectable*> touched;
740         list<Selectable*>::size_type n = 0;
741         TrackViewList touched_tracks;
742
743         for (TrackViewList::const_iterator iter = tracklist.begin(); iter != tracklist.end(); ++iter) {
744                 if ((*iter)->hidden()) {
745                         continue;
746                 }
747
748                 n = touched.size();
749
750                 (*iter)->get_selectables (start, end, top, bot, touched);
751                 
752                 if (n != touched.size()) {
753                         touched_tracks.push_back (*iter);
754                 }
755         }
756
757         if (touched.empty()) {
758                 return false;
759         }
760
761         if (!touched_tracks.empty()) {
762
763                 switch (op) {
764                 case Selection::Add:
765                         selection->add (touched_tracks);
766                         break;
767                 case Selection::Toggle:
768                         selection->toggle (touched_tracks);
769                         break;
770                 case Selection::Set:
771                         selection->set (touched_tracks);
772                         break;
773                 case Selection::Extend:
774                         /* not defined yet */
775                         break;
776                 }
777         }
778
779         begin_reversible_command (_("select all within"));
780         switch (op) {
781         case Selection::Add:
782                 selection->add (touched);
783                 break;
784         case Selection::Toggle:
785                 selection->toggle (touched);
786                 break;
787         case Selection::Set:
788                 selection->set (touched);
789                 break;
790         case Selection::Extend:
791                 /* not defined yet */
792                 break;
793         }
794         
795         commit_reversible_command ();
796
797         return !touched.empty();
798 }
799
800 void
801 Editor::set_selection_from_audio_region ()
802 {
803         if (selection->regions.empty()) {
804                 return;
805         }
806
807         RegionView* rv = *(selection->regions.begin());
808         boost::shared_ptr<Region> region = rv->region();
809         
810         begin_reversible_command (_("set selection from region"));
811         selection->set (0, region->position(), region->last_frame());
812         commit_reversible_command ();
813
814         set_mouse_mode (Editing::MouseRange, false);
815 }
816
817 void
818 Editor::set_selection_from_punch()
819 {
820         Location* location;
821
822         if ((location = session->locations()->auto_punch_location()) == 0)  {
823                 return;
824         }
825
826         set_selection_from_range (*location);
827 }
828
829 void
830 Editor::set_selection_from_loop()
831 {
832         Location* location;
833
834         if ((location = session->locations()->auto_loop_location()) == 0)  {
835                 return;
836         }
837         set_selection_from_range (*location);
838 }
839
840 void
841 Editor::set_selection_from_range (Location& loc)
842 {
843         begin_reversible_command (_("set selection from range"));
844         selection->set (0, loc.start(), loc.end());
845         commit_reversible_command ();
846
847         set_mouse_mode (Editing::MouseRange, false);
848 }
849
850 void
851 Editor::select_all_selectables_using_time_selection ()
852 {
853         list<Selectable *> touched;
854
855         if (selection->time.empty()) {
856                 return;
857         }
858
859         nframes_t start = selection->time[clicked_selection].start;
860         nframes_t end = selection->time[clicked_selection].end;
861
862         if (end - start < 1)  {
863                 return;
864         }
865
866         for (TrackViewList::iterator iter = selection->tracks.begin(); iter != selection->tracks.end(); ++iter) {
867                 if ((*iter)->hidden()) {
868                         continue;
869                 }
870                 (*iter)->get_selectables (start, end - 1, 0, DBL_MAX, touched);
871         }
872
873         begin_reversible_command (_("select all from range"));
874         selection->set (touched);
875         commit_reversible_command ();
876 }
877
878
879 void
880 Editor::select_all_selectables_using_punch()
881 {
882         Location* location = session->locations()->auto_punch_location();
883         list<Selectable *> touched;
884
885         if (location == 0 || (location->end() - location->start() <= 1))  {
886                 return;
887         }
888
889         for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
890                 if ((*iter)->hidden()) {
891                         continue;
892                 }
893                 (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched);
894         }
895         begin_reversible_command (_("select all from punch"));
896         selection->set (touched);
897         commit_reversible_command ();
898
899 }
900
901 void
902 Editor::select_all_selectables_using_loop()
903 {
904         Location* location = session->locations()->auto_loop_location();
905         list<Selectable *> touched;
906
907         if (location == 0 || (location->end() - location->start() <= 1))  {
908                 return;
909         }
910
911         for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
912                 if ((*iter)->hidden()) {
913                         continue;
914                 }
915                 (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched);
916         }
917         begin_reversible_command (_("select all from loop"));
918         selection->set (touched);
919         commit_reversible_command ();
920
921 }
922
923 void
924 Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
925 {
926         nframes_t start;
927         nframes_t end;
928         list<Selectable *> touched;
929
930         if (after) {
931                 begin_reversible_command (_("select all after cursor"));
932                 start = cursor->current_frame ;
933                 end = session->current_end_frame();
934         } else {
935                 if (cursor->current_frame > 0) {
936                         begin_reversible_command (_("select all before cursor"));
937                         start = 0;
938                         end = cursor->current_frame - 1;
939                 } else {
940                         return;
941                 }
942         }
943
944         for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
945                 if ((*iter)->hidden()) {
946                         continue;
947                 }
948                 (*iter)->get_selectables (start, end, 0, DBL_MAX, touched);
949         }
950         selection->set (touched);
951         commit_reversible_command ();
952 }
953
954 void
955 Editor::select_all_selectables_between_cursors (Cursor *cursor, Cursor *other_cursor)
956 {
957         nframes_t start;
958         nframes_t end;
959         list<Selectable *> touched;
960         bool  other_cursor_is_first = cursor->current_frame > other_cursor->current_frame;
961
962         if (cursor->current_frame == other_cursor->current_frame) {
963                 return;
964         }
965
966         begin_reversible_command (_("select all between cursors"));
967         if (other_cursor_is_first) {
968                 start = other_cursor->current_frame;
969                 end = cursor->current_frame - 1;
970                 
971         } else {
972                 start = cursor->current_frame;
973                 end = other_cursor->current_frame - 1;
974         }
975         
976         for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
977                 if ((*iter)->hidden()) {
978                         continue;
979                 }
980                 (*iter)->get_selectables (start, end, 0, DBL_MAX, touched);
981         }
982         selection->set (touched);
983         commit_reversible_command ();
984 }
985