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::set_meter_hold (int32_t cnt)
98 session->set_meter_hold (cnt);
103 Editor::set_meter_falloff (float val)
106 session->set_meter_falloff (val);
112 Editor::ensure_cursor (jack_nframes_t *pos)
114 *pos = edit_cursor->current_frame;
119 Editor::split_region ()
121 split_region_at (edit_cursor->current_frame);
125 Editor::split_region_at (jack_nframes_t where)
127 split_regions_at (where, selection->audio_regions);
131 Editor::split_regions_at (jack_nframes_t where, AudioRegionSelection& regions)
133 begin_reversible_command (_("split"));
136 for (AudioRegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
138 AudioRegionSelection::iterator tmp;
143 Playlist* pl = (*a)->region.playlist();
145 _new_regionviews_show_envelope = (*a)->envelope_visible();
148 session->add_undo (pl->get_memento());
149 pl->split_region ((*a)->region, where);
150 session->add_redo_no_execute (pl->get_memento());
156 commit_reversible_command ();
157 _new_regionviews_show_envelope = false;
161 Editor::remove_clicked_region ()
163 if (clicked_audio_trackview == 0 || clicked_regionview == 0) {
167 Playlist* playlist = clicked_audio_trackview->playlist();
169 begin_reversible_command (_("remove region"));
170 session->add_undo (playlist->get_memento());
171 playlist->remove_region (&clicked_regionview->region);
172 session->add_redo_no_execute (playlist->get_memento());
173 commit_reversible_command ();
177 Editor::destroy_clicked_region ()
179 int32_t selected = selection->audio_regions.size();
181 if (!session || clicked_regionview == 0 && selected == 0) {
185 vector<string> choices;
188 prompt = string_compose (_(" This is destructive, will possibly delete audio files\n\
189 It cannot be undone\n\
190 Do you really want to destroy %1 ?"),
192 _("these regions") : _("this region")));
195 choices.push_back (_("Yes, destroy them."));
197 choices.push_back (_("Yes, destroy it."));
200 choices.push_back (_("No, do nothing."));
202 Gtkmm2ext::Choice prompter (prompt, choices);
204 prompter.chosen.connect (ptr_fun (Main::quit));
205 prompter.show_all ();
209 if (prompter.get_choice() != 0) {
216 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
217 r.push_back (&(*i)->region);
220 session->destroy_regions (r);
222 } else if (clicked_regionview) {
223 session->destroy_region (&clicked_regionview->region);
228 Editor::select_region_for_operation (int dir, TimeAxisView **tv)
232 jack_nframes_t start = 0;
234 if (selection->time.start () == selection->time.end_frame ()) {
236 /* no current selection-> is there a selected regionview? */
238 if (selection->audio_regions.empty()) {
246 if (!selection->audio_regions.empty()) {
248 rv = *(selection->audio_regions.begin());
249 (*tv) = &rv->get_time_axis_view();
250 region = &rv->region;
252 } else if (!selection->tracks.empty()) {
254 (*tv) = selection->tracks.front();
256 AudioTimeAxisView* atv;
258 if ((atv = dynamic_cast<AudioTimeAxisView*> (*tv)) != 0) {
261 if ((pl = atv->playlist()) == 0) {
265 region = dynamic_cast<AudioRegion*> (pl->top_region_at (start));
273 Editor::extend_selection_to_end_of_region (bool next)
277 jack_nframes_t start;
279 if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) {
283 if (region && selection->time.start () == selection->time.end_frame ()) {
284 start = region->position();
286 start = selection->time.start ();
289 /* Try to leave the selection with the same route if possible */
291 if ((tv = selection->time.track) == 0) {
295 begin_reversible_command (_("extend selection"));
296 selection->set (tv, start, region->position() + region->length());
297 commit_reversible_command ();
301 Editor::extend_selection_to_start_of_region (bool previous)
307 if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) {
311 if (region && selection->time.start () == selection->time.end_frame ()) {
312 end = region->position() + region->length();
314 end = selection->time.end_frame ();
317 /* Try to leave the selection with the same route if possible */
319 if ((tv = selection->time.track) == 0) {
323 begin_reversible_command (_("extend selection"));
324 selection->set (tv, region->position(), end);
325 commit_reversible_command ();
330 Editor::nudge_forward (bool next)
332 jack_nframes_t distance;
333 jack_nframes_t next_distance;
335 if (!session) return;
337 if (!selection->audio_regions.empty()) {
339 begin_reversible_command (_("nudge forward"));
341 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
342 AudioRegion& r ((*i)->region);
344 distance = get_nudge_distance (r.position(), next_distance);
347 distance = next_distance;
350 session->add_undo (r.playlist()->get_memento());
351 r.set_position (r.position() + distance, this);
352 session->add_redo_no_execute (r.playlist()->get_memento());
355 commit_reversible_command ();
358 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
359 session->request_locate (playhead_cursor->current_frame + distance);
364 Editor::nudge_backward (bool next)
366 jack_nframes_t distance;
367 jack_nframes_t next_distance;
369 if (!session) return;
371 if (!selection->audio_regions.empty()) {
373 begin_reversible_command (_("nudge forward"));
375 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
376 AudioRegion& r ((*i)->region);
378 distance = get_nudge_distance (r.position(), next_distance);
381 distance = next_distance;
384 session->add_undo (r.playlist()->get_memento());
386 if (r.position() > distance) {
387 r.set_position (r.position() - distance, this);
389 r.set_position (0, this);
391 session->add_redo_no_execute (r.playlist()->get_memento());
394 commit_reversible_command ();
398 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
400 if (playhead_cursor->current_frame > distance) {
401 session->request_locate (playhead_cursor->current_frame - distance);
403 session->request_locate (0);
409 Editor::nudge_forward_capture_offset ()
411 jack_nframes_t distance;
413 if (!session) return;
415 if (!selection->audio_regions.empty()) {
417 begin_reversible_command (_("nudge forward"));
419 distance = session->worst_output_latency();
421 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
422 AudioRegion& r ((*i)->region);
424 session->add_undo (r.playlist()->get_memento());
425 r.set_position (r.position() + distance, this);
426 session->add_redo_no_execute (r.playlist()->get_memento());
429 commit_reversible_command ();
435 Editor::nudge_backward_capture_offset ()
437 jack_nframes_t distance;
439 if (!session) return;
441 if (!selection->audio_regions.empty()) {
443 begin_reversible_command (_("nudge forward"));
445 distance = session->worst_output_latency();
447 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
448 AudioRegion& r ((*i)->region);
450 session->add_undo (r.playlist()->get_memento());
452 if (r.position() > distance) {
453 r.set_position (r.position() - distance, this);
455 r.set_position (0, this);
457 session->add_redo_no_execute (r.playlist()->get_memento());
460 commit_reversible_command ();
467 Editor::move_to_start ()
469 session->request_locate (0);
473 Editor::move_to_end ()
476 session->request_locate (session->current_end_frame());
480 Editor::build_region_boundary_cache ()
482 jack_nframes_t pos = 0;
485 TrackViewList tracks;
487 region_boundary_cache.clear ();
494 case SnapToRegionStart:
497 case SnapToRegionEnd:
500 case SnapToRegionSync:
503 case SnapToRegionBoundary:
507 fatal << string_compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type) << endmsg;
512 TimeAxisView *ontrack = 0;
514 while (pos < session->current_end_frame()) {
516 if (!selection->tracks.empty()) {
518 if ((r = find_next_region (pos, point, 1, selection->tracks, &ontrack)) == 0) {
522 } else if (clicked_trackview) {
525 t.push_back (clicked_trackview);
527 if ((r = find_next_region (pos, point, 1, t, &ontrack)) == 0) {
533 if ((r = find_next_region (pos, point, 1, track_views, &ontrack)) == 0) {
541 case SnapToRegionStart:
542 rpos = r->first_frame();
544 case SnapToRegionEnd:
545 rpos = r->last_frame();
547 case SnapToRegionSync:
548 rpos = r->adjust_to_sync (r->first_frame());
551 case SnapToRegionBoundary:
552 rpos = r->last_frame();
559 AudioTimeAxisView *atav;
561 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
562 if (atav->get_diskstream() != 0) {
563 speed = atav->get_diskstream()->speed();
567 rpos = track_frame_to_session_frame(rpos, speed);
569 if (region_boundary_cache.empty() || rpos != region_boundary_cache.back()) {
570 if (snap_type == SnapToRegionBoundary) {
571 region_boundary_cache.push_back (r->first_frame());
573 region_boundary_cache.push_back (rpos);
581 Editor::find_next_region (jack_nframes_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack)
583 TrackViewList::iterator i;
584 jack_nframes_t closest = max_frames;
586 jack_nframes_t rpos = 0;
589 jack_nframes_t track_frame;
590 AudioTimeAxisView *atav;
592 for (i = tracks.begin(); i != tracks.end(); ++i) {
594 jack_nframes_t distance;
598 if ( (atav = dynamic_cast<AudioTimeAxisView*>(*i)) != 0 ) {
599 if (atav->get_diskstream()!=0)
600 track_speed = atav->get_diskstream()->speed();
603 track_frame = session_frame_to_track_frame(frame, track_speed);
605 if ((r = (*i)->find_next_region (track_frame, point, dir)) == 0) {
611 rpos = r->first_frame ();
615 rpos = r->last_frame ();
619 rpos = r->adjust_to_sync (r->first_frame());
622 // rpos is a "track frame", converting it to "session frame"
623 rpos = track_frame_to_session_frame(rpos, track_speed);
626 distance = rpos - frame;
628 distance = frame - rpos;
631 if (distance < closest) {
643 Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir)
646 jack_nframes_t pos = cursor->current_frame;
652 TimeAxisView *ontrack = 0;
654 // so we don't find the current region again..
658 if (!selection->tracks.empty()) {
660 r = find_next_region (pos, point, dir, selection->tracks, &ontrack);
662 } else if (clicked_trackview) {
665 t.push_back (clicked_trackview);
667 r = find_next_region (pos, point, dir, t, &ontrack);
671 r = find_next_region (pos, point, dir, track_views, &ontrack);
680 pos = r->first_frame ();
684 pos = r->last_frame ();
688 pos = r->adjust_to_sync (r->first_frame());
693 AudioTimeAxisView *atav;
695 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
696 if (atav->get_diskstream() != 0) {
697 speed = atav->get_diskstream()->speed();
701 pos = track_frame_to_session_frame(pos, speed);
703 if (cursor == playhead_cursor) {
704 session->request_locate (pos);
706 cursor->set_position (pos);
711 Editor::cursor_to_next_region_point (Cursor* cursor, RegionPoint point)
713 cursor_to_region_point (cursor, point, 1);
717 Editor::cursor_to_previous_region_point (Cursor* cursor, RegionPoint point)
719 cursor_to_region_point (cursor, point, -1);
723 Editor::cursor_to_selection_start (Cursor *cursor)
725 jack_nframes_t pos = 0;
726 switch (mouse_mode) {
728 if (!selection->audio_regions.empty()) {
729 pos = selection->audio_regions.start();
734 if (!selection->time.empty()) {
735 pos = selection->time.start ();
743 if (cursor == playhead_cursor) {
744 session->request_locate (pos);
746 cursor->set_position (pos);
751 Editor::cursor_to_selection_end (Cursor *cursor)
753 jack_nframes_t pos = 0;
755 switch (mouse_mode) {
757 if (!selection->audio_regions.empty()) {
758 pos = selection->audio_regions.end_frame();
763 if (!selection->time.empty()) {
764 pos = selection->time.end_frame ();
772 if (cursor == playhead_cursor) {
773 session->request_locate (pos);
775 cursor->set_position (pos);
780 Editor::playhead_backward ()
787 if (get_prefix (prefix, was_floating)) {
791 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
793 cnt = (jack_nframes_t) prefix;
797 pos = playhead_cursor->current_frame;
799 if ((jack_nframes_t) pos < cnt) {
805 /* XXX this is completely insane. with the current buffering
806 design, we'll force a complete track buffer flush and
807 reload, just to move 1 sample !!!
810 session->request_locate (pos);
814 Editor::playhead_forward ()
821 if (get_prefix (prefix, was_floating)) {
825 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
827 cnt = (jack_nframes_t) floor (prefix);
831 pos = playhead_cursor->current_frame;
833 /* XXX this is completely insane. with the current buffering
834 design, we'll force a complete track buffer flush and
835 reload, just to move 1 sample !!!
838 session->request_locate (pos+cnt);
842 Editor::cursor_align (bool playhead_to_edit)
844 if (playhead_to_edit) {
846 session->request_locate (edit_cursor->current_frame);
849 edit_cursor->set_position (playhead_cursor->current_frame);
854 Editor::edit_cursor_backward ()
861 if (get_prefix (prefix, was_floating)) {
865 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
867 cnt = (jack_nframes_t) prefix;
871 pos = edit_cursor->current_frame;
873 if ((jack_nframes_t) pos < cnt) {
879 edit_cursor->set_position (pos);
883 Editor::edit_cursor_forward ()
890 if (get_prefix (prefix, was_floating)) {
894 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
896 cnt = (jack_nframes_t) floor (prefix);
900 pos = edit_cursor->current_frame;
901 edit_cursor->set_position (pos+cnt);
905 Editor::goto_frame ()
909 jack_nframes_t frame;
911 if (get_prefix (prefix, was_floating)) {
916 frame = (jack_nframes_t) floor (prefix * session->frame_rate());
918 frame = (jack_nframes_t) floor (prefix);
921 session->request_locate (frame);
925 Editor::scroll_backward (float pages)
927 jack_nframes_t frame;
928 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
933 if (get_prefix (prefix, was_floating)) {
934 cnt = (jack_nframes_t) floor (pages * one_page);
937 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
939 cnt = (jack_nframes_t) floor (prefix * one_page);
943 if (leftmost_frame < cnt) {
946 frame = leftmost_frame - cnt;
949 reposition_x_origin (frame);
953 Editor::scroll_forward (float pages)
955 jack_nframes_t frame;
956 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
961 if (get_prefix (prefix, was_floating)) {
962 cnt = (jack_nframes_t) floor (pages * one_page);
965 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
967 cnt = (jack_nframes_t) floor (prefix * one_page);
971 if (ULONG_MAX - cnt < leftmost_frame) {
972 frame = ULONG_MAX - cnt;
974 frame = leftmost_frame + cnt;
977 reposition_x_origin (frame);
981 Editor::scroll_tracks_down ()
987 if (get_prefix (prefix, was_floating)) {
990 cnt = (int) floor (prefix);
993 vertical_adjustment.set_value (vertical_adjustment.get_value() + (cnt * vertical_adjustment.get_page_size()));
997 Editor::scroll_tracks_up ()
1003 if (get_prefix (prefix, was_floating)) {
1006 cnt = (int) floor (prefix);
1009 vertical_adjustment.set_value (vertical_adjustment.get_value() - (cnt * vertical_adjustment.get_page_size()));
1013 Editor::scroll_tracks_down_line ()
1015 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
1016 adj->set_value (adj->get_value() + 10);
1020 Editor::scroll_tracks_up_line ()
1022 Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
1023 adj->set_value (adj->get_value() - 10);
1029 Editor::temporal_zoom_step (bool coarser)
1033 nfpu = frames_per_unit;
1038 nfpu = max(1.0,(nfpu/2.0));
1041 temporal_zoom (nfpu);
1045 Editor::temporal_zoom (gdouble fpu)
1047 if (!session) return;
1049 jack_nframes_t current_page = current_page_frames();
1050 jack_nframes_t current_leftmost = leftmost_frame;
1051 jack_nframes_t current_rightmost;
1052 jack_nframes_t current_center;
1053 jack_nframes_t new_page;
1054 jack_nframes_t leftmost_after_zoom = 0;
1059 new_page = (jack_nframes_t) floor (canvas_width * nfpu);
1061 switch (zoom_focus) {
1063 leftmost_after_zoom = current_leftmost;
1066 case ZoomFocusRight:
1067 current_rightmost = leftmost_frame + current_page;
1068 if (current_rightmost > new_page) {
1069 leftmost_after_zoom = current_rightmost - new_page;
1071 leftmost_after_zoom = 0;
1075 case ZoomFocusCenter:
1076 current_center = current_leftmost + (current_page/2);
1077 if (current_center > (new_page/2)) {
1078 leftmost_after_zoom = current_center - (new_page / 2);
1080 leftmost_after_zoom = 0;
1084 case ZoomFocusPlayhead:
1085 /* try to keep the playhead in the center */
1086 if (playhead_cursor->current_frame > new_page/2) {
1087 leftmost_after_zoom = playhead_cursor->current_frame - (new_page/2);
1089 leftmost_after_zoom = 0;
1094 /* try to keep the edit cursor in the center */
1095 if (edit_cursor->current_frame > leftmost_frame + (new_page/2)) {
1096 leftmost_after_zoom = edit_cursor->current_frame - (new_page/2);
1098 leftmost_after_zoom = 0;
1104 // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
1106 // begin_reversible_command (_("zoom"));
1107 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
1108 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
1109 // commit_reversible_command ();
1111 reposition_and_zoom (leftmost_after_zoom, nfpu);
1115 Editor::temporal_zoom_selection ()
1117 if (!selection) return;
1119 if (selection->time.empty()) {
1123 jack_nframes_t start = selection->time[clicked_selection].start;
1124 jack_nframes_t end = selection->time[clicked_selection].end;
1126 temporal_zoom_by_frame (start, end, "zoom to selection");
1130 Editor::temporal_zoom_session ()
1133 temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
1138 Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, const string & op)
1140 if (!session) return;
1142 if ((start == 0 && end == 0) || end < start) {
1146 jack_nframes_t range = end - start;
1148 double new_fpu = (double)range / (double)canvas_width;
1151 // while (p2 < new_fpu) {
1156 jack_nframes_t new_page = (jack_nframes_t) floor (canvas_width * new_fpu);
1157 jack_nframes_t middle = (jack_nframes_t) floor( (double)start + ((double)range / 2.0f ));
1158 jack_nframes_t new_leftmost = (jack_nframes_t) floor( (double)middle - ((double)new_page/2.0f));
1160 if (new_leftmost > middle) new_leftmost = 0;
1162 // begin_reversible_command (op);
1163 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1164 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1165 // commit_reversible_command ();
1167 reposition_and_zoom (new_leftmost, new_fpu);
1171 Editor::temporal_zoom_to_frame (bool coarser, jack_nframes_t frame)
1173 if (!session) return;
1175 jack_nframes_t range_before = frame - leftmost_frame;
1178 new_fpu = frames_per_unit;
1184 new_fpu = max(1.0,(new_fpu/2.0));
1188 if (new_fpu == frames_per_unit) return;
1190 jack_nframes_t new_leftmost = frame - range_before;
1192 if (new_leftmost > frame) new_leftmost = 0;
1194 // begin_reversible_command (_("zoom to frame"));
1195 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1196 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1197 // commit_reversible_command ();
1199 reposition_and_zoom (new_leftmost, new_fpu);
1203 Editor::select_all_in_track (bool add)
1205 list<Selectable *> touched;
1207 if (!clicked_trackview) {
1211 clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1214 selection->add (touched);
1216 selection->set (touched);
1221 Editor::select_all (bool add)
1223 list<Selectable *> touched;
1225 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1226 if ((*iter)->hidden()) {
1229 (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1233 selection->add (touched);
1235 selection->set (touched);
1241 Editor::invert_selection_in_track ()
1243 list<Selectable *> touched;
1245 if (!clicked_trackview) {
1249 clicked_trackview->get_inverted_selectables (*selection, touched);
1250 selection->set (touched);
1254 Editor::invert_selection ()
1256 list<Selectable *> touched;
1258 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1259 if ((*iter)->hidden()) {
1262 (*iter)->get_inverted_selectables (*selection, touched);
1265 selection->set (touched);
1269 Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
1271 list<Selectable *> touched;
1273 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1274 if ((*iter)->hidden()) {
1277 (*iter)->get_selectables (start, end, top, bot, touched);
1281 selection->add (touched);
1283 selection->set (touched);
1286 return !touched.empty();
1290 Editor::set_selection_from_punch()
1294 if ((location = session->locations()->auto_punch_location()) == 0) {
1298 set_selection_from_range (*location);
1302 Editor::set_selection_from_loop()
1306 if ((location = session->locations()->auto_loop_location()) == 0) {
1310 set_selection_from_range (*location);
1314 Editor::set_selection_from_range (Location& range)
1316 if (clicked_trackview == 0) {
1320 begin_reversible_command (_("set selection from range"));
1321 selection->set (0, range.start(), range.end());
1322 commit_reversible_command ();
1326 Editor::amplitude_zoom_step (bool in)
1340 #ifdef FIX_FOR_CANVAS
1341 /* XXX DO SOMETHING */
1350 Editor::delete_sample_forward ()
1355 Editor::delete_sample_backward ()
1360 Editor::delete_screen ()
1367 Editor::search_backwards ()
1373 Editor::search_forwards ()
1381 Editor::jump_forward_to_mark ()
1387 Location *location = session->locations()->first_location_after (playhead_cursor->current_frame);
1390 session->request_locate (location->start(), session->transport_rolling());
1392 session->request_locate (session->current_end_frame());
1397 Editor::jump_backward_to_mark ()
1403 Location *location = session->locations()->first_location_before (playhead_cursor->current_frame);
1406 session->request_locate (location->start(), session->transport_rolling());
1408 session->request_locate (0);
1419 if (get_prefix (prefix, was_floating)) {
1420 pos = session->audible_frame ();
1423 pos = (jack_nframes_t) floor (prefix * session->frame_rate ());
1425 pos = (jack_nframes_t) floor (prefix);
1429 session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true);
1433 Editor::clear_markers ()
1436 session->begin_reversible_command (_("clear markers"));
1437 session->add_undo (session->locations()->get_memento());
1438 session->locations()->clear_markers ();
1439 session->add_redo_no_execute (session->locations()->get_memento());
1440 session->commit_reversible_command ();
1445 Editor::clear_ranges ()
1448 session->begin_reversible_command (_("clear ranges"));
1449 session->add_undo (session->locations()->get_memento());
1451 Location * looploc = session->locations()->auto_loop_location();
1452 Location * punchloc = session->locations()->auto_punch_location();
1454 session->locations()->clear_ranges ();
1456 if (looploc) session->locations()->add (looploc);
1457 if (punchloc) session->locations()->add (punchloc);
1459 session->add_redo_no_execute (session->locations()->get_memento());
1460 session->commit_reversible_command ();
1465 Editor::clear_locations ()
1467 session->begin_reversible_command (_("clear locations"));
1468 session->add_undo (session->locations()->get_memento());
1469 session->locations()->clear ();
1470 session->add_redo_no_execute (session->locations()->get_memento());
1471 session->commit_reversible_command ();
1472 session->locations()->clear ();
1475 /* INSERT/REPLACE */
1478 Editor::insert_region_list_drag (AudioRegion& region, int x, int y)
1483 jack_nframes_t where;
1484 AudioTimeAxisView *atv = 0;
1487 track_canvas.window_to_world (x, y, wx, wy);
1488 wx += horizontal_adjustment.get_value();
1489 wy += vertical_adjustment.get_value();
1492 event.type = GDK_BUTTON_RELEASE;
1493 event.button.x = wx;
1494 event.button.y = wy;
1496 where = event_frame (&event, &cx, &cy);
1498 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1499 /* clearly outside canvas area */
1503 if ((tv = trackview_by_y_position (cy)) == 0) {
1507 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) == 0) {
1511 if ((playlist = atv->playlist()) == 0) {
1517 begin_reversible_command (_("insert dragged region"));
1518 session->add_undo (playlist->get_memento());
1519 playlist->add_region (*(new AudioRegion (region)), where, 1.0);
1520 session->add_redo_no_execute (playlist->get_memento());
1521 commit_reversible_command ();
1525 Editor::insert_region_list_selection (float times)
1527 AudioTimeAxisView *tv = 0;
1530 if (clicked_audio_trackview != 0) {
1531 tv = clicked_audio_trackview;
1532 } else if (!selection->tracks.empty()) {
1533 if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
1540 if ((playlist = tv->playlist()) == 0) {
1544 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
1546 if (selected->count_selected_rows() != 1) {
1550 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
1551 Region* region = (*i)[region_list_columns.region];
1553 begin_reversible_command (_("insert region"));
1554 session->add_undo (playlist->get_memento());
1555 playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times);
1556 session->add_redo_no_execute (playlist->get_memento());
1557 commit_reversible_command ();
1561 /* BUILT-IN EFFECTS */
1564 Editor::reverse_selection ()
1569 /* GAIN ENVELOPE EDITING */
1572 Editor::edit_envelope ()
1579 Editor::toggle_playback (bool with_abort)
1585 switch (session->slave_source()) {
1590 /* transport controlled by the master */
1594 if (session->is_auditioning()) {
1595 session->cancel_audition ();
1599 if (session->transport_rolling()) {
1600 session->request_stop (with_abort);
1601 if (session->get_auto_loop()) {
1602 session->request_auto_loop (false);
1605 session->request_transport_speed (1.0f);
1610 Editor::play_from_start ()
1612 session->request_locate (0, true);
1616 Editor::play_selection ()
1618 if (selection->time.empty()) {
1622 session->request_play_range (true);
1626 Editor::play_selected_region ()
1628 if (!selection->audio_regions.empty()) {
1629 AudioRegionView *rv = *(selection->audio_regions.begin());
1631 session->request_bounded_roll (rv->region.position(), rv->region.last_frame());
1636 Editor::loop_selected_region ()
1638 if (!selection->audio_regions.empty()) {
1639 AudioRegionView *rv = *(selection->audio_regions.begin());
1642 if ((tll = transport_loop_location()) != 0) {
1644 tll->set (rv->region.position(), rv->region.last_frame());
1646 // enable looping, reposition and start rolling
1648 session->request_auto_loop (true);
1649 session->request_locate (tll->start(), false);
1650 session->request_transport_speed (1.0f);
1656 Editor::play_location (Location& location)
1658 if (location.start() <= location.end()) {
1662 session->request_bounded_roll (location.start(), location.end());
1666 Editor::loop_location (Location& location)
1668 if (location.start() <= location.end()) {
1674 if ((tll = transport_loop_location()) != 0) {
1675 tll->set (location.start(), location.end());
1677 // enable looping, reposition and start rolling
1678 session->request_auto_loop (true);
1679 session->request_locate (tll->start(), true);
1684 Editor::toggle_region_mute ()
1686 if (clicked_regionview) {
1687 clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
1688 } else if (!selection->audio_regions.empty()) {
1689 bool yn = ! (*selection->audio_regions.begin())->region.muted();
1690 selection->foreach_audio_region (&AudioRegion::set_muted, yn);
1695 Editor::toggle_region_opaque ()
1697 if (clicked_regionview) {
1698 clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
1699 } else if (!selection->audio_regions.empty()) {
1700 bool yn = ! (*selection->audio_regions.begin())->region.opaque();
1701 selection->foreach_audio_region (&Region::set_opaque, yn);
1706 Editor::raise_region ()
1708 selection->foreach_audio_region (&Region::raise);
1712 Editor::raise_region_to_top ()
1714 selection->foreach_audio_region (&Region::raise_to_top);
1718 Editor::lower_region ()
1720 selection->foreach_audio_region (&Region::lower);
1724 Editor::lower_region_to_bottom ()
1726 selection->foreach_audio_region (&Region::lower_to_bottom);
1730 Editor::edit_region ()
1732 if (clicked_regionview == 0) {
1736 clicked_regionview->show_region_editor ();
1740 Editor::rename_region ()
1744 Button ok_button (_("OK"));
1745 Button cancel_button (_("Cancel"));
1747 if (selection->audio_regions.empty()) {
1751 dialog.set_title (_("ardour: rename region"));
1752 dialog.set_name ("RegionRenameWindow");
1753 dialog.set_size_request (300, -1);
1754 dialog.set_position (Gtk::WIN_POS_MOUSE);
1755 dialog.set_modal (true);
1757 dialog.get_vbox()->set_border_width (10);
1758 dialog.get_vbox()->pack_start (entry);
1759 dialog.get_action_area()->pack_start (ok_button);
1760 dialog.get_action_area()->pack_start (cancel_button);
1762 entry.set_name ("RegionNameDisplay");
1763 ok_button.set_name ("EditorGTKButton");
1764 cancel_button.set_name ("EditorGTKButton");
1766 region_renamed = false;
1768 entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1769 ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1770 cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
1777 if (region_renamed) {
1778 (*selection->audio_regions.begin())->region.set_name (entry.get_text());
1779 redisplay_regions ();
1784 Editor::rename_region_finished (bool status)
1787 region_renamed = status;
1792 Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
1794 if (session->is_auditioning()) {
1795 session->cancel_audition ();
1798 // note: some potential for creativity here, because region doesn't
1799 // have to belong to the playlist that Route is handling
1801 // bool was_soloed = route.soloed();
1803 route.set_solo (true, this);
1805 session->request_bounded_roll (region.position(), region.position() + region.length());
1807 /* XXX how to unset the solo state ? */
1811 Editor::audition_selected_region ()
1813 if (!selection->audio_regions.empty()) {
1814 AudioRegionView* rv = *(selection->audio_regions.begin());
1815 session->audition_region (rv->region);
1820 Editor::audition_playlist_region_standalone (AudioRegion& region)
1822 session->audition_region (region);
1826 Editor::build_interthread_progress_window ()
1828 interthread_progress_window = new ArdourDialog (X_("interthread progress"), true);
1830 interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
1832 interthread_progress_window->get_vbox()->pack_start (interthread_progress_label, false, false);
1833 interthread_progress_window->get_vbox()->pack_start (interthread_progress_bar,false, false);
1835 // GTK2FIX: this button needs a modifiable label
1837 Button* b = interthread_progress_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1838 b->signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
1840 interthread_cancel_button.add (interthread_cancel_label);
1842 interthread_progress_window->set_default_size (200, 100);
1846 Editor::interthread_cancel_clicked ()
1848 if (current_interthread_info) {
1849 current_interthread_info->cancel = true;
1854 Editor::_import_thread (void *arg)
1856 PBD::ThreadCreated (pthread_self(), X_("Import"));
1858 Editor *ed = (Editor *) arg;
1859 return ed->import_thread ();
1863 Editor::import_thread ()
1865 session->import_audiofile (import_status);
1870 Editor::import_progress_timeout (void *arg)
1872 interthread_progress_label.set_text (import_status.doing_what);
1874 if (import_status.freeze) {
1875 interthread_cancel_button.set_sensitive(false);
1877 interthread_cancel_button.set_sensitive(true);
1880 if (import_status.doing_what == "building peak files") {
1881 interthread_progress_bar.pulse ();
1884 interthread_progress_bar.set_fraction (import_status.progress/100);
1887 return !(import_status.done || import_status.cancel);
1891 Editor::import_audio (bool as_tracks)
1894 warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
1901 str =_("Import selected as tracks");
1903 str = _("Import selected to region list");
1906 SoundFileOmega sfdb (str);
1907 sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks));
1913 Editor::catch_new_audio_region (AudioRegion* ar)
1915 last_audio_region = ar;
1919 Editor::do_import (vector<string> paths, bool split, bool as_tracks)
1923 /* SFDB sets "multichan" to true to indicate "split channels"
1924 so reverse the setting to match the way libardour
1928 import_status.multichan = !split;
1930 if (interthread_progress_window == 0) {
1931 build_interthread_progress_window ();
1934 interthread_progress_window->set_title (_("ardour: audio import in progress"));
1935 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
1936 interthread_progress_window->show_all ();
1937 interthread_progress_bar.set_fraction (0.0f);
1938 interthread_cancel_label.set_text (_("Cancel Import"));
1939 current_interthread_info = &import_status;
1941 c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
1943 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
1945 interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
1947 import_status.pathname = (*i);
1948 import_status.done = false;
1949 import_status.cancel = false;
1950 import_status.freeze = false;
1951 import_status.done = 0.0;
1953 interthread_progress_connection =
1954 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
1956 last_audio_region = 0;
1958 pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
1959 pthread_detach (import_status.thread);
1961 while (!(import_status.done || import_status.cancel)) {
1962 gtk_main_iteration ();
1965 import_status.done = true;
1966 interthread_progress_connection.disconnect ();
1968 if (as_tracks && last_audio_region != 0) {
1969 uint32_t channels = last_audio_region->n_channels();
1971 AudioTrack* at = session->new_audio_track (channels, channels);
1972 AudioRegion* copy = new AudioRegion (*last_audio_region);
1973 at->disk_stream().playlist()->add_region (*copy, 0);
1978 interthread_progress_window->hide_all ();
1982 Editor::reject_because_rate_differs (const string & path, SF_INFO& finfo, const string & action, bool multiple_pending)
1988 if (finfo.samplerate != (int) session->frame_rate()) {
1989 vector<string> choices;
1991 choices.push_back (string_compose (_("%1 it anyway"), action));
1993 if (multiple_pending) {
1994 /* XXX assumptions about sentence structure
1995 here for translators. Sorry.
1997 choices.push_back (string_compose (_("Don't %1 it"), action));
1998 choices.push_back (string_compose (_("%1 all without questions"), action));
1999 choices.push_back (_("Cancel entire import"));
2001 choices.push_back (_("Cancel"));
2004 Gtkmm2ext::Choice rate_choice (
2005 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
2008 rate_choice.chosen.connect (ptr_fun (Main::quit));
2009 rate_choice.show_all ();
2013 switch (rate_choice.get_choice()) {
2014 case 0: /* do it anyway */
2016 case 1: /* don't import this one */
2018 case 2: /* do the rest without asking */
2020 case 3: /* stop a multi-file import */
2030 Editor::embed_audio ()
2033 warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
2037 SoundFileOmega sfdb (_("Add to External Region list"));
2038 sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
2044 Editor::do_embed_sndfiles (vector<string> paths, bool split)
2046 bool multiple_files = paths.size() > 1;
2047 bool check_sample_rate = true;
2049 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
2050 embed_sndfile (*i, split, multiple_files, check_sample_rate);
2053 session->save_state ("");
2057 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
2059 SndFileSource *source = 0; /* keep g++ quiet */
2060 AudioRegion::SourceList sources;
2066 /* lets see if we can link it into the session */
2068 linked_path = session->sound_dir();
2069 linked_path += PBD::basename (path);
2071 if (link (path.c_str(), linked_path.c_str()) == 0) {
2073 /* there are many reasons why link(2) might have failed.
2074 but if it succeeds, we now have a link in the
2075 session sound dir that will protect against
2076 unlinking of the original path. nice.
2082 memset (&finfo, 0, sizeof(finfo));
2084 /* note that we temporarily truncated _id at the colon */
2086 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2088 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2089 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
2095 if (check_sample_rate) {
2096 switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
2102 check_sample_rate = false;
2111 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2112 ARDOUR_UI::instance()->flush_pending ();
2114 /* make the proper number of channels in the region */
2116 for (int n=0; n < finfo.channels; ++n)
2119 idspec += string_compose(":%1", n);
2122 source = new SndFileSource (idspec.c_str());
2123 sources.push_back(source);
2126 catch (failed_constructor& err) {
2127 error << string_compose(_("could not open %1"), path) << endmsg;
2131 ARDOUR_UI::instance()->flush_pending ();
2134 if (sources.size() > 0) {
2136 string region_name = PBD::basename_nosuffix (path);
2137 region_name += "-0";
2139 /* The created region isn't dropped. It emits a signal
2140 that is picked up by the session.
2143 new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
2144 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2146 /* make sure we can see it in the list */
2148 /* its the second node, always */
2150 // GTK2FIX ?? is it still always the 2nd node
2152 TreeModel::Path path ("2");
2153 region_list_display.expand_row (path, true);
2155 ARDOUR_UI::instance()->flush_pending ();
2159 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2163 Editor::insert_sndfile (bool as_tracks)
2165 // SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2171 // c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
2172 str = _("Insert selected as new tracks");
2178 if (clicked_audio_trackview == 0) {
2182 if (ensure_cursor (&pos)) {
2186 // c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
2187 str = _("Insert selected");
2190 // sfdb.run (str, false);
2195 Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
2199 bool multiple_files;
2200 bool check_sample_rate = true;
2202 multiple_files = paths.size() > 1;
2204 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
2206 memset (&finfo, 0, sizeof(finfo));
2208 if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
2210 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2211 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
2218 /* add a new track */
2220 if (check_sample_rate) {
2221 switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
2227 check_sample_rate = false;
2235 uint32_t input_chan = finfo.channels;
2236 uint32_t output_chan;
2238 if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
2239 output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
2241 output_chan = input_chan;
2244 (void) session->new_audio_track (input_chan, output_chan);
2247 /* get the last (most recently added) track view */
2249 AudioTimeAxisView* tv;
2251 if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
2252 fatal << _("programming error: ")
2253 << X_("last trackview after new_audio_track is not an audio track!")
2258 jack_nframes_t pos = 0;
2259 insert_sndfile_into (*p, true, tv, pos, false);
2264 Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
2266 for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
2267 insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
2272 Editor::insert_sndfile_into (const string & path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
2274 SndFileSource *source = 0; /* keep g++ quiet */
2275 AudioRegion::SourceList sources;
2280 memset (&finfo, 0, sizeof(finfo));
2282 /* note that we temporarily truncated _id at the colon */
2284 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2286 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2287 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
2293 if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
2297 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2298 ARDOUR_UI::instance()->flush_pending ();
2300 /* make the proper number of channels in the region */
2302 for (int n=0; n < finfo.channels; ++n)
2305 idspec += string_compose(":%1", n);
2308 source = new SndFileSource (idspec.c_str());
2309 sources.push_back(source);
2312 catch (failed_constructor& err) {
2313 error << string_compose(_("could not open %1"), path) << endmsg;
2317 ARDOUR_UI::instance()->flush_pending ();
2320 if (sources.size() > 0) {
2322 string region_name = region_name_from_path (PBD::basename (path));
2324 AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
2325 0, /* irrelevant these days */
2326 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2328 begin_reversible_command (_("insert sndfile"));
2329 session->add_undo (tv->playlist()->get_memento());
2330 tv->playlist()->add_region (*region, pos);
2331 session->add_redo_no_execute (tv->playlist()->get_memento());
2332 commit_reversible_command ();
2334 pos += sources[0]->length();
2336 ARDOUR_UI::instance()->flush_pending ();
2340 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2345 Editor::region_from_selection ()
2347 if (clicked_trackview == 0) {
2351 if (selection->time.empty()) {
2355 jack_nframes_t start = selection->time[clicked_selection].start;
2356 jack_nframes_t end = selection->time[clicked_selection].end;
2358 jack_nframes_t selection_cnt = end - start + 1;
2360 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2362 AudioRegion *region;
2363 AudioRegion *current;
2367 jack_nframes_t internal_start;
2370 if ((pl = (*i)->playlist()) == 0) {
2374 if ((current_r = pl->top_region_at (start)) == 0) {
2378 if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
2379 internal_start = start - current->position();
2380 session->region_name (new_name, current->name(), true);
2381 region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
2387 Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
2389 if (selection->time.empty() || selection->tracks.empty()) {
2393 jack_nframes_t start = selection->time[clicked_selection].start;
2394 jack_nframes_t end = selection->time[clicked_selection].end;
2396 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2398 AudioRegion* current;
2401 jack_nframes_t internal_start;
2404 if ((playlist = (*i)->playlist()) == 0) {
2408 if ((current_r = playlist->top_region_at(start)) == 0) {
2412 if ((current = dynamic_cast<AudioRegion*>(current_r)) == 0) {
2416 internal_start = start - current->position();
2417 session->region_name (new_name, current->name(), true);
2419 new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name));
2424 Editor::split_multichannel_region ()
2426 vector<AudioRegion*> v;
2428 if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
2432 clicked_regionview->region.separate_by_channel (*session, v);
2434 /* nothing else to do, really */
2438 Editor::new_region_from_selection ()
2440 region_from_selection ();
2441 cancel_selection ();
2445 Editor::separate_region_from_selection ()
2447 bool doing_undo = false;
2449 if (selection->time.empty()) {
2455 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2457 AudioTimeAxisView* atv;
2459 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2461 if (atv->is_audio_track()) {
2463 if ((playlist = atv->playlist()) != 0) {
2465 begin_reversible_command (_("separate"));
2468 if (doing_undo) session->add_undo ((playlist)->get_memento());
2470 /* XXX need to consider musical time selections here at some point */
2472 double speed = atv->get_diskstream()->speed();
2474 for (list<AudioRange>::iterator t = selection->time.begin(); t != selection->time.end(); ++t) {
2475 playlist->partition ((jack_nframes_t)((*t).start * speed), (jack_nframes_t)((*t).end * speed), true);
2478 if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
2484 if (doing_undo) commit_reversible_command ();
2488 Editor::crop_region_to_selection ()
2490 if (selection->time.empty()) {
2494 vector<Playlist*> playlists;
2497 if (clicked_trackview != 0) {
2499 if ((playlist = clicked_trackview->playlist()) == 0) {
2503 playlists.push_back (playlist);
2507 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2509 AudioTimeAxisView* atv;
2511 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2513 if (atv->is_audio_track()) {
2515 if ((playlist = atv->playlist()) != 0) {
2516 playlists.push_back (playlist);
2523 if (!playlists.empty()) {
2525 jack_nframes_t start;
2529 begin_reversible_command (_("trim to selection"));
2531 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2535 start = selection->time.start();
2537 if ((region = (*i)->top_region_at(start)) == 0) {
2541 /* now adjust lengths to that we do the right thing
2542 if the selection extends beyond the region
2545 start = max (start, region->position());
2546 end = min (selection->time.end_frame(), start + region->length() - 1);
2547 cnt = end - start + 1;
2549 session->add_undo ((*i)->get_memento());
2550 region->trim_to (start, cnt, this);
2551 session->add_redo_no_execute ((*i)->get_memento());
2554 commit_reversible_command ();
2559 Editor::region_fill_track ()
2563 if (!session || selection->audio_regions.empty()) {
2567 end = session->current_end_frame ();
2569 begin_reversible_command (_("region fill"));
2571 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2573 AudioRegion& region ((*i)->region);
2574 Playlist* pl = region.playlist();
2576 if (end <= region.last_frame()) {
2580 double times = (double) (end - region.last_frame()) / (double) region.length();
2586 session->add_undo (pl->get_memento());
2587 pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
2588 session->add_redo_no_execute (pl->get_memento());
2591 commit_reversible_command ();
2595 Editor::region_fill_selection ()
2597 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2601 if (selection->time.empty()) {
2607 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
2609 if (selected->count_selected_rows() != 1) {
2613 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
2614 region = (*i)[region_list_columns.region];
2616 jack_nframes_t start = selection->time[clicked_selection].start;
2617 jack_nframes_t end = selection->time[clicked_selection].end;
2621 if (selection->tracks.empty()) {
2625 jack_nframes_t selection_length = end - start;
2626 float times = (float)selection_length / region->length();
2628 begin_reversible_command (_("fill selection"));
2630 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2632 if ((playlist = (*i)->playlist()) == 0) {
2636 session->add_undo (playlist->get_memento());
2637 playlist->add_region (*(createRegion (*region)), start, times);
2638 session->add_redo_no_execute (playlist->get_memento());
2641 commit_reversible_command ();
2645 Editor::set_region_sync_from_edit_cursor ()
2647 if (clicked_regionview == 0) {
2651 if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
2652 error << _("Place the edit cursor at the desired sync point") << endmsg;
2656 Region& region (clicked_regionview->region);
2658 begin_reversible_command (_("set sync from edit cursor"));
2659 session->add_undo (region.playlist()->get_memento());
2660 region.set_sync_position (edit_cursor->current_frame);
2661 session->add_redo_no_execute (region.playlist()->get_memento());
2662 commit_reversible_command ();
2666 Editor::remove_region_sync ()
2668 if (clicked_regionview) {
2669 Region& region (clicked_regionview->region);
2670 begin_reversible_command (_("remove sync"));
2671 session->add_undo (region.playlist()->get_memento());
2672 region.clear_sync_position ();
2673 session->add_redo_no_execute (region.playlist()->get_memento());
2674 commit_reversible_command ();
2679 Editor::naturalize ()
2681 if (selection->audio_regions.empty()) {
2684 begin_reversible_command (_("naturalize"));
2685 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2686 session->add_undo ((*i)->region.get_memento());
2687 (*i)->region.move_to_natural_position (this);
2688 session->add_redo_no_execute ((*i)->region.get_memento());
2690 commit_reversible_command ();
2694 Editor::align (RegionPoint what)
2696 align_selection (what, edit_cursor->current_frame);
2700 Editor::align_relative (RegionPoint what)
2702 align_selection_relative (what, edit_cursor->current_frame);
2705 struct RegionSortByTime {
2706 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
2707 return a->region.position() < b->region.position();
2712 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
2714 if (selection->audio_regions.empty()) {
2718 jack_nframes_t distance;
2719 jack_nframes_t pos = 0;
2722 list<AudioRegionView*> sorted;
2723 selection->audio_regions.by_position (sorted);
2724 Region& r ((*sorted.begin())->region);
2728 pos = r.first_frame ();
2732 pos = r.last_frame();
2736 pos = r.adjust_to_sync (r.first_frame());
2740 if (pos > position) {
2741 distance = pos - position;
2744 distance = position - pos;
2748 begin_reversible_command (_("align selection (relative)"));
2750 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2752 Region& region ((*i)->region);
2754 session->add_undo (region.playlist()->get_memento());
2757 region.set_position (region.position() + distance, this);
2759 region.set_position (region.position() - distance, this);
2762 session->add_redo_no_execute (region.playlist()->get_memento());
2766 commit_reversible_command ();
2770 Editor::align_selection (RegionPoint point, jack_nframes_t position)
2772 if (selection->audio_regions.empty()) {
2776 begin_reversible_command (_("align selection"));
2778 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2779 align_region_internal ((*i)->region, point, position);
2782 commit_reversible_command ();
2786 Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position)
2788 begin_reversible_command (_("align region"));
2789 align_region_internal (region, point, position);
2790 commit_reversible_command ();
2794 Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position)
2796 session->add_undo (region.playlist()->get_memento());
2800 region.set_position (region.adjust_to_sync (position), this);
2804 if (position > region.length()) {
2805 region.set_position (position - region.length(), this);
2810 region.set_position (position, this);
2814 session->add_redo_no_execute (region.playlist()->get_memento());
2818 Editor::trim_region_to_edit_cursor ()
2820 if (clicked_regionview == 0) {
2824 Region& region (clicked_regionview->region);
2827 AudioTimeAxisView *atav;
2829 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2830 if (atav->get_diskstream() != 0) {
2831 speed = atav->get_diskstream()->speed();
2835 begin_reversible_command (_("trim to edit"));
2836 session->add_undo (region.playlist()->get_memento());
2837 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2838 session->add_redo_no_execute (region.playlist()->get_memento());
2839 commit_reversible_command ();
2843 Editor::trim_region_from_edit_cursor ()
2845 if (clicked_regionview == 0) {
2849 Region& region (clicked_regionview->region);
2852 AudioTimeAxisView *atav;
2854 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2855 if (atav->get_diskstream() != 0) {
2856 speed = atav->get_diskstream()->speed();
2860 begin_reversible_command (_("trim to edit"));
2861 session->add_undo (region.playlist()->get_memento());
2862 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2863 session->add_redo_no_execute (region.playlist()->get_memento());
2864 commit_reversible_command ();
2868 Editor::unfreeze_route ()
2870 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2874 clicked_audio_trackview->audio_track()->unfreeze ();
2878 Editor::_freeze_thread (void* arg)
2880 PBD::ThreadCreated (pthread_self(), X_("Freeze"));
2881 return static_cast<Editor*>(arg)->freeze_thread ();
2885 Editor::freeze_thread ()
2887 clicked_audio_trackview->audio_track()->freeze (*current_interthread_info);
2892 Editor::freeze_progress_timeout (void *arg)
2894 interthread_progress_bar.set_fraction (current_interthread_info->progress/100);
2895 return !(current_interthread_info->done || current_interthread_info->cancel);
2899 Editor::freeze_route ()
2901 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2905 InterThreadInfo itt;
2907 if (interthread_progress_window == 0) {
2908 build_interthread_progress_window ();
2911 interthread_progress_window->set_title (_("ardour: freeze"));
2912 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2913 interthread_progress_window->show_all ();
2914 interthread_progress_bar.set_fraction (0.0f);
2915 interthread_progress_label.set_text ("");
2916 interthread_cancel_label.set_text (_("Cancel Freeze"));
2917 current_interthread_info = &itt;
2919 interthread_progress_connection =
2920 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
2924 itt.progress = 0.0f;
2926 pthread_create (&itt.thread, 0, _freeze_thread, this);
2928 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2930 while (!itt.done && !itt.cancel) {
2931 gtk_main_iteration ();
2934 interthread_progress_connection.disconnect ();
2935 interthread_progress_window->hide_all ();
2936 current_interthread_info = 0;
2937 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2941 Editor::bounce_range_selection ()
2943 if (selection->time.empty()) {
2947 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
2949 jack_nframes_t start = selection->time[clicked_selection].start;
2950 jack_nframes_t end = selection->time[clicked_selection].end;
2951 jack_nframes_t cnt = end - start + 1;
2953 begin_reversible_command (_("bounce range"));
2955 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
2957 AudioTimeAxisView* atv;
2959 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
2965 if ((playlist = atv->playlist()) == 0) {
2969 InterThreadInfo itt;
2973 itt.progress = false;
2975 session->add_undo (playlist->get_memento());
2976 atv->audio_track()->bounce_range (start, cnt, itt);
2977 session->add_redo_no_execute (playlist->get_memento());
2980 commit_reversible_command ();
2998 Editor::cut_copy (CutCopyOp op)
3000 /* only cancel selection if cut/copy is successful.*/
3012 opname = _("clear");
3016 cut_buffer->clear ();
3018 switch (current_mouse_mode()) {
3020 if (!selection->audio_regions.empty() || !selection->points.empty()) {
3022 begin_reversible_command (opname + _(" objects"));
3024 if (!selection->audio_regions.empty()) {
3026 cut_copy_regions (op);
3029 selection->clear_audio_regions ();
3033 if (!selection->points.empty()) {
3034 cut_copy_points (op);
3037 selection->clear_points ();
3041 commit_reversible_command ();
3046 if (!selection->time.empty()) {
3048 begin_reversible_command (opname + _(" range"));
3049 cut_copy_ranges (op);
3050 commit_reversible_command ();
3053 selection->clear_time ();
3065 Editor::cut_copy_points (CutCopyOp op)
3067 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3069 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
3072 atv->cut_copy_clear_objects (selection->points, op);
3078 Editor::cut_copy_regions (CutCopyOp op)
3080 typedef std::map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
3081 PlaylistMapping pmap;
3082 jack_nframes_t first_position = max_frames;
3083 set<Playlist*> freezelist;
3084 pair<set<Playlist*>::iterator,bool> insert_result;
3086 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
3087 first_position = min ((*x)->region.position(), first_position);
3089 if (op == Cut || op == Clear) {
3090 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3092 insert_result = freezelist.insert (pl);
3093 if (insert_result.second) {
3095 session->add_undo (pl->get_memento());
3101 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
3103 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3105 AudioRegionSelection::iterator tmp;
3112 PlaylistMapping::iterator pi = pmap.find (pl);
3114 if (pi == pmap.end()) {
3115 npl = new AudioPlaylist (*session, "cutlist", true);
3124 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3125 pl->remove_region (&((*x)->region));
3129 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3133 pl->remove_region (&((*x)->region));
3141 list<Playlist*> foo;
3143 for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3144 foo.push_back (i->second);
3148 cut_buffer->set (foo);
3151 for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3153 session->add_redo_no_execute ((*pl)->get_memento());
3158 Editor::cut_copy_ranges (CutCopyOp op)
3160 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3161 (*i)->cut_copy_clear (*selection, op);
3166 Editor::paste (float times)
3168 paste_internal (edit_cursor->current_frame, times);
3172 Editor::mouse_paste ()
3177 track_canvas.get_pointer (x, y);
3178 track_canvas.window_to_world (x, y, wx, wy);
3179 wx += horizontal_adjustment.get_value();
3180 wy += vertical_adjustment.get_value();
3183 event.type = GDK_BUTTON_RELEASE;
3184 event.button.x = wx;
3185 event.button.y = wy;
3187 jack_nframes_t where = event_frame (&event, 0, 0);
3189 paste_internal (where, 1);
3193 Editor::paste_internal (jack_nframes_t position, float times)
3195 bool commit = false;
3197 if (cut_buffer->empty() || selection->tracks.empty()) {
3201 if (position == max_frames) {
3202 position = edit_cursor->current_frame;
3205 begin_reversible_command (_("paste"));
3207 TrackSelection::iterator i;
3210 for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) {
3212 /* undo/redo is handled by individual tracks */
3214 if ((*i)->paste (position, times, *cut_buffer, nth)) {
3220 commit_reversible_command ();
3225 Editor::paste_named_selection (float times)
3227 TrackSelection::iterator t;
3229 Glib::RefPtr<TreeSelection> selected = named_selection_display.get_selection();
3231 if (selected->count_selected_rows() != 1 || selection->tracks.empty()) {
3235 TreeModel::iterator i = selected->get_selected();
3236 NamedSelection* ns = (*i)[named_selection_columns.selection];
3238 list<Playlist*>::iterator chunk;
3239 list<Playlist*>::iterator tmp;
3241 chunk = ns->playlists.begin();
3243 begin_reversible_command (_("paste chunk"));
3245 for (t = selection->tracks.begin(); t != selection->tracks.end(); ++t) {
3247 AudioTimeAxisView* atv;
3251 if ((atv = dynamic_cast<AudioTimeAxisView*> (*t)) == 0) {
3255 if ((pl = atv->playlist()) == 0) {
3259 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
3266 session->add_undo (apl->get_memento());
3267 apl->paste (**chunk, edit_cursor->current_frame, times);
3268 session->add_redo_no_execute (apl->get_memento());
3270 if (tmp != ns->playlists.end()) {
3275 commit_reversible_command();
3279 Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
3282 AudioRegionSelection sel = regions; // clear (below) will clear the argument list
3284 begin_reversible_command (_("duplicate region"));
3286 selection->clear_audio_regions ();
3288 for (AudioRegionSelection::iterator i = sel.begin(); i != sel.end(); ++i) {
3290 Region& r ((*i)->region);
3292 TimeAxisView& tv = (*i)->get_time_axis_view();
3293 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
3294 sigc::connection c = atv->view->AudioRegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
3296 playlist = (*i)->region.playlist();
3297 session->add_undo (playlist->get_memento());
3298 playlist->duplicate (r, r.last_frame(), times);
3299 session->add_redo_no_execute (playlist->get_memento());
3303 if (latest_regionview) {
3304 selection->add (latest_regionview);
3309 commit_reversible_command ();
3313 Editor::duplicate_selection (float times)
3315 if (selection->time.empty() || selection->tracks.empty()) {
3320 vector<AudioRegion*> new_regions;
3321 vector<AudioRegion*>::iterator ri;
3323 create_region_from_selection (new_regions);
3325 if (new_regions.empty()) {
3329 begin_reversible_command (_("duplicate selection"));
3331 ri = new_regions.begin();
3333 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3334 if ((playlist = (*i)->playlist()) == 0) {
3337 session->add_undo (playlist->get_memento());
3338 playlist->duplicate (**ri, selection->time[clicked_selection].end, times);
3339 session->add_redo_no_execute (playlist->get_memento());
3342 if (ri == new_regions.end()) {
3347 commit_reversible_command ();
3351 Editor::center_playhead ()
3353 float page = canvas_width * frames_per_unit;
3355 center_screen_internal (playhead_cursor->current_frame, page);
3359 Editor::center_edit_cursor ()
3361 float page = canvas_width * frames_per_unit;
3363 center_screen_internal (edit_cursor->current_frame, page);
3367 Editor::clear_playlist (Playlist& playlist)
3369 begin_reversible_command (_("clear playlist"));
3370 session->add_undo (playlist.get_memento());
3372 session->add_redo_no_execute (playlist.get_memento());
3373 commit_reversible_command ();
3377 Editor::nudge_track (bool use_edit_cursor, bool forwards)
3380 jack_nframes_t distance;
3381 jack_nframes_t next_distance;
3382 jack_nframes_t start;
3384 if (use_edit_cursor) {
3385 start = edit_cursor->current_frame;
3390 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
3394 if (selection->tracks.empty()) {
3398 begin_reversible_command (_("nudge track"));
3400 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3402 if ((playlist = (*i)->playlist()) == 0) {
3406 session->add_undo (playlist->get_memento());
3407 playlist->nudge_after (start, distance, forwards);
3408 session->add_redo_no_execute (playlist->get_memento());
3411 commit_reversible_command ();
3415 Editor::toggle_xfades_active ()
3418 session->set_crossfades_active (!session->get_crossfades_active());
3423 Editor::set_xfade_visibility (bool yn)
3429 Editor::toggle_xfade_visibility ()
3431 set_xfade_visibility (!xfade_visibility());
3435 Editor::remove_last_capture ()
3437 vector<string> choices;
3444 if (Config->get_verify_remove_last_capture()) {
3445 prompt = _("Do you really want to destroy the last capture?"
3446 "\n(This is destructive and cannot be undone)");
3448 choices.push_back (_("Yes, destroy it."));
3449 choices.push_back (_("No, do nothing."));
3451 Gtkmm2ext::Choice prompter (prompt, choices);
3452 prompter.chosen.connect (ptr_fun (Main::quit));
3453 prompter.show_all ();
3457 if (prompter.get_choice() == 0) {
3458 session->remove_last_capture ();
3462 session->remove_last_capture();
3467 Editor::normalize_region ()
3473 if (selection->audio_regions.empty()) {
3477 begin_reversible_command (_("normalize"));
3479 track_canvas.get_window()->set_cursor (*wait_cursor);
3482 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3483 session->add_undo ((*r)->region.get_memento());
3484 (*r)->region.normalize_to (0.0f);
3485 session->add_redo_no_execute ((*r)->region.get_memento());
3488 commit_reversible_command ();
3489 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
3494 Editor::denormalize_region ()
3500 if (selection->audio_regions.empty()) {
3504 begin_reversible_command ("denormalize");
3506 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3507 session->add_undo ((*r)->region.get_memento());
3508 (*r)->region.set_scale_amplitude (1.0f);
3509 session->add_redo_no_execute ((*r)->region.get_memento());
3512 commit_reversible_command ();
3517 Editor::reverse_region ()
3523 Reverse rev (*session);
3524 apply_filter (rev, _("reverse regions"));
3528 Editor::apply_filter (AudioFilter& filter, string command)
3530 if (selection->audio_regions.empty()) {
3534 begin_reversible_command (command);
3536 track_canvas.get_window()->set_cursor (*wait_cursor);
3539 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
3541 AudioRegion& region ((*r)->region);
3542 Playlist* playlist = region.playlist();
3544 AudioRegionSelection::iterator tmp;
3549 if (region.apply (filter) == 0) {
3551 session->add_undo (playlist->get_memento());
3552 playlist->replace_region (region, *(filter.results.front()), region.position());
3553 session->add_redo_no_execute (playlist->get_memento());
3561 commit_reversible_command ();
3562 selection->audio_regions.clear ();
3565 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
3569 Editor::region_selection_op (void (Region::*pmf)(void))
3571 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3572 ((*i)->region.*pmf)();
3578 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
3580 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3581 ((*i)->region.*pmf)(arg);
3586 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
3588 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3589 ((*i)->region.*pmf)(yn);
3594 Editor::external_edit_region ()
3596 if (!clicked_regionview) {
3604 Editor::brush (jack_nframes_t pos)
3606 AudioRegionSelection sel;
3609 if (selection->audio_regions.empty()) {
3610 /* XXX get selection from region list */
3612 sel = selection->audio_regions;
3619 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3620 mouse_brush_insert_region ((*i), pos);
3625 Editor::toggle_gain_envelope_visibility ()
3627 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3628 (*i)->set_envelope_visible (!(*i)->envelope_visible());
3633 Editor::toggle_gain_envelope_active ()
3635 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3636 AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
3638 ar->set_envelope_active (true);