2 Copyright (C) 2000-2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <pbd/error.h>
31 #include <pbd/basename.h>
32 #include <pbd/pthread_utils.h>
34 #include <gtkmm2ext/utils.h>
35 #include <gtkmm2ext/choice.h>
37 #include <ardour/audioengine.h>
38 #include <ardour/session.h>
39 #include <ardour/audioplaylist.h>
40 #include <ardour/audioregion.h>
41 #include <ardour/diskstream.h>
42 #include <ardour/filesource.h>
43 #include <ardour/sndfilesource.h>
44 #include <ardour/utils.h>
45 #include <ardour/location.h>
46 #include <ardour/named_selection.h>
47 #include <ardour/audio_track.h>
48 #include <ardour/audioplaylist.h>
49 #include <ardour/region_factory.h>
50 #include <ardour/reverse.h>
52 #include "ardour_ui.h"
54 #include "time_axis_view.h"
55 #include "audio_time_axis.h"
56 #include "automation_time_axis.h"
57 #include "streamview.h"
58 #include "regionview.h"
59 #include "rgb_macros.h"
60 #include "selection_templates.h"
61 #include "selection.h"
64 #include "gtk-custom-hruler.h"
69 using namespace ARDOUR;
72 using namespace Editing;
74 /***********************************************************************
76 ***********************************************************************/
79 Editor::undo (uint32_t n)
87 Editor::redo (uint32_t n)
95 Editor::ensure_cursor (jack_nframes_t *pos)
97 *pos = edit_cursor->current_frame;
102 Editor::split_region ()
104 split_region_at (edit_cursor->current_frame);
108 Editor::split_region_at (jack_nframes_t where)
110 split_regions_at (where, selection->audio_regions);
114 Editor::split_regions_at (jack_nframes_t where, AudioRegionSelection& regions)
116 begin_reversible_command (_("split"));
119 for (AudioRegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
121 AudioRegionSelection::iterator tmp;
126 Playlist* pl = (*a)->region.playlist();
128 _new_regionviews_show_envelope = (*a)->envelope_visible();
131 session->add_undo (pl->get_memento());
132 pl->split_region ((*a)->region, where);
133 session->add_redo_no_execute (pl->get_memento());
139 commit_reversible_command ();
140 _new_regionviews_show_envelope = false;
144 Editor::remove_clicked_region ()
146 if (clicked_audio_trackview == 0 || clicked_regionview == 0) {
150 Playlist* playlist = clicked_audio_trackview->playlist();
152 begin_reversible_command (_("remove region"));
153 session->add_undo (playlist->get_memento());
154 playlist->remove_region (&clicked_regionview->region);
155 session->add_redo_no_execute (playlist->get_memento());
156 commit_reversible_command ();
160 Editor::destroy_clicked_region ()
162 int32_t selected = selection->audio_regions.size();
164 if (!session || clicked_regionview == 0 && selected == 0) {
168 vector<string> choices;
171 prompt = string_compose (_(" This is destructive, will possibly delete audio files\n\
172 It cannot be undone\n\
173 Do you really want to destroy %1 ?"),
175 _("these regions") : _("this region")));
178 choices.push_back (_("Yes, destroy them."));
180 choices.push_back (_("Yes, destroy it."));
183 choices.push_back (_("No, do nothing."));
185 Gtkmm2ext::Choice prompter (prompt, choices);
187 prompter.chosen.connect (Gtk::Main::quit.slot());
188 prompter.show_all ();
192 if (prompter.get_choice() != 0) {
199 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
200 r.push_back (&(*i)->region);
203 session->destroy_regions (r);
205 } else if (clicked_regionview) {
206 session->destroy_region (&clicked_regionview->region);
211 Editor::select_region_for_operation (int dir, TimeAxisView **tv)
215 jack_nframes_t start = 0;
217 if (selection->time.start () == selection->time.end_frame ()) {
219 /* no current selection-> is there a selected regionview? */
221 if (selection->audio_regions.empty()) {
229 if (!selection->audio_regions.empty()) {
231 rv = *(selection->audio_regions.begin());
232 (*tv) = &rv->get_time_axis_view();
233 region = &rv->region;
235 } else if (!selection->tracks.empty()) {
237 (*tv) = selection->tracks.front();
239 AudioTimeAxisView* atv;
241 if ((atv = dynamic_cast<AudioTimeAxisView*> (*tv)) != 0) {
244 if ((pl = atv->playlist()) == 0) {
248 region = dynamic_cast<AudioRegion*> (pl->top_region_at (start));
256 Editor::extend_selection_to_end_of_region (bool next)
260 jack_nframes_t start;
262 if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) {
266 if (region && selection->time.start () == selection->time.end_frame ()) {
267 start = region->position();
269 start = selection->time.start ();
272 /* Try to leave the selection with the same route if possible */
274 if ((tv = selection->time.track) == 0) {
278 begin_reversible_command (_("extend selection"));
279 selection->set (tv, start, region->position() + region->length());
280 commit_reversible_command ();
284 Editor::extend_selection_to_start_of_region (bool previous)
290 if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) {
294 if (region && selection->time.start () == selection->time.end_frame ()) {
295 end = region->position() + region->length();
297 end = selection->time.end_frame ();
300 /* Try to leave the selection with the same route if possible */
302 if ((tv = selection->time.track) == 0) {
306 begin_reversible_command (_("extend selection"));
307 selection->set (tv, region->position(), end);
308 commit_reversible_command ();
313 Editor::nudge_forward (bool next)
315 jack_nframes_t distance;
316 jack_nframes_t next_distance;
318 if (!session) return;
320 if (!selection->audio_regions.empty()) {
322 begin_reversible_command (_("nudge forward"));
324 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
325 AudioRegion& r ((*i)->region);
327 distance = get_nudge_distance (r.position(), next_distance);
330 distance = next_distance;
333 session->add_undo (r.playlist()->get_memento());
334 r.set_position (r.position() + distance, this);
335 session->add_redo_no_execute (r.playlist()->get_memento());
338 commit_reversible_command ();
341 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
342 session->request_locate (playhead_cursor->current_frame + distance);
347 Editor::nudge_backward (bool next)
349 jack_nframes_t distance;
350 jack_nframes_t next_distance;
352 if (!session) return;
354 if (!selection->audio_regions.empty()) {
356 begin_reversible_command (_("nudge forward"));
358 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
359 AudioRegion& r ((*i)->region);
361 distance = get_nudge_distance (r.position(), next_distance);
364 distance = next_distance;
367 session->add_undo (r.playlist()->get_memento());
369 if (r.position() > distance) {
370 r.set_position (r.position() - distance, this);
372 r.set_position (0, this);
374 session->add_redo_no_execute (r.playlist()->get_memento());
377 commit_reversible_command ();
381 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
383 if (playhead_cursor->current_frame > distance) {
384 session->request_locate (playhead_cursor->current_frame - distance);
386 session->request_locate (0);
392 Editor::nudge_forward_capture_offset ()
394 jack_nframes_t distance;
396 if (!session) return;
398 if (!selection->audio_regions.empty()) {
400 begin_reversible_command (_("nudge forward"));
402 distance = session->worst_output_latency();
404 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
405 AudioRegion& r ((*i)->region);
407 session->add_undo (r.playlist()->get_memento());
408 r.set_position (r.position() + distance, this);
409 session->add_redo_no_execute (r.playlist()->get_memento());
412 commit_reversible_command ();
418 Editor::nudge_backward_capture_offset ()
420 jack_nframes_t distance;
422 if (!session) return;
424 if (!selection->audio_regions.empty()) {
426 begin_reversible_command (_("nudge forward"));
428 distance = session->worst_output_latency();
430 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
431 AudioRegion& r ((*i)->region);
433 session->add_undo (r.playlist()->get_memento());
435 if (r.position() > distance) {
436 r.set_position (r.position() - distance, this);
438 r.set_position (0, this);
440 session->add_redo_no_execute (r.playlist()->get_memento());
443 commit_reversible_command ();
450 Editor::move_to_start ()
452 session->request_locate (0);
456 Editor::move_to_end ()
459 session->request_locate (session->current_end_frame());
463 Editor::build_region_boundary_cache ()
465 jack_nframes_t pos = 0;
468 TrackViewList tracks;
470 region_boundary_cache.clear ();
477 case SnapToRegionStart:
480 case SnapToRegionEnd:
483 case SnapToRegionSync:
486 case SnapToRegionBoundary:
490 fatal << string_compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type) << endmsg;
495 TimeAxisView *ontrack = 0;
497 while (pos < session->current_end_frame()) {
499 if (!selection->tracks.empty()) {
501 if ((r = find_next_region (pos, point, 1, selection->tracks, &ontrack)) == 0) {
505 } else if (clicked_trackview) {
508 t.push_back (clicked_trackview);
510 if ((r = find_next_region (pos, point, 1, t, &ontrack)) == 0) {
516 if ((r = find_next_region (pos, point, 1, track_views, &ontrack)) == 0) {
524 case SnapToRegionStart:
525 rpos = r->first_frame();
527 case SnapToRegionEnd:
528 rpos = r->last_frame();
530 case SnapToRegionSync:
531 rpos = r->adjust_to_sync (r->first_frame());
534 case SnapToRegionBoundary:
535 rpos = r->last_frame();
542 AudioTimeAxisView *atav;
544 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
545 if (atav->get_diskstream() != 0) {
546 speed = atav->get_diskstream()->speed();
550 rpos = (jack_nframes_t) floor ( (float) rpos / speed );
552 if (region_boundary_cache.empty() || rpos != region_boundary_cache.back()) {
553 if (snap_type == SnapToRegionBoundary) {
554 region_boundary_cache.push_back (r->first_frame());
556 region_boundary_cache.push_back (rpos);
564 Editor::find_next_region (jack_nframes_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack)
566 TrackViewList::iterator i;
567 jack_nframes_t closest = max_frames;
569 jack_nframes_t rpos = 0;
572 jack_nframes_t track_frame;
573 AudioTimeAxisView *atav;
575 for (i = tracks.begin(); i != tracks.end(); ++i) {
577 jack_nframes_t distance;
581 if ( (atav = dynamic_cast<AudioTimeAxisView*>(*i)) != 0 ) {
582 if (atav->get_diskstream()!=0)
583 track_speed = atav->get_diskstream()->speed();
586 track_frame = (jack_nframes_t) floor ( (float) frame * track_speed );
588 if ((r = (*i)->find_next_region (track_frame, point, dir)) == 0) {
594 rpos = r->first_frame ();
598 rpos = r->last_frame ();
602 rpos = r->adjust_to_sync (r->first_frame());
605 // rpos is a "track frame", converting it to "time frame"
606 rpos = (jack_nframes_t) floor ( (float) rpos / track_speed );
609 distance = rpos - frame;
611 distance = frame - rpos;
614 if (distance < closest) {
626 Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir)
629 jack_nframes_t pos = cursor->current_frame;
635 TimeAxisView *ontrack = 0;
637 // so we don't find the current region again..
641 if (!selection->tracks.empty()) {
643 r = find_next_region (pos, point, dir, selection->tracks, &ontrack);
645 } else if (clicked_trackview) {
648 t.push_back (clicked_trackview);
650 r = find_next_region (pos, point, dir, t, &ontrack);
654 r = find_next_region (pos, point, dir, track_views, &ontrack);
663 pos = r->first_frame ();
667 pos = r->last_frame ();
671 pos = r->adjust_to_sync (r->first_frame());
676 AudioTimeAxisView *atav;
678 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
679 if (atav->get_diskstream() != 0) {
680 speed = atav->get_diskstream()->speed();
684 pos = (jack_nframes_t) floor ( (float) pos / speed );
687 if (cursor == playhead_cursor) {
688 session->request_locate (pos);
690 cursor->set_position (pos);
695 Editor::cursor_to_next_region_point (Cursor* cursor, RegionPoint point)
697 cursor_to_region_point (cursor, point, 1);
701 Editor::cursor_to_previous_region_point (Cursor* cursor, RegionPoint point)
703 cursor_to_region_point (cursor, point, -1);
707 Editor::cursor_to_selection_start (Cursor *cursor)
709 jack_nframes_t pos = 0;
710 switch (mouse_mode) {
712 if (!selection->audio_regions.empty()) {
713 pos = selection->audio_regions.start();
718 if (!selection->time.empty()) {
719 pos = selection->time.start ();
727 if (cursor == playhead_cursor) {
728 session->request_locate (pos);
730 cursor->set_position (pos);
735 Editor::cursor_to_selection_end (Cursor *cursor)
737 jack_nframes_t pos = 0;
739 switch (mouse_mode) {
741 if (!selection->audio_regions.empty()) {
742 pos = selection->audio_regions.end_frame();
747 if (!selection->time.empty()) {
748 pos = selection->time.end_frame ();
756 if (cursor == playhead_cursor) {
757 session->request_locate (pos);
759 cursor->set_position (pos);
764 Editor::playhead_backward ()
771 if (get_prefix (prefix, was_floating)) {
775 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
777 cnt = (jack_nframes_t) prefix;
781 pos = playhead_cursor->current_frame;
783 if ((jack_nframes_t) pos < cnt) {
789 /* XXX this is completely insane. with the current buffering
790 design, we'll force a complete track buffer flush and
791 reload, just to move 1 sample !!!
794 session->request_locate (pos);
798 Editor::playhead_forward ()
805 if (get_prefix (prefix, was_floating)) {
809 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
811 cnt = (jack_nframes_t) floor (prefix);
815 pos = playhead_cursor->current_frame;
817 /* XXX this is completely insane. with the current buffering
818 design, we'll force a complete track buffer flush and
819 reload, just to move 1 sample !!!
822 session->request_locate (pos+cnt);
826 Editor::cursor_align (bool playhead_to_edit)
828 if (playhead_to_edit) {
830 session->request_locate (edit_cursor->current_frame);
833 edit_cursor->set_position (playhead_cursor->current_frame);
838 Editor::edit_cursor_backward ()
845 if (get_prefix (prefix, was_floating)) {
849 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
851 cnt = (jack_nframes_t) prefix;
855 pos = edit_cursor->current_frame;
857 if ((jack_nframes_t) pos < cnt) {
863 edit_cursor->set_position (pos);
867 Editor::edit_cursor_forward ()
874 if (get_prefix (prefix, was_floating)) {
878 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
880 cnt = (jack_nframes_t) floor (prefix);
884 pos = edit_cursor->current_frame;
885 edit_cursor->set_position (pos+cnt);
889 Editor::goto_frame ()
893 jack_nframes_t frame;
895 if (get_prefix (prefix, was_floating)) {
900 frame = (jack_nframes_t) floor (prefix * session->frame_rate());
902 frame = (jack_nframes_t) floor (prefix);
905 session->request_locate (frame);
909 Editor::scroll_backward (float pages)
911 jack_nframes_t frame;
912 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
917 if (get_prefix (prefix, was_floating)) {
918 cnt = (jack_nframes_t) floor (pages * one_page);
921 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
923 cnt = (jack_nframes_t) floor (prefix * one_page);
927 if (leftmost_frame < cnt) {
930 frame = leftmost_frame - cnt;
933 reposition_x_origin (frame);
937 Editor::scroll_forward (float pages)
939 jack_nframes_t frame;
940 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
945 if (get_prefix (prefix, was_floating)) {
946 cnt = (jack_nframes_t) floor (pages * one_page);
949 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
951 cnt = (jack_nframes_t) floor (prefix * one_page);
955 if (ULONG_MAX - cnt < leftmost_frame) {
956 frame = ULONG_MAX - cnt;
958 frame = leftmost_frame + cnt;
961 reposition_x_origin (frame);
965 Editor::scroll_tracks_down ()
971 if (get_prefix (prefix, was_floating)) {
974 cnt = (int) floor (prefix);
977 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
978 adj->set_value (adj->get_value() + (cnt * adj->get_page_size()));
982 Editor::scroll_tracks_up ()
988 if (get_prefix (prefix, was_floating)) {
991 cnt = (int) floor (prefix);
994 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
995 adj->set_value (adj->get_value() - (cnt * adj->get_page_size()));
999 Editor::scroll_tracks_down_line ()
1001 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
1002 adj->set_value (adj->get_value() + 10);
1006 Editor::scroll_tracks_up_line ()
1008 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
1009 adj->set_value (adj->get_value() - 10);
1015 Editor::temporal_zoom_step (bool coarser)
1019 nfpu = frames_per_unit;
1024 nfpu = max(1.0,(nfpu/2.0));
1027 temporal_zoom (nfpu);
1031 Editor::temporal_zoom (gdouble fpu)
1033 if (!session) return;
1035 jack_nframes_t current_page = current_page_frames();
1036 jack_nframes_t current_leftmost = leftmost_frame;
1037 jack_nframes_t current_rightmost;
1038 jack_nframes_t current_center;
1039 jack_nframes_t new_page;
1040 jack_nframes_t leftmost_after_zoom = 0;
1045 new_page = (jack_nframes_t) floor (canvas_width * nfpu);
1047 switch (zoom_focus) {
1049 leftmost_after_zoom = current_leftmost;
1052 case ZoomFocusRight:
1053 current_rightmost = leftmost_frame + current_page;
1054 if (current_rightmost > new_page) {
1055 leftmost_after_zoom = current_rightmost - new_page;
1057 leftmost_after_zoom = 0;
1061 case ZoomFocusCenter:
1062 current_center = current_leftmost + (current_page/2);
1063 if (current_center > (new_page/2)) {
1064 leftmost_after_zoom = current_center - (new_page / 2);
1066 leftmost_after_zoom = 0;
1070 case ZoomFocusPlayhead:
1071 /* try to keep the playhead in the center */
1072 if (playhead_cursor->current_frame > new_page/2) {
1073 leftmost_after_zoom = playhead_cursor->current_frame - (new_page/2);
1075 leftmost_after_zoom = 0;
1080 /* try to keep the edit cursor in the center */
1081 if (edit_cursor->current_frame > leftmost_frame + (new_page/2)) {
1082 leftmost_after_zoom = edit_cursor->current_frame - (new_page/2);
1084 leftmost_after_zoom = 0;
1090 // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
1092 // begin_reversible_command (_("zoom"));
1093 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
1094 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
1095 // commit_reversible_command ();
1097 reposition_and_zoom (leftmost_after_zoom, nfpu);
1101 Editor::temporal_zoom_selection ()
1103 if (!selection) return;
1105 if (selection->time.empty()) {
1109 jack_nframes_t start = selection->time[clicked_selection].start;
1110 jack_nframes_t end = selection->time[clicked_selection].end;
1112 temporal_zoom_by_frame (start, end, "zoom to selection");
1116 Editor::temporal_zoom_session ()
1119 temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
1124 Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, string op)
1126 if (!session) return;
1128 if ((start == 0 && end == 0) || end < start) {
1132 jack_nframes_t range = end - start;
1134 double new_fpu = (double)range / (double)canvas_width;
1137 // while (p2 < new_fpu) {
1142 jack_nframes_t new_page = (jack_nframes_t) floor (canvas_width * new_fpu);
1143 jack_nframes_t middle = (jack_nframes_t) floor( (double)start + ((double)range / 2.0f ));
1144 jack_nframes_t new_leftmost = (jack_nframes_t) floor( (double)middle - ((double)new_page/2.0f));
1146 if (new_leftmost > middle) new_leftmost = 0;
1148 // begin_reversible_command (op);
1149 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1150 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1151 // commit_reversible_command ();
1153 reposition_and_zoom (new_leftmost, new_fpu);
1157 Editor::temporal_zoom_to_frame (bool coarser, jack_nframes_t frame)
1159 if (!session) return;
1161 jack_nframes_t range_before = frame - leftmost_frame;
1164 new_fpu = frames_per_unit;
1170 new_fpu = max(1.0,(new_fpu/2.0));
1174 if (new_fpu == frames_per_unit) return;
1176 jack_nframes_t new_leftmost = frame - range_before;
1178 if (new_leftmost > frame) new_leftmost = 0;
1180 // begin_reversible_command (_("zoom to frame"));
1181 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1182 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1183 // commit_reversible_command ();
1185 reposition_and_zoom (new_leftmost, new_fpu);
1189 Editor::select_all_in_track (bool add)
1191 list<Selectable *> touched;
1193 if (!clicked_trackview) {
1197 clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1200 selection->add (touched);
1202 selection->set (touched);
1207 Editor::select_all (bool add)
1209 list<Selectable *> touched;
1211 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1212 if ((*iter)->hidden()) {
1215 (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1219 selection->add (touched);
1221 selection->set (touched);
1227 Editor::invert_selection_in_track ()
1229 list<Selectable *> touched;
1231 if (!clicked_trackview) {
1235 clicked_trackview->get_inverted_selectables (*selection, touched);
1236 selection->set (touched);
1240 Editor::invert_selection ()
1242 list<Selectable *> touched;
1244 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1245 if ((*iter)->hidden()) {
1248 (*iter)->get_inverted_selectables (*selection, touched);
1251 selection->set (touched);
1255 Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
1257 list<Selectable *> touched;
1259 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1260 if ((*iter)->hidden()) {
1263 (*iter)->get_selectables (start, end, top, bot, touched);
1267 selection->add (touched);
1269 selection->set (touched);
1272 return !touched.empty();
1276 Editor::set_selection_from_punch()
1280 if ((location = session->locations()->auto_punch_location()) == 0) {
1284 set_selection_from_range (*location);
1288 Editor::set_selection_from_loop()
1292 if ((location = session->locations()->auto_loop_location()) == 0) {
1296 set_selection_from_range (*location);
1300 Editor::set_selection_from_range (Location& range)
1302 if (clicked_trackview == 0) {
1306 begin_reversible_command (_("set selection from range"));
1307 selection->set (0, range.start(), range.end());
1308 commit_reversible_command ();
1312 Editor::amplitude_zoom_step (bool in)
1326 #ifdef FIX_FOR_CANVAS
1327 /* XXX DO SOMETHING */
1336 Editor::delete_sample_forward ()
1341 Editor::delete_sample_backward ()
1346 Editor::delete_screen ()
1353 Editor::search_backwards ()
1359 Editor::search_forwards ()
1367 Editor::jump_forward_to_mark ()
1373 Location *location = session->locations()->first_location_after (playhead_cursor->current_frame);
1376 session->request_locate (location->start(), session->transport_rolling());
1378 session->request_locate (session->current_end_frame());
1383 Editor::jump_backward_to_mark ()
1389 Location *location = session->locations()->first_location_before (playhead_cursor->current_frame);
1392 session->request_locate (location->start(), session->transport_rolling());
1394 session->request_locate (0);
1405 if (get_prefix (prefix, was_floating)) {
1406 pos = session->audible_frame ();
1409 pos = (jack_nframes_t) floor (prefix * session->frame_rate ());
1411 pos = (jack_nframes_t) floor (prefix);
1415 session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true);
1419 Editor::clear_markers ()
1422 session->begin_reversible_command (_("clear markers"));
1423 session->add_undo (session->locations()->get_memento());
1424 session->locations()->clear_markers ();
1425 session->add_redo_no_execute (session->locations()->get_memento());
1426 session->commit_reversible_command ();
1431 Editor::clear_ranges ()
1434 session->begin_reversible_command (_("clear ranges"));
1435 session->add_undo (session->locations()->get_memento());
1437 Location * looploc = session->locations()->auto_loop_location();
1438 Location * punchloc = session->locations()->auto_punch_location();
1440 session->locations()->clear_ranges ();
1442 if (looploc) session->locations()->add (looploc);
1443 if (punchloc) session->locations()->add (punchloc);
1445 session->add_redo_no_execute (session->locations()->get_memento());
1446 session->commit_reversible_command ();
1451 Editor::clear_locations ()
1453 session->begin_reversible_command (_("clear locations"));
1454 session->add_undo (session->locations()->get_memento());
1455 session->locations()->clear ();
1456 session->add_redo_no_execute (session->locations()->get_memento());
1457 session->commit_reversible_command ();
1458 session->locations()->clear ();
1461 /* INSERT/REPLACE */
1464 Editor::insert_region_list_drag (AudioRegion& region)
1470 jack_nframes_t where;
1471 AudioTimeAxisView *atv = 0;
1474 track_canvas.get_pointer (x, y);
1476 track_canvas.window_to_world (x, y, wx, wy);
1479 event.type = GDK_BUTTON_RELEASE;
1480 event.button.x = wx;
1481 event.button.y = wy;
1483 where = event_frame (&event, &cx, &cy);
1485 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1486 /* clearly outside canvas area */
1490 if ((tv = trackview_by_y_position (cy)) == 0) {
1494 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) == 0) {
1498 if ((playlist = atv->playlist()) == 0) {
1504 begin_reversible_command (_("insert dragged region"));
1505 session->add_undo (playlist->get_memento());
1506 playlist->add_region (*(new AudioRegion (region)), where, 1.0);
1507 session->add_redo_no_execute (playlist->get_memento());
1508 commit_reversible_command ();
1512 Editor::insert_region_list_selection (float times)
1514 AudioTimeAxisView *tv = 0;
1517 if (clicked_audio_trackview != 0) {
1518 tv = clicked_audio_trackview;
1519 } else if (!selection->tracks.empty()) {
1520 if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
1527 if ((playlist = tv->playlist()) == 0) {
1531 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
1533 if (selected.count_selected_rows() != 1) {
1537 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
1538 Region* region = (*i)[region_list_columns.region];
1540 begin_reversible_command (_("insert region"));
1541 session->add_undo (playlist->get_memento());
1542 playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times);
1543 session->add_redo_no_execute (playlist->get_memento());
1544 commit_reversible_command ();
1548 /* BUILT-IN EFFECTS */
1551 Editor::reverse_selection ()
1556 /* GAIN ENVELOPE EDITING */
1559 Editor::edit_envelope ()
1566 Editor::toggle_playback (bool with_abort)
1572 switch (session->slave_source()) {
1577 /* transport controlled by the master */
1581 if (session->is_auditioning()) {
1582 session->cancel_audition ();
1586 if (session->transport_rolling()) {
1587 session->request_stop (with_abort);
1588 if (session->get_auto_loop()) {
1589 session->request_auto_loop (false);
1592 session->request_transport_speed (1.0f);
1597 Editor::play_from_start ()
1599 session->request_locate (0, true);
1603 Editor::play_selection ()
1605 if (selection->time.empty()) {
1609 session->request_play_range (true);
1613 Editor::play_selected_region ()
1615 if (!selection->audio_regions.empty()) {
1616 AudioRegionView *rv = *(selection->audio_regions.begin());
1618 session->request_bounded_roll (rv->region.position(), rv->region.last_frame());
1623 Editor::toggle_loop_playback ()
1626 session->request_auto_loop (true);
1631 Editor::loop_selected_region ()
1633 if (!selection->audio_regions.empty()) {
1634 AudioRegionView *rv = *(selection->audio_regions.begin());
1637 if ((tll = transport_loop_location()) != 0) {
1639 tll->set (rv->region.position(), rv->region.last_frame());
1641 // enable looping, reposition and start rolling
1643 session->request_auto_loop (true);
1644 session->request_locate (tll->start(), false);
1645 session->request_transport_speed (1.0f);
1651 Editor::play_location (Location& location)
1653 if (location.start() <= location.end()) {
1657 session->request_bounded_roll (location.start(), location.end());
1661 Editor::loop_location (Location& location)
1663 if (location.start() <= location.end()) {
1669 if ((tll = transport_loop_location()) != 0) {
1670 tll->set (location.start(), location.end());
1672 // enable looping, reposition and start rolling
1673 session->request_auto_loop (true);
1674 session->request_locate (tll->start(), true);
1679 Editor::toggle_region_mute ()
1681 if (clicked_regionview) {
1682 clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
1683 } else if (!selection->audio_regions.empty()) {
1684 bool yn = ! (*selection->audio_regions.begin())->region.muted();
1685 selection->foreach_audio_region (&AudioRegion::set_muted, yn);
1690 Editor::toggle_region_opaque ()
1692 if (clicked_regionview) {
1693 clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
1694 } else if (!selection->audio_regions.empty()) {
1695 bool yn = ! (*selection->audio_regions.begin())->region.opaque();
1696 selection->foreach_audio_region (&Region::set_opaque, yn);
1701 Editor::raise_region ()
1703 selection->foreach_audio_region (&Region::raise);
1707 Editor::raise_region_to_top ()
1709 selection->foreach_audio_region (&Region::raise_to_top);
1713 Editor::lower_region ()
1715 selection->foreach_audio_region (&Region::lower);
1719 Editor::lower_region_to_bottom ()
1721 selection->foreach_audio_region (&Region::lower_to_bottom);
1725 Editor::edit_region ()
1727 if (clicked_regionview == 0) {
1731 clicked_regionview->show_region_editor ();
1735 Editor::rename_region ()
1739 Button ok_button (_("OK"));
1740 Button cancel_button (_("Cancel"));
1742 if (selection->audio_regions.empty()) {
1746 dialog.set_title (_("ardour: rename region"));
1747 dialog.set_name ("RegionRenameWindow");
1748 dialog.set_size_request (300, -1);
1749 dialog.set_position (Gtk::WIN_POS_MOUSE);
1750 dialog.set_modal (true);
1752 dialog.get_vbox()->set_border_width (10);
1753 dialog.get_vbox()->pack_start (entry);
1754 dialog.get_action_area()->pack_start (ok_button);
1755 dialog.get_action_area()->pack_start (cancel_button);
1757 entry.set_name ("RegionNameDisplay");
1758 ok_button.set_name ("EditorGTKButton");
1759 cancel_button.set_name ("EditorGTKButton");
1761 region_renamed = false;
1763 entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1764 ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1765 cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
1770 ARDOUR_UI::instance()->allow_focus (true);
1772 ARDOUR_UI::instance()->allow_focus (false);
1774 if (region_renamed) {
1775 (*selection->audio_regions.begin())->region.set_name (entry.get_text());
1776 redisplay_regions ();
1781 Editor::rename_region_finished (bool status)
1784 region_renamed = status;
1789 Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
1791 if (session->is_auditioning()) {
1792 session->cancel_audition ();
1795 // note: some potential for creativity here, because region doesn't
1796 // have to belong to the playlist that Route is handling
1798 // bool was_soloed = route.soloed();
1800 route.set_solo (true, this);
1802 session->request_bounded_roll (region.position(), region.position() + region.length());
1804 /* XXX how to unset the solo state ? */
1808 Editor::audition_selected_region ()
1810 if (!selection->audio_regions.empty()) {
1811 AudioRegionView* rv = *(selection->audio_regions.begin());
1812 session->audition_region (rv->region);
1817 Editor::audition_playlist_region_standalone (AudioRegion& region)
1819 session->audition_region (region);
1823 Editor::build_interthread_progress_window ()
1825 interthread_progress_window = new ArdourDialog (X_("interthread progress"));
1827 interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
1829 interthread_progress_vbox.set_border_width (10);
1830 interthread_progress_vbox.set_spacing (5);
1831 interthread_progress_vbox.pack_start (interthread_progress_label, false, false);
1832 interthread_progress_vbox.pack_start (interthread_progress_bar,false, false);
1833 interthread_progress_vbox.pack_start (interthread_cancel_button,false, false);
1835 interthread_cancel_button.add (interthread_cancel_label);
1837 interthread_cancel_button.signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
1839 interthread_progress_window->set_modal (true);
1840 interthread_progress_window->set_default_size (200, 100);
1841 interthread_progress_window->add (interthread_progress_vbox);
1845 Editor::interthread_cancel_clicked ()
1847 if (current_interthread_info) {
1848 current_interthread_info->cancel = true;
1853 Editor::_import_thread (void *arg)
1855 PBD::ThreadCreated (pthread_self(), X_("Import"));
1857 Editor *ed = (Editor *) arg;
1858 return ed->import_thread ();
1862 Editor::import_thread ()
1864 session->import_audiofile (import_status);
1869 Editor::import_progress_timeout (void *arg)
1871 interthread_progress_label.set_text (import_status.doing_what);
1873 if (import_status.freeze) {
1874 interthread_cancel_button.set_sensitive(false);
1876 interthread_cancel_button.set_sensitive(true);
1879 if (import_status.doing_what == "building peak files") {
1880 interthread_progress_bar.pulse ();
1883 interthread_progress_bar.set_fraction (import_status.progress/100);
1886 return !(import_status.done || import_status.cancel);
1890 Editor::import_audio (bool as_tracks)
1893 warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
1900 str =_("Import selected as tracks");
1902 str = _("Import selected to region list");
1905 SoundFileOmega sfdb (str);
1906 sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks));
1912 Editor::catch_new_audio_region (AudioRegion* ar)
1914 last_audio_region = ar;
1918 Editor::do_import (vector<string> paths, bool split, bool as_tracks)
1922 /* SFDB sets "multichan" to true to indicate "split channels"
1923 so reverse the setting to match the way libardour
1927 import_status.multichan = !split;
1929 if (interthread_progress_window == 0) {
1930 build_interthread_progress_window ();
1933 interthread_progress_window->set_title (_("ardour: audio import in progress"));
1934 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
1935 interthread_progress_window->show_all ();
1936 interthread_progress_bar.set_fraction (0.0f);
1937 interthread_cancel_label.set_text (_("Cancel Import"));
1938 current_interthread_info = &import_status;
1940 c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
1942 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
1944 interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
1946 import_status.pathname = (*i);
1947 import_status.done = false;
1948 import_status.cancel = false;
1949 import_status.freeze = false;
1950 import_status.done = 0.0;
1952 interthread_progress_connection =
1953 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
1955 last_audio_region = 0;
1957 pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
1958 pthread_detach (import_status.thread);
1960 while (!(import_status.done || import_status.cancel)) {
1961 gtk_main_iteration ();
1964 import_status.done = true;
1965 interthread_progress_connection.disconnect ();
1967 if (as_tracks && last_audio_region != 0) {
1968 uint32_t channels = last_audio_region->n_channels();
1970 AudioTrack* at = session->new_audio_track (channels, channels);
1971 AudioRegion* copy = new AudioRegion (*last_audio_region);
1972 at->disk_stream().playlist()->add_region (*copy, 0);
1977 interthread_progress_window->hide_all ();
1981 Editor::reject_because_rate_differs (string path, SF_INFO& finfo, string action, bool multiple_pending)
1987 if (finfo.samplerate != (int) session->frame_rate()) {
1988 vector<string> choices;
1990 choices.push_back (string_compose (_("%1 it anyway"), action));
1992 if (multiple_pending) {
1993 /* XXX assumptions about sentence structure
1994 here for translators. Sorry.
1996 choices.push_back (string_compose (_("Don't %1 it"), action));
1997 choices.push_back (string_compose (_("%1 all without questions"), action));
1998 choices.push_back (_("Cancel entire import"));
2000 choices.push_back (_("Cancel"));
2003 Gtkmm2ext::Choice rate_choice (
2004 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
2007 rate_choice.chosen.connect (Main::quit.slot());
2008 rate_choice.show_all ();
2012 switch (rate_choice.get_choice()) {
2013 case 0: /* do it anyway */
2015 case 1: /* don't import this one */
2017 case 2: /* do the rest without asking */
2019 case 3: /* stop a multi-file import */
2029 Editor::embed_audio ()
2032 warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
2036 SoundFileOmega sfdb (_("Add to External Region list"));
2037 sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
2043 Editor::do_embed_sndfiles (vector<string> paths, bool split)
2045 bool multiple_files = paths.size() > 1;
2046 bool check_sample_rate = true;
2048 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
2049 embed_sndfile (*i, split, multiple_files, check_sample_rate);
2052 session->save_state ("");
2056 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
2058 SndFileSource *source = 0; /* keep g++ quiet */
2059 AudioRegion::SourceList sources;
2065 /* lets see if we can link it into the session */
2067 linked_path = session->sound_dir();
2068 linked_path += PBD::basename (path);
2070 if (link (path.c_str(), linked_path.c_str()) == 0) {
2072 /* there are many reasons why link(2) might have failed.
2073 but if it succeeds, we now have a link in the
2074 session sound dir that will protect against
2075 unlinking of the original path. nice.
2081 memset (&finfo, 0, sizeof(finfo));
2083 /* note that we temporarily truncated _id at the colon */
2085 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2087 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2088 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
2094 if (check_sample_rate) {
2095 switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
2101 check_sample_rate = false;
2110 track_canvas_scroller.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2111 ARDOUR_UI::instance()->flush_pending ();
2113 /* make the proper number of channels in the region */
2115 for (int n=0; n < finfo.channels; ++n)
2118 idspec += string_compose(":%1", n);
2121 source = new SndFileSource (idspec.c_str());
2122 sources.push_back(source);
2125 catch (failed_constructor& err) {
2126 error << string_compose(_("could not open %1"), path) << endmsg;
2130 ARDOUR_UI::instance()->flush_pending ();
2133 if (sources.size() > 0) {
2135 string region_name = PBD::basename_nosuffix (path);
2136 region_name += "-0";
2138 /* The created region isn't dropped. It emits a signal
2139 that is picked up by the session.
2142 new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
2143 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2145 /* make sure we can see it in the list */
2147 /* its the second node, always */
2149 // GTK2FIX ?? is it still always the 2nd node
2151 TreeModel::Path path ("2");
2152 region_list_display.expand_row (path, true);
2154 ARDOUR_UI::instance()->flush_pending ();
2158 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
2162 Editor::insert_sndfile (bool as_tracks)
2164 // SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2170 // c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
2171 str = _("Insert selected as new tracks");
2177 if (clicked_audio_trackview == 0) {
2181 if (ensure_cursor (&pos)) {
2185 // c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
2186 str = _("Insert selected");
2189 // sfdb.run (str, false);
2194 Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
2198 bool multiple_files;
2199 bool check_sample_rate = true;
2201 multiple_files = paths.size() > 1;
2203 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
2205 memset (&finfo, 0, sizeof(finfo));
2207 if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
2209 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2210 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
2217 /* add a new track */
2219 if (check_sample_rate) {
2220 switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
2226 check_sample_rate = false;
2234 uint32_t input_chan = finfo.channels;
2235 uint32_t output_chan;
2237 if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
2238 output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
2240 output_chan = input_chan;
2243 (void) session->new_audio_track (input_chan, output_chan);
2246 /* get the last (most recently added) track view */
2248 AudioTimeAxisView* tv;
2250 if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
2251 fatal << _("programming error: ")
2252 << X_("last trackview after new_audio_track is not an audio track!")
2257 jack_nframes_t pos = 0;
2258 insert_sndfile_into (*p, true, tv, pos, false);
2263 Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
2265 for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
2266 insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
2271 Editor::insert_sndfile_into (string path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
2273 SndFileSource *source = 0; /* keep g++ quiet */
2274 AudioRegion::SourceList sources;
2279 memset (&finfo, 0, sizeof(finfo));
2281 /* note that we temporarily truncated _id at the colon */
2283 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2285 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2286 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
2292 if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
2296 track_canvas_scroller.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2297 ARDOUR_UI::instance()->flush_pending ();
2299 /* make the proper number of channels in the region */
2301 for (int n=0; n < finfo.channels; ++n)
2304 idspec += string_compose(":%1", n);
2307 source = new SndFileSource (idspec.c_str());
2308 sources.push_back(source);
2311 catch (failed_constructor& err) {
2312 error << string_compose(_("could not open %1"), path) << endmsg;
2316 ARDOUR_UI::instance()->flush_pending ();
2319 if (sources.size() > 0) {
2321 string region_name = region_name_from_path (PBD::basename (path));
2323 AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
2324 0, /* irrelevant these days */
2325 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2327 begin_reversible_command (_("insert sndfile"));
2328 session->add_undo (tv->playlist()->get_memento());
2329 tv->playlist()->add_region (*region, pos);
2330 session->add_redo_no_execute (tv->playlist()->get_memento());
2331 commit_reversible_command ();
2333 pos += sources[0]->length();
2335 ARDOUR_UI::instance()->flush_pending ();
2339 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
2344 Editor::region_from_selection ()
2346 if (clicked_trackview == 0) {
2350 if (selection->time.empty()) {
2354 jack_nframes_t start = selection->time[clicked_selection].start;
2355 jack_nframes_t end = selection->time[clicked_selection].end;
2357 jack_nframes_t selection_cnt = end - start + 1;
2359 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2361 AudioRegion *region;
2362 AudioRegion *current;
2366 jack_nframes_t internal_start;
2369 if ((pl = (*i)->playlist()) == 0) {
2373 if ((current_r = pl->top_region_at (start)) == 0) {
2377 if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
2378 internal_start = start - current->position();
2379 session->region_name (new_name, current->name(), true);
2380 region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
2386 Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
2388 if (selection->time.empty() || selection->tracks.empty()) {
2392 jack_nframes_t start = selection->time[clicked_selection].start;
2393 jack_nframes_t end = selection->time[clicked_selection].end;
2395 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2397 AudioRegion* current;
2400 jack_nframes_t internal_start;
2403 if ((playlist = (*i)->playlist()) == 0) {
2407 if ((current_r = playlist->top_region_at(start)) == 0) {
2411 if ((current = dynamic_cast<AudioRegion*>(current_r)) == 0) {
2415 internal_start = start - current->position();
2416 session->region_name (new_name, current->name(), true);
2418 new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name));
2423 Editor::split_multichannel_region ()
2425 vector<AudioRegion*> v;
2427 if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
2431 clicked_regionview->region.separate_by_channel (*session, v);
2433 /* nothing else to do, really */
2437 Editor::new_region_from_selection ()
2439 region_from_selection ();
2440 cancel_selection ();
2444 Editor::separate_region_from_selection ()
2446 bool doing_undo = false;
2448 if (selection->time.empty()) {
2454 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2456 AudioTimeAxisView* atv;
2458 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2460 if (atv->is_audio_track()) {
2462 if ((playlist = atv->playlist()) != 0) {
2464 begin_reversible_command (_("separate"));
2467 if (doing_undo) session->add_undo ((playlist)->get_memento());
2469 /* XXX need to consider musical time selections here at some point */
2471 double speed = atv->get_diskstream()->speed();
2473 for (list<AudioRange>::iterator t = selection->time.begin(); t != selection->time.end(); ++t) {
2474 playlist->partition ((jack_nframes_t)((*t).start * speed), (jack_nframes_t)((*t).end * speed), true);
2477 if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
2483 if (doing_undo) commit_reversible_command ();
2487 Editor::crop_region_to_selection ()
2489 if (selection->time.empty()) {
2493 vector<Playlist*> playlists;
2496 if (clicked_trackview != 0) {
2498 if ((playlist = clicked_trackview->playlist()) == 0) {
2502 playlists.push_back (playlist);
2506 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2508 AudioTimeAxisView* atv;
2510 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2512 if (atv->is_audio_track()) {
2514 if ((playlist = atv->playlist()) != 0) {
2515 playlists.push_back (playlist);
2522 if (!playlists.empty()) {
2524 jack_nframes_t start;
2528 begin_reversible_command (_("trim to selection"));
2530 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2534 start = selection->time.start();
2536 if ((region = (*i)->top_region_at(start)) == 0) {
2540 /* now adjust lengths to that we do the right thing
2541 if the selection extends beyond the region
2544 start = max (start, region->position());
2545 end = min (selection->time.end_frame(), start + region->length() - 1);
2546 cnt = end - start + 1;
2548 session->add_undo ((*i)->get_memento());
2549 region->trim_to (start, cnt, this);
2550 session->add_redo_no_execute ((*i)->get_memento());
2553 commit_reversible_command ();
2558 Editor::region_fill_track ()
2562 if (!session || selection->audio_regions.empty()) {
2566 end = session->current_end_frame ();
2568 begin_reversible_command (_("region fill"));
2570 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2572 AudioRegion& region ((*i)->region);
2573 Playlist* pl = region.playlist();
2575 if (end <= region.last_frame()) {
2579 double times = (double) (end - region.last_frame()) / (double) region.length();
2585 session->add_undo (pl->get_memento());
2586 pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
2587 session->add_redo_no_execute (pl->get_memento());
2590 commit_reversible_command ();
2594 Editor::region_fill_selection ()
2596 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2600 if (selection->time.empty()) {
2606 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
2608 if (selected.count_selected_rows() != 1) {
2612 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
2613 region = (*i)[region_list_columns.region];
2615 jack_nframes_t start = selection->time[clicked_selection].start;
2616 jack_nframes_t end = selection->time[clicked_selection].end;
2620 if (selection->tracks.empty()) {
2624 jack_nframes_t selection_length = end - start;
2625 float times = (float)selection_length / region->length();
2627 begin_reversible_command (_("fill selection"));
2629 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2631 if ((playlist = (*i)->playlist()) == 0) {
2635 session->add_undo (playlist->get_memento());
2636 playlist->add_region (*(createRegion (*region)), start, times);
2637 session->add_redo_no_execute (playlist->get_memento());
2640 commit_reversible_command ();
2644 Editor::set_region_sync_from_edit_cursor ()
2646 if (clicked_regionview == 0) {
2650 if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
2651 error << _("Place the edit cursor at the desired sync point") << endmsg;
2655 Region& region (clicked_regionview->region);
2657 begin_reversible_command (_("set sync from edit cursor"));
2658 session->add_undo (region.playlist()->get_memento());
2659 region.set_sync_position (edit_cursor->current_frame);
2660 session->add_redo_no_execute (region.playlist()->get_memento());
2661 commit_reversible_command ();
2665 Editor::remove_region_sync ()
2667 if (clicked_regionview) {
2668 Region& region (clicked_regionview->region);
2669 begin_reversible_command (_("remove sync"));
2670 session->add_undo (region.playlist()->get_memento());
2671 region.clear_sync_position ();
2672 session->add_redo_no_execute (region.playlist()->get_memento());
2673 commit_reversible_command ();
2678 Editor::naturalize ()
2680 if (selection->audio_regions.empty()) {
2683 begin_reversible_command (_("naturalize"));
2684 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2685 session->add_undo ((*i)->region.get_memento());
2686 (*i)->region.move_to_natural_position (this);
2687 session->add_redo_no_execute ((*i)->region.get_memento());
2689 commit_reversible_command ();
2693 Editor::align (RegionPoint what)
2695 align_selection (what, edit_cursor->current_frame);
2699 Editor::align_relative (RegionPoint what)
2701 align_selection_relative (what, edit_cursor->current_frame);
2704 struct RegionSortByTime {
2705 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
2706 return a->region.position() < b->region.position();
2711 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
2713 if (selection->audio_regions.empty()) {
2717 jack_nframes_t distance;
2718 jack_nframes_t pos = 0;
2721 list<AudioRegionView*> sorted;
2722 selection->audio_regions.by_position (sorted);
2723 Region& r ((*sorted.begin())->region);
2727 pos = r.first_frame ();
2731 pos = r.last_frame();
2735 pos = r.adjust_to_sync (r.first_frame());
2739 if (pos > position) {
2740 distance = pos - position;
2743 distance = position - pos;
2747 begin_reversible_command (_("align selection (relative)"));
2749 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2751 Region& region ((*i)->region);
2753 session->add_undo (region.playlist()->get_memento());
2756 region.set_position (region.position() + distance, this);
2758 region.set_position (region.position() - distance, this);
2761 session->add_redo_no_execute (region.playlist()->get_memento());
2765 commit_reversible_command ();
2769 Editor::align_selection (RegionPoint point, jack_nframes_t position)
2771 if (selection->audio_regions.empty()) {
2775 begin_reversible_command (_("align selection"));
2777 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2778 align_region_internal ((*i)->region, point, position);
2781 commit_reversible_command ();
2785 Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position)
2787 begin_reversible_command (_("align region"));
2788 align_region_internal (region, point, position);
2789 commit_reversible_command ();
2793 Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position)
2795 session->add_undo (region.playlist()->get_memento());
2799 region.set_position (region.adjust_to_sync (position), this);
2803 if (position > region.length()) {
2804 region.set_position (position - region.length(), this);
2809 region.set_position (position, this);
2813 session->add_redo_no_execute (region.playlist()->get_memento());
2817 Editor::trim_region_to_edit_cursor ()
2819 if (clicked_regionview == 0) {
2823 Region& region (clicked_regionview->region);
2826 AudioTimeAxisView *atav;
2828 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2829 if (atav->get_diskstream() != 0) {
2830 speed = atav->get_diskstream()->speed();
2834 begin_reversible_command (_("trim to edit"));
2835 session->add_undo (region.playlist()->get_memento());
2836 region.trim_end ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
2837 session->add_redo_no_execute (region.playlist()->get_memento());
2838 commit_reversible_command ();
2842 Editor::trim_region_from_edit_cursor ()
2844 if (clicked_regionview == 0) {
2848 Region& region (clicked_regionview->region);
2851 AudioTimeAxisView *atav;
2853 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2854 if (atav->get_diskstream() != 0) {
2855 speed = atav->get_diskstream()->speed();
2859 begin_reversible_command (_("trim to edit"));
2860 session->add_undo (region.playlist()->get_memento());
2861 region.trim_front ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
2862 session->add_redo_no_execute (region.playlist()->get_memento());
2863 commit_reversible_command ();
2867 Editor::unfreeze_route ()
2869 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2873 clicked_audio_trackview->audio_track()->unfreeze ();
2877 Editor::_freeze_thread (void* arg)
2879 PBD::ThreadCreated (pthread_self(), X_("Freeze"));
2880 return static_cast<Editor*>(arg)->freeze_thread ();
2884 Editor::freeze_thread ()
2886 clicked_audio_trackview->audio_track()->freeze (*current_interthread_info);
2891 Editor::freeze_progress_timeout (void *arg)
2893 interthread_progress_bar.set_fraction (current_interthread_info->progress/100);
2894 return !(current_interthread_info->done || current_interthread_info->cancel);
2898 Editor::freeze_route ()
2900 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2904 InterThreadInfo itt;
2906 if (interthread_progress_window == 0) {
2907 build_interthread_progress_window ();
2910 interthread_progress_window->set_title (_("ardour: freeze"));
2911 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2912 interthread_progress_window->show_all ();
2913 interthread_progress_bar.set_fraction (0.0f);
2914 interthread_progress_label.set_text ("");
2915 interthread_cancel_label.set_text (_("Cancel Freeze"));
2916 current_interthread_info = &itt;
2918 interthread_progress_connection =
2919 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
2923 itt.progress = 0.0f;
2925 pthread_create (&itt.thread, 0, _freeze_thread, this);
2927 track_canvas_scroller.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2929 while (!itt.done && !itt.cancel) {
2930 gtk_main_iteration ();
2933 interthread_progress_connection.disconnect ();
2934 interthread_progress_window->hide_all ();
2935 current_interthread_info = 0;
2936 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
2940 Editor::bounce_range_selection ()
2942 if (selection->time.empty()) {
2946 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
2948 jack_nframes_t start = selection->time[clicked_selection].start;
2949 jack_nframes_t end = selection->time[clicked_selection].end;
2950 jack_nframes_t cnt = end - start + 1;
2952 begin_reversible_command (_("bounce range"));
2954 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
2956 AudioTimeAxisView* atv;
2958 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
2964 if ((playlist = atv->playlist()) == 0) {
2968 InterThreadInfo itt;
2972 itt.progress = false;
2974 session->add_undo (playlist->get_memento());
2975 atv->audio_track()->bounce_range (start, cnt, itt);
2976 session->add_redo_no_execute (playlist->get_memento());
2979 commit_reversible_command ();
2997 Editor::cut_copy (CutCopyOp op)
2999 /* only cancel selection if cut/copy is successful.*/
3011 opname = _("clear");
3015 cut_buffer->clear ();
3017 switch (current_mouse_mode()) {
3019 if (!selection->audio_regions.empty() || !selection->points.empty()) {
3021 begin_reversible_command (opname + _(" objects"));
3023 if (!selection->audio_regions.empty()) {
3025 cut_copy_regions (op);
3028 selection->clear_audio_regions ();
3032 if (!selection->points.empty()) {
3033 cut_copy_points (op);
3036 selection->clear_points ();
3040 commit_reversible_command ();
3045 if (!selection->time.empty()) {
3047 begin_reversible_command (opname + _(" range"));
3048 cut_copy_ranges (op);
3049 commit_reversible_command ();
3052 selection->clear_time ();
3064 Editor::cut_copy_points (CutCopyOp op)
3066 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3068 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
3071 atv->cut_copy_clear_objects (selection->points, op);
3077 Editor::cut_copy_regions (CutCopyOp op)
3079 typedef std::map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
3080 PlaylistMapping pmap;
3081 jack_nframes_t first_position = max_frames;
3082 set<Playlist*> freezelist;
3083 pair<set<Playlist*>::iterator,bool> insert_result;
3085 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
3086 first_position = min ((*x)->region.position(), first_position);
3088 if (op == Cut || op == Clear) {
3089 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3091 insert_result = freezelist.insert (pl);
3092 if (insert_result.second) {
3094 session->add_undo (pl->get_memento());
3100 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
3102 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3104 AudioRegionSelection::iterator tmp;
3111 PlaylistMapping::iterator pi = pmap.find (pl);
3113 if (pi == pmap.end()) {
3114 npl = new AudioPlaylist (*session, "cutlist", true);
3123 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3124 pl->remove_region (&((*x)->region));
3128 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3132 pl->remove_region (&((*x)->region));
3140 list<Playlist*> foo;
3142 for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3143 foo.push_back (i->second);
3147 cut_buffer->set (foo);
3150 for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3152 session->add_redo_no_execute ((*pl)->get_memento());
3157 Editor::cut_copy_ranges (CutCopyOp op)
3159 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3160 (*i)->cut_copy_clear (*selection, op);
3165 Editor::paste (float times)
3167 paste_internal (edit_cursor->current_frame, times);
3171 Editor::mouse_paste ()
3175 track_canvas.get_pointer (x, y);
3176 track_canvas.window_to_world (x, y, wx, wy);
3178 event.type = GDK_BUTTON_RELEASE;
3179 event.button.x = wx;
3180 event.button.y = wy;
3182 jack_nframes_t where = event_frame (&event, 0, 0);
3184 paste_internal (where, 1);
3188 Editor::paste_internal (jack_nframes_t position, float times)
3190 bool commit = false;
3192 if (cut_buffer->empty() || selection->tracks.empty()) {
3196 if (position == max_frames) {
3197 position = edit_cursor->current_frame;
3200 begin_reversible_command (_("paste"));
3202 TrackSelection::iterator i;
3205 for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) {
3207 /* undo/redo is handled by individual tracks */
3209 if ((*i)->paste (position, times, *cut_buffer, nth)) {
3215 commit_reversible_command ();
3220 Editor::paste_named_selection (float times)
3222 TrackSelection::iterator i;
3224 Glib::RefPtr<TreeSelection> selected = named_selection_display.get_selection();
3226 if (selected.count_selected_rows() == 0 || selection->tracks.empty()) {
3230 TreeModel::iterator i = selected->get_selected();
3231 NamedSelection* ns = (*i)[named_selection_columns.selection];
3233 list<Playlist*>::iterator chunk;
3234 list<Playlist*>::iterator tmp;
3236 chunk = ns->playlists.begin();
3238 begin_reversible_command (_("paste chunk"));
3240 for (i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3242 AudioTimeAxisView* atv;
3246 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
3250 if ((pl = atv->playlist()) == 0) {
3254 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
3261 session->add_undo (apl->get_memento());
3262 apl->paste (**chunk, edit_cursor->current_frame, times);
3263 session->add_redo_no_execute (apl->get_memento());
3265 if (tmp != ns->playlists.end()) {
3270 commit_reversible_command();
3274 Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
3278 begin_reversible_command (_("duplicate region"));
3280 for (AudioRegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
3282 Region& r ((*i)->region);
3284 playlist = (*i)->region.playlist();
3285 session->add_undo (playlist->get_memento());
3286 playlist->duplicate (r, r.last_frame(), times);
3287 session->add_redo_no_execute (playlist->get_memento());
3291 commit_reversible_command ();
3295 Editor::duplicate_selection (float times)
3297 if (selection->time.empty() || selection->tracks.empty()) {
3302 vector<AudioRegion*> new_regions;
3303 vector<AudioRegion*>::iterator ri;
3305 create_region_from_selection (new_regions);
3307 if (new_regions.empty()) {
3311 begin_reversible_command (_("duplicate selection"));
3313 ri = new_regions.begin();
3315 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3316 if ((playlist = (*i)->playlist()) == 0) {
3319 session->add_undo (playlist->get_memento());
3320 playlist->duplicate (**ri, selection->time[clicked_selection].end, times);
3321 session->add_redo_no_execute (playlist->get_memento());
3324 if (ri == new_regions.end()) {
3329 commit_reversible_command ();
3333 Editor::center_playhead ()
3335 float page = canvas_width * frames_per_unit;
3337 center_screen_internal (playhead_cursor->current_frame, page);
3341 Editor::center_edit_cursor ()
3343 float page = canvas_width * frames_per_unit;
3345 center_screen_internal (edit_cursor->current_frame, page);
3349 Editor::clear_playlist (Playlist& playlist)
3351 begin_reversible_command (_("clear playlist"));
3352 session->add_undo (playlist.get_memento());
3354 session->add_redo_no_execute (playlist.get_memento());
3355 commit_reversible_command ();
3359 Editor::nudge_track (bool use_edit_cursor, bool forwards)
3362 jack_nframes_t distance;
3363 jack_nframes_t next_distance;
3364 jack_nframes_t start;
3366 if (use_edit_cursor) {
3367 start = edit_cursor->current_frame;
3372 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
3376 if (selection->tracks.empty()) {
3380 begin_reversible_command (_("nudge track"));
3382 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3384 if ((playlist = (*i)->playlist()) == 0) {
3388 session->add_undo (playlist->get_memento());
3389 playlist->nudge_after (start, distance, forwards);
3390 session->add_redo_no_execute (playlist->get_memento());
3393 commit_reversible_command ();
3397 Editor::toggle_xfades_active ()
3400 session->set_crossfades_active (!session->get_crossfades_active());
3405 Editor::toggle_follow_playhead ()
3407 set_follow_playhead (!_follow_playhead);
3411 Editor::set_xfade_visibility (bool yn)
3417 Editor::toggle_xfade_visibility ()
3419 set_xfade_visibility (!xfade_visibility());
3423 Editor::remove_last_capture ()
3425 vector<string> choices;
3432 if (Config->get_verify_remove_last_capture()) {
3433 prompt = _("Do you really want to destroy the last capture?"
3434 "\n(This is destructive and cannot be undone)");
3436 choices.push_back (_("Yes, destroy it."));
3437 choices.push_back (_("No, do nothing."));
3439 Gtkmm2ext::Choice prompter (prompt, choices);
3440 prompter.done.connect (Gtk::Main::quit.slot());
3441 prompter.show_all ();
3445 if (prompter.get_choice() == 0) {
3446 session->remove_last_capture ();
3449 session->remove_last_capture();
3454 Editor::normalize_region ()
3460 if (selection->audio_regions.empty()) {
3464 begin_reversible_command (_("normalize"));
3466 track_canvas_scroller.get_window()->set_cursor (*wait_cursor);
3469 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3470 session->add_undo ((*r)->region.get_memento());
3471 (*r)->region.normalize_to (0.0f);
3472 session->add_redo_no_execute ((*r)->region.get_memento());
3475 commit_reversible_command ();
3476 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
3481 Editor::denormalize_region ()
3487 if (selection->audio_regions.empty()) {
3491 begin_reversible_command ("denormalize");
3493 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3494 session->add_undo ((*r)->region.get_memento());
3495 (*r)->region.set_scale_amplitude (1.0f);
3496 session->add_redo_no_execute ((*r)->region.get_memento());
3499 commit_reversible_command ();
3504 Editor::reverse_region ()
3510 Reverse rev (*session);
3511 apply_filter (rev, _("reverse regions"));
3515 Editor::apply_filter (AudioFilter& filter, string command)
3517 if (selection->audio_regions.empty()) {
3521 begin_reversible_command (command);
3523 track_canvas_scroller.get_window()->set_cursor (*wait_cursor);
3526 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
3528 AudioRegion& region ((*r)->region);
3529 Playlist* playlist = region.playlist();
3531 AudioRegionSelection::iterator tmp;
3536 if (region.apply (filter) == 0) {
3538 session->add_undo (playlist->get_memento());
3539 playlist->replace_region (region, *(filter.results.front()), region.position());
3540 session->add_redo_no_execute (playlist->get_memento());
3548 commit_reversible_command ();
3549 selection->audio_regions.clear ();
3552 track_canvas_scroller.get_window()->set_cursor (*current_canvas_cursor);
3556 Editor::region_selection_op (void (Region::*pmf)(void))
3558 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3559 ((*i)->region.*pmf)();
3565 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
3567 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3568 ((*i)->region.*pmf)(arg);
3573 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
3575 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3576 ((*i)->region.*pmf)(yn);
3581 Editor::external_edit_region ()
3583 if (!clicked_regionview) {
3591 Editor::brush (jack_nframes_t pos)
3593 AudioRegionSelection sel;
3596 if (selection->audio_regions.empty()) {
3597 /* XXX get selection from region list */
3599 sel = selection->audio_regions;
3606 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3607 mouse_brush_insert_region ((*i), pos);
3612 Editor::toggle_gain_envelope_visibility ()
3614 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3615 (*i)->set_envelope_visible (!(*i)->envelope_visible());
3620 Editor::toggle_gain_envelope_active ()
3622 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3623 AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
3625 ar->set_envelope_active (true);