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 (ptr_fun (Main::quit));
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 = track_frame_to_session_frame(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 = session_frame_to_track_frame(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 "session frame"
606 rpos = track_frame_to_session_frame(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 = track_frame_to_session_frame(pos, speed);
686 if (cursor == playhead_cursor) {
687 session->request_locate (pos);
689 cursor->set_position (pos);
694 Editor::cursor_to_next_region_point (Cursor* cursor, RegionPoint point)
696 cursor_to_region_point (cursor, point, 1);
700 Editor::cursor_to_previous_region_point (Cursor* cursor, RegionPoint point)
702 cursor_to_region_point (cursor, point, -1);
706 Editor::cursor_to_selection_start (Cursor *cursor)
708 jack_nframes_t pos = 0;
709 switch (mouse_mode) {
711 if (!selection->audio_regions.empty()) {
712 pos = selection->audio_regions.start();
717 if (!selection->time.empty()) {
718 pos = selection->time.start ();
726 if (cursor == playhead_cursor) {
727 session->request_locate (pos);
729 cursor->set_position (pos);
734 Editor::cursor_to_selection_end (Cursor *cursor)
736 jack_nframes_t pos = 0;
738 switch (mouse_mode) {
740 if (!selection->audio_regions.empty()) {
741 pos = selection->audio_regions.end_frame();
746 if (!selection->time.empty()) {
747 pos = selection->time.end_frame ();
755 if (cursor == playhead_cursor) {
756 session->request_locate (pos);
758 cursor->set_position (pos);
763 Editor::playhead_backward ()
770 if (get_prefix (prefix, was_floating)) {
774 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
776 cnt = (jack_nframes_t) prefix;
780 pos = playhead_cursor->current_frame;
782 if ((jack_nframes_t) pos < cnt) {
788 /* XXX this is completely insane. with the current buffering
789 design, we'll force a complete track buffer flush and
790 reload, just to move 1 sample !!!
793 session->request_locate (pos);
797 Editor::playhead_forward ()
804 if (get_prefix (prefix, was_floating)) {
808 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
810 cnt = (jack_nframes_t) floor (prefix);
814 pos = playhead_cursor->current_frame;
816 /* XXX this is completely insane. with the current buffering
817 design, we'll force a complete track buffer flush and
818 reload, just to move 1 sample !!!
821 session->request_locate (pos+cnt);
825 Editor::cursor_align (bool playhead_to_edit)
827 if (playhead_to_edit) {
829 session->request_locate (edit_cursor->current_frame);
832 edit_cursor->set_position (playhead_cursor->current_frame);
837 Editor::edit_cursor_backward ()
844 if (get_prefix (prefix, was_floating)) {
848 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
850 cnt = (jack_nframes_t) prefix;
854 pos = edit_cursor->current_frame;
856 if ((jack_nframes_t) pos < cnt) {
862 edit_cursor->set_position (pos);
866 Editor::edit_cursor_forward ()
873 if (get_prefix (prefix, was_floating)) {
877 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
879 cnt = (jack_nframes_t) floor (prefix);
883 pos = edit_cursor->current_frame;
884 edit_cursor->set_position (pos+cnt);
888 Editor::goto_frame ()
892 jack_nframes_t frame;
894 if (get_prefix (prefix, was_floating)) {
899 frame = (jack_nframes_t) floor (prefix * session->frame_rate());
901 frame = (jack_nframes_t) floor (prefix);
904 session->request_locate (frame);
908 Editor::scroll_backward (float pages)
910 jack_nframes_t frame;
911 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
916 if (get_prefix (prefix, was_floating)) {
917 cnt = (jack_nframes_t) floor (pages * one_page);
920 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
922 cnt = (jack_nframes_t) floor (prefix * one_page);
926 if (leftmost_frame < cnt) {
929 frame = leftmost_frame - cnt;
932 reposition_x_origin (frame);
936 Editor::scroll_forward (float pages)
938 jack_nframes_t frame;
939 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
944 if (get_prefix (prefix, was_floating)) {
945 cnt = (jack_nframes_t) floor (pages * one_page);
948 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
950 cnt = (jack_nframes_t) floor (prefix * one_page);
954 if (ULONG_MAX - cnt < leftmost_frame) {
955 frame = ULONG_MAX - cnt;
957 frame = leftmost_frame + cnt;
960 reposition_x_origin (frame);
964 Editor::scroll_tracks_down ()
970 if (get_prefix (prefix, was_floating)) {
973 cnt = (int) floor (prefix);
976 vertical_adjustment.set_value (vertical_adjustment.get_value() + (cnt * vertical_adjustment.get_page_size()));
980 Editor::scroll_tracks_up ()
986 if (get_prefix (prefix, was_floating)) {
989 cnt = (int) floor (prefix);
992 vertical_adjustment.set_value (vertical_adjustment.get_value() - (cnt * vertical_adjustment.get_page_size()));
996 Editor::scroll_tracks_down_line ()
998 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
999 adj->set_value (adj->get_value() + 10);
1003 Editor::scroll_tracks_up_line ()
1005 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
1006 adj->set_value (adj->get_value() - 10);
1012 Editor::temporal_zoom_step (bool coarser)
1016 nfpu = frames_per_unit;
1021 nfpu = max(1.0,(nfpu/2.0));
1024 temporal_zoom (nfpu);
1028 Editor::temporal_zoom (gdouble fpu)
1030 if (!session) return;
1032 jack_nframes_t current_page = current_page_frames();
1033 jack_nframes_t current_leftmost = leftmost_frame;
1034 jack_nframes_t current_rightmost;
1035 jack_nframes_t current_center;
1036 jack_nframes_t new_page;
1037 jack_nframes_t leftmost_after_zoom = 0;
1042 new_page = (jack_nframes_t) floor (canvas_width * nfpu);
1044 switch (zoom_focus) {
1046 leftmost_after_zoom = current_leftmost;
1049 case ZoomFocusRight:
1050 current_rightmost = leftmost_frame + current_page;
1051 if (current_rightmost > new_page) {
1052 leftmost_after_zoom = current_rightmost - new_page;
1054 leftmost_after_zoom = 0;
1058 case ZoomFocusCenter:
1059 current_center = current_leftmost + (current_page/2);
1060 if (current_center > (new_page/2)) {
1061 leftmost_after_zoom = current_center - (new_page / 2);
1063 leftmost_after_zoom = 0;
1067 case ZoomFocusPlayhead:
1068 /* try to keep the playhead in the center */
1069 if (playhead_cursor->current_frame > new_page/2) {
1070 leftmost_after_zoom = playhead_cursor->current_frame - (new_page/2);
1072 leftmost_after_zoom = 0;
1077 /* try to keep the edit cursor in the center */
1078 if (edit_cursor->current_frame > leftmost_frame + (new_page/2)) {
1079 leftmost_after_zoom = edit_cursor->current_frame - (new_page/2);
1081 leftmost_after_zoom = 0;
1087 // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
1089 // begin_reversible_command (_("zoom"));
1090 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
1091 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
1092 // commit_reversible_command ();
1094 reposition_and_zoom (leftmost_after_zoom, nfpu);
1098 Editor::temporal_zoom_selection ()
1100 if (!selection) return;
1102 if (selection->time.empty()) {
1106 jack_nframes_t start = selection->time[clicked_selection].start;
1107 jack_nframes_t end = selection->time[clicked_selection].end;
1109 temporal_zoom_by_frame (start, end, "zoom to selection");
1113 Editor::temporal_zoom_session ()
1116 temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
1121 Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, stringcr_t op)
1123 if (!session) return;
1125 if ((start == 0 && end == 0) || end < start) {
1129 jack_nframes_t range = end - start;
1131 double new_fpu = (double)range / (double)canvas_width;
1134 // while (p2 < new_fpu) {
1139 jack_nframes_t new_page = (jack_nframes_t) floor (canvas_width * new_fpu);
1140 jack_nframes_t middle = (jack_nframes_t) floor( (double)start + ((double)range / 2.0f ));
1141 jack_nframes_t new_leftmost = (jack_nframes_t) floor( (double)middle - ((double)new_page/2.0f));
1143 if (new_leftmost > middle) new_leftmost = 0;
1145 // begin_reversible_command (op);
1146 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1147 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1148 // commit_reversible_command ();
1150 reposition_and_zoom (new_leftmost, new_fpu);
1154 Editor::temporal_zoom_to_frame (bool coarser, jack_nframes_t frame)
1156 if (!session) return;
1158 jack_nframes_t range_before = frame - leftmost_frame;
1161 new_fpu = frames_per_unit;
1167 new_fpu = max(1.0,(new_fpu/2.0));
1171 if (new_fpu == frames_per_unit) return;
1173 jack_nframes_t new_leftmost = frame - range_before;
1175 if (new_leftmost > frame) new_leftmost = 0;
1177 // begin_reversible_command (_("zoom to frame"));
1178 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1179 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1180 // commit_reversible_command ();
1182 reposition_and_zoom (new_leftmost, new_fpu);
1186 Editor::select_all_in_track (bool add)
1188 list<Selectable *> touched;
1190 if (!clicked_trackview) {
1194 clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1197 selection->add (touched);
1199 selection->set (touched);
1204 Editor::select_all (bool add)
1206 list<Selectable *> touched;
1208 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1209 if ((*iter)->hidden()) {
1212 (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1216 selection->add (touched);
1218 selection->set (touched);
1224 Editor::invert_selection_in_track ()
1226 list<Selectable *> touched;
1228 if (!clicked_trackview) {
1232 clicked_trackview->get_inverted_selectables (*selection, touched);
1233 selection->set (touched);
1237 Editor::invert_selection ()
1239 list<Selectable *> touched;
1241 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1242 if ((*iter)->hidden()) {
1245 (*iter)->get_inverted_selectables (*selection, touched);
1248 selection->set (touched);
1252 Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
1254 list<Selectable *> touched;
1256 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1257 if ((*iter)->hidden()) {
1260 (*iter)->get_selectables (start, end, top, bot, touched);
1264 selection->add (touched);
1266 selection->set (touched);
1269 return !touched.empty();
1273 Editor::set_selection_from_punch()
1277 if ((location = session->locations()->auto_punch_location()) == 0) {
1281 set_selection_from_range (*location);
1285 Editor::set_selection_from_loop()
1289 if ((location = session->locations()->auto_loop_location()) == 0) {
1293 set_selection_from_range (*location);
1297 Editor::set_selection_from_range (Location& range)
1299 if (clicked_trackview == 0) {
1303 begin_reversible_command (_("set selection from range"));
1304 selection->set (0, range.start(), range.end());
1305 commit_reversible_command ();
1309 Editor::amplitude_zoom_step (bool in)
1323 #ifdef FIX_FOR_CANVAS
1324 /* XXX DO SOMETHING */
1333 Editor::delete_sample_forward ()
1338 Editor::delete_sample_backward ()
1343 Editor::delete_screen ()
1350 Editor::search_backwards ()
1356 Editor::search_forwards ()
1364 Editor::jump_forward_to_mark ()
1370 Location *location = session->locations()->first_location_after (playhead_cursor->current_frame);
1373 session->request_locate (location->start(), session->transport_rolling());
1375 session->request_locate (session->current_end_frame());
1380 Editor::jump_backward_to_mark ()
1386 Location *location = session->locations()->first_location_before (playhead_cursor->current_frame);
1389 session->request_locate (location->start(), session->transport_rolling());
1391 session->request_locate (0);
1402 if (get_prefix (prefix, was_floating)) {
1403 pos = session->audible_frame ();
1406 pos = (jack_nframes_t) floor (prefix * session->frame_rate ());
1408 pos = (jack_nframes_t) floor (prefix);
1412 session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true);
1416 Editor::clear_markers ()
1419 session->begin_reversible_command (_("clear markers"));
1420 session->add_undo (session->locations()->get_memento());
1421 session->locations()->clear_markers ();
1422 session->add_redo_no_execute (session->locations()->get_memento());
1423 session->commit_reversible_command ();
1428 Editor::clear_ranges ()
1431 session->begin_reversible_command (_("clear ranges"));
1432 session->add_undo (session->locations()->get_memento());
1434 Location * looploc = session->locations()->auto_loop_location();
1435 Location * punchloc = session->locations()->auto_punch_location();
1437 session->locations()->clear_ranges ();
1439 if (looploc) session->locations()->add (looploc);
1440 if (punchloc) session->locations()->add (punchloc);
1442 session->add_redo_no_execute (session->locations()->get_memento());
1443 session->commit_reversible_command ();
1448 Editor::clear_locations ()
1450 session->begin_reversible_command (_("clear locations"));
1451 session->add_undo (session->locations()->get_memento());
1452 session->locations()->clear ();
1453 session->add_redo_no_execute (session->locations()->get_memento());
1454 session->commit_reversible_command ();
1455 session->locations()->clear ();
1458 /* INSERT/REPLACE */
1461 Editor::insert_region_list_drag (AudioRegion& region)
1467 jack_nframes_t where;
1468 AudioTimeAxisView *atv = 0;
1471 track_canvas.get_pointer (x, y);
1472 track_canvas.window_to_world (x, y, wx, wy);
1475 event.type = GDK_BUTTON_RELEASE;
1476 event.button.x = wx;
1477 event.button.y = wy;
1479 where = event_frame (&event, &cx, &cy);
1481 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1482 /* clearly outside canvas area */
1486 if ((tv = trackview_by_y_position (cy)) == 0) {
1490 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) == 0) {
1494 if ((playlist = atv->playlist()) == 0) {
1500 begin_reversible_command (_("insert dragged region"));
1501 session->add_undo (playlist->get_memento());
1502 playlist->add_region (*(new AudioRegion (region)), where, 1.0);
1503 session->add_redo_no_execute (playlist->get_memento());
1504 commit_reversible_command ();
1508 Editor::insert_region_list_selection (float times)
1510 AudioTimeAxisView *tv = 0;
1513 if (clicked_audio_trackview != 0) {
1514 tv = clicked_audio_trackview;
1515 } else if (!selection->tracks.empty()) {
1516 if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
1523 if ((playlist = tv->playlist()) == 0) {
1527 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
1529 if (selected->count_selected_rows() != 1) {
1533 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
1534 Region* region = (*i)[region_list_columns.region];
1536 begin_reversible_command (_("insert region"));
1537 session->add_undo (playlist->get_memento());
1538 playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times);
1539 session->add_redo_no_execute (playlist->get_memento());
1540 commit_reversible_command ();
1544 /* BUILT-IN EFFECTS */
1547 Editor::reverse_selection ()
1552 /* GAIN ENVELOPE EDITING */
1555 Editor::edit_envelope ()
1562 Editor::toggle_playback (bool with_abort)
1568 switch (session->slave_source()) {
1573 /* transport controlled by the master */
1577 if (session->is_auditioning()) {
1578 session->cancel_audition ();
1582 if (session->transport_rolling()) {
1583 session->request_stop (with_abort);
1584 if (session->get_auto_loop()) {
1585 session->request_auto_loop (false);
1588 session->request_transport_speed (1.0f);
1593 Editor::play_from_start ()
1595 session->request_locate (0, true);
1599 Editor::play_selection ()
1601 if (selection->time.empty()) {
1605 session->request_play_range (true);
1609 Editor::play_selected_region ()
1611 if (!selection->audio_regions.empty()) {
1612 AudioRegionView *rv = *(selection->audio_regions.begin());
1614 session->request_bounded_roll (rv->region.position(), rv->region.last_frame());
1619 Editor::loop_selected_region ()
1621 if (!selection->audio_regions.empty()) {
1622 AudioRegionView *rv = *(selection->audio_regions.begin());
1625 if ((tll = transport_loop_location()) != 0) {
1627 tll->set (rv->region.position(), rv->region.last_frame());
1629 // enable looping, reposition and start rolling
1631 session->request_auto_loop (true);
1632 session->request_locate (tll->start(), false);
1633 session->request_transport_speed (1.0f);
1639 Editor::play_location (Location& location)
1641 if (location.start() <= location.end()) {
1645 session->request_bounded_roll (location.start(), location.end());
1649 Editor::loop_location (Location& location)
1651 if (location.start() <= location.end()) {
1657 if ((tll = transport_loop_location()) != 0) {
1658 tll->set (location.start(), location.end());
1660 // enable looping, reposition and start rolling
1661 session->request_auto_loop (true);
1662 session->request_locate (tll->start(), true);
1667 Editor::toggle_region_mute ()
1669 if (clicked_regionview) {
1670 clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
1671 } else if (!selection->audio_regions.empty()) {
1672 bool yn = ! (*selection->audio_regions.begin())->region.muted();
1673 selection->foreach_audio_region (&AudioRegion::set_muted, yn);
1678 Editor::toggle_region_opaque ()
1680 if (clicked_regionview) {
1681 clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
1682 } else if (!selection->audio_regions.empty()) {
1683 bool yn = ! (*selection->audio_regions.begin())->region.opaque();
1684 selection->foreach_audio_region (&Region::set_opaque, yn);
1689 Editor::raise_region ()
1691 selection->foreach_audio_region (&Region::raise);
1695 Editor::raise_region_to_top ()
1697 selection->foreach_audio_region (&Region::raise_to_top);
1701 Editor::lower_region ()
1703 selection->foreach_audio_region (&Region::lower);
1707 Editor::lower_region_to_bottom ()
1709 selection->foreach_audio_region (&Region::lower_to_bottom);
1713 Editor::edit_region ()
1715 if (clicked_regionview == 0) {
1719 clicked_regionview->show_region_editor ();
1723 Editor::rename_region ()
1727 Button ok_button (_("OK"));
1728 Button cancel_button (_("Cancel"));
1730 if (selection->audio_regions.empty()) {
1734 dialog.set_title (_("ardour: rename region"));
1735 dialog.set_name ("RegionRenameWindow");
1736 dialog.set_size_request (300, -1);
1737 dialog.set_position (Gtk::WIN_POS_MOUSE);
1738 dialog.set_modal (true);
1740 dialog.get_vbox()->set_border_width (10);
1741 dialog.get_vbox()->pack_start (entry);
1742 dialog.get_action_area()->pack_start (ok_button);
1743 dialog.get_action_area()->pack_start (cancel_button);
1745 entry.set_name ("RegionNameDisplay");
1746 ok_button.set_name ("EditorGTKButton");
1747 cancel_button.set_name ("EditorGTKButton");
1749 region_renamed = false;
1751 entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1752 ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1753 cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
1760 if (region_renamed) {
1761 (*selection->audio_regions.begin())->region.set_name (entry.get_text());
1762 redisplay_regions ();
1767 Editor::rename_region_finished (bool status)
1770 region_renamed = status;
1775 Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
1777 if (session->is_auditioning()) {
1778 session->cancel_audition ();
1781 // note: some potential for creativity here, because region doesn't
1782 // have to belong to the playlist that Route is handling
1784 // bool was_soloed = route.soloed();
1786 route.set_solo (true, this);
1788 session->request_bounded_roll (region.position(), region.position() + region.length());
1790 /* XXX how to unset the solo state ? */
1794 Editor::audition_selected_region ()
1796 if (!selection->audio_regions.empty()) {
1797 AudioRegionView* rv = *(selection->audio_regions.begin());
1798 session->audition_region (rv->region);
1803 Editor::audition_playlist_region_standalone (AudioRegion& region)
1805 session->audition_region (region);
1809 Editor::build_interthread_progress_window ()
1811 interthread_progress_window = new ArdourDialog (X_("interthread progress"), true);
1813 interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
1815 interthread_progress_window->get_vbox()->pack_start (interthread_progress_label, false, false);
1816 interthread_progress_window->get_vbox()->pack_start (interthread_progress_bar,false, false);
1818 // GTK2FIX: this button needs a modifiable label
1820 Button* b = interthread_progress_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1821 b->signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
1823 interthread_cancel_button.add (interthread_cancel_label);
1825 interthread_progress_window->set_default_size (200, 100);
1829 Editor::interthread_cancel_clicked ()
1831 if (current_interthread_info) {
1832 current_interthread_info->cancel = true;
1837 Editor::_import_thread (void *arg)
1839 PBD::ThreadCreated (pthread_self(), X_("Import"));
1841 Editor *ed = (Editor *) arg;
1842 return ed->import_thread ();
1846 Editor::import_thread ()
1848 session->import_audiofile (import_status);
1853 Editor::import_progress_timeout (void *arg)
1855 interthread_progress_label.set_text (import_status.doing_what);
1857 if (import_status.freeze) {
1858 interthread_cancel_button.set_sensitive(false);
1860 interthread_cancel_button.set_sensitive(true);
1863 if (import_status.doing_what == "building peak files") {
1864 interthread_progress_bar.pulse ();
1867 interthread_progress_bar.set_fraction (import_status.progress/100);
1870 return !(import_status.done || import_status.cancel);
1874 Editor::import_audio (bool as_tracks)
1877 warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
1884 str =_("Import selected as tracks");
1886 str = _("Import selected to region list");
1889 SoundFileOmega sfdb (str);
1890 sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks));
1896 Editor::catch_new_audio_region (AudioRegion* ar)
1898 last_audio_region = ar;
1902 Editor::do_import (vector<string> paths, bool split, bool as_tracks)
1906 /* SFDB sets "multichan" to true to indicate "split channels"
1907 so reverse the setting to match the way libardour
1911 import_status.multichan = !split;
1913 if (interthread_progress_window == 0) {
1914 build_interthread_progress_window ();
1917 interthread_progress_window->set_title (_("ardour: audio import in progress"));
1918 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
1919 interthread_progress_window->show_all ();
1920 interthread_progress_bar.set_fraction (0.0f);
1921 interthread_cancel_label.set_text (_("Cancel Import"));
1922 current_interthread_info = &import_status;
1924 c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
1926 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
1928 interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
1930 import_status.pathname = (*i);
1931 import_status.done = false;
1932 import_status.cancel = false;
1933 import_status.freeze = false;
1934 import_status.done = 0.0;
1936 interthread_progress_connection =
1937 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
1939 last_audio_region = 0;
1941 pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
1942 pthread_detach (import_status.thread);
1944 while (!(import_status.done || import_status.cancel)) {
1945 gtk_main_iteration ();
1948 import_status.done = true;
1949 interthread_progress_connection.disconnect ();
1951 if (as_tracks && last_audio_region != 0) {
1952 uint32_t channels = last_audio_region->n_channels();
1954 AudioTrack* at = session->new_audio_track (channels, channels);
1955 AudioRegion* copy = new AudioRegion (*last_audio_region);
1956 at->disk_stream().playlist()->add_region (*copy, 0);
1961 interthread_progress_window->hide_all ();
1965 Editor::reject_because_rate_differs (stringcr_t path, SF_INFO& finfo, stringcr_t action, bool multiple_pending)
1971 if (finfo.samplerate != (int) session->frame_rate()) {
1972 vector<string> choices;
1974 choices.push_back (string_compose (_("%1 it anyway"), action));
1976 if (multiple_pending) {
1977 /* XXX assumptions about sentence structure
1978 here for translators. Sorry.
1980 choices.push_back (string_compose (_("Don't %1 it"), action));
1981 choices.push_back (string_compose (_("%1 all without questions"), action));
1982 choices.push_back (_("Cancel entire import"));
1984 choices.push_back (_("Cancel"));
1987 Gtkmm2ext::Choice rate_choice (
1988 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
1991 rate_choice.chosen.connect (ptr_fun (Main::quit));
1992 rate_choice.show_all ();
1996 switch (rate_choice.get_choice()) {
1997 case 0: /* do it anyway */
1999 case 1: /* don't import this one */
2001 case 2: /* do the rest without asking */
2003 case 3: /* stop a multi-file import */
2013 Editor::embed_audio ()
2016 warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
2020 SoundFileOmega sfdb (_("Add to External Region list"));
2021 sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
2027 Editor::do_embed_sndfiles (vector<string> paths, bool split)
2029 bool multiple_files = paths.size() > 1;
2030 bool check_sample_rate = true;
2032 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
2033 embed_sndfile (*i, split, multiple_files, check_sample_rate);
2036 session->save_state ("");
2040 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
2042 SndFileSource *source = 0; /* keep g++ quiet */
2043 AudioRegion::SourceList sources;
2049 /* lets see if we can link it into the session */
2051 linked_path = session->sound_dir();
2052 linked_path += PBD::basename (path);
2054 if (link (path.c_str(), linked_path.c_str()) == 0) {
2056 /* there are many reasons why link(2) might have failed.
2057 but if it succeeds, we now have a link in the
2058 session sound dir that will protect against
2059 unlinking of the original path. nice.
2065 memset (&finfo, 0, sizeof(finfo));
2067 /* note that we temporarily truncated _id at the colon */
2069 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2071 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2072 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
2078 if (check_sample_rate) {
2079 switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
2085 check_sample_rate = false;
2094 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2095 ARDOUR_UI::instance()->flush_pending ();
2097 /* make the proper number of channels in the region */
2099 for (int n=0; n < finfo.channels; ++n)
2102 idspec += string_compose(":%1", n);
2105 source = new SndFileSource (idspec.c_str());
2106 sources.push_back(source);
2109 catch (failed_constructor& err) {
2110 error << string_compose(_("could not open %1"), path) << endmsg;
2114 ARDOUR_UI::instance()->flush_pending ();
2117 if (sources.size() > 0) {
2119 string region_name = PBD::basename_nosuffix (path);
2120 region_name += "-0";
2122 /* The created region isn't dropped. It emits a signal
2123 that is picked up by the session.
2126 new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
2127 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2129 /* make sure we can see it in the list */
2131 /* its the second node, always */
2133 // GTK2FIX ?? is it still always the 2nd node
2135 TreeModel::Path path ("2");
2136 region_list_display.expand_row (path, true);
2138 ARDOUR_UI::instance()->flush_pending ();
2142 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2146 Editor::insert_sndfile (bool as_tracks)
2148 // SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2154 // c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
2155 str = _("Insert selected as new tracks");
2161 if (clicked_audio_trackview == 0) {
2165 if (ensure_cursor (&pos)) {
2169 // c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
2170 str = _("Insert selected");
2173 // sfdb.run (str, false);
2178 Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
2182 bool multiple_files;
2183 bool check_sample_rate = true;
2185 multiple_files = paths.size() > 1;
2187 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
2189 memset (&finfo, 0, sizeof(finfo));
2191 if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
2193 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2194 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
2201 /* add a new track */
2203 if (check_sample_rate) {
2204 switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
2210 check_sample_rate = false;
2218 uint32_t input_chan = finfo.channels;
2219 uint32_t output_chan;
2221 if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
2222 output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
2224 output_chan = input_chan;
2227 (void) session->new_audio_track (input_chan, output_chan);
2230 /* get the last (most recently added) track view */
2232 AudioTimeAxisView* tv;
2234 if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
2235 fatal << _("programming error: ")
2236 << X_("last trackview after new_audio_track is not an audio track!")
2241 jack_nframes_t pos = 0;
2242 insert_sndfile_into (*p, true, tv, pos, false);
2247 Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
2249 for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
2250 insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
2255 Editor::insert_sndfile_into (stringcr_t path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
2257 SndFileSource *source = 0; /* keep g++ quiet */
2258 AudioRegion::SourceList sources;
2263 memset (&finfo, 0, sizeof(finfo));
2265 /* note that we temporarily truncated _id at the colon */
2267 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2269 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2270 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
2276 if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
2280 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2281 ARDOUR_UI::instance()->flush_pending ();
2283 /* make the proper number of channels in the region */
2285 for (int n=0; n < finfo.channels; ++n)
2288 idspec += string_compose(":%1", n);
2291 source = new SndFileSource (idspec.c_str());
2292 sources.push_back(source);
2295 catch (failed_constructor& err) {
2296 error << string_compose(_("could not open %1"), path) << endmsg;
2300 ARDOUR_UI::instance()->flush_pending ();
2303 if (sources.size() > 0) {
2305 string region_name = region_name_from_path (PBD::basename (path));
2307 AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
2308 0, /* irrelevant these days */
2309 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2311 begin_reversible_command (_("insert sndfile"));
2312 session->add_undo (tv->playlist()->get_memento());
2313 tv->playlist()->add_region (*region, pos);
2314 session->add_redo_no_execute (tv->playlist()->get_memento());
2315 commit_reversible_command ();
2317 pos += sources[0]->length();
2319 ARDOUR_UI::instance()->flush_pending ();
2323 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2328 Editor::region_from_selection ()
2330 if (clicked_trackview == 0) {
2334 if (selection->time.empty()) {
2338 jack_nframes_t start = selection->time[clicked_selection].start;
2339 jack_nframes_t end = selection->time[clicked_selection].end;
2341 jack_nframes_t selection_cnt = end - start + 1;
2343 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2345 AudioRegion *region;
2346 AudioRegion *current;
2350 jack_nframes_t internal_start;
2353 if ((pl = (*i)->playlist()) == 0) {
2357 if ((current_r = pl->top_region_at (start)) == 0) {
2361 if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
2362 internal_start = start - current->position();
2363 session->region_name (new_name, current->name(), true);
2364 region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
2370 Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
2372 if (selection->time.empty() || selection->tracks.empty()) {
2376 jack_nframes_t start = selection->time[clicked_selection].start;
2377 jack_nframes_t end = selection->time[clicked_selection].end;
2379 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2381 AudioRegion* current;
2384 jack_nframes_t internal_start;
2387 if ((playlist = (*i)->playlist()) == 0) {
2391 if ((current_r = playlist->top_region_at(start)) == 0) {
2395 if ((current = dynamic_cast<AudioRegion*>(current_r)) == 0) {
2399 internal_start = start - current->position();
2400 session->region_name (new_name, current->name(), true);
2402 new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name));
2407 Editor::split_multichannel_region ()
2409 vector<AudioRegion*> v;
2411 if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
2415 clicked_regionview->region.separate_by_channel (*session, v);
2417 /* nothing else to do, really */
2421 Editor::new_region_from_selection ()
2423 region_from_selection ();
2424 cancel_selection ();
2428 Editor::separate_region_from_selection ()
2430 bool doing_undo = false;
2432 if (selection->time.empty()) {
2438 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2440 AudioTimeAxisView* atv;
2442 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2444 if (atv->is_audio_track()) {
2446 if ((playlist = atv->playlist()) != 0) {
2448 begin_reversible_command (_("separate"));
2451 if (doing_undo) session->add_undo ((playlist)->get_memento());
2453 /* XXX need to consider musical time selections here at some point */
2455 double speed = atv->get_diskstream()->speed();
2457 for (list<AudioRange>::iterator t = selection->time.begin(); t != selection->time.end(); ++t) {
2458 playlist->partition ((jack_nframes_t)((*t).start * speed), (jack_nframes_t)((*t).end * speed), true);
2461 if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
2467 if (doing_undo) commit_reversible_command ();
2471 Editor::crop_region_to_selection ()
2473 if (selection->time.empty()) {
2477 vector<Playlist*> playlists;
2480 if (clicked_trackview != 0) {
2482 if ((playlist = clicked_trackview->playlist()) == 0) {
2486 playlists.push_back (playlist);
2490 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2492 AudioTimeAxisView* atv;
2494 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2496 if (atv->is_audio_track()) {
2498 if ((playlist = atv->playlist()) != 0) {
2499 playlists.push_back (playlist);
2506 if (!playlists.empty()) {
2508 jack_nframes_t start;
2512 begin_reversible_command (_("trim to selection"));
2514 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2518 start = selection->time.start();
2520 if ((region = (*i)->top_region_at(start)) == 0) {
2524 /* now adjust lengths to that we do the right thing
2525 if the selection extends beyond the region
2528 start = max (start, region->position());
2529 end = min (selection->time.end_frame(), start + region->length() - 1);
2530 cnt = end - start + 1;
2532 session->add_undo ((*i)->get_memento());
2533 region->trim_to (start, cnt, this);
2534 session->add_redo_no_execute ((*i)->get_memento());
2537 commit_reversible_command ();
2542 Editor::region_fill_track ()
2546 if (!session || selection->audio_regions.empty()) {
2550 end = session->current_end_frame ();
2552 begin_reversible_command (_("region fill"));
2554 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2556 AudioRegion& region ((*i)->region);
2557 Playlist* pl = region.playlist();
2559 if (end <= region.last_frame()) {
2563 double times = (double) (end - region.last_frame()) / (double) region.length();
2569 session->add_undo (pl->get_memento());
2570 pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
2571 session->add_redo_no_execute (pl->get_memento());
2574 commit_reversible_command ();
2578 Editor::region_fill_selection ()
2580 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2584 if (selection->time.empty()) {
2590 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
2592 if (selected->count_selected_rows() != 1) {
2596 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
2597 region = (*i)[region_list_columns.region];
2599 jack_nframes_t start = selection->time[clicked_selection].start;
2600 jack_nframes_t end = selection->time[clicked_selection].end;
2604 if (selection->tracks.empty()) {
2608 jack_nframes_t selection_length = end - start;
2609 float times = (float)selection_length / region->length();
2611 begin_reversible_command (_("fill selection"));
2613 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2615 if ((playlist = (*i)->playlist()) == 0) {
2619 session->add_undo (playlist->get_memento());
2620 playlist->add_region (*(createRegion (*region)), start, times);
2621 session->add_redo_no_execute (playlist->get_memento());
2624 commit_reversible_command ();
2628 Editor::set_region_sync_from_edit_cursor ()
2630 if (clicked_regionview == 0) {
2634 if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
2635 error << _("Place the edit cursor at the desired sync point") << endmsg;
2639 Region& region (clicked_regionview->region);
2641 begin_reversible_command (_("set sync from edit cursor"));
2642 session->add_undo (region.playlist()->get_memento());
2643 region.set_sync_position (edit_cursor->current_frame);
2644 session->add_redo_no_execute (region.playlist()->get_memento());
2645 commit_reversible_command ();
2649 Editor::remove_region_sync ()
2651 if (clicked_regionview) {
2652 Region& region (clicked_regionview->region);
2653 begin_reversible_command (_("remove sync"));
2654 session->add_undo (region.playlist()->get_memento());
2655 region.clear_sync_position ();
2656 session->add_redo_no_execute (region.playlist()->get_memento());
2657 commit_reversible_command ();
2662 Editor::naturalize ()
2664 if (selection->audio_regions.empty()) {
2667 begin_reversible_command (_("naturalize"));
2668 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2669 session->add_undo ((*i)->region.get_memento());
2670 (*i)->region.move_to_natural_position (this);
2671 session->add_redo_no_execute ((*i)->region.get_memento());
2673 commit_reversible_command ();
2677 Editor::align (RegionPoint what)
2679 align_selection (what, edit_cursor->current_frame);
2683 Editor::align_relative (RegionPoint what)
2685 align_selection_relative (what, edit_cursor->current_frame);
2688 struct RegionSortByTime {
2689 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
2690 return a->region.position() < b->region.position();
2695 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
2697 if (selection->audio_regions.empty()) {
2701 jack_nframes_t distance;
2702 jack_nframes_t pos = 0;
2705 list<AudioRegionView*> sorted;
2706 selection->audio_regions.by_position (sorted);
2707 Region& r ((*sorted.begin())->region);
2711 pos = r.first_frame ();
2715 pos = r.last_frame();
2719 pos = r.adjust_to_sync (r.first_frame());
2723 if (pos > position) {
2724 distance = pos - position;
2727 distance = position - pos;
2731 begin_reversible_command (_("align selection (relative)"));
2733 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2735 Region& region ((*i)->region);
2737 session->add_undo (region.playlist()->get_memento());
2740 region.set_position (region.position() + distance, this);
2742 region.set_position (region.position() - distance, this);
2745 session->add_redo_no_execute (region.playlist()->get_memento());
2749 commit_reversible_command ();
2753 Editor::align_selection (RegionPoint point, jack_nframes_t position)
2755 if (selection->audio_regions.empty()) {
2759 begin_reversible_command (_("align selection"));
2761 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2762 align_region_internal ((*i)->region, point, position);
2765 commit_reversible_command ();
2769 Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position)
2771 begin_reversible_command (_("align region"));
2772 align_region_internal (region, point, position);
2773 commit_reversible_command ();
2777 Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position)
2779 session->add_undo (region.playlist()->get_memento());
2783 region.set_position (region.adjust_to_sync (position), this);
2787 if (position > region.length()) {
2788 region.set_position (position - region.length(), this);
2793 region.set_position (position, this);
2797 session->add_redo_no_execute (region.playlist()->get_memento());
2801 Editor::trim_region_to_edit_cursor ()
2803 if (clicked_regionview == 0) {
2807 Region& region (clicked_regionview->region);
2810 AudioTimeAxisView *atav;
2812 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2813 if (atav->get_diskstream() != 0) {
2814 speed = atav->get_diskstream()->speed();
2818 begin_reversible_command (_("trim to edit"));
2819 session->add_undo (region.playlist()->get_memento());
2820 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2821 session->add_redo_no_execute (region.playlist()->get_memento());
2822 commit_reversible_command ();
2826 Editor::trim_region_from_edit_cursor ()
2828 if (clicked_regionview == 0) {
2832 Region& region (clicked_regionview->region);
2835 AudioTimeAxisView *atav;
2837 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2838 if (atav->get_diskstream() != 0) {
2839 speed = atav->get_diskstream()->speed();
2843 begin_reversible_command (_("trim to edit"));
2844 session->add_undo (region.playlist()->get_memento());
2845 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2846 session->add_redo_no_execute (region.playlist()->get_memento());
2847 commit_reversible_command ();
2851 Editor::unfreeze_route ()
2853 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2857 clicked_audio_trackview->audio_track()->unfreeze ();
2861 Editor::_freeze_thread (void* arg)
2863 PBD::ThreadCreated (pthread_self(), X_("Freeze"));
2864 return static_cast<Editor*>(arg)->freeze_thread ();
2868 Editor::freeze_thread ()
2870 clicked_audio_trackview->audio_track()->freeze (*current_interthread_info);
2875 Editor::freeze_progress_timeout (void *arg)
2877 interthread_progress_bar.set_fraction (current_interthread_info->progress/100);
2878 return !(current_interthread_info->done || current_interthread_info->cancel);
2882 Editor::freeze_route ()
2884 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2888 InterThreadInfo itt;
2890 if (interthread_progress_window == 0) {
2891 build_interthread_progress_window ();
2894 interthread_progress_window->set_title (_("ardour: freeze"));
2895 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2896 interthread_progress_window->show_all ();
2897 interthread_progress_bar.set_fraction (0.0f);
2898 interthread_progress_label.set_text ("");
2899 interthread_cancel_label.set_text (_("Cancel Freeze"));
2900 current_interthread_info = &itt;
2902 interthread_progress_connection =
2903 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
2907 itt.progress = 0.0f;
2909 pthread_create (&itt.thread, 0, _freeze_thread, this);
2911 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2913 while (!itt.done && !itt.cancel) {
2914 gtk_main_iteration ();
2917 interthread_progress_connection.disconnect ();
2918 interthread_progress_window->hide_all ();
2919 current_interthread_info = 0;
2920 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2924 Editor::bounce_range_selection ()
2926 if (selection->time.empty()) {
2930 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
2932 jack_nframes_t start = selection->time[clicked_selection].start;
2933 jack_nframes_t end = selection->time[clicked_selection].end;
2934 jack_nframes_t cnt = end - start + 1;
2936 begin_reversible_command (_("bounce range"));
2938 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
2940 AudioTimeAxisView* atv;
2942 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
2948 if ((playlist = atv->playlist()) == 0) {
2952 InterThreadInfo itt;
2956 itt.progress = false;
2958 session->add_undo (playlist->get_memento());
2959 atv->audio_track()->bounce_range (start, cnt, itt);
2960 session->add_redo_no_execute (playlist->get_memento());
2963 commit_reversible_command ();
2981 Editor::cut_copy (CutCopyOp op)
2983 /* only cancel selection if cut/copy is successful.*/
2995 opname = _("clear");
2999 cut_buffer->clear ();
3001 switch (current_mouse_mode()) {
3003 if (!selection->audio_regions.empty() || !selection->points.empty()) {
3005 begin_reversible_command (opname + _(" objects"));
3007 if (!selection->audio_regions.empty()) {
3009 cut_copy_regions (op);
3012 selection->clear_audio_regions ();
3016 if (!selection->points.empty()) {
3017 cut_copy_points (op);
3020 selection->clear_points ();
3024 commit_reversible_command ();
3029 if (!selection->time.empty()) {
3031 begin_reversible_command (opname + _(" range"));
3032 cut_copy_ranges (op);
3033 commit_reversible_command ();
3036 selection->clear_time ();
3048 Editor::cut_copy_points (CutCopyOp op)
3050 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3052 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
3055 atv->cut_copy_clear_objects (selection->points, op);
3061 Editor::cut_copy_regions (CutCopyOp op)
3063 typedef std::map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
3064 PlaylistMapping pmap;
3065 jack_nframes_t first_position = max_frames;
3066 set<Playlist*> freezelist;
3067 pair<set<Playlist*>::iterator,bool> insert_result;
3069 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
3070 first_position = min ((*x)->region.position(), first_position);
3072 if (op == Cut || op == Clear) {
3073 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3075 insert_result = freezelist.insert (pl);
3076 if (insert_result.second) {
3078 session->add_undo (pl->get_memento());
3084 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
3086 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3088 AudioRegionSelection::iterator tmp;
3095 PlaylistMapping::iterator pi = pmap.find (pl);
3097 if (pi == pmap.end()) {
3098 npl = new AudioPlaylist (*session, "cutlist", true);
3107 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3108 pl->remove_region (&((*x)->region));
3112 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3116 pl->remove_region (&((*x)->region));
3124 list<Playlist*> foo;
3126 for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3127 foo.push_back (i->second);
3131 cut_buffer->set (foo);
3134 for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3136 session->add_redo_no_execute ((*pl)->get_memento());
3141 Editor::cut_copy_ranges (CutCopyOp op)
3143 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3144 (*i)->cut_copy_clear (*selection, op);
3149 Editor::paste (float times)
3151 paste_internal (edit_cursor->current_frame, times);
3155 Editor::mouse_paste ()
3159 track_canvas.get_pointer (x, y);
3160 track_canvas.window_to_world (x, y, wx, wy);
3162 event.type = GDK_BUTTON_RELEASE;
3163 event.button.x = wx;
3164 event.button.y = wy;
3166 jack_nframes_t where = event_frame (&event, 0, 0);
3168 paste_internal (where, 1);
3172 Editor::paste_internal (jack_nframes_t position, float times)
3174 bool commit = false;
3176 if (cut_buffer->empty() || selection->tracks.empty()) {
3180 if (position == max_frames) {
3181 position = edit_cursor->current_frame;
3184 begin_reversible_command (_("paste"));
3186 TrackSelection::iterator i;
3189 for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) {
3191 /* undo/redo is handled by individual tracks */
3193 if ((*i)->paste (position, times, *cut_buffer, nth)) {
3199 commit_reversible_command ();
3204 Editor::paste_named_selection (float times)
3206 TrackSelection::iterator t;
3208 Glib::RefPtr<TreeSelection> selected = named_selection_display.get_selection();
3210 if (selected->count_selected_rows() != 1 || selection->tracks.empty()) {
3214 TreeModel::iterator i = selected->get_selected();
3215 NamedSelection* ns = (*i)[named_selection_columns.selection];
3217 list<Playlist*>::iterator chunk;
3218 list<Playlist*>::iterator tmp;
3220 chunk = ns->playlists.begin();
3222 begin_reversible_command (_("paste chunk"));
3224 for (t = selection->tracks.begin(); t != selection->tracks.end(); ++t) {
3226 AudioTimeAxisView* atv;
3230 if ((atv = dynamic_cast<AudioTimeAxisView*> (*t)) == 0) {
3234 if ((pl = atv->playlist()) == 0) {
3238 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
3245 session->add_undo (apl->get_memento());
3246 apl->paste (**chunk, edit_cursor->current_frame, times);
3247 session->add_redo_no_execute (apl->get_memento());
3249 if (tmp != ns->playlists.end()) {
3254 commit_reversible_command();
3258 Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
3262 begin_reversible_command (_("duplicate region"));
3264 for (AudioRegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
3266 Region& r ((*i)->region);
3268 playlist = (*i)->region.playlist();
3269 session->add_undo (playlist->get_memento());
3270 playlist->duplicate (r, r.last_frame(), times);
3271 session->add_redo_no_execute (playlist->get_memento());
3275 commit_reversible_command ();
3279 Editor::duplicate_selection (float times)
3281 if (selection->time.empty() || selection->tracks.empty()) {
3286 vector<AudioRegion*> new_regions;
3287 vector<AudioRegion*>::iterator ri;
3289 create_region_from_selection (new_regions);
3291 if (new_regions.empty()) {
3295 begin_reversible_command (_("duplicate selection"));
3297 ri = new_regions.begin();
3299 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3300 if ((playlist = (*i)->playlist()) == 0) {
3303 session->add_undo (playlist->get_memento());
3304 playlist->duplicate (**ri, selection->time[clicked_selection].end, times);
3305 session->add_redo_no_execute (playlist->get_memento());
3308 if (ri == new_regions.end()) {
3313 commit_reversible_command ();
3317 Editor::center_playhead ()
3319 float page = canvas_width * frames_per_unit;
3321 center_screen_internal (playhead_cursor->current_frame, page);
3325 Editor::center_edit_cursor ()
3327 float page = canvas_width * frames_per_unit;
3329 center_screen_internal (edit_cursor->current_frame, page);
3333 Editor::clear_playlist (Playlist& playlist)
3335 begin_reversible_command (_("clear playlist"));
3336 session->add_undo (playlist.get_memento());
3338 session->add_redo_no_execute (playlist.get_memento());
3339 commit_reversible_command ();
3343 Editor::nudge_track (bool use_edit_cursor, bool forwards)
3346 jack_nframes_t distance;
3347 jack_nframes_t next_distance;
3348 jack_nframes_t start;
3350 if (use_edit_cursor) {
3351 start = edit_cursor->current_frame;
3356 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
3360 if (selection->tracks.empty()) {
3364 begin_reversible_command (_("nudge track"));
3366 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3368 if ((playlist = (*i)->playlist()) == 0) {
3372 session->add_undo (playlist->get_memento());
3373 playlist->nudge_after (start, distance, forwards);
3374 session->add_redo_no_execute (playlist->get_memento());
3377 commit_reversible_command ();
3381 Editor::toggle_xfades_active ()
3384 session->set_crossfades_active (!session->get_crossfades_active());
3389 Editor::toggle_follow_playhead ()
3391 set_follow_playhead (!_follow_playhead);
3395 Editor::set_xfade_visibility (bool yn)
3401 Editor::toggle_xfade_visibility ()
3403 set_xfade_visibility (!xfade_visibility());
3407 Editor::remove_last_capture ()
3409 vector<string> choices;
3416 if (Config->get_verify_remove_last_capture()) {
3417 prompt = _("Do you really want to destroy the last capture?"
3418 "\n(This is destructive and cannot be undone)");
3420 choices.push_back (_("Yes, destroy it."));
3421 choices.push_back (_("No, do nothing."));
3423 Gtkmm2ext::Choice prompter (prompt, choices);
3424 prompter.chosen.connect (ptr_fun (Main::quit));
3425 prompter.show_all ();
3429 if (prompter.get_choice() == 0) {
3430 session->remove_last_capture ();
3434 session->remove_last_capture();
3439 Editor::normalize_region ()
3445 if (selection->audio_regions.empty()) {
3449 begin_reversible_command (_("normalize"));
3451 track_canvas.get_window()->set_cursor (*wait_cursor);
3454 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3455 session->add_undo ((*r)->region.get_memento());
3456 (*r)->region.normalize_to (0.0f);
3457 session->add_redo_no_execute ((*r)->region.get_memento());
3460 commit_reversible_command ();
3461 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
3466 Editor::denormalize_region ()
3472 if (selection->audio_regions.empty()) {
3476 begin_reversible_command ("denormalize");
3478 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3479 session->add_undo ((*r)->region.get_memento());
3480 (*r)->region.set_scale_amplitude (1.0f);
3481 session->add_redo_no_execute ((*r)->region.get_memento());
3484 commit_reversible_command ();
3489 Editor::reverse_region ()
3495 Reverse rev (*session);
3496 apply_filter (rev, _("reverse regions"));
3500 Editor::apply_filter (AudioFilter& filter, string command)
3502 if (selection->audio_regions.empty()) {
3506 begin_reversible_command (command);
3508 track_canvas.get_window()->set_cursor (*wait_cursor);
3511 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
3513 AudioRegion& region ((*r)->region);
3514 Playlist* playlist = region.playlist();
3516 AudioRegionSelection::iterator tmp;
3521 if (region.apply (filter) == 0) {
3523 session->add_undo (playlist->get_memento());
3524 playlist->replace_region (region, *(filter.results.front()), region.position());
3525 session->add_redo_no_execute (playlist->get_memento());
3533 commit_reversible_command ();
3534 selection->audio_regions.clear ();
3537 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
3541 Editor::region_selection_op (void (Region::*pmf)(void))
3543 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3544 ((*i)->region.*pmf)();
3550 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
3552 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3553 ((*i)->region.*pmf)(arg);
3558 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
3560 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3561 ((*i)->region.*pmf)(yn);
3566 Editor::external_edit_region ()
3568 if (!clicked_regionview) {
3576 Editor::brush (jack_nframes_t pos)
3578 AudioRegionSelection sel;
3581 if (selection->audio_regions.empty()) {
3582 /* XXX get selection from region list */
3584 sel = selection->audio_regions;
3591 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3592 mouse_brush_insert_region ((*i), pos);
3597 Editor::toggle_gain_envelope_visibility ()
3599 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3600 (*i)->set_envelope_visible (!(*i)->envelope_visible());
3605 Editor::toggle_gain_envelope_active ()
3607 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3608 AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
3610 ar->set_envelope_active (true);