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 = 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 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
977 adj->set_value (adj->get_value() + (cnt * adj->get_page_size()));
981 Editor::scroll_tracks_up ()
987 if (get_prefix (prefix, was_floating)) {
990 cnt = (int) floor (prefix);
993 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
994 adj->set_value (adj->get_value() - (cnt * adj->get_page_size()));
998 Editor::scroll_tracks_down_line ()
1000 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
1001 adj->set_value (adj->get_value() + 10);
1005 Editor::scroll_tracks_up_line ()
1007 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
1008 adj->set_value (adj->get_value() - 10);
1014 Editor::temporal_zoom_step (bool coarser)
1018 nfpu = frames_per_unit;
1023 nfpu = max(1.0,(nfpu/2.0));
1026 temporal_zoom (nfpu);
1030 Editor::temporal_zoom (gdouble fpu)
1032 if (!session) return;
1034 jack_nframes_t current_page = current_page_frames();
1035 jack_nframes_t current_leftmost = leftmost_frame;
1036 jack_nframes_t current_rightmost;
1037 jack_nframes_t current_center;
1038 jack_nframes_t new_page;
1039 jack_nframes_t leftmost_after_zoom = 0;
1044 new_page = (jack_nframes_t) floor (canvas_width * nfpu);
1046 switch (zoom_focus) {
1048 leftmost_after_zoom = current_leftmost;
1051 case ZoomFocusRight:
1052 current_rightmost = leftmost_frame + current_page;
1053 if (current_rightmost > new_page) {
1054 leftmost_after_zoom = current_rightmost - new_page;
1056 leftmost_after_zoom = 0;
1060 case ZoomFocusCenter:
1061 current_center = current_leftmost + (current_page/2);
1062 if (current_center > (new_page/2)) {
1063 leftmost_after_zoom = current_center - (new_page / 2);
1065 leftmost_after_zoom = 0;
1069 case ZoomFocusPlayhead:
1070 /* try to keep the playhead in the center */
1071 if (playhead_cursor->current_frame > new_page/2) {
1072 leftmost_after_zoom = playhead_cursor->current_frame - (new_page/2);
1074 leftmost_after_zoom = 0;
1079 /* try to keep the edit cursor in the center */
1080 if (edit_cursor->current_frame > leftmost_frame + (new_page/2)) {
1081 leftmost_after_zoom = edit_cursor->current_frame - (new_page/2);
1083 leftmost_after_zoom = 0;
1089 // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
1091 // begin_reversible_command (_("zoom"));
1092 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
1093 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
1094 // commit_reversible_command ();
1096 reposition_and_zoom (leftmost_after_zoom, nfpu);
1100 Editor::temporal_zoom_selection ()
1102 if (!selection) return;
1104 if (selection->time.empty()) {
1108 jack_nframes_t start = selection->time[clicked_selection].start;
1109 jack_nframes_t end = selection->time[clicked_selection].end;
1111 temporal_zoom_by_frame (start, end, "zoom to selection");
1115 Editor::temporal_zoom_session ()
1118 temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
1123 Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, string op)
1125 if (!session) return;
1127 if ((start == 0 && end == 0) || end < start) {
1131 jack_nframes_t range = end - start;
1133 double new_fpu = (double)range / (double)canvas_width;
1136 // while (p2 < new_fpu) {
1141 jack_nframes_t new_page = (jack_nframes_t) floor (canvas_width * new_fpu);
1142 jack_nframes_t middle = (jack_nframes_t) floor( (double)start + ((double)range / 2.0f ));
1143 jack_nframes_t new_leftmost = (jack_nframes_t) floor( (double)middle - ((double)new_page/2.0f));
1145 if (new_leftmost > middle) new_leftmost = 0;
1147 // begin_reversible_command (op);
1148 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1149 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1150 // commit_reversible_command ();
1152 reposition_and_zoom (new_leftmost, new_fpu);
1156 Editor::temporal_zoom_to_frame (bool coarser, jack_nframes_t frame)
1158 if (!session) return;
1160 jack_nframes_t range_before = frame - leftmost_frame;
1163 new_fpu = frames_per_unit;
1169 new_fpu = max(1.0,(new_fpu/2.0));
1173 if (new_fpu == frames_per_unit) return;
1175 jack_nframes_t new_leftmost = frame - range_before;
1177 if (new_leftmost > frame) new_leftmost = 0;
1179 // begin_reversible_command (_("zoom to frame"));
1180 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1181 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1182 // commit_reversible_command ();
1184 reposition_and_zoom (new_leftmost, new_fpu);
1188 Editor::select_all_in_track (bool add)
1190 list<Selectable *> touched;
1192 if (!clicked_trackview) {
1196 clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1199 selection->add (touched);
1201 selection->set (touched);
1206 Editor::select_all (bool add)
1208 list<Selectable *> touched;
1210 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1211 if ((*iter)->hidden()) {
1214 (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1218 selection->add (touched);
1220 selection->set (touched);
1226 Editor::invert_selection_in_track ()
1228 list<Selectable *> touched;
1230 if (!clicked_trackview) {
1234 clicked_trackview->get_inverted_selectables (*selection, touched);
1235 selection->set (touched);
1239 Editor::invert_selection ()
1241 list<Selectable *> touched;
1243 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1244 if ((*iter)->hidden()) {
1247 (*iter)->get_inverted_selectables (*selection, touched);
1250 selection->set (touched);
1254 Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
1256 list<Selectable *> touched;
1258 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1259 if ((*iter)->hidden()) {
1262 (*iter)->get_selectables (start, end, top, bot, touched);
1266 selection->add (touched);
1268 selection->set (touched);
1271 return !touched.empty();
1275 Editor::set_selection_from_punch()
1279 if ((location = session->locations()->auto_punch_location()) == 0) {
1283 set_selection_from_range (*location);
1287 Editor::set_selection_from_loop()
1291 if ((location = session->locations()->auto_loop_location()) == 0) {
1295 set_selection_from_range (*location);
1299 Editor::set_selection_from_range (Location& range)
1301 if (clicked_trackview == 0) {
1305 begin_reversible_command (_("set selection from range"));
1306 selection->set (0, range.start(), range.end());
1307 commit_reversible_command ();
1311 Editor::amplitude_zoom_step (bool in)
1325 #ifdef FIX_FOR_CANVAS
1326 /* XXX DO SOMETHING */
1335 Editor::delete_sample_forward ()
1340 Editor::delete_sample_backward ()
1345 Editor::delete_screen ()
1352 Editor::search_backwards ()
1358 Editor::search_forwards ()
1366 Editor::jump_forward_to_mark ()
1372 Location *location = session->locations()->first_location_after (playhead_cursor->current_frame);
1375 session->request_locate (location->start(), session->transport_rolling());
1377 session->request_locate (session->current_end_frame());
1382 Editor::jump_backward_to_mark ()
1388 Location *location = session->locations()->first_location_before (playhead_cursor->current_frame);
1391 session->request_locate (location->start(), session->transport_rolling());
1393 session->request_locate (0);
1404 if (get_prefix (prefix, was_floating)) {
1405 pos = session->audible_frame ();
1408 pos = (jack_nframes_t) floor (prefix * session->frame_rate ());
1410 pos = (jack_nframes_t) floor (prefix);
1414 session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true);
1418 Editor::clear_markers ()
1421 session->begin_reversible_command (_("clear markers"));
1422 session->add_undo (session->locations()->get_memento());
1423 session->locations()->clear_markers ();
1424 session->add_redo_no_execute (session->locations()->get_memento());
1425 session->commit_reversible_command ();
1430 Editor::clear_ranges ()
1433 session->begin_reversible_command (_("clear ranges"));
1434 session->add_undo (session->locations()->get_memento());
1436 Location * looploc = session->locations()->auto_loop_location();
1437 Location * punchloc = session->locations()->auto_punch_location();
1439 session->locations()->clear_ranges ();
1441 if (looploc) session->locations()->add (looploc);
1442 if (punchloc) session->locations()->add (punchloc);
1444 session->add_redo_no_execute (session->locations()->get_memento());
1445 session->commit_reversible_command ();
1450 Editor::clear_locations ()
1452 session->begin_reversible_command (_("clear locations"));
1453 session->add_undo (session->locations()->get_memento());
1454 session->locations()->clear ();
1455 session->add_redo_no_execute (session->locations()->get_memento());
1456 session->commit_reversible_command ();
1457 session->locations()->clear ();
1460 /* INSERT/REPLACE */
1463 Editor::insert_region_list_drag (AudioRegion& region)
1469 jack_nframes_t where;
1470 AudioTimeAxisView *atv = 0;
1473 track_canvas.get_pointer (x, y);
1475 track_canvas.window_to_world (x, y, wx, wy);
1478 event.type = GDK_BUTTON_RELEASE;
1479 event.button.x = wx;
1480 event.button.y = wy;
1482 where = event_frame (&event, &cx, &cy);
1484 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1485 /* clearly outside canvas area */
1489 if ((tv = trackview_by_y_position (cy)) == 0) {
1493 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) == 0) {
1497 if ((playlist = atv->playlist()) == 0) {
1503 begin_reversible_command (_("insert dragged region"));
1504 session->add_undo (playlist->get_memento());
1505 playlist->add_region (*(new AudioRegion (region)), where, 1.0);
1506 session->add_redo_no_execute (playlist->get_memento());
1507 commit_reversible_command ();
1511 Editor::insert_region_list_selection (float times)
1513 AudioTimeAxisView *tv = 0;
1516 if (clicked_audio_trackview != 0) {
1517 tv = clicked_audio_trackview;
1518 } else if (!selection->tracks.empty()) {
1519 if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
1526 if ((playlist = tv->playlist()) == 0) {
1530 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
1532 if (selected.count_selected_rows() != 1) {
1536 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
1537 Region* region = (*i)[region_list_columns.region];
1539 begin_reversible_command (_("insert region"));
1540 session->add_undo (playlist->get_memento());
1541 playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times);
1542 session->add_redo_no_execute (playlist->get_memento());
1543 commit_reversible_command ();
1547 /* BUILT-IN EFFECTS */
1550 Editor::reverse_selection ()
1555 /* GAIN ENVELOPE EDITING */
1558 Editor::edit_envelope ()
1565 Editor::toggle_playback (bool with_abort)
1571 switch (session->slave_source()) {
1576 /* transport controlled by the master */
1580 if (session->is_auditioning()) {
1581 session->cancel_audition ();
1585 if (session->transport_rolling()) {
1586 session->request_stop (with_abort);
1587 if (session->get_auto_loop()) {
1588 session->request_auto_loop (false);
1591 session->request_transport_speed (1.0f);
1596 Editor::play_from_start ()
1598 session->request_locate (0, true);
1602 Editor::play_selection ()
1604 if (selection->time.empty()) {
1608 session->request_play_range (true);
1612 Editor::play_selected_region ()
1614 if (!selection->audio_regions.empty()) {
1615 AudioRegionView *rv = *(selection->audio_regions.begin());
1617 session->request_bounded_roll (rv->region.position(), rv->region.last_frame());
1622 Editor::toggle_loop_playback ()
1625 session->request_auto_loop (true);
1630 Editor::loop_selected_region ()
1632 if (!selection->audio_regions.empty()) {
1633 AudioRegionView *rv = *(selection->audio_regions.begin());
1636 if ((tll = transport_loop_location()) != 0) {
1638 tll->set (rv->region.position(), rv->region.last_frame());
1640 // enable looping, reposition and start rolling
1642 session->request_auto_loop (true);
1643 session->request_locate (tll->start(), false);
1644 session->request_transport_speed (1.0f);
1650 Editor::play_location (Location& location)
1652 if (location.start() <= location.end()) {
1656 session->request_bounded_roll (location.start(), location.end());
1660 Editor::loop_location (Location& location)
1662 if (location.start() <= location.end()) {
1668 if ((tll = transport_loop_location()) != 0) {
1669 tll->set (location.start(), location.end());
1671 // enable looping, reposition and start rolling
1672 session->request_auto_loop (true);
1673 session->request_locate (tll->start(), true);
1678 Editor::toggle_region_mute ()
1680 if (clicked_regionview) {
1681 clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
1682 } else if (!selection->audio_regions.empty()) {
1683 bool yn = ! (*selection->audio_regions.begin())->region.muted();
1684 selection->foreach_audio_region (&AudioRegion::set_muted, yn);
1689 Editor::toggle_region_opaque ()
1691 if (clicked_regionview) {
1692 clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
1693 } else if (!selection->audio_regions.empty()) {
1694 bool yn = ! (*selection->audio_regions.begin())->region.opaque();
1695 selection->foreach_audio_region (&Region::set_opaque, yn);
1700 Editor::raise_region ()
1702 selection->foreach_audio_region (&Region::raise);
1706 Editor::raise_region_to_top ()
1708 selection->foreach_audio_region (&Region::raise_to_top);
1712 Editor::lower_region ()
1714 selection->foreach_audio_region (&Region::lower);
1718 Editor::lower_region_to_bottom ()
1720 selection->foreach_audio_region (&Region::lower_to_bottom);
1724 Editor::edit_region ()
1726 if (clicked_regionview == 0) {
1730 clicked_regionview->show_region_editor ();
1734 Editor::rename_region ()
1738 Button ok_button (_("OK"));
1739 Button cancel_button (_("Cancel"));
1741 if (selection->audio_regions.empty()) {
1745 dialog.set_title (_("ardour: rename region"));
1746 dialog.set_name ("RegionRenameWindow");
1747 dialog.set_size_request (300, -1);
1748 dialog.set_position (Gtk::WIN_POS_MOUSE);
1749 dialog.set_modal (true);
1751 dialog.get_vbox()->set_border_width (10);
1752 dialog.get_vbox()->pack_start (entry);
1753 dialog.get_action_area()->pack_start (ok_button);
1754 dialog.get_action_area()->pack_start (cancel_button);
1756 entry.set_name ("RegionNameDisplay");
1757 ok_button.set_name ("EditorGTKButton");
1758 cancel_button.set_name ("EditorGTKButton");
1760 region_renamed = false;
1762 entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1763 ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1764 cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
1769 ARDOUR_UI::instance()->allow_focus (true);
1771 ARDOUR_UI::instance()->allow_focus (false);
1773 if (region_renamed) {
1774 (*selection->audio_regions.begin())->region.set_name (entry.get_text());
1775 redisplay_regions ();
1780 Editor::rename_region_finished (bool status)
1783 region_renamed = status;
1788 Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
1790 if (session->is_auditioning()) {
1791 session->cancel_audition ();
1794 // note: some potential for creativity here, because region doesn't
1795 // have to belong to the playlist that Route is handling
1797 // bool was_soloed = route.soloed();
1799 route.set_solo (true, this);
1801 session->request_bounded_roll (region.position(), region.position() + region.length());
1803 /* XXX how to unset the solo state ? */
1807 Editor::audition_selected_region ()
1809 if (!selection->audio_regions.empty()) {
1810 AudioRegionView* rv = *(selection->audio_regions.begin());
1811 session->audition_region (rv->region);
1816 Editor::audition_playlist_region_standalone (AudioRegion& region)
1818 session->audition_region (region);
1822 Editor::build_interthread_progress_window ()
1824 interthread_progress_window = new ArdourDialog (X_("interthread progress"));
1826 interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
1828 interthread_progress_vbox.set_border_width (10);
1829 interthread_progress_vbox.set_spacing (5);
1830 interthread_progress_vbox.pack_start (interthread_progress_label, false, false);
1831 interthread_progress_vbox.pack_start (interthread_progress_bar,false, false);
1832 interthread_progress_vbox.pack_start (interthread_cancel_button,false, false);
1834 interthread_cancel_button.add (interthread_cancel_label);
1836 interthread_cancel_button.signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
1838 interthread_progress_window->set_modal (true);
1839 interthread_progress_window->set_default_size (200, 100);
1840 interthread_progress_window->add (interthread_progress_vbox);
1844 Editor::interthread_cancel_clicked ()
1846 if (current_interthread_info) {
1847 current_interthread_info->cancel = true;
1852 Editor::_import_thread (void *arg)
1854 PBD::ThreadCreated (pthread_self(), X_("Import"));
1856 Editor *ed = (Editor *) arg;
1857 return ed->import_thread ();
1861 Editor::import_thread ()
1863 session->import_audiofile (import_status);
1868 Editor::import_progress_timeout (void *arg)
1870 interthread_progress_label.set_text (import_status.doing_what);
1872 if (import_status.freeze) {
1873 interthread_cancel_button.set_sensitive(false);
1875 interthread_cancel_button.set_sensitive(true);
1878 if (import_status.doing_what == "building peak files") {
1879 interthread_progress_bar.pulse ();
1882 interthread_progress_bar.set_fraction (import_status.progress/100);
1885 return !(import_status.done || import_status.cancel);
1889 Editor::import_audio (bool as_tracks)
1892 warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
1899 str =_("Import selected as tracks");
1901 str = _("Import selected to region list");
1904 SoundFileOmega sfdb (str);
1905 sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks));
1911 Editor::catch_new_audio_region (AudioRegion* ar)
1913 last_audio_region = ar;
1917 Editor::do_import (vector<string> paths, bool split, bool as_tracks)
1921 /* SFDB sets "multichan" to true to indicate "split channels"
1922 so reverse the setting to match the way libardour
1926 import_status.multichan = !split;
1928 if (interthread_progress_window == 0) {
1929 build_interthread_progress_window ();
1932 interthread_progress_window->set_title (_("ardour: audio import in progress"));
1933 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
1934 interthread_progress_window->show_all ();
1935 interthread_progress_bar.set_fraction (0.0f);
1936 interthread_cancel_label.set_text (_("Cancel Import"));
1937 current_interthread_info = &import_status;
1939 c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
1941 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
1943 interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
1945 import_status.pathname = (*i);
1946 import_status.done = false;
1947 import_status.cancel = false;
1948 import_status.freeze = false;
1949 import_status.done = 0.0;
1951 interthread_progress_connection =
1952 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
1954 last_audio_region = 0;
1956 pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
1957 pthread_detach (import_status.thread);
1959 while (!(import_status.done || import_status.cancel)) {
1960 gtk_main_iteration ();
1963 import_status.done = true;
1964 interthread_progress_connection.disconnect ();
1966 if (as_tracks && last_audio_region != 0) {
1967 uint32_t channels = last_audio_region->n_channels();
1969 AudioTrack* at = session->new_audio_track (channels, channels);
1970 AudioRegion* copy = new AudioRegion (*last_audio_region);
1971 at->disk_stream().playlist()->add_region (*copy, 0);
1976 interthread_progress_window->hide_all ();
1980 Editor::reject_because_rate_differs (string path, SF_INFO& finfo, string action, bool multiple_pending)
1986 if (finfo.samplerate != (int) session->frame_rate()) {
1987 vector<string> choices;
1989 choices.push_back (string_compose (_("%1 it anyway"), action));
1991 if (multiple_pending) {
1992 /* XXX assumptions about sentence structure
1993 here for translators. Sorry.
1995 choices.push_back (string_compose (_("Don't %1 it"), action));
1996 choices.push_back (string_compose (_("%1 all without questions"), action));
1997 choices.push_back (_("Cancel entire import"));
1999 choices.push_back (_("Cancel"));
2002 Gtkmm2ext::Choice rate_choice (
2003 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
2006 rate_choice.chosen.connect (Main::quit.slot());
2007 rate_choice.show_all ();
2011 switch (rate_choice.get_choice()) {
2012 case 0: /* do it anyway */
2014 case 1: /* don't import this one */
2016 case 2: /* do the rest without asking */
2018 case 3: /* stop a multi-file import */
2028 Editor::embed_audio ()
2031 warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
2035 SoundFileOmega sfdb (_("Add to External Region list"));
2036 sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
2042 Editor::do_embed_sndfiles (vector<string> paths, bool split)
2044 bool multiple_files = paths.size() > 1;
2045 bool check_sample_rate = true;
2047 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
2048 embed_sndfile (*i, split, multiple_files, check_sample_rate);
2051 session->save_state ("");
2055 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
2057 SndFileSource *source = 0; /* keep g++ quiet */
2058 AudioRegion::SourceList sources;
2064 /* lets see if we can link it into the session */
2066 linked_path = session->sound_dir();
2067 linked_path += PBD::basename (path);
2069 if (link (path.c_str(), linked_path.c_str()) == 0) {
2071 /* there are many reasons why link(2) might have failed.
2072 but if it succeeds, we now have a link in the
2073 session sound dir that will protect against
2074 unlinking of the original path. nice.
2080 memset (&finfo, 0, sizeof(finfo));
2082 /* note that we temporarily truncated _id at the colon */
2084 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2086 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2087 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
2093 if (check_sample_rate) {
2094 switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
2100 check_sample_rate = false;
2109 track_canvas_scroller.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2110 ARDOUR_UI::instance()->flush_pending ();
2112 /* make the proper number of channels in the region */
2114 for (int n=0; n < finfo.channels; ++n)
2117 idspec += string_compose(":%1", n);
2120 source = new SndFileSource (idspec.c_str());
2121 sources.push_back(source);
2124 catch (failed_constructor& err) {
2125 error << string_compose(_("could not open %1"), path) << endmsg;
2129 ARDOUR_UI::instance()->flush_pending ();
2132 if (sources.size() > 0) {
2134 string region_name = PBD::basename_nosuffix (path);
2135 region_name += "-0";
2137 /* The created region isn't dropped. It emits a signal
2138 that is picked up by the session.
2141 new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
2142 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2144 /* make sure we can see it in the list */
2146 /* its the second node, always */
2148 // GTK2FIX ?? is it still always the 2nd node
2150 TreeModel::Path path ("2");
2151 region_list_display.expand_row (path, true);
2153 ARDOUR_UI::instance()->flush_pending ();
2157 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
2161 Editor::insert_sndfile (bool as_tracks)
2163 // SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2169 // c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
2170 str = _("Insert selected as new tracks");
2176 if (clicked_audio_trackview == 0) {
2180 if (ensure_cursor (&pos)) {
2184 // c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
2185 str = _("Insert selected");
2188 // sfdb.run (str, false);
2193 Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
2197 bool multiple_files;
2198 bool check_sample_rate = true;
2200 multiple_files = paths.size() > 1;
2202 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
2204 memset (&finfo, 0, sizeof(finfo));
2206 if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
2208 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2209 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
2216 /* add a new track */
2218 if (check_sample_rate) {
2219 switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
2225 check_sample_rate = false;
2233 uint32_t input_chan = finfo.channels;
2234 uint32_t output_chan;
2236 if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
2237 output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
2239 output_chan = input_chan;
2242 (void) session->new_audio_track (input_chan, output_chan);
2245 /* get the last (most recently added) track view */
2247 AudioTimeAxisView* tv;
2249 if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
2250 fatal << _("programming error: ")
2251 << X_("last trackview after new_audio_track is not an audio track!")
2256 jack_nframes_t pos = 0;
2257 insert_sndfile_into (*p, true, tv, pos, false);
2262 Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
2264 for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
2265 insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
2270 Editor::insert_sndfile_into (string path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
2272 SndFileSource *source = 0; /* keep g++ quiet */
2273 AudioRegion::SourceList sources;
2278 memset (&finfo, 0, sizeof(finfo));
2280 /* note that we temporarily truncated _id at the colon */
2282 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2284 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2285 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
2291 if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
2295 track_canvas_scroller.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2296 ARDOUR_UI::instance()->flush_pending ();
2298 /* make the proper number of channels in the region */
2300 for (int n=0; n < finfo.channels; ++n)
2303 idspec += string_compose(":%1", n);
2306 source = new SndFileSource (idspec.c_str());
2307 sources.push_back(source);
2310 catch (failed_constructor& err) {
2311 error << string_compose(_("could not open %1"), path) << endmsg;
2315 ARDOUR_UI::instance()->flush_pending ();
2318 if (sources.size() > 0) {
2320 string region_name = region_name_from_path (PBD::basename (path));
2322 AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
2323 0, /* irrelevant these days */
2324 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2326 begin_reversible_command (_("insert sndfile"));
2327 session->add_undo (tv->playlist()->get_memento());
2328 tv->playlist()->add_region (*region, pos);
2329 session->add_redo_no_execute (tv->playlist()->get_memento());
2330 commit_reversible_command ();
2332 pos += sources[0]->length();
2334 ARDOUR_UI::instance()->flush_pending ();
2338 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
2343 Editor::region_from_selection ()
2345 if (clicked_trackview == 0) {
2349 if (selection->time.empty()) {
2353 jack_nframes_t start = selection->time[clicked_selection].start;
2354 jack_nframes_t end = selection->time[clicked_selection].end;
2356 jack_nframes_t selection_cnt = end - start + 1;
2358 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2360 AudioRegion *region;
2361 AudioRegion *current;
2365 jack_nframes_t internal_start;
2368 if ((pl = (*i)->playlist()) == 0) {
2372 if ((current_r = pl->top_region_at (start)) == 0) {
2376 if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
2377 internal_start = start - current->position();
2378 session->region_name (new_name, current->name(), true);
2379 region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
2385 Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
2387 if (selection->time.empty() || selection->tracks.empty()) {
2391 jack_nframes_t start = selection->time[clicked_selection].start;
2392 jack_nframes_t end = selection->time[clicked_selection].end;
2394 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2396 AudioRegion* current;
2399 jack_nframes_t internal_start;
2402 if ((playlist = (*i)->playlist()) == 0) {
2406 if ((current_r = playlist->top_region_at(start)) == 0) {
2410 if ((current = dynamic_cast<AudioRegion*>(current_r)) == 0) {
2414 internal_start = start - current->position();
2415 session->region_name (new_name, current->name(), true);
2417 new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name));
2422 Editor::split_multichannel_region ()
2424 vector<AudioRegion*> v;
2426 if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
2430 clicked_regionview->region.separate_by_channel (*session, v);
2432 /* nothing else to do, really */
2436 Editor::new_region_from_selection ()
2438 region_from_selection ();
2439 cancel_selection ();
2443 Editor::separate_region_from_selection ()
2445 bool doing_undo = false;
2447 if (selection->time.empty()) {
2453 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2455 AudioTimeAxisView* atv;
2457 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2459 if (atv->is_audio_track()) {
2461 if ((playlist = atv->playlist()) != 0) {
2463 begin_reversible_command (_("separate"));
2466 if (doing_undo) session->add_undo ((playlist)->get_memento());
2468 /* XXX need to consider musical time selections here at some point */
2470 double speed = atv->get_diskstream()->speed();
2472 for (list<AudioRange>::iterator t = selection->time.begin(); t != selection->time.end(); ++t) {
2473 playlist->partition ((jack_nframes_t)((*t).start * speed), (jack_nframes_t)((*t).end * speed), true);
2476 if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
2482 if (doing_undo) commit_reversible_command ();
2486 Editor::crop_region_to_selection ()
2488 if (selection->time.empty()) {
2492 vector<Playlist*> playlists;
2495 if (clicked_trackview != 0) {
2497 if ((playlist = clicked_trackview->playlist()) == 0) {
2501 playlists.push_back (playlist);
2505 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2507 AudioTimeAxisView* atv;
2509 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2511 if (atv->is_audio_track()) {
2513 if ((playlist = atv->playlist()) != 0) {
2514 playlists.push_back (playlist);
2521 if (!playlists.empty()) {
2523 jack_nframes_t start;
2527 begin_reversible_command (_("trim to selection"));
2529 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2533 start = selection->time.start();
2535 if ((region = (*i)->top_region_at(start)) == 0) {
2539 /* now adjust lengths to that we do the right thing
2540 if the selection extends beyond the region
2543 start = max (start, region->position());
2544 end = min (selection->time.end_frame(), start + region->length() - 1);
2545 cnt = end - start + 1;
2547 session->add_undo ((*i)->get_memento());
2548 region->trim_to (start, cnt, this);
2549 session->add_redo_no_execute ((*i)->get_memento());
2552 commit_reversible_command ();
2557 Editor::region_fill_track ()
2561 if (!session || selection->audio_regions.empty()) {
2565 end = session->current_end_frame ();
2567 begin_reversible_command (_("region fill"));
2569 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2571 AudioRegion& region ((*i)->region);
2572 Playlist* pl = region.playlist();
2574 if (end <= region.last_frame()) {
2578 double times = (double) (end - region.last_frame()) / (double) region.length();
2584 session->add_undo (pl->get_memento());
2585 pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
2586 session->add_redo_no_execute (pl->get_memento());
2589 commit_reversible_command ();
2593 Editor::region_fill_selection ()
2595 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2599 if (selection->time.empty()) {
2605 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
2607 if (selected.count_selected_rows() != 1) {
2611 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
2612 region = (*i)[region_list_columns.region];
2614 jack_nframes_t start = selection->time[clicked_selection].start;
2615 jack_nframes_t end = selection->time[clicked_selection].end;
2619 if (selection->tracks.empty()) {
2623 jack_nframes_t selection_length = end - start;
2624 float times = (float)selection_length / region->length();
2626 begin_reversible_command (_("fill selection"));
2628 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2630 if ((playlist = (*i)->playlist()) == 0) {
2634 session->add_undo (playlist->get_memento());
2635 playlist->add_region (*(createRegion (*region)), start, times);
2636 session->add_redo_no_execute (playlist->get_memento());
2639 commit_reversible_command ();
2643 Editor::set_region_sync_from_edit_cursor ()
2645 if (clicked_regionview == 0) {
2649 if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
2650 error << _("Place the edit cursor at the desired sync point") << endmsg;
2654 Region& region (clicked_regionview->region);
2656 begin_reversible_command (_("set sync from edit cursor"));
2657 session->add_undo (region.playlist()->get_memento());
2658 region.set_sync_position (edit_cursor->current_frame);
2659 session->add_redo_no_execute (region.playlist()->get_memento());
2660 commit_reversible_command ();
2664 Editor::remove_region_sync ()
2666 if (clicked_regionview) {
2667 Region& region (clicked_regionview->region);
2668 begin_reversible_command (_("remove sync"));
2669 session->add_undo (region.playlist()->get_memento());
2670 region.clear_sync_position ();
2671 session->add_redo_no_execute (region.playlist()->get_memento());
2672 commit_reversible_command ();
2677 Editor::naturalize ()
2679 if (selection->audio_regions.empty()) {
2682 begin_reversible_command (_("naturalize"));
2683 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2684 session->add_undo ((*i)->region.get_memento());
2685 (*i)->region.move_to_natural_position (this);
2686 session->add_redo_no_execute ((*i)->region.get_memento());
2688 commit_reversible_command ();
2692 Editor::align (RegionPoint what)
2694 align_selection (what, edit_cursor->current_frame);
2698 Editor::align_relative (RegionPoint what)
2700 align_selection_relative (what, edit_cursor->current_frame);
2703 struct RegionSortByTime {
2704 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
2705 return a->region.position() < b->region.position();
2710 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
2712 if (selection->audio_regions.empty()) {
2716 jack_nframes_t distance;
2717 jack_nframes_t pos = 0;
2720 list<AudioRegionView*> sorted;
2721 selection->audio_regions.by_position (sorted);
2722 Region& r ((*sorted.begin())->region);
2726 pos = r.first_frame ();
2730 pos = r.last_frame();
2734 pos = r.adjust_to_sync (r.first_frame());
2738 if (pos > position) {
2739 distance = pos - position;
2742 distance = position - pos;
2746 begin_reversible_command (_("align selection (relative)"));
2748 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2750 Region& region ((*i)->region);
2752 session->add_undo (region.playlist()->get_memento());
2755 region.set_position (region.position() + distance, this);
2757 region.set_position (region.position() - distance, this);
2760 session->add_redo_no_execute (region.playlist()->get_memento());
2764 commit_reversible_command ();
2768 Editor::align_selection (RegionPoint point, jack_nframes_t position)
2770 if (selection->audio_regions.empty()) {
2774 begin_reversible_command (_("align selection"));
2776 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2777 align_region_internal ((*i)->region, point, position);
2780 commit_reversible_command ();
2784 Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position)
2786 begin_reversible_command (_("align region"));
2787 align_region_internal (region, point, position);
2788 commit_reversible_command ();
2792 Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position)
2794 session->add_undo (region.playlist()->get_memento());
2798 region.set_position (region.adjust_to_sync (position), this);
2802 if (position > region.length()) {
2803 region.set_position (position - region.length(), this);
2808 region.set_position (position, this);
2812 session->add_redo_no_execute (region.playlist()->get_memento());
2816 Editor::trim_region_to_edit_cursor ()
2818 if (clicked_regionview == 0) {
2822 Region& region (clicked_regionview->region);
2825 AudioTimeAxisView *atav;
2827 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2828 if (atav->get_diskstream() != 0) {
2829 speed = atav->get_diskstream()->speed();
2833 begin_reversible_command (_("trim to edit"));
2834 session->add_undo (region.playlist()->get_memento());
2835 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2836 session->add_redo_no_execute (region.playlist()->get_memento());
2837 commit_reversible_command ();
2841 Editor::trim_region_from_edit_cursor ()
2843 if (clicked_regionview == 0) {
2847 Region& region (clicked_regionview->region);
2850 AudioTimeAxisView *atav;
2852 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2853 if (atav->get_diskstream() != 0) {
2854 speed = atav->get_diskstream()->speed();
2858 begin_reversible_command (_("trim to edit"));
2859 session->add_undo (region.playlist()->get_memento());
2860 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2861 session->add_redo_no_execute (region.playlist()->get_memento());
2862 commit_reversible_command ();
2866 Editor::unfreeze_route ()
2868 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2872 clicked_audio_trackview->audio_track()->unfreeze ();
2876 Editor::_freeze_thread (void* arg)
2878 PBD::ThreadCreated (pthread_self(), X_("Freeze"));
2879 return static_cast<Editor*>(arg)->freeze_thread ();
2883 Editor::freeze_thread ()
2885 clicked_audio_trackview->audio_track()->freeze (*current_interthread_info);
2890 Editor::freeze_progress_timeout (void *arg)
2892 interthread_progress_bar.set_fraction (current_interthread_info->progress/100);
2893 return !(current_interthread_info->done || current_interthread_info->cancel);
2897 Editor::freeze_route ()
2899 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2903 InterThreadInfo itt;
2905 if (interthread_progress_window == 0) {
2906 build_interthread_progress_window ();
2909 interthread_progress_window->set_title (_("ardour: freeze"));
2910 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2911 interthread_progress_window->show_all ();
2912 interthread_progress_bar.set_fraction (0.0f);
2913 interthread_progress_label.set_text ("");
2914 interthread_cancel_label.set_text (_("Cancel Freeze"));
2915 current_interthread_info = &itt;
2917 interthread_progress_connection =
2918 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
2922 itt.progress = 0.0f;
2924 pthread_create (&itt.thread, 0, _freeze_thread, this);
2926 track_canvas_scroller.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2928 while (!itt.done && !itt.cancel) {
2929 gtk_main_iteration ();
2932 interthread_progress_connection.disconnect ();
2933 interthread_progress_window->hide_all ();
2934 current_interthread_info = 0;
2935 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
2939 Editor::bounce_range_selection ()
2941 if (selection->time.empty()) {
2945 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
2947 jack_nframes_t start = selection->time[clicked_selection].start;
2948 jack_nframes_t end = selection->time[clicked_selection].end;
2949 jack_nframes_t cnt = end - start + 1;
2951 begin_reversible_command (_("bounce range"));
2953 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
2955 AudioTimeAxisView* atv;
2957 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
2963 if ((playlist = atv->playlist()) == 0) {
2967 InterThreadInfo itt;
2971 itt.progress = false;
2973 session->add_undo (playlist->get_memento());
2974 atv->audio_track()->bounce_range (start, cnt, itt);
2975 session->add_redo_no_execute (playlist->get_memento());
2978 commit_reversible_command ();
2996 Editor::cut_copy (CutCopyOp op)
2998 /* only cancel selection if cut/copy is successful.*/
3010 opname = _("clear");
3014 cut_buffer->clear ();
3016 switch (current_mouse_mode()) {
3018 if (!selection->audio_regions.empty() || !selection->points.empty()) {
3020 begin_reversible_command (opname + _(" objects"));
3022 if (!selection->audio_regions.empty()) {
3024 cut_copy_regions (op);
3027 selection->clear_audio_regions ();
3031 if (!selection->points.empty()) {
3032 cut_copy_points (op);
3035 selection->clear_points ();
3039 commit_reversible_command ();
3044 if (!selection->time.empty()) {
3046 begin_reversible_command (opname + _(" range"));
3047 cut_copy_ranges (op);
3048 commit_reversible_command ();
3051 selection->clear_time ();
3063 Editor::cut_copy_points (CutCopyOp op)
3065 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3067 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
3070 atv->cut_copy_clear_objects (selection->points, op);
3076 Editor::cut_copy_regions (CutCopyOp op)
3078 typedef std::map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
3079 PlaylistMapping pmap;
3080 jack_nframes_t first_position = max_frames;
3081 set<Playlist*> freezelist;
3082 pair<set<Playlist*>::iterator,bool> insert_result;
3084 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
3085 first_position = min ((*x)->region.position(), first_position);
3087 if (op == Cut || op == Clear) {
3088 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3090 insert_result = freezelist.insert (pl);
3091 if (insert_result.second) {
3093 session->add_undo (pl->get_memento());
3099 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
3101 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3103 AudioRegionSelection::iterator tmp;
3110 PlaylistMapping::iterator pi = pmap.find (pl);
3112 if (pi == pmap.end()) {
3113 npl = new AudioPlaylist (*session, "cutlist", true);
3122 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3123 pl->remove_region (&((*x)->region));
3127 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3131 pl->remove_region (&((*x)->region));
3139 list<Playlist*> foo;
3141 for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3142 foo.push_back (i->second);
3146 cut_buffer->set (foo);
3149 for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3151 session->add_redo_no_execute ((*pl)->get_memento());
3156 Editor::cut_copy_ranges (CutCopyOp op)
3158 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3159 (*i)->cut_copy_clear (*selection, op);
3164 Editor::paste (float times)
3166 paste_internal (edit_cursor->current_frame, times);
3170 Editor::mouse_paste ()
3174 track_canvas.get_pointer (x, y);
3175 track_canvas.window_to_world (x, y, wx, wy);
3177 event.type = GDK_BUTTON_RELEASE;
3178 event.button.x = wx;
3179 event.button.y = wy;
3181 jack_nframes_t where = event_frame (&event, 0, 0);
3183 paste_internal (where, 1);
3187 Editor::paste_internal (jack_nframes_t position, float times)
3189 bool commit = false;
3191 if (cut_buffer->empty() || selection->tracks.empty()) {
3195 if (position == max_frames) {
3196 position = edit_cursor->current_frame;
3199 begin_reversible_command (_("paste"));
3201 TrackSelection::iterator i;
3204 for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) {
3206 /* undo/redo is handled by individual tracks */
3208 if ((*i)->paste (position, times, *cut_buffer, nth)) {
3214 commit_reversible_command ();
3219 Editor::paste_named_selection (float times)
3221 TrackSelection::iterator i;
3223 Glib::RefPtr<TreeSelection> selected = named_selection_display.get_selection();
3225 if (selected.count_selected_rows() == 0 || selection->tracks.empty()) {
3229 TreeModel::iterator i = selected->get_selected();
3230 NamedSelection* ns = (*i)[named_selection_columns.selection];
3232 list<Playlist*>::iterator chunk;
3233 list<Playlist*>::iterator tmp;
3235 chunk = ns->playlists.begin();
3237 begin_reversible_command (_("paste chunk"));
3239 for (i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3241 AudioTimeAxisView* atv;
3245 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
3249 if ((pl = atv->playlist()) == 0) {
3253 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
3260 session->add_undo (apl->get_memento());
3261 apl->paste (**chunk, edit_cursor->current_frame, times);
3262 session->add_redo_no_execute (apl->get_memento());
3264 if (tmp != ns->playlists.end()) {
3269 commit_reversible_command();
3273 Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
3277 begin_reversible_command (_("duplicate region"));
3279 for (AudioRegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
3281 Region& r ((*i)->region);
3283 playlist = (*i)->region.playlist();
3284 session->add_undo (playlist->get_memento());
3285 playlist->duplicate (r, r.last_frame(), times);
3286 session->add_redo_no_execute (playlist->get_memento());
3290 commit_reversible_command ();
3294 Editor::duplicate_selection (float times)
3296 if (selection->time.empty() || selection->tracks.empty()) {
3301 vector<AudioRegion*> new_regions;
3302 vector<AudioRegion*>::iterator ri;
3304 create_region_from_selection (new_regions);
3306 if (new_regions.empty()) {
3310 begin_reversible_command (_("duplicate selection"));
3312 ri = new_regions.begin();
3314 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3315 if ((playlist = (*i)->playlist()) == 0) {
3318 session->add_undo (playlist->get_memento());
3319 playlist->duplicate (**ri, selection->time[clicked_selection].end, times);
3320 session->add_redo_no_execute (playlist->get_memento());
3323 if (ri == new_regions.end()) {
3328 commit_reversible_command ();
3332 Editor::center_playhead ()
3334 float page = canvas_width * frames_per_unit;
3336 center_screen_internal (playhead_cursor->current_frame, page);
3340 Editor::center_edit_cursor ()
3342 float page = canvas_width * frames_per_unit;
3344 center_screen_internal (edit_cursor->current_frame, page);
3348 Editor::clear_playlist (Playlist& playlist)
3350 begin_reversible_command (_("clear playlist"));
3351 session->add_undo (playlist.get_memento());
3353 session->add_redo_no_execute (playlist.get_memento());
3354 commit_reversible_command ();
3358 Editor::nudge_track (bool use_edit_cursor, bool forwards)
3361 jack_nframes_t distance;
3362 jack_nframes_t next_distance;
3363 jack_nframes_t start;
3365 if (use_edit_cursor) {
3366 start = edit_cursor->current_frame;
3371 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
3375 if (selection->tracks.empty()) {
3379 begin_reversible_command (_("nudge track"));
3381 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3383 if ((playlist = (*i)->playlist()) == 0) {
3387 session->add_undo (playlist->get_memento());
3388 playlist->nudge_after (start, distance, forwards);
3389 session->add_redo_no_execute (playlist->get_memento());
3392 commit_reversible_command ();
3396 Editor::toggle_xfades_active ()
3399 session->set_crossfades_active (!session->get_crossfades_active());
3404 Editor::toggle_follow_playhead ()
3406 set_follow_playhead (!_follow_playhead);
3410 Editor::set_xfade_visibility (bool yn)
3416 Editor::toggle_xfade_visibility ()
3418 set_xfade_visibility (!xfade_visibility());
3422 Editor::remove_last_capture ()
3424 vector<string> choices;
3431 if (Config->get_verify_remove_last_capture()) {
3432 prompt = _("Do you really want to destroy the last capture?"
3433 "\n(This is destructive and cannot be undone)");
3435 choices.push_back (_("Yes, destroy it."));
3436 choices.push_back (_("No, do nothing."));
3438 Gtkmm2ext::Choice prompter (prompt, choices);
3439 prompter.done.connect (Gtk::Main::quit.slot());
3440 prompter.show_all ();
3444 if (prompter.get_choice() == 0) {
3445 session->remove_last_capture ();
3448 session->remove_last_capture();
3453 Editor::normalize_region ()
3459 if (selection->audio_regions.empty()) {
3463 begin_reversible_command (_("normalize"));
3465 track_canvas_scroller.get_window()->set_cursor (*wait_cursor);
3468 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3469 session->add_undo ((*r)->region.get_memento());
3470 (*r)->region.normalize_to (0.0f);
3471 session->add_redo_no_execute ((*r)->region.get_memento());
3474 commit_reversible_command ();
3475 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
3480 Editor::denormalize_region ()
3486 if (selection->audio_regions.empty()) {
3490 begin_reversible_command ("denormalize");
3492 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3493 session->add_undo ((*r)->region.get_memento());
3494 (*r)->region.set_scale_amplitude (1.0f);
3495 session->add_redo_no_execute ((*r)->region.get_memento());
3498 commit_reversible_command ();
3503 Editor::reverse_region ()
3509 Reverse rev (*session);
3510 apply_filter (rev, _("reverse regions"));
3514 Editor::apply_filter (AudioFilter& filter, string command)
3516 if (selection->audio_regions.empty()) {
3520 begin_reversible_command (command);
3522 track_canvas_scroller.get_window()->set_cursor (*wait_cursor);
3525 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
3527 AudioRegion& region ((*r)->region);
3528 Playlist* playlist = region.playlist();
3530 AudioRegionSelection::iterator tmp;
3535 if (region.apply (filter) == 0) {
3537 session->add_undo (playlist->get_memento());
3538 playlist->replace_region (region, *(filter.results.front()), region.position());
3539 session->add_redo_no_execute (playlist->get_memento());
3547 commit_reversible_command ();
3548 selection->audio_regions.clear ();
3551 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
3555 Editor::region_selection_op (void (Region::*pmf)(void))
3557 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3558 ((*i)->region.*pmf)();
3564 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
3566 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3567 ((*i)->region.*pmf)(arg);
3572 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
3574 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3575 ((*i)->region.*pmf)(yn);
3580 Editor::external_edit_region ()
3582 if (!clicked_regionview) {
3590 Editor::brush (jack_nframes_t pos)
3592 AudioRegionSelection sel;
3595 if (selection->audio_regions.empty()) {
3596 /* XXX get selection from region list */
3598 sel = selection->audio_regions;
3605 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3606 mouse_brush_insert_region ((*i), pos);
3611 Editor::toggle_gain_envelope_visibility ()
3613 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3614 (*i)->set_envelope_visible (!(*i)->envelope_visible());
3619 Editor::toggle_gain_envelope_active ()
3621 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3622 AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
3624 ar->set_envelope_active (true);