2 Copyright (C) 2000-2004 Paul Davis
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.
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.
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.
30 #include <pbd/error.h>
31 #include <pbd/basename.h>
32 #include <pbd/pthread_utils.h>
34 #include <gtkmm2ext/utils.h>
35 #include <gtkmm2ext/choice.h>
37 #include <ardour/audioengine.h>
38 #include <ardour/session.h>
39 #include <ardour/audioplaylist.h>
40 #include <ardour/audioregion.h>
41 #include <ardour/diskstream.h>
42 #include <ardour/filesource.h>
43 #include <ardour/sndfilesource.h>
44 #include <ardour/utils.h>
45 #include <ardour/location.h>
46 #include <ardour/named_selection.h>
47 #include <ardour/audio_track.h>
48 #include <ardour/audioplaylist.h>
49 #include <ardour/region_factory.h>
50 #include <ardour/reverse.h>
52 #include "ardour_ui.h"
54 #include "time_axis_view.h"
55 #include "audio_time_axis.h"
56 #include "automation_time_axis.h"
57 #include "streamview.h"
58 #include "regionview.h"
59 #include "rgb_macros.h"
60 #include "selection_templates.h"
61 #include "selection.h"
64 #include "gtk-custom-hruler.h"
69 using namespace ARDOUR;
72 using namespace Editing;
74 /***********************************************************************
76 ***********************************************************************/
79 Editor::undo (uint32_t n)
87 Editor::redo (uint32_t n)
95 Editor::ensure_cursor (jack_nframes_t *pos)
97 *pos = edit_cursor->current_frame;
102 Editor::split_region ()
104 split_region_at (edit_cursor->current_frame);
108 Editor::split_region_at (jack_nframes_t where)
110 split_regions_at (where, selection->audio_regions);
114 Editor::split_regions_at (jack_nframes_t where, AudioRegionSelection& regions)
116 begin_reversible_command (_("split"));
119 for (AudioRegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
121 AudioRegionSelection::iterator tmp;
126 Playlist* pl = (*a)->region.playlist();
128 _new_regionviews_show_envelope = (*a)->envelope_visible();
131 session->add_undo (pl->get_memento());
132 pl->split_region ((*a)->region, where);
133 session->add_redo_no_execute (pl->get_memento());
139 commit_reversible_command ();
140 _new_regionviews_show_envelope = false;
144 Editor::remove_clicked_region ()
146 if (clicked_audio_trackview == 0 || clicked_regionview == 0) {
150 Playlist* playlist = clicked_audio_trackview->playlist();
152 begin_reversible_command (_("remove region"));
153 session->add_undo (playlist->get_memento());
154 playlist->remove_region (&clicked_regionview->region);
155 session->add_redo_no_execute (playlist->get_memento());
156 commit_reversible_command ();
160 Editor::destroy_clicked_region ()
162 int32_t selected = selection->audio_regions.size();
164 if (!session || clicked_regionview == 0 && selected == 0) {
168 vector<string> choices;
171 prompt = string_compose (_(" This is destructive, will possibly delete audio files\n\
172 It cannot be undone\n\
173 Do you really want to destroy %1 ?"),
175 _("these regions") : _("this region")));
178 choices.push_back (_("Yes, destroy them."));
180 choices.push_back (_("Yes, destroy it."));
183 choices.push_back (_("No, do nothing."));
185 Gtkmm2ext::Choice prompter (prompt, choices);
187 prompter.chosen.connect (Gtk::Main::quit.slot());
188 prompter.show_all ();
192 if (prompter.get_choice() != 0) {
199 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
200 r.push_back (&(*i)->region);
203 session->destroy_regions (r);
205 } else if (clicked_regionview) {
206 session->destroy_region (&clicked_regionview->region);
211 Editor::select_region_for_operation (int dir, TimeAxisView **tv)
215 jack_nframes_t start = 0;
217 if (selection->time.start () == selection->time.end_frame ()) {
219 /* no current selection-> is there a selected regionview? */
221 if (selection->audio_regions.empty()) {
229 if (!selection->audio_regions.empty()) {
231 rv = *(selection->audio_regions.begin());
232 (*tv) = &rv->get_time_axis_view();
233 region = &rv->region;
235 } else if (!selection->tracks.empty()) {
237 (*tv) = selection->tracks.front();
239 AudioTimeAxisView* atv;
241 if ((atv = dynamic_cast<AudioTimeAxisView*> (*tv)) != 0) {
244 if ((pl = atv->playlist()) == 0) {
248 region = dynamic_cast<AudioRegion*> (pl->top_region_at (start));
256 Editor::extend_selection_to_end_of_region (bool next)
260 jack_nframes_t start;
262 if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) {
266 if (region && selection->time.start () == selection->time.end_frame ()) {
267 start = region->position();
269 start = selection->time.start ();
272 /* Try to leave the selection with the same route if possible */
274 if ((tv = selection->time.track) == 0) {
278 begin_reversible_command (_("extend selection"));
279 selection->set (tv, start, region->position() + region->length());
280 commit_reversible_command ();
284 Editor::extend_selection_to_start_of_region (bool previous)
290 if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) {
294 if (region && selection->time.start () == selection->time.end_frame ()) {
295 end = region->position() + region->length();
297 end = selection->time.end_frame ();
300 /* Try to leave the selection with the same route if possible */
302 if ((tv = selection->time.track) == 0) {
306 begin_reversible_command (_("extend selection"));
307 selection->set (tv, region->position(), end);
308 commit_reversible_command ();
313 Editor::nudge_forward (bool next)
315 jack_nframes_t distance;
316 jack_nframes_t next_distance;
318 if (!session) return;
320 if (!selection->audio_regions.empty()) {
322 begin_reversible_command (_("nudge forward"));
324 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
325 AudioRegion& r ((*i)->region);
327 distance = get_nudge_distance (r.position(), next_distance);
330 distance = next_distance;
333 session->add_undo (r.playlist()->get_memento());
334 r.set_position (r.position() + distance, this);
335 session->add_redo_no_execute (r.playlist()->get_memento());
338 commit_reversible_command ();
341 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
342 session->request_locate (playhead_cursor->current_frame + distance);
347 Editor::nudge_backward (bool next)
349 jack_nframes_t distance;
350 jack_nframes_t next_distance;
352 if (!session) return;
354 if (!selection->audio_regions.empty()) {
356 begin_reversible_command (_("nudge forward"));
358 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
359 AudioRegion& r ((*i)->region);
361 distance = get_nudge_distance (r.position(), next_distance);
364 distance = next_distance;
367 session->add_undo (r.playlist()->get_memento());
369 if (r.position() > distance) {
370 r.set_position (r.position() - distance, this);
372 r.set_position (0, this);
374 session->add_redo_no_execute (r.playlist()->get_memento());
377 commit_reversible_command ();
381 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
383 if (playhead_cursor->current_frame > distance) {
384 session->request_locate (playhead_cursor->current_frame - distance);
386 session->request_locate (0);
392 Editor::nudge_forward_capture_offset ()
394 jack_nframes_t distance;
396 if (!session) return;
398 if (!selection->audio_regions.empty()) {
400 begin_reversible_command (_("nudge forward"));
402 distance = session->worst_output_latency();
404 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
405 AudioRegion& r ((*i)->region);
407 session->add_undo (r.playlist()->get_memento());
408 r.set_position (r.position() + distance, this);
409 session->add_redo_no_execute (r.playlist()->get_memento());
412 commit_reversible_command ();
418 Editor::nudge_backward_capture_offset ()
420 jack_nframes_t distance;
422 if (!session) return;
424 if (!selection->audio_regions.empty()) {
426 begin_reversible_command (_("nudge forward"));
428 distance = session->worst_output_latency();
430 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
431 AudioRegion& r ((*i)->region);
433 session->add_undo (r.playlist()->get_memento());
435 if (r.position() > distance) {
436 r.set_position (r.position() - distance, this);
438 r.set_position (0, this);
440 session->add_redo_no_execute (r.playlist()->get_memento());
443 commit_reversible_command ();
450 Editor::move_to_start ()
452 session->request_locate (0);
456 Editor::move_to_end ()
459 session->request_locate (session->current_end_frame());
463 Editor::build_region_boundary_cache ()
465 jack_nframes_t pos = 0;
468 TrackViewList tracks;
470 region_boundary_cache.clear ();
477 case SnapToRegionStart:
480 case SnapToRegionEnd:
483 case SnapToRegionSync:
486 case SnapToRegionBoundary:
490 fatal << string_compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type) << endmsg;
495 TimeAxisView *ontrack = 0;
497 while (pos < session->current_end_frame()) {
499 if (!selection->tracks.empty()) {
501 if ((r = find_next_region (pos, point, 1, selection->tracks, &ontrack)) == 0) {
505 } else if (clicked_trackview) {
508 t.push_back (clicked_trackview);
510 if ((r = find_next_region (pos, point, 1, t, &ontrack)) == 0) {
516 if ((r = find_next_region (pos, point, 1, track_views, &ontrack)) == 0) {
524 case SnapToRegionStart:
525 rpos = r->first_frame();
527 case SnapToRegionEnd:
528 rpos = r->last_frame();
530 case SnapToRegionSync:
531 rpos = r->adjust_to_sync (r->first_frame());
534 case SnapToRegionBoundary:
535 rpos = r->last_frame();
542 AudioTimeAxisView *atav;
544 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
545 if (atav->get_diskstream() != 0) {
546 speed = atav->get_diskstream()->speed();
550 rpos = (jack_nframes_t) floor ( (float) rpos / speed );
552 if (region_boundary_cache.empty() || rpos != region_boundary_cache.back()) {
553 if (snap_type == SnapToRegionBoundary) {
554 region_boundary_cache.push_back (r->first_frame());
556 region_boundary_cache.push_back (rpos);
564 Editor::find_next_region (jack_nframes_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack)
566 TrackViewList::iterator i;
567 jack_nframes_t closest = max_frames;
569 jack_nframes_t rpos = 0;
572 jack_nframes_t track_frame;
573 AudioTimeAxisView *atav;
575 for (i = tracks.begin(); i != tracks.end(); ++i) {
577 jack_nframes_t distance;
581 if ( (atav = dynamic_cast<AudioTimeAxisView*>(*i)) != 0 ) {
582 if (atav->get_diskstream()!=0)
583 track_speed = atav->get_diskstream()->speed();
586 track_frame = (jack_nframes_t) floor ( (float) frame * track_speed );
588 if ((r = (*i)->find_next_region (track_frame, point, dir)) == 0) {
594 rpos = r->first_frame ();
598 rpos = r->last_frame ();
602 rpos = r->adjust_to_sync (r->first_frame());
605 // rpos is a "track frame", converting it to "time frame"
606 rpos = (jack_nframes_t) floor ( (float) rpos / track_speed );
609 distance = rpos - frame;
611 distance = frame - rpos;
614 if (distance < closest) {
626 Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir)
629 jack_nframes_t pos = cursor->current_frame;
635 TimeAxisView *ontrack = 0;
637 // so we don't find the current region again..
641 if (!selection->tracks.empty()) {
643 r = find_next_region (pos, point, dir, selection->tracks, &ontrack);
645 } else if (clicked_trackview) {
648 t.push_back (clicked_trackview);
650 r = find_next_region (pos, point, dir, t, &ontrack);
654 r = find_next_region (pos, point, dir, track_views, &ontrack);
663 pos = r->first_frame ();
667 pos = r->last_frame ();
671 pos = r->adjust_to_sync (r->first_frame());
676 AudioTimeAxisView *atav;
678 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
679 if (atav->get_diskstream() != 0) {
680 speed = atav->get_diskstream()->speed();
684 pos = (jack_nframes_t) floor ( (float) pos / speed );
687 if (cursor == playhead_cursor) {
688 session->request_locate (pos);
690 cursor->set_position (pos);
695 Editor::cursor_to_next_region_point (Cursor* cursor, RegionPoint point)
697 cursor_to_region_point (cursor, point, 1);
701 Editor::cursor_to_previous_region_point (Cursor* cursor, RegionPoint point)
703 cursor_to_region_point (cursor, point, -1);
707 Editor::cursor_to_selection_start (Cursor *cursor)
709 jack_nframes_t pos = 0;
710 switch (mouse_mode) {
712 if (!selection->audio_regions.empty()) {
713 pos = selection->audio_regions.start();
718 if (!selection->time.empty()) {
719 pos = selection->time.start ();
727 if (cursor == playhead_cursor) {
728 session->request_locate (pos);
730 cursor->set_position (pos);
735 Editor::cursor_to_selection_end (Cursor *cursor)
737 jack_nframes_t pos = 0;
739 switch (mouse_mode) {
741 if (!selection->audio_regions.empty()) {
742 pos = selection->audio_regions.end_frame();
747 if (!selection->time.empty()) {
748 pos = selection->time.end_frame ();
756 if (cursor == playhead_cursor) {
757 session->request_locate (pos);
759 cursor->set_position (pos);
764 Editor::playhead_backward ()
771 if (get_prefix (prefix, was_floating)) {
775 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
777 cnt = (jack_nframes_t) prefix;
781 pos = playhead_cursor->current_frame;
783 if ((jack_nframes_t) pos < cnt) {
789 /* XXX this is completely insane. with the current buffering
790 design, we'll force a complete track buffer flush and
791 reload, just to move 1 sample !!!
794 session->request_locate (pos);
798 Editor::playhead_forward ()
805 if (get_prefix (prefix, was_floating)) {
809 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
811 cnt = (jack_nframes_t) floor (prefix);
815 pos = playhead_cursor->current_frame;
817 /* XXX this is completely insane. with the current buffering
818 design, we'll force a complete track buffer flush and
819 reload, just to move 1 sample !!!
822 session->request_locate (pos+cnt);
826 Editor::cursor_align (bool playhead_to_edit)
828 if (playhead_to_edit) {
830 session->request_locate (edit_cursor->current_frame);
833 edit_cursor->set_position (playhead_cursor->current_frame);
838 Editor::edit_cursor_backward ()
845 if (get_prefix (prefix, was_floating)) {
849 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
851 cnt = (jack_nframes_t) prefix;
855 pos = edit_cursor->current_frame;
857 if ((jack_nframes_t) pos < cnt) {
863 edit_cursor->set_position (pos);
867 Editor::edit_cursor_forward ()
874 if (get_prefix (prefix, was_floating)) {
878 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
880 cnt = (jack_nframes_t) floor (prefix);
884 pos = edit_cursor->current_frame;
885 edit_cursor->set_position (pos+cnt);
889 Editor::goto_frame ()
893 jack_nframes_t frame;
895 if (get_prefix (prefix, was_floating)) {
900 frame = (jack_nframes_t) floor (prefix * session->frame_rate());
902 frame = (jack_nframes_t) floor (prefix);
905 session->request_locate (frame);
909 Editor::scroll_backward (float pages)
911 jack_nframes_t frame;
912 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
917 if (get_prefix (prefix, was_floating)) {
918 cnt = (jack_nframes_t) floor (pages * one_page);
921 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
923 cnt = (jack_nframes_t) floor (prefix * one_page);
927 if (leftmost_frame < cnt) {
930 frame = leftmost_frame - cnt;
933 reposition_x_origin (frame);
937 Editor::scroll_forward (float pages)
939 jack_nframes_t frame;
940 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
945 if (get_prefix (prefix, was_floating)) {
946 cnt = (jack_nframes_t) floor (pages * one_page);
949 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
951 cnt = (jack_nframes_t) floor (prefix * one_page);
955 if (ULONG_MAX - cnt < leftmost_frame) {
956 frame = ULONG_MAX - cnt;
958 frame = leftmost_frame + cnt;
961 reposition_x_origin (frame);
965 Editor::scroll_tracks_down ()
971 if (get_prefix (prefix, was_floating)) {
974 cnt = (int) floor (prefix);
977 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
978 adj->set_value (adj->get_value() + (cnt * adj->get_page_size()));
982 Editor::scroll_tracks_up ()
988 if (get_prefix (prefix, was_floating)) {
991 cnt = (int) floor (prefix);
994 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
995 adj->set_value (adj->get_value() - (cnt * adj->get_page_size()));
999 Editor::scroll_tracks_down_line ()
1001 edit_vscrollbar.default_vmotion (0, 10);
1005 Editor::scroll_tracks_up_line ()
1007 edit_vscrollbar.default_vmotion (0, -10);
1013 Editor::temporal_zoom_step (bool coarser)
1017 nfpu = frames_per_unit;
1022 nfpu = max(1.0,(nfpu/2.0));
1025 temporal_zoom (nfpu);
1029 Editor::temporal_zoom (gdouble fpu)
1031 if (!session) return;
1033 jack_nframes_t current_page = current_page_frames();
1034 jack_nframes_t current_leftmost = leftmost_frame;
1035 jack_nframes_t current_rightmost;
1036 jack_nframes_t current_center;
1037 jack_nframes_t new_page;
1038 jack_nframes_t leftmost_after_zoom = 0;
1043 new_page = (jack_nframes_t) floor (canvas_width * nfpu);
1045 switch (zoom_focus) {
1047 leftmost_after_zoom = current_leftmost;
1050 case ZoomFocusRight:
1051 current_rightmost = leftmost_frame + current_page;
1052 if (current_rightmost > new_page) {
1053 leftmost_after_zoom = current_rightmost - new_page;
1055 leftmost_after_zoom = 0;
1059 case ZoomFocusCenter:
1060 current_center = current_leftmost + (current_page/2);
1061 if (current_center > (new_page/2)) {
1062 leftmost_after_zoom = current_center - (new_page / 2);
1064 leftmost_after_zoom = 0;
1068 case ZoomFocusPlayhead:
1069 /* try to keep the playhead in the center */
1070 if (playhead_cursor->current_frame > new_page/2) {
1071 leftmost_after_zoom = playhead_cursor->current_frame - (new_page/2);
1073 leftmost_after_zoom = 0;
1078 /* try to keep the edit cursor in the center */
1079 if (edit_cursor->current_frame > leftmost_frame + (new_page/2)) {
1080 leftmost_after_zoom = edit_cursor->current_frame - (new_page/2);
1082 leftmost_after_zoom = 0;
1088 // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
1090 // begin_reversible_command (_("zoom"));
1091 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
1092 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
1093 // commit_reversible_command ();
1095 reposition_and_zoom (leftmost_after_zoom, nfpu);
1099 Editor::temporal_zoom_selection ()
1101 if (!selection) return;
1103 if (selection->time.empty()) {
1107 jack_nframes_t start = selection->time[clicked_selection].start;
1108 jack_nframes_t end = selection->time[clicked_selection].end;
1110 temporal_zoom_by_frame (start, end, "zoom to selection");
1114 Editor::temporal_zoom_session ()
1117 temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
1122 Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, string op)
1124 if (!session) return;
1126 if ((start == 0 && end == 0) || end < start) {
1130 jack_nframes_t range = end - start;
1132 double new_fpu = (double)range / (double)canvas_width;
1135 // while (p2 < new_fpu) {
1140 jack_nframes_t new_page = (jack_nframes_t) floor (canvas_width * new_fpu);
1141 jack_nframes_t middle = (jack_nframes_t) floor( (double)start + ((double)range / 2.0f ));
1142 jack_nframes_t new_leftmost = (jack_nframes_t) floor( (double)middle - ((double)new_page/2.0f));
1144 if (new_leftmost > middle) new_leftmost = 0;
1146 // begin_reversible_command (op);
1147 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1148 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1149 // commit_reversible_command ();
1151 reposition_and_zoom (new_leftmost, new_fpu);
1155 Editor::temporal_zoom_to_frame (bool coarser, jack_nframes_t frame)
1157 if (!session) return;
1159 jack_nframes_t range_before = frame - leftmost_frame;
1162 new_fpu = frames_per_unit;
1168 new_fpu = max(1.0,(new_fpu/2.0));
1172 if (new_fpu == frames_per_unit) return;
1174 jack_nframes_t new_leftmost = frame - range_before;
1176 if (new_leftmost > frame) new_leftmost = 0;
1178 // begin_reversible_command (_("zoom to frame"));
1179 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1180 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1181 // commit_reversible_command ();
1183 reposition_and_zoom (new_leftmost, new_fpu);
1187 Editor::select_all_in_track (bool add)
1189 list<Selectable *> touched;
1191 if (!clicked_trackview) {
1195 clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1198 selection->add (touched);
1200 selection->set (touched);
1205 Editor::select_all (bool add)
1207 list<Selectable *> touched;
1209 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1210 if ((*iter)->hidden()) {
1213 (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1217 selection->add (touched);
1219 selection->set (touched);
1225 Editor::invert_selection_in_track ()
1227 list<Selectable *> touched;
1229 if (!clicked_trackview) {
1233 clicked_trackview->get_inverted_selectables (*selection, touched);
1234 selection->set (touched);
1238 Editor::invert_selection ()
1240 list<Selectable *> touched;
1242 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1243 if ((*iter)->hidden()) {
1246 (*iter)->get_inverted_selectables (*selection, touched);
1249 selection->set (touched);
1253 Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
1255 list<Selectable *> touched;
1257 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1258 if ((*iter)->hidden()) {
1261 (*iter)->get_selectables (start, end, top, bot, touched);
1265 selection->add (touched);
1267 selection->set (touched);
1270 return !touched.empty();
1274 Editor::set_selection_from_punch()
1278 if ((location = session->locations()->auto_punch_location()) == 0) {
1282 set_selection_from_range (*location);
1286 Editor::set_selection_from_loop()
1290 if ((location = session->locations()->auto_loop_location()) == 0) {
1294 set_selection_from_range (*location);
1298 Editor::set_selection_from_range (Location& range)
1300 if (clicked_trackview == 0) {
1304 begin_reversible_command (_("set selection from range"));
1305 selection->set (0, range.start(), range.end());
1306 commit_reversible_command ();
1310 Editor::amplitude_zoom_step (bool in)
1324 #ifdef FIX_FOR_CANVAS
1325 /* XXX DO SOMETHING */
1334 Editor::delete_sample_forward ()
1339 Editor::delete_sample_backward ()
1344 Editor::delete_screen ()
1351 Editor::search_backwards ()
1357 Editor::search_forwards ()
1365 Editor::jump_forward_to_mark ()
1371 Location *location = session->locations()->first_location_after (playhead_cursor->current_frame);
1374 session->request_locate (location->start(), session->transport_rolling());
1376 session->request_locate (session->current_end_frame());
1381 Editor::jump_backward_to_mark ()
1387 Location *location = session->locations()->first_location_before (playhead_cursor->current_frame);
1390 session->request_locate (location->start(), session->transport_rolling());
1392 session->request_locate (0);
1403 if (get_prefix (prefix, was_floating)) {
1404 pos = session->audible_frame ();
1407 pos = (jack_nframes_t) floor (prefix * session->frame_rate ());
1409 pos = (jack_nframes_t) floor (prefix);
1413 session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true);
1417 Editor::clear_markers ()
1420 session->begin_reversible_command (_("clear markers"));
1421 session->add_undo (session->locations()->get_memento());
1422 session->locations()->clear_markers ();
1423 session->add_redo_no_execute (session->locations()->get_memento());
1424 session->commit_reversible_command ();
1429 Editor::clear_ranges ()
1432 session->begin_reversible_command (_("clear ranges"));
1433 session->add_undo (session->locations()->get_memento());
1435 Location * looploc = session->locations()->auto_loop_location();
1436 Location * punchloc = session->locations()->auto_punch_location();
1438 session->locations()->clear_ranges ();
1440 if (looploc) session->locations()->add (looploc);
1441 if (punchloc) session->locations()->add (punchloc);
1443 session->add_redo_no_execute (session->locations()->get_memento());
1444 session->commit_reversible_command ();
1449 Editor::clear_locations ()
1451 session->begin_reversible_command (_("clear locations"));
1452 session->add_undo (session->locations()->get_memento());
1453 session->locations()->clear ();
1454 session->add_redo_no_execute (session->locations()->get_memento());
1455 session->commit_reversible_command ();
1456 session->locations()->clear ();
1459 /* INSERT/REPLACE */
1462 Editor::insert_region_list_drag (AudioRegion& region)
1468 jack_nframes_t where;
1469 AudioTimeAxisView *atv = 0;
1472 track_canvas.get_pointer (x, y);
1474 gnome_canvas_window_to_world (GNOME_CANVAS(track_canvas), x, y, &wx, &wy);
1477 event.type = GDK_BUTTON_RELEASE;
1478 event.button.x = wx;
1479 event.button.y = wy;
1481 where = event_frame (&event, &cx, &cy);
1483 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1484 /* clearly outside canvas area */
1488 if ((tv = trackview_by_y_position (cy)) == 0) {
1492 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) == 0) {
1496 if ((playlist = atv->playlist()) == 0) {
1502 begin_reversible_command (_("insert dragged region"));
1503 session->add_undo (playlist->get_memento());
1504 playlist->add_region (*(new AudioRegion (region)), where, 1.0);
1505 session->add_redo_no_execute (playlist->get_memento());
1506 commit_reversible_command ();
1510 Editor::insert_region_list_selection (float times)
1512 AudioTimeAxisView *tv = 0;
1515 if (clicked_audio_trackview != 0) {
1516 tv = clicked_audio_trackview;
1517 } else if (!selection->tracks.empty()) {
1518 if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
1525 if ((playlist = tv->playlist()) == 0) {
1529 Gtk::CTree_Helpers::SelectionList& selected = region_list_display.selection();
1531 if (selected.empty()) {
1535 Region* region = reinterpret_cast<Region *> (selected.front().get_data ());
1537 begin_reversible_command (_("insert region"));
1538 session->add_undo (playlist->get_memento());
1539 playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times);
1540 session->add_redo_no_execute (playlist->get_memento());
1541 commit_reversible_command ();
1545 /* BUILT-IN EFFECTS */
1548 Editor::reverse_selection ()
1553 /* GAIN ENVELOPE EDITING */
1556 Editor::edit_envelope ()
1563 Editor::toggle_playback (bool with_abort)
1569 switch (session->slave_source()) {
1574 /* transport controlled by the master */
1578 if (session->is_auditioning()) {
1579 session->cancel_audition ();
1583 if (session->transport_rolling()) {
1584 session->request_stop (with_abort);
1585 if (session->get_auto_loop()) {
1586 session->request_auto_loop (false);
1589 session->request_transport_speed (1.0f);
1594 Editor::play_from_start ()
1596 session->request_locate (0, true);
1600 Editor::play_selection ()
1602 if (selection->time.empty()) {
1606 session->request_play_range (true);
1610 Editor::play_selected_region ()
1612 if (!selection->audio_regions.empty()) {
1613 AudioRegionView *rv = *(selection->audio_regions.begin());
1615 session->request_bounded_roll (rv->region.position(), rv->region.last_frame());
1620 Editor::toggle_loop_playback ()
1623 session->request_auto_loop (true);
1628 Editor::loop_selected_region ()
1630 if (!selection->audio_regions.empty()) {
1631 AudioRegionView *rv = *(selection->audio_regions.begin());
1634 if ((tll = transport_loop_location()) != 0) {
1636 tll->set (rv->region.position(), rv->region.last_frame());
1638 // enable looping, reposition and start rolling
1640 session->request_auto_loop (true);
1641 session->request_locate (tll->start(), false);
1642 session->request_transport_speed (1.0f);
1648 Editor::play_location (Location& location)
1650 if (location.start() <= location.end()) {
1654 session->request_bounded_roll (location.start(), location.end());
1658 Editor::loop_location (Location& location)
1660 if (location.start() <= location.end()) {
1666 if ((tll = transport_loop_location()) != 0) {
1667 tll->set (location.start(), location.end());
1669 // enable looping, reposition and start rolling
1670 session->request_auto_loop (true);
1671 session->request_locate (tll->start(), true);
1676 Editor::toggle_region_mute ()
1678 if (clicked_regionview) {
1679 clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
1680 } else if (!selection->audio_regions.empty()) {
1681 bool yn = ! (*selection->audio_regions.begin())->region.muted();
1682 selection->foreach_audio_region (&AudioRegion::set_muted, yn);
1687 Editor::toggle_region_opaque ()
1689 if (clicked_regionview) {
1690 clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
1691 } else if (!selection->audio_regions.empty()) {
1692 bool yn = ! (*selection->audio_regions.begin())->region.opaque();
1693 selection->foreach_audio_region (&Region::set_opaque, yn);
1698 Editor::raise_region ()
1700 selection->foreach_audio_region (&Region::raise);
1704 Editor::raise_region_to_top ()
1706 selection->foreach_audio_region (&Region::raise_to_top);
1710 Editor::lower_region ()
1712 selection->foreach_audio_region (&Region::lower);
1716 Editor::lower_region_to_bottom ()
1718 selection->foreach_audio_region (&Region::lower_to_bottom);
1722 Editor::edit_region ()
1724 if (clicked_regionview == 0) {
1728 clicked_regionview->show_region_editor ();
1732 Editor::rename_region ()
1736 Button ok_button (_("OK"));
1737 Button cancel_button (_("Cancel"));
1739 if (selection->audio_regions.empty()) {
1743 dialog.set_title (_("ardour: rename region"));
1744 dialog.set_name ("RegionRenameWindow");
1745 dialog.set_size_request (300, -1);
1746 dialog.set_position (Gtk::WIN_POS_MOUSE);
1747 dialog.set_modal (true);
1749 dialog.get_vbox()->set_border_width (10);
1750 dialog.get_vbox()->pack_start (entry);
1751 dialog.get_action_area()->pack_start (ok_button);
1752 dialog.get_action_area()->pack_start (cancel_button);
1754 entry.set_name ("RegionNameDisplay");
1755 ok_button.set_name ("EditorGTKButton");
1756 cancel_button.set_name ("EditorGTKButton");
1758 region_renamed = false;
1760 entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1761 ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1762 cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
1767 ARDOUR_UI::instance()->allow_focus (true);
1769 ARDOUR_UI::instance()->allow_focus (false);
1771 if (region_renamed) {
1772 (*selection->audio_regions.begin())->region.set_name (entry.get_text());
1773 redisplay_regions ();
1778 Editor::rename_region_finished (bool status)
1781 region_renamed = status;
1786 Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
1788 if (session->is_auditioning()) {
1789 session->cancel_audition ();
1792 // note: some potential for creativity here, because region doesn't
1793 // have to belong to the playlist that Route is handling
1795 // bool was_soloed = route.soloed();
1797 route.set_solo (true, this);
1799 session->request_bounded_roll (region.position(), region.position() + region.length());
1801 /* XXX how to unset the solo state ? */
1805 Editor::audition_selected_region ()
1807 if (!selection->audio_regions.empty()) {
1808 AudioRegionView* rv = *(selection->audio_regions.begin());
1809 session->audition_region (rv->region);
1814 Editor::audition_playlist_region_standalone (AudioRegion& region)
1816 session->audition_region (region);
1820 Editor::build_interthread_progress_window ()
1822 interthread_progress_window = new ArdourDialog (X_("interthread progress"));
1824 interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
1826 interthread_progress_vbox.set_border_width (10);
1827 interthread_progress_vbox.set_spacing (5);
1828 interthread_progress_vbox.pack_start (interthread_progress_label, false, false);
1829 interthread_progress_vbox.pack_start (interthread_progress_bar,false, false);
1830 interthread_progress_vbox.pack_start (interthread_cancel_button,false, false);
1832 interthread_cancel_button.add (interthread_cancel_label);
1834 interthread_cancel_button.signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
1836 interthread_progress_window->set_modal (true);
1837 interthread_progress_window->set_default_size (200, 100);
1838 interthread_progress_window->add (interthread_progress_vbox);
1842 Editor::interthread_cancel_clicked ()
1844 if (current_interthread_info) {
1845 current_interthread_info->cancel = true;
1850 Editor::_import_thread (void *arg)
1852 PBD::ThreadCreated (pthread_self(), X_("Import"));
1854 Editor *ed = (Editor *) arg;
1855 return ed->import_thread ();
1859 Editor::import_thread ()
1861 session->import_audiofile (import_status);
1866 Editor::import_progress_timeout (void *arg)
1868 interthread_progress_label.set_text (import_status.doing_what);
1870 if (import_status.freeze) {
1871 interthread_cancel_button.set_sensitive(false);
1873 interthread_cancel_button.set_sensitive(true);
1876 if (import_status.doing_what == "building peak files") {
1877 interthread_progress_bar.set_activity_mode (true);
1880 interthread_progress_bar.set_fraction (import_status.progress/100);
1883 return !(import_status.done || import_status.cancel);
1887 Editor::import_audio (bool as_tracks)
1890 warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
1897 str =_("Import selected as tracks");
1899 str = _("Import selected to region list");
1902 SoundFileOmega sfdb (str);
1903 sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks));
1909 Editor::catch_new_audio_region (AudioRegion* ar)
1911 last_audio_region = ar;
1915 Editor::do_import (vector<string> paths, bool split, bool as_tracks)
1919 /* SFDB sets "multichan" to true to indicate "split channels"
1920 so reverse the setting to match the way libardour
1924 import_status.multichan = !split;
1926 if (interthread_progress_window == 0) {
1927 build_interthread_progress_window ();
1930 interthread_progress_window->set_title (_("ardour: audio import in progress"));
1931 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
1932 interthread_progress_window->show_all ();
1933 interthread_progress_bar.set_fraction (0.0f);
1934 interthread_cancel_label.set_text (_("Cancel Import"));
1935 current_interthread_info = &import_status;
1937 c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
1939 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
1941 interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
1943 import_status.pathname = (*i);
1944 import_status.done = false;
1945 import_status.cancel = false;
1946 import_status.freeze = false;
1947 import_status.done = 0.0;
1949 interthread_progress_connection =
1950 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
1952 last_audio_region = 0;
1954 pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
1955 pthread_detach (import_status.thread);
1957 while (!(import_status.done || import_status.cancel)) {
1958 gtk_main_iteration ();
1961 import_status.done = true;
1962 interthread_progress_connection.disconnect ();
1964 if (as_tracks && last_audio_region != 0) {
1965 uint32_t channels = last_audio_region->n_channels();
1967 AudioTrack* at = session->new_audio_track (channels, channels);
1968 AudioRegion* copy = new AudioRegion (*last_audio_region);
1969 at->disk_stream().playlist()->add_region (*copy, 0);
1974 interthread_progress_window->hide_all ();
1978 Editor::reject_because_rate_differs (string path, SF_INFO& finfo, string action, bool multiple_pending)
1984 if (finfo.samplerate != (int) session->frame_rate()) {
1985 vector<string> choices;
1987 choices.push_back (string_compose (_("%1 it anyway"), action));
1989 if (multiple_pending) {
1990 /* XXX assumptions about sentence structure
1991 here for translators. Sorry.
1993 choices.push_back (string_compose (_("Don't %1 it"), action));
1994 choices.push_back (string_compose (_("%1 all without questions"), action));
1995 choices.push_back (_("Cancel entire import"));
1997 choices.push_back (_("Cancel"));
2000 Gtkmm2ext::Choice rate_choice (
2001 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
2004 rate_choice.chosen.connect (Main::quit.slot());
2005 rate_choice.show_all ();
2009 switch (rate_choice.get_choice()) {
2010 case 0: /* do it anyway */
2012 case 1: /* don't import this one */
2014 case 2: /* do the rest without asking */
2016 case 3: /* stop a multi-file import */
2026 Editor::embed_audio ()
2029 warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
2033 SoundFileOmega sfdb (_("Add to External Region list"));
2034 sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
2040 Editor::do_embed_sndfiles (vector<string> paths, bool split)
2042 bool multiple_files = paths.size() > 1;
2043 bool check_sample_rate = true;
2045 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
2046 embed_sndfile (*i, split, multiple_files, check_sample_rate);
2049 session->save_state ("");
2053 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
2055 SndFileSource *source = 0; /* keep g++ quiet */
2056 AudioRegion::SourceList sources;
2062 /* lets see if we can link it into the session */
2064 linked_path = session->sound_dir();
2065 linked_path += PBD::basename (path);
2067 if (link (path.c_str(), linked_path.c_str()) == 0) {
2069 /* there are many reasons why link(2) might have failed.
2070 but if it succeeds, we now have a link in the
2071 session sound dir that will protect against
2072 unlinking of the original path. nice.
2078 memset (&finfo, 0, sizeof(finfo));
2080 /* note that we temporarily truncated _id at the colon */
2082 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2084 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2085 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
2091 if (check_sample_rate) {
2092 switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
2098 check_sample_rate = false;
2107 track_canvas_scroller.get_window()->set_cursor (GDK_WATCH);
2108 ARDOUR_UI::instance()->flush_pending ();
2110 /* make the proper number of channels in the region */
2112 for (int n=0; n < finfo.channels; ++n)
2115 idspec += string_compose(":%1", n);
2118 source = new SndFileSource (idspec.c_str());
2119 sources.push_back(source);
2122 catch (failed_constructor& err) {
2123 error << string_compose(_("could not open %1"), path) << endmsg;
2127 ARDOUR_UI::instance()->flush_pending ();
2130 if (sources.size() > 0) {
2132 string region_name = PBD::basename_nosuffix (path);
2133 region_name += "-0";
2135 /* The created region isn't dropped. It emits a signal
2136 that is picked up by the session.
2139 new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
2140 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2142 /* make sure we can see it in the list */
2144 Gtk::CTree_Helpers::RowList::iterator external_node;
2145 external_node = region_list_display.rows().begin();
2146 ++external_node; /* its the second node, always */
2147 external_node->expand_recursive ();
2149 ARDOUR_UI::instance()->flush_pending ();
2153 track_canvas_scroller.get_window()->set_cursor (current_canvas_cursor);
2157 Editor::insert_sndfile (bool as_tracks)
2159 // SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2165 // c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
2166 str = _("Insert selected as new tracks");
2172 if (clicked_audio_trackview == 0) {
2176 if (ensure_cursor (&pos)) {
2180 // c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
2181 str = _("Insert selected");
2184 // sfdb.run (str, false);
2189 Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
2193 bool multiple_files;
2194 bool check_sample_rate = true;
2196 multiple_files = paths.size() > 1;
2198 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
2200 memset (&finfo, 0, sizeof(finfo));
2202 if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
2204 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2205 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
2212 /* add a new track */
2214 if (check_sample_rate) {
2215 switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
2221 check_sample_rate = false;
2229 uint32_t input_chan = finfo.channels;
2230 uint32_t output_chan;
2232 if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
2233 output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
2235 output_chan = input_chan;
2238 (void) session->new_audio_track (input_chan, output_chan);
2241 /* get the last (most recently added) track view */
2243 AudioTimeAxisView* tv;
2245 if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
2246 fatal << _("programming error: ")
2247 << X_("last trackview after new_audio_track is not an audio track!")
2252 jack_nframes_t pos = 0;
2253 insert_sndfile_into (*p, true, tv, pos, false);
2258 Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
2260 for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
2261 insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
2266 Editor::insert_sndfile_into (string path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
2268 SndFileSource *source = 0; /* keep g++ quiet */
2269 AudioRegion::SourceList sources;
2274 memset (&finfo, 0, sizeof(finfo));
2276 /* note that we temporarily truncated _id at the colon */
2278 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2280 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2281 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
2287 if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
2291 track_canvas_scroller.get_window()->set_cursor (GDK_WATCH);
2292 ARDOUR_UI::instance()->flush_pending ();
2294 /* make the proper number of channels in the region */
2296 for (int n=0; n < finfo.channels; ++n)
2299 idspec += string_compose(":%1", n);
2302 source = new SndFileSource (idspec.c_str());
2303 sources.push_back(source);
2306 catch (failed_constructor& err) {
2307 error << string_compose(_("could not open %1"), path) << endmsg;
2311 ARDOUR_UI::instance()->flush_pending ();
2314 if (sources.size() > 0) {
2316 string region_name = region_name_from_path (PBD::basename (path));
2318 AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
2319 0, /* irrelevant these days */
2320 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2322 begin_reversible_command (_("insert sndfile"));
2323 session->add_undo (tv->playlist()->get_memento());
2324 tv->playlist()->add_region (*region, pos);
2325 session->add_redo_no_execute (tv->playlist()->get_memento());
2326 commit_reversible_command ();
2328 pos += sources[0]->length();
2330 ARDOUR_UI::instance()->flush_pending ();
2334 track_canvas_scroller.get_window()->set_cursor (current_canvas_cursor);
2339 Editor::region_from_selection ()
2341 if (clicked_trackview == 0) {
2345 if (selection->time.empty()) {
2349 jack_nframes_t start = selection->time[clicked_selection].start;
2350 jack_nframes_t end = selection->time[clicked_selection].end;
2352 jack_nframes_t selection_cnt = end - start + 1;
2354 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2356 AudioRegion *region;
2357 AudioRegion *current;
2361 jack_nframes_t internal_start;
2364 if ((pl = (*i)->playlist()) == 0) {
2368 if ((current_r = pl->top_region_at (start)) == 0) {
2372 if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
2373 internal_start = start - current->position();
2374 session->region_name (new_name, current->name(), true);
2375 region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
2381 Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
2383 if (selection->time.empty() || selection->tracks.empty()) {
2387 jack_nframes_t start = selection->time[clicked_selection].start;
2388 jack_nframes_t end = selection->time[clicked_selection].end;
2390 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2392 AudioRegion* current;
2395 jack_nframes_t internal_start;
2398 if ((playlist = (*i)->playlist()) == 0) {
2402 if ((current_r = playlist->top_region_at(start)) == 0) {
2406 if ((current = dynamic_cast<AudioRegion*>(current_r)) == 0) {
2410 internal_start = start - current->position();
2411 session->region_name (new_name, current->name(), true);
2413 new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name));
2418 Editor::split_multichannel_region ()
2420 vector<AudioRegion*> v;
2422 if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
2426 clicked_regionview->region.separate_by_channel (*session, v);
2428 /* nothing else to do, really */
2432 Editor::new_region_from_selection ()
2434 region_from_selection ();
2435 cancel_selection ();
2439 Editor::separate_region_from_selection ()
2441 bool doing_undo = false;
2443 if (selection->time.empty()) {
2449 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2451 AudioTimeAxisView* atv;
2453 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2455 if (atv->is_audio_track()) {
2457 if ((playlist = atv->playlist()) != 0) {
2459 begin_reversible_command (_("separate"));
2462 if (doing_undo) session->add_undo ((playlist)->get_memento());
2464 /* XXX need to consider musical time selections here at some point */
2466 double speed = atv->get_diskstream()->speed();
2468 for (list<AudioRange>::iterator t = selection->time.begin(); t != selection->time.end(); ++t) {
2469 playlist->partition ((jack_nframes_t)((*t).start * speed), (jack_nframes_t)((*t).end * speed), true);
2472 if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
2478 if (doing_undo) commit_reversible_command ();
2482 Editor::crop_region_to_selection ()
2484 if (selection->time.empty()) {
2488 vector<Playlist*> playlists;
2491 if (clicked_trackview != 0) {
2493 if ((playlist = clicked_trackview->playlist()) == 0) {
2497 playlists.push_back (playlist);
2501 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2503 AudioTimeAxisView* atv;
2505 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2507 if (atv->is_audio_track()) {
2509 if ((playlist = atv->playlist()) != 0) {
2510 playlists.push_back (playlist);
2517 if (!playlists.empty()) {
2519 jack_nframes_t start;
2523 begin_reversible_command (_("trim to selection"));
2525 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2529 start = selection->time.start();
2531 if ((region = (*i)->top_region_at(start)) == 0) {
2535 /* now adjust lengths to that we do the right thing
2536 if the selection extends beyond the region
2539 start = max (start, region->position());
2540 end = min (selection->time.end_frame(), start + region->length() - 1);
2541 cnt = end - start + 1;
2543 session->add_undo ((*i)->get_memento());
2544 region->trim_to (start, cnt, this);
2545 session->add_redo_no_execute ((*i)->get_memento());
2548 commit_reversible_command ();
2553 Editor::region_fill_track ()
2557 if (!session || selection->audio_regions.empty()) {
2561 end = session->current_end_frame ();
2563 begin_reversible_command (_("region fill"));
2565 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2567 AudioRegion& region ((*i)->region);
2568 Playlist* pl = region.playlist();
2570 if (end <= region.last_frame()) {
2574 double times = (double) (end - region.last_frame()) / (double) region.length();
2580 session->add_undo (pl->get_memento());
2581 pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
2582 session->add_redo_no_execute (pl->get_memento());
2585 commit_reversible_command ();
2589 Editor::region_fill_selection ()
2591 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2595 if (selection->time.empty()) {
2601 Gtk::CTree_Helpers::SelectionList& selected = region_list_display.selection();
2603 if (selected.empty()) {
2607 region = reinterpret_cast<Region *> (selected.front().get_data());
2609 jack_nframes_t start = selection->time[clicked_selection].start;
2610 jack_nframes_t end = selection->time[clicked_selection].end;
2614 if (selection->tracks.empty()) {
2618 jack_nframes_t selection_length = end - start;
2619 float times = (float)selection_length / region->length();
2621 begin_reversible_command (_("fill selection"));
2623 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2625 if ((playlist = (*i)->playlist()) == 0) {
2629 session->add_undo (playlist->get_memento());
2630 playlist->add_region (*(createRegion (*region)), start, times);
2631 session->add_redo_no_execute (playlist->get_memento());
2634 commit_reversible_command ();
2638 Editor::set_region_sync_from_edit_cursor ()
2640 if (clicked_regionview == 0) {
2644 if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
2645 error << _("Place the edit cursor at the desired sync point") << endmsg;
2649 Region& region (clicked_regionview->region);
2651 begin_reversible_command (_("set sync from edit cursor"));
2652 session->add_undo (region.playlist()->get_memento());
2653 region.set_sync_position (edit_cursor->current_frame);
2654 session->add_redo_no_execute (region.playlist()->get_memento());
2655 commit_reversible_command ();
2659 Editor::remove_region_sync ()
2661 if (clicked_regionview) {
2662 Region& region (clicked_regionview->region);
2663 begin_reversible_command (_("remove sync"));
2664 session->add_undo (region.playlist()->get_memento());
2665 region.clear_sync_position ();
2666 session->add_redo_no_execute (region.playlist()->get_memento());
2667 commit_reversible_command ();
2672 Editor::naturalize ()
2674 if (selection->audio_regions.empty()) {
2677 begin_reversible_command (_("naturalize"));
2678 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2679 session->add_undo ((*i)->region.get_memento());
2680 (*i)->region.move_to_natural_position (this);
2681 session->add_redo_no_execute ((*i)->region.get_memento());
2683 commit_reversible_command ();
2687 Editor::align (RegionPoint what)
2689 align_selection (what, edit_cursor->current_frame);
2693 Editor::align_relative (RegionPoint what)
2695 align_selection_relative (what, edit_cursor->current_frame);
2698 struct RegionSortByTime {
2699 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
2700 return a->region.position() < b->region.position();
2705 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
2707 if (selection->audio_regions.empty()) {
2711 jack_nframes_t distance;
2712 jack_nframes_t pos = 0;
2715 list<AudioRegionView*> sorted;
2716 selection->audio_regions.by_position (sorted);
2717 Region& r ((*sorted.begin())->region);
2721 pos = r.first_frame ();
2725 pos = r.last_frame();
2729 pos = r.adjust_to_sync (r.first_frame());
2733 if (pos > position) {
2734 distance = pos - position;
2737 distance = position - pos;
2741 begin_reversible_command (_("align selection (relative)"));
2743 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2745 Region& region ((*i)->region);
2747 session->add_undo (region.playlist()->get_memento());
2750 region.set_position (region.position() + distance, this);
2752 region.set_position (region.position() - distance, this);
2755 session->add_redo_no_execute (region.playlist()->get_memento());
2759 commit_reversible_command ();
2763 Editor::align_selection (RegionPoint point, jack_nframes_t position)
2765 if (selection->audio_regions.empty()) {
2769 begin_reversible_command (_("align selection"));
2771 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2772 align_region_internal ((*i)->region, point, position);
2775 commit_reversible_command ();
2779 Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position)
2781 begin_reversible_command (_("align region"));
2782 align_region_internal (region, point, position);
2783 commit_reversible_command ();
2787 Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position)
2789 session->add_undo (region.playlist()->get_memento());
2793 region.set_position (region.adjust_to_sync (position), this);
2797 if (position > region.length()) {
2798 region.set_position (position - region.length(), this);
2803 region.set_position (position, this);
2807 session->add_redo_no_execute (region.playlist()->get_memento());
2811 Editor::trim_region_to_edit_cursor ()
2813 if (clicked_regionview == 0) {
2817 Region& region (clicked_regionview->region);
2820 AudioTimeAxisView *atav;
2822 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2823 if (atav->get_diskstream() != 0) {
2824 speed = atav->get_diskstream()->speed();
2828 begin_reversible_command (_("trim to edit"));
2829 session->add_undo (region.playlist()->get_memento());
2830 region.trim_end ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
2831 session->add_redo_no_execute (region.playlist()->get_memento());
2832 commit_reversible_command ();
2836 Editor::trim_region_from_edit_cursor ()
2838 if (clicked_regionview == 0) {
2842 Region& region (clicked_regionview->region);
2845 AudioTimeAxisView *atav;
2847 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2848 if (atav->get_diskstream() != 0) {
2849 speed = atav->get_diskstream()->speed();
2853 begin_reversible_command (_("trim to edit"));
2854 session->add_undo (region.playlist()->get_memento());
2855 region.trim_front ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
2856 session->add_redo_no_execute (region.playlist()->get_memento());
2857 commit_reversible_command ();
2861 Editor::unfreeze_route ()
2863 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2867 clicked_audio_trackview->audio_track()->unfreeze ();
2871 Editor::_freeze_thread (void* arg)
2873 PBD::ThreadCreated (pthread_self(), X_("Freeze"));
2874 return static_cast<Editor*>(arg)->freeze_thread ();
2878 Editor::freeze_thread ()
2880 clicked_audio_trackview->audio_track()->freeze (*current_interthread_info);
2885 Editor::freeze_progress_timeout (void *arg)
2887 interthread_progress_bar.set_fraction (current_interthread_info->progress/100);
2888 return !(current_interthread_info->done || current_interthread_info->cancel);
2892 Editor::freeze_route ()
2894 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2898 InterThreadInfo itt;
2900 if (interthread_progress_window == 0) {
2901 build_interthread_progress_window ();
2904 interthread_progress_window->set_title (_("ardour: freeze"));
2905 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2906 interthread_progress_window->show_all ();
2907 interthread_progress_bar.set_fraction (0.0f);
2908 interthread_progress_label.set_text ("");
2909 interthread_cancel_label.set_text (_("Cancel Freeze"));
2910 current_interthread_info = &itt;
2912 interthread_progress_connection =
2913 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
2917 itt.progress = 0.0f;
2919 pthread_create (&itt.thread, 0, _freeze_thread, this);
2921 track_canvas_scroller.get_window()->set_cursor (Gdk::WATCH);
2923 while (!itt.done && !itt.cancel) {
2924 gtk_main_iteration ();
2927 interthread_progress_connection.disconnect ();
2928 interthread_progress_window->hide_all ();
2929 current_interthread_info = 0;
2930 track_canvas_scroller.get_window()->set_cursor (current_canvas_cursor);
2934 Editor::bounce_range_selection ()
2936 if (selection->time.empty()) {
2940 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
2942 jack_nframes_t start = selection->time[clicked_selection].start;
2943 jack_nframes_t end = selection->time[clicked_selection].end;
2944 jack_nframes_t cnt = end - start + 1;
2946 begin_reversible_command (_("bounce range"));
2948 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
2950 AudioTimeAxisView* atv;
2952 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
2958 if ((playlist = atv->playlist()) == 0) {
2962 InterThreadInfo itt;
2966 itt.progress = false;
2968 session->add_undo (playlist->get_memento());
2969 atv->audio_track()->bounce_range (start, cnt, itt);
2970 session->add_redo_no_execute (playlist->get_memento());
2973 commit_reversible_command ();
2991 Editor::cut_copy (CutCopyOp op)
2993 /* only cancel selection if cut/copy is successful.*/
3005 opname = _("clear");
3009 cut_buffer->clear ();
3011 switch (current_mouse_mode()) {
3013 if (!selection->audio_regions.empty() || !selection->points.empty()) {
3015 begin_reversible_command (opname + _(" objects"));
3017 if (!selection->audio_regions.empty()) {
3019 cut_copy_regions (op);
3022 selection->clear_audio_regions ();
3026 if (!selection->points.empty()) {
3027 cut_copy_points (op);
3030 selection->clear_points ();
3034 commit_reversible_command ();
3039 if (!selection->time.empty()) {
3041 begin_reversible_command (opname + _(" range"));
3042 cut_copy_ranges (op);
3043 commit_reversible_command ();
3046 selection->clear_time ();
3058 Editor::cut_copy_points (CutCopyOp op)
3060 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3062 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
3065 atv->cut_copy_clear_objects (selection->points, op);
3071 Editor::cut_copy_regions (CutCopyOp op)
3073 typedef std::map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
3074 PlaylistMapping pmap;
3075 jack_nframes_t first_position = max_frames;
3076 set<Playlist*> freezelist;
3077 pair<set<Playlist*>::iterator,bool> insert_result;
3079 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
3080 first_position = min ((*x)->region.position(), first_position);
3082 if (op == Cut || op == Clear) {
3083 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3085 insert_result = freezelist.insert (pl);
3086 if (insert_result.second) {
3088 session->add_undo (pl->get_memento());
3094 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
3096 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3098 AudioRegionSelection::iterator tmp;
3105 PlaylistMapping::iterator pi = pmap.find (pl);
3107 if (pi == pmap.end()) {
3108 npl = new AudioPlaylist (*session, "cutlist", true);
3117 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3118 pl->remove_region (&((*x)->region));
3122 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3126 pl->remove_region (&((*x)->region));
3134 list<Playlist*> foo;
3136 for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3137 foo.push_back (i->second);
3141 cut_buffer->set (foo);
3144 for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3146 session->add_redo_no_execute ((*pl)->get_memento());
3151 Editor::cut_copy_ranges (CutCopyOp op)
3153 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3154 (*i)->cut_copy_clear (*selection, op);
3159 Editor::paste (float times)
3161 paste_internal (edit_cursor->current_frame, times);
3165 Editor::mouse_paste ()
3169 track_canvas.get_pointer (x, y);
3171 gnome_canvas_window_to_world (GNOME_CANVAS(track_canvas), x, y, &wx, &wy);
3174 event.type = GDK_BUTTON_RELEASE;
3175 event.button.x = wx;
3176 event.button.y = wy;
3178 jack_nframes_t where = event_frame (&event, 0, 0);
3180 paste_internal (where, 1);
3184 Editor::paste_internal (jack_nframes_t position, float times)
3186 bool commit = false;
3188 if (cut_buffer->empty() || selection->tracks.empty()) {
3192 if (position == max_frames) {
3193 position = edit_cursor->current_frame;
3196 begin_reversible_command (_("paste"));
3198 TrackSelection::iterator i;
3201 for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) {
3203 /* undo/redo is handled by individual tracks */
3205 if ((*i)->paste (position, times, *cut_buffer, nth)) {
3211 commit_reversible_command ();
3216 Editor::paste_named_selection (float times)
3218 Gtk::CList_Helpers::SelectionList& selected = named_selection_display.selection();
3219 TrackSelection::iterator i;
3221 if (selected.empty() || selection->tracks.empty()) {
3225 NamedSelection* ns = static_cast<NamedSelection*> (selected.front()->get_data ());
3226 list<Playlist*>::iterator chunk;
3227 list<Playlist*>::iterator tmp;
3229 chunk = ns->playlists.begin();
3231 begin_reversible_command (_("paste chunk"));
3233 for (i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3235 AudioTimeAxisView* atv;
3239 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
3243 if ((pl = atv->playlist()) == 0) {
3247 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
3254 session->add_undo (apl->get_memento());
3255 apl->paste (**chunk, edit_cursor->current_frame, times);
3256 session->add_redo_no_execute (apl->get_memento());
3258 if (tmp != ns->playlists.end()) {
3263 commit_reversible_command();
3267 Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
3271 begin_reversible_command (_("duplicate region"));
3273 for (AudioRegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
3275 Region& r ((*i)->region);
3277 playlist = (*i)->region.playlist();
3278 session->add_undo (playlist->get_memento());
3279 playlist->duplicate (r, r.last_frame(), times);
3280 session->add_redo_no_execute (playlist->get_memento());
3284 commit_reversible_command ();
3288 Editor::duplicate_selection (float times)
3290 if (selection->time.empty() || selection->tracks.empty()) {
3295 vector<AudioRegion*> new_regions;
3296 vector<AudioRegion*>::iterator ri;
3298 create_region_from_selection (new_regions);
3300 if (new_regions.empty()) {
3304 begin_reversible_command (_("duplicate selection"));
3306 ri = new_regions.begin();
3308 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3309 if ((playlist = (*i)->playlist()) == 0) {
3312 session->add_undo (playlist->get_memento());
3313 playlist->duplicate (**ri, selection->time[clicked_selection].end, times);
3314 session->add_redo_no_execute (playlist->get_memento());
3317 if (ri == new_regions.end()) {
3322 commit_reversible_command ();
3326 Editor::center_playhead ()
3328 float page = canvas_width * frames_per_unit;
3330 center_screen_internal (playhead_cursor->current_frame, page);
3334 Editor::center_edit_cursor ()
3336 float page = canvas_width * frames_per_unit;
3338 center_screen_internal (edit_cursor->current_frame, page);
3342 Editor::clear_playlist (Playlist& playlist)
3344 begin_reversible_command (_("clear playlist"));
3345 session->add_undo (playlist.get_memento());
3347 session->add_redo_no_execute (playlist.get_memento());
3348 commit_reversible_command ();
3352 Editor::nudge_track (bool use_edit_cursor, bool forwards)
3355 jack_nframes_t distance;
3356 jack_nframes_t next_distance;
3357 jack_nframes_t start;
3359 if (use_edit_cursor) {
3360 start = edit_cursor->current_frame;
3365 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
3369 if (selection->tracks.empty()) {
3373 begin_reversible_command (_("nudge track"));
3375 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3377 if ((playlist = (*i)->playlist()) == 0) {
3381 session->add_undo (playlist->get_memento());
3382 playlist->nudge_after (start, distance, forwards);
3383 session->add_redo_no_execute (playlist->get_memento());
3386 commit_reversible_command ();
3390 Editor::toggle_xfades_active ()
3393 session->set_crossfades_active (!session->get_crossfades_active());
3398 Editor::toggle_follow_playhead ()
3400 set_follow_playhead (!_follow_playhead);
3404 Editor::set_xfade_visibility (bool yn)
3410 Editor::toggle_xfade_visibility ()
3412 set_xfade_visibility (!xfade_visibility());
3416 Editor::remove_last_capture ()
3418 vector<string> choices;
3425 if (Config->get_verify_remove_last_capture()) {
3426 prompt = _("Do you really want to destroy the last capture?"
3427 "\n(This is destructive and cannot be undone)");
3429 choices.push_back (_("Yes, destroy it."));
3430 choices.push_back (_("No, do nothing."));
3432 Gtkmm2ext::Choice prompter (prompt, choices);
3434 prompter.chosen.connect (Gtk::Main::quit.slot());
3435 prompter.show_all ();
3439 if (prompter.get_choice() == 0) {
3440 session->remove_last_capture ();
3443 session->remove_last_capture();
3448 Editor::normalize_region ()
3454 if (selection->audio_regions.empty()) {
3458 begin_reversible_command (_("normalize"));
3460 track_canvas_scroller.get_window()->set_cursor (wait_cursor);
3463 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3464 session->add_undo ((*r)->region.get_memento());
3465 (*r)->region.normalize_to (0.0f);
3466 session->add_redo_no_execute ((*r)->region.get_memento());
3469 commit_reversible_command ();
3470 gdk_window_set_cursor (track_canvas_scroller.get_window()->gobj(), current_canvas_cursor);
3475 Editor::denormalize_region ()
3481 if (selection->audio_regions.empty()) {
3485 begin_reversible_command ("denormalize");
3487 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3488 session->add_undo ((*r)->region.get_memento());
3489 (*r)->region.set_scale_amplitude (1.0f);
3490 session->add_redo_no_execute ((*r)->region.get_memento());
3493 commit_reversible_command ();
3498 Editor::reverse_region ()
3504 Reverse rev (*session);
3505 apply_filter (rev, _("reverse regions"));
3509 Editor::apply_filter (AudioFilter& filter, string command)
3511 if (selection->audio_regions.empty()) {
3515 begin_reversible_command (command);
3517 track_canvas_scroller.get_window()->set_cursor (wait_cursor);
3520 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
3522 AudioRegion& region ((*r)->region);
3523 Playlist* playlist = region.playlist();
3525 AudioRegionSelection::iterator tmp;
3530 if (region.apply (filter) == 0) {
3532 session->add_undo (playlist->get_memento());
3533 playlist->replace_region (region, *(filter.results.front()), region.position());
3534 session->add_redo_no_execute (playlist->get_memento());
3542 commit_reversible_command ();
3543 selection->audio_regions.clear ();
3546 gdk_window_set_cursor (track_canvas_scroller.get_window()->gobj(), current_canvas_cursor);
3550 Editor::region_selection_op (void (Region::*pmf)(void))
3552 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3553 ((*i)->region.*pmf)();
3559 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
3561 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3562 ((*i)->region.*pmf)(arg);
3567 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
3569 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3570 ((*i)->region.*pmf)(yn);
3575 Editor::external_edit_region ()
3577 if (!clicked_regionview) {
3585 Editor::brush (jack_nframes_t pos)
3587 AudioRegionSelection sel;
3590 if (selection->audio_regions.empty()) {
3591 /* XXX get selection from region list */
3593 sel = selection->audio_regions;
3600 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3601 mouse_brush_insert_region ((*i), pos);
3606 Editor::toggle_gain_envelope_visibility ()
3608 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3609 (*i)->set_envelope_visible (!(*i)->envelope_visible());
3614 Editor::toggle_gain_envelope_active ()
3616 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3617 AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
3619 ar->set_envelope_active (true);