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) {
1309 set_selection_from_range (*location);
1313 Editor::select_all_from_punch()
1316 list<Selectable *> touched;
1317 if ((location = session->locations()->auto_punch_location()) == 0) {
1321 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1322 if ((*iter)->hidden()) {
1325 (*iter)->get_selectables (location->start(), location->end(), 0, DBL_MAX, touched);
1327 begin_reversible_command (_("select all from punch"));
1328 selection->set (touched);
1329 commit_reversible_command ();
1334 Editor::select_all_from_loop()
1337 list<Selectable *> touched;
1339 if ((location = session->locations()->auto_loop_location()) == 0) {
1342 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1343 if ((*iter)->hidden()) {
1346 (*iter)->get_selectables (location->start(), location->end(), 0, DBL_MAX, touched);
1348 begin_reversible_command (_("select all from loop"));
1349 selection->set (touched);
1350 commit_reversible_command ();
1355 Editor::set_selection_from_range (Location& range)
1357 if (clicked_trackview == 0) {
1361 begin_reversible_command (_("set selection from range"));
1362 selection->set (0, range.start(), range.end());
1363 commit_reversible_command ();
1367 Editor::select_all_after_cursor (Cursor *cursor, bool after)
1369 jack_nframes_t start;
1371 list<Selectable *> touched;
1374 begin_reversible_command (_("select all after cursor"));
1375 start = cursor->current_frame ;
1376 end = session->current_end_frame();
1378 begin_reversible_command (_("select all before cursor"));
1380 end = cursor->current_frame ;
1382 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1383 if ((*iter)->hidden()) {
1386 (*iter)->get_selectables (start, end, 0, DBL_MAX, touched);
1388 selection->set (touched);
1389 commit_reversible_command ();
1393 Editor::amplitude_zoom_step (bool in)
1407 #ifdef FIX_FOR_CANVAS
1408 /* XXX DO SOMETHING */
1417 Editor::delete_sample_forward ()
1422 Editor::delete_sample_backward ()
1427 Editor::delete_screen ()
1434 Editor::search_backwards ()
1440 Editor::search_forwards ()
1448 Editor::jump_forward_to_mark ()
1454 Location *location = session->locations()->first_location_after (playhead_cursor->current_frame);
1457 session->request_locate (location->start(), session->transport_rolling());
1459 session->request_locate (session->current_end_frame());
1464 Editor::jump_backward_to_mark ()
1470 Location *location = session->locations()->first_location_before (playhead_cursor->current_frame);
1473 session->request_locate (location->start(), session->transport_rolling());
1475 session->request_locate (0);
1486 if (get_prefix (prefix, was_floating)) {
1487 pos = session->audible_frame ();
1490 pos = (jack_nframes_t) floor (prefix * session->frame_rate ());
1492 pos = (jack_nframes_t) floor (prefix);
1496 session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true);
1500 Editor::clear_markers ()
1503 session->begin_reversible_command (_("clear markers"));
1504 session->add_undo (session->locations()->get_memento());
1505 session->locations()->clear_markers ();
1506 session->add_redo_no_execute (session->locations()->get_memento());
1507 session->commit_reversible_command ();
1512 Editor::clear_ranges ()
1515 session->begin_reversible_command (_("clear ranges"));
1516 session->add_undo (session->locations()->get_memento());
1518 Location * looploc = session->locations()->auto_loop_location();
1519 Location * punchloc = session->locations()->auto_punch_location();
1521 session->locations()->clear_ranges ();
1523 if (looploc) session->locations()->add (looploc);
1524 if (punchloc) session->locations()->add (punchloc);
1526 session->add_redo_no_execute (session->locations()->get_memento());
1527 session->commit_reversible_command ();
1532 Editor::clear_locations ()
1534 session->begin_reversible_command (_("clear locations"));
1535 session->add_undo (session->locations()->get_memento());
1536 session->locations()->clear ();
1537 session->add_redo_no_execute (session->locations()->get_memento());
1538 session->commit_reversible_command ();
1539 session->locations()->clear ();
1542 /* INSERT/REPLACE */
1545 Editor::insert_region_list_drag (AudioRegion& region, int x, int y)
1550 jack_nframes_t where;
1551 AudioTimeAxisView *atv = 0;
1554 track_canvas.window_to_world (x, y, wx, wy);
1555 wx += horizontal_adjustment.get_value();
1556 wy += vertical_adjustment.get_value();
1559 event.type = GDK_BUTTON_RELEASE;
1560 event.button.x = wx;
1561 event.button.y = wy;
1563 where = event_frame (&event, &cx, &cy);
1565 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1566 /* clearly outside canvas area */
1570 if ((tv = trackview_by_y_position (cy)) == 0) {
1574 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) == 0) {
1578 if ((playlist = atv->playlist()) == 0) {
1584 begin_reversible_command (_("insert dragged region"));
1585 session->add_undo (playlist->get_memento());
1586 playlist->add_region (*(new AudioRegion (region)), where, 1.0);
1587 session->add_redo_no_execute (playlist->get_memento());
1588 commit_reversible_command ();
1592 Editor::insert_region_list_selection (float times)
1594 AudioTimeAxisView *tv = 0;
1597 if (clicked_audio_trackview != 0) {
1598 tv = clicked_audio_trackview;
1599 } else if (!selection->tracks.empty()) {
1600 if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
1607 if ((playlist = tv->playlist()) == 0) {
1611 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
1613 if (selected->count_selected_rows() != 1) {
1617 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
1618 Region* region = (*i)[region_list_columns.region];
1620 begin_reversible_command (_("insert region"));
1621 session->add_undo (playlist->get_memento());
1622 playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times);
1623 session->add_redo_no_execute (playlist->get_memento());
1624 commit_reversible_command ();
1628 /* BUILT-IN EFFECTS */
1631 Editor::reverse_selection ()
1636 /* GAIN ENVELOPE EDITING */
1639 Editor::edit_envelope ()
1646 Editor::toggle_playback (bool with_abort)
1652 switch (session->slave_source()) {
1657 /* transport controlled by the master */
1661 if (session->is_auditioning()) {
1662 session->cancel_audition ();
1666 if (session->transport_rolling()) {
1667 session->request_stop (with_abort);
1668 if (session->get_auto_loop()) {
1669 session->request_auto_loop (false);
1672 session->request_transport_speed (1.0f);
1677 Editor::play_from_start ()
1679 session->request_locate (0, true);
1683 Editor::play_selection ()
1685 if (selection->time.empty()) {
1689 session->request_play_range (true);
1693 Editor::play_selected_region ()
1695 if (!selection->audio_regions.empty()) {
1696 AudioRegionView *rv = *(selection->audio_regions.begin());
1698 session->request_bounded_roll (rv->region.position(), rv->region.last_frame());
1703 Editor::loop_selected_region ()
1705 if (!selection->audio_regions.empty()) {
1706 AudioRegionView *rv = *(selection->audio_regions.begin());
1709 if ((tll = transport_loop_location()) != 0) {
1711 tll->set (rv->region.position(), rv->region.last_frame());
1713 // enable looping, reposition and start rolling
1715 session->request_auto_loop (true);
1716 session->request_locate (tll->start(), false);
1717 session->request_transport_speed (1.0f);
1723 Editor::play_location (Location& location)
1725 if (location.start() <= location.end()) {
1729 session->request_bounded_roll (location.start(), location.end());
1733 Editor::loop_location (Location& location)
1735 if (location.start() <= location.end()) {
1741 if ((tll = transport_loop_location()) != 0) {
1742 tll->set (location.start(), location.end());
1744 // enable looping, reposition and start rolling
1745 session->request_auto_loop (true);
1746 session->request_locate (tll->start(), true);
1751 Editor::toggle_region_mute ()
1753 if (clicked_regionview) {
1754 clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
1755 } else if (!selection->audio_regions.empty()) {
1756 bool yn = ! (*selection->audio_regions.begin())->region.muted();
1757 selection->foreach_audio_region (&AudioRegion::set_muted, yn);
1762 Editor::toggle_region_opaque ()
1764 if (clicked_regionview) {
1765 clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
1766 } else if (!selection->audio_regions.empty()) {
1767 bool yn = ! (*selection->audio_regions.begin())->region.opaque();
1768 selection->foreach_audio_region (&Region::set_opaque, yn);
1773 Editor::raise_region ()
1775 selection->foreach_audio_region (&Region::raise);
1779 Editor::raise_region_to_top ()
1781 selection->foreach_audio_region (&Region::raise_to_top);
1785 Editor::lower_region ()
1787 selection->foreach_audio_region (&Region::lower);
1791 Editor::lower_region_to_bottom ()
1793 selection->foreach_audio_region (&Region::lower_to_bottom);
1797 Editor::edit_region ()
1799 if (clicked_regionview == 0) {
1803 clicked_regionview->show_region_editor ();
1807 Editor::rename_region ()
1811 Button ok_button (_("OK"));
1812 Button cancel_button (_("Cancel"));
1814 if (selection->audio_regions.empty()) {
1818 dialog.set_title (_("ardour: rename region"));
1819 dialog.set_name ("RegionRenameWindow");
1820 dialog.set_size_request (300, -1);
1821 dialog.set_position (Gtk::WIN_POS_MOUSE);
1822 dialog.set_modal (true);
1824 dialog.get_vbox()->set_border_width (10);
1825 dialog.get_vbox()->pack_start (entry);
1826 dialog.get_action_area()->pack_start (ok_button);
1827 dialog.get_action_area()->pack_start (cancel_button);
1829 entry.set_name ("RegionNameDisplay");
1830 ok_button.set_name ("EditorGTKButton");
1831 cancel_button.set_name ("EditorGTKButton");
1833 region_renamed = false;
1835 entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1836 ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1837 cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
1844 if (region_renamed) {
1845 (*selection->audio_regions.begin())->region.set_name (entry.get_text());
1846 redisplay_regions ();
1851 Editor::rename_region_finished (bool status)
1854 region_renamed = status;
1859 Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
1861 if (session->is_auditioning()) {
1862 session->cancel_audition ();
1865 // note: some potential for creativity here, because region doesn't
1866 // have to belong to the playlist that Route is handling
1868 // bool was_soloed = route.soloed();
1870 route.set_solo (true, this);
1872 session->request_bounded_roll (region.position(), region.position() + region.length());
1874 /* XXX how to unset the solo state ? */
1878 Editor::audition_selected_region ()
1880 if (!selection->audio_regions.empty()) {
1881 AudioRegionView* rv = *(selection->audio_regions.begin());
1882 session->audition_region (rv->region);
1887 Editor::audition_playlist_region_standalone (AudioRegion& region)
1889 session->audition_region (region);
1893 Editor::build_interthread_progress_window ()
1895 interthread_progress_window = new ArdourDialog (X_("interthread progress"), true);
1897 interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
1899 interthread_progress_window->get_vbox()->pack_start (interthread_progress_label, false, false);
1900 interthread_progress_window->get_vbox()->pack_start (interthread_progress_bar,false, false);
1902 // GTK2FIX: this button needs a modifiable label
1904 Button* b = interthread_progress_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
1905 b->signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
1907 interthread_cancel_button.add (interthread_cancel_label);
1909 interthread_progress_window->set_default_size (200, 100);
1913 Editor::interthread_cancel_clicked ()
1915 if (current_interthread_info) {
1916 current_interthread_info->cancel = true;
1921 Editor::_import_thread (void *arg)
1923 PBD::ThreadCreated (pthread_self(), X_("Import"));
1925 Editor *ed = (Editor *) arg;
1926 return ed->import_thread ();
1930 Editor::import_thread ()
1932 session->import_audiofile (import_status);
1937 Editor::import_progress_timeout (void *arg)
1939 interthread_progress_label.set_text (import_status.doing_what);
1941 if (import_status.freeze) {
1942 interthread_cancel_button.set_sensitive(false);
1944 interthread_cancel_button.set_sensitive(true);
1947 if (import_status.doing_what == "building peak files") {
1948 interthread_progress_bar.pulse ();
1951 interthread_progress_bar.set_fraction (import_status.progress/100);
1954 return !(import_status.done || import_status.cancel);
1958 Editor::import_audio (bool as_tracks)
1961 warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
1968 str =_("Import selected as tracks");
1970 str = _("Import selected to region list");
1973 SoundFileOmega sfdb (str);
1974 sfdb.Imported.connect (bind (mem_fun (*this, &Editor::do_import), as_tracks));
1980 Editor::catch_new_audio_region (AudioRegion* ar)
1982 last_audio_region = ar;
1986 Editor::do_import (vector<string> paths, bool split, bool as_tracks)
1990 /* SFDB sets "multichan" to true to indicate "split channels"
1991 so reverse the setting to match the way libardour
1995 import_status.multichan = !split;
1997 if (interthread_progress_window == 0) {
1998 build_interthread_progress_window ();
2001 interthread_progress_window->set_title (_("ardour: audio import in progress"));
2002 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2003 interthread_progress_window->show_all ();
2004 interthread_progress_bar.set_fraction (0.0f);
2005 interthread_cancel_label.set_text (_("Cancel Import"));
2006 current_interthread_info = &import_status;
2008 c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
2010 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
2012 interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
2014 import_status.pathname = (*i);
2015 import_status.done = false;
2016 import_status.cancel = false;
2017 import_status.freeze = false;
2018 import_status.done = 0.0;
2020 interthread_progress_connection =
2021 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
2023 last_audio_region = 0;
2025 pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
2026 pthread_detach (import_status.thread);
2028 while (!(import_status.done || import_status.cancel)) {
2029 gtk_main_iteration ();
2032 import_status.done = true;
2033 interthread_progress_connection.disconnect ();
2035 if (as_tracks && last_audio_region != 0) {
2036 uint32_t channels = last_audio_region->n_channels();
2038 AudioTrack* at = session->new_audio_track (channels, channels);
2039 AudioRegion* copy = new AudioRegion (*last_audio_region);
2040 at->disk_stream().playlist()->add_region (*copy, 0);
2045 interthread_progress_window->hide_all ();
2049 Editor::reject_because_rate_differs (const string & path, SF_INFO& finfo, const string & action, bool multiple_pending)
2055 if (finfo.samplerate != (int) session->frame_rate()) {
2056 vector<string> choices;
2058 choices.push_back (string_compose (_("%1 it anyway"), action));
2060 if (multiple_pending) {
2061 /* XXX assumptions about sentence structure
2062 here for translators. Sorry.
2064 choices.push_back (string_compose (_("Don't %1 it"), action));
2065 choices.push_back (string_compose (_("%1 all without questions"), action));
2066 choices.push_back (_("Cancel entire import"));
2068 choices.push_back (_("Cancel"));
2071 Gtkmm2ext::Choice rate_choice (
2072 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
2075 rate_choice.chosen.connect (ptr_fun (Main::quit));
2076 rate_choice.show_all ();
2080 switch (rate_choice.get_choice()) {
2081 case 0: /* do it anyway */
2083 case 1: /* don't import this one */
2085 case 2: /* do the rest without asking */
2087 case 3: /* stop a multi-file import */
2097 Editor::embed_audio ()
2100 warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
2104 SoundFileOmega sfdb (_("Add to External Region list"));
2105 sfdb.Embedded.connect (mem_fun (*this, &Editor::do_embed_sndfiles));
2111 Editor::do_embed_sndfiles (vector<string> paths, bool split)
2113 bool multiple_files = paths.size() > 1;
2114 bool check_sample_rate = true;
2116 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
2117 embed_sndfile (*i, split, multiple_files, check_sample_rate);
2120 session->save_state ("");
2124 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
2126 SndFileSource *source = 0; /* keep g++ quiet */
2127 AudioRegion::SourceList sources;
2133 /* lets see if we can link it into the session */
2135 linked_path = session->sound_dir();
2136 linked_path += PBD::basename (path);
2138 if (link (path.c_str(), linked_path.c_str()) == 0) {
2140 /* there are many reasons why link(2) might have failed.
2141 but if it succeeds, we now have a link in the
2142 session sound dir that will protect against
2143 unlinking of the original path. nice.
2149 memset (&finfo, 0, sizeof(finfo));
2151 /* note that we temporarily truncated _id at the colon */
2153 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2155 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2156 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
2162 if (check_sample_rate) {
2163 switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
2169 check_sample_rate = false;
2178 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2179 ARDOUR_UI::instance()->flush_pending ();
2181 /* make the proper number of channels in the region */
2183 for (int n=0; n < finfo.channels; ++n)
2186 idspec += string_compose(":%1", n);
2189 source = new SndFileSource (idspec.c_str());
2190 sources.push_back(source);
2193 catch (failed_constructor& err) {
2194 error << string_compose(_("could not open %1"), path) << endmsg;
2198 ARDOUR_UI::instance()->flush_pending ();
2201 if (sources.size() > 0) {
2203 string region_name = PBD::basename_nosuffix (path);
2204 region_name += "-0";
2206 /* The created region isn't dropped. It emits a signal
2207 that is picked up by the session.
2210 new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
2211 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2213 /* make sure we can see it in the list */
2215 /* its the second node, always */
2217 // GTK2FIX ?? is it still always the 2nd node
2219 TreeModel::Path path ("2");
2220 region_list_display.expand_row (path, true);
2222 ARDOUR_UI::instance()->flush_pending ();
2226 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2230 Editor::insert_sndfile (bool as_tracks)
2232 // SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2238 // c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
2239 str = _("Insert selected as new tracks");
2245 if (clicked_audio_trackview == 0) {
2249 if (ensure_cursor (&pos)) {
2253 // c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
2254 str = _("Insert selected");
2257 // sfdb.run (str, false);
2262 Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
2266 bool multiple_files;
2267 bool check_sample_rate = true;
2269 multiple_files = paths.size() > 1;
2271 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
2273 memset (&finfo, 0, sizeof(finfo));
2275 if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
2277 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2278 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
2285 /* add a new track */
2287 if (check_sample_rate) {
2288 switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
2294 check_sample_rate = false;
2302 uint32_t input_chan = finfo.channels;
2303 uint32_t output_chan;
2305 if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
2306 output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
2308 output_chan = input_chan;
2311 (void) session->new_audio_track (input_chan, output_chan);
2314 /* get the last (most recently added) track view */
2316 AudioTimeAxisView* tv;
2318 if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
2319 fatal << _("programming error: ")
2320 << X_("last trackview after new_audio_track is not an audio track!")
2325 jack_nframes_t pos = 0;
2326 insert_sndfile_into (*p, true, tv, pos, false);
2331 Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
2333 for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
2334 insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
2339 Editor::insert_sndfile_into (const string & path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
2341 SndFileSource *source = 0; /* keep g++ quiet */
2342 AudioRegion::SourceList sources;
2347 memset (&finfo, 0, sizeof(finfo));
2349 /* note that we temporarily truncated _id at the colon */
2351 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2353 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2354 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
2360 if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
2364 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2365 ARDOUR_UI::instance()->flush_pending ();
2367 /* make the proper number of channels in the region */
2369 for (int n=0; n < finfo.channels; ++n)
2372 idspec += string_compose(":%1", n);
2375 source = new SndFileSource (idspec.c_str());
2376 sources.push_back(source);
2379 catch (failed_constructor& err) {
2380 error << string_compose(_("could not open %1"), path) << endmsg;
2384 ARDOUR_UI::instance()->flush_pending ();
2387 if (sources.size() > 0) {
2389 string region_name = region_name_from_path (PBD::basename (path));
2391 AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
2392 0, /* irrelevant these days */
2393 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2395 begin_reversible_command (_("insert sndfile"));
2396 session->add_undo (tv->playlist()->get_memento());
2397 tv->playlist()->add_region (*region, pos);
2398 session->add_redo_no_execute (tv->playlist()->get_memento());
2399 commit_reversible_command ();
2401 pos += sources[0]->length();
2403 ARDOUR_UI::instance()->flush_pending ();
2407 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
2412 Editor::region_from_selection ()
2414 if (clicked_trackview == 0) {
2418 if (selection->time.empty()) {
2422 jack_nframes_t start = selection->time[clicked_selection].start;
2423 jack_nframes_t end = selection->time[clicked_selection].end;
2425 jack_nframes_t selection_cnt = end - start + 1;
2427 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2429 AudioRegion *region;
2430 AudioRegion *current;
2434 jack_nframes_t internal_start;
2437 if ((pl = (*i)->playlist()) == 0) {
2441 if ((current_r = pl->top_region_at (start)) == 0) {
2445 if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
2446 internal_start = start - current->position();
2447 session->region_name (new_name, current->name(), true);
2448 region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
2454 Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
2456 if (selection->time.empty() || selection->tracks.empty()) {
2460 jack_nframes_t start = selection->time[clicked_selection].start;
2461 jack_nframes_t end = selection->time[clicked_selection].end;
2463 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2465 AudioRegion* current;
2468 jack_nframes_t internal_start;
2471 if ((playlist = (*i)->playlist()) == 0) {
2475 if ((current_r = playlist->top_region_at(start)) == 0) {
2479 if ((current = dynamic_cast<AudioRegion*>(current_r)) == 0) {
2483 internal_start = start - current->position();
2484 session->region_name (new_name, current->name(), true);
2486 new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name));
2491 Editor::split_multichannel_region ()
2493 vector<AudioRegion*> v;
2495 if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
2499 clicked_regionview->region.separate_by_channel (*session, v);
2501 /* nothing else to do, really */
2505 Editor::new_region_from_selection ()
2507 region_from_selection ();
2508 cancel_selection ();
2512 Editor::separate_region_from_selection ()
2514 bool doing_undo = false;
2516 if (selection->time.empty()) {
2522 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2524 AudioTimeAxisView* atv;
2526 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2528 if (atv->is_audio_track()) {
2530 if ((playlist = atv->playlist()) != 0) {
2532 begin_reversible_command (_("separate"));
2535 if (doing_undo) session->add_undo ((playlist)->get_memento());
2537 /* XXX need to consider musical time selections here at some point */
2539 double speed = atv->get_diskstream()->speed();
2541 for (list<AudioRange>::iterator t = selection->time.begin(); t != selection->time.end(); ++t) {
2542 playlist->partition ((jack_nframes_t)((*t).start * speed), (jack_nframes_t)((*t).end * speed), true);
2545 if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
2551 if (doing_undo) commit_reversible_command ();
2555 Editor::crop_region_to_selection ()
2557 if (selection->time.empty()) {
2561 vector<Playlist*> playlists;
2564 if (clicked_trackview != 0) {
2566 if ((playlist = clicked_trackview->playlist()) == 0) {
2570 playlists.push_back (playlist);
2574 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2576 AudioTimeAxisView* atv;
2578 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2580 if (atv->is_audio_track()) {
2582 if ((playlist = atv->playlist()) != 0) {
2583 playlists.push_back (playlist);
2590 if (!playlists.empty()) {
2592 jack_nframes_t start;
2596 begin_reversible_command (_("trim to selection"));
2598 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2602 start = selection->time.start();
2604 if ((region = (*i)->top_region_at(start)) == 0) {
2608 /* now adjust lengths to that we do the right thing
2609 if the selection extends beyond the region
2612 start = max (start, region->position());
2613 end = min (selection->time.end_frame(), start + region->length() - 1);
2614 cnt = end - start + 1;
2616 session->add_undo ((*i)->get_memento());
2617 region->trim_to (start, cnt, this);
2618 session->add_redo_no_execute ((*i)->get_memento());
2621 commit_reversible_command ();
2626 Editor::region_fill_track ()
2630 if (!session || selection->audio_regions.empty()) {
2634 end = session->current_end_frame ();
2636 begin_reversible_command (_("region fill"));
2638 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2640 AudioRegion& region ((*i)->region);
2641 Playlist* pl = region.playlist();
2643 if (end <= region.last_frame()) {
2647 double times = (double) (end - region.last_frame()) / (double) region.length();
2653 session->add_undo (pl->get_memento());
2654 pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
2655 session->add_redo_no_execute (pl->get_memento());
2658 commit_reversible_command ();
2662 Editor::region_fill_selection ()
2664 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2668 if (selection->time.empty()) {
2674 Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
2676 if (selected->count_selected_rows() != 1) {
2680 TreeModel::iterator i = region_list_display.get_selection()->get_selected();
2681 region = (*i)[region_list_columns.region];
2683 jack_nframes_t start = selection->time[clicked_selection].start;
2684 jack_nframes_t end = selection->time[clicked_selection].end;
2688 if (selection->tracks.empty()) {
2692 jack_nframes_t selection_length = end - start;
2693 float times = (float)selection_length / region->length();
2695 begin_reversible_command (_("fill selection"));
2697 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2699 if ((playlist = (*i)->playlist()) == 0) {
2703 session->add_undo (playlist->get_memento());
2704 playlist->add_region (*(createRegion (*region)), start, times);
2705 session->add_redo_no_execute (playlist->get_memento());
2708 commit_reversible_command ();
2712 Editor::set_region_sync_from_edit_cursor ()
2714 if (clicked_regionview == 0) {
2718 if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
2719 error << _("Place the edit cursor at the desired sync point") << endmsg;
2723 Region& region (clicked_regionview->region);
2724 begin_reversible_command (_("set sync from edit cursor"));
2725 session->add_undo (region.playlist()->get_memento());
2726 region.set_sync_position (edit_cursor->current_frame);
2727 session->add_redo_no_execute (region.playlist()->get_memento());
2728 commit_reversible_command ();
2732 Editor::remove_region_sync ()
2734 if (clicked_regionview) {
2735 Region& region (clicked_regionview->region);
2736 begin_reversible_command (_("remove sync"));
2737 session->add_undo (region.playlist()->get_memento());
2738 region.clear_sync_position ();
2739 session->add_redo_no_execute (region.playlist()->get_memento());
2740 commit_reversible_command ();
2745 Editor::naturalize ()
2747 if (selection->audio_regions.empty()) {
2750 begin_reversible_command (_("naturalize"));
2751 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2752 session->add_undo ((*i)->region.get_memento());
2753 (*i)->region.move_to_natural_position (this);
2754 session->add_redo_no_execute ((*i)->region.get_memento());
2756 commit_reversible_command ();
2760 Editor::align (RegionPoint what)
2762 align_selection (what, edit_cursor->current_frame);
2766 Editor::align_relative (RegionPoint what)
2768 align_selection_relative (what, edit_cursor->current_frame);
2771 struct RegionSortByTime {
2772 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
2773 return a->region.position() < b->region.position();
2778 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
2780 if (selection->audio_regions.empty()) {
2784 jack_nframes_t distance;
2785 jack_nframes_t pos = 0;
2788 list<AudioRegionView*> sorted;
2789 selection->audio_regions.by_position (sorted);
2790 Region& r ((*sorted.begin())->region);
2794 pos = r.first_frame ();
2798 pos = r.last_frame();
2802 pos = r.adjust_to_sync (r.first_frame());
2806 if (pos > position) {
2807 distance = pos - position;
2810 distance = position - pos;
2814 begin_reversible_command (_("align selection (relative)"));
2816 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2818 Region& region ((*i)->region);
2820 session->add_undo (region.playlist()->get_memento());
2823 region.set_position (region.position() + distance, this);
2825 region.set_position (region.position() - distance, this);
2828 session->add_redo_no_execute (region.playlist()->get_memento());
2832 commit_reversible_command ();
2836 Editor::align_selection (RegionPoint point, jack_nframes_t position)
2838 if (selection->audio_regions.empty()) {
2842 begin_reversible_command (_("align selection"));
2844 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2845 align_region_internal ((*i)->region, point, position);
2848 commit_reversible_command ();
2852 Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position)
2854 begin_reversible_command (_("align region"));
2855 align_region_internal (region, point, position);
2856 commit_reversible_command ();
2860 Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position)
2862 session->add_undo (region.playlist()->get_memento());
2866 region.set_position (region.adjust_to_sync (position), this);
2870 if (position > region.length()) {
2871 region.set_position (position - region.length(), this);
2876 region.set_position (position, this);
2880 session->add_redo_no_execute (region.playlist()->get_memento());
2884 Editor::trim_region_to_edit_cursor ()
2886 if (clicked_regionview == 0) {
2890 Region& region (clicked_regionview->region);
2893 AudioTimeAxisView *atav;
2895 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2896 if (atav->get_diskstream() != 0) {
2897 speed = atav->get_diskstream()->speed();
2901 begin_reversible_command (_("trim to edit"));
2902 session->add_undo (region.playlist()->get_memento());
2903 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2904 session->add_redo_no_execute (region.playlist()->get_memento());
2905 commit_reversible_command ();
2909 Editor::trim_region_from_edit_cursor ()
2911 if (clicked_regionview == 0) {
2915 Region& region (clicked_regionview->region);
2918 AudioTimeAxisView *atav;
2920 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2921 if (atav->get_diskstream() != 0) {
2922 speed = atav->get_diskstream()->speed();
2926 begin_reversible_command (_("trim to edit"));
2927 session->add_undo (region.playlist()->get_memento());
2928 region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
2929 session->add_redo_no_execute (region.playlist()->get_memento());
2930 commit_reversible_command ();
2934 Editor::unfreeze_route ()
2936 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2940 clicked_audio_trackview->audio_track()->unfreeze ();
2944 Editor::_freeze_thread (void* arg)
2946 PBD::ThreadCreated (pthread_self(), X_("Freeze"));
2947 return static_cast<Editor*>(arg)->freeze_thread ();
2951 Editor::freeze_thread ()
2953 clicked_audio_trackview->audio_track()->freeze (*current_interthread_info);
2958 Editor::freeze_progress_timeout (void *arg)
2960 interthread_progress_bar.set_fraction (current_interthread_info->progress/100);
2961 return !(current_interthread_info->done || current_interthread_info->cancel);
2965 Editor::freeze_route ()
2967 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2971 InterThreadInfo itt;
2973 if (interthread_progress_window == 0) {
2974 build_interthread_progress_window ();
2977 interthread_progress_window->set_title (_("ardour: freeze"));
2978 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2979 interthread_progress_window->show_all ();
2980 interthread_progress_bar.set_fraction (0.0f);
2981 interthread_progress_label.set_text ("");
2982 interthread_cancel_label.set_text (_("Cancel Freeze"));
2983 current_interthread_info = &itt;
2985 interthread_progress_connection =
2986 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
2990 itt.progress = 0.0f;
2992 pthread_create (&itt.thread, 0, _freeze_thread, this);
2994 track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
2996 while (!itt.done && !itt.cancel) {
2997 gtk_main_iteration ();
3000 interthread_progress_connection.disconnect ();
3001 interthread_progress_window->hide_all ();
3002 current_interthread_info = 0;
3003 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
3007 Editor::bounce_range_selection ()
3009 if (selection->time.empty()) {
3013 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
3015 jack_nframes_t start = selection->time[clicked_selection].start;
3016 jack_nframes_t end = selection->time[clicked_selection].end;
3017 jack_nframes_t cnt = end - start + 1;
3019 begin_reversible_command (_("bounce range"));
3021 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
3023 AudioTimeAxisView* atv;
3025 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
3031 if ((playlist = atv->playlist()) == 0) {
3035 InterThreadInfo itt;
3039 itt.progress = false;
3041 session->add_undo (playlist->get_memento());
3042 atv->audio_track()->bounce_range (start, cnt, itt);
3043 session->add_redo_no_execute (playlist->get_memento());
3046 commit_reversible_command ();
3064 Editor::cut_copy (CutCopyOp op)
3066 /* only cancel selection if cut/copy is successful.*/
3078 opname = _("clear");
3082 cut_buffer->clear ();
3084 switch (current_mouse_mode()) {
3086 if (!selection->audio_regions.empty() || !selection->points.empty()) {
3088 begin_reversible_command (opname + _(" objects"));
3090 if (!selection->audio_regions.empty()) {
3092 cut_copy_regions (op);
3095 selection->clear_audio_regions ();
3099 if (!selection->points.empty()) {
3100 cut_copy_points (op);
3103 selection->clear_points ();
3107 commit_reversible_command ();
3112 if (!selection->time.empty()) {
3114 begin_reversible_command (opname + _(" range"));
3115 cut_copy_ranges (op);
3116 commit_reversible_command ();
3119 selection->clear_time ();
3131 Editor::cut_copy_points (CutCopyOp op)
3133 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3135 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
3138 atv->cut_copy_clear_objects (selection->points, op);
3144 Editor::cut_copy_regions (CutCopyOp op)
3146 typedef std::map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
3147 PlaylistMapping pmap;
3148 jack_nframes_t first_position = max_frames;
3149 set<Playlist*> freezelist;
3150 pair<set<Playlist*>::iterator,bool> insert_result;
3152 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
3153 first_position = min ((*x)->region.position(), first_position);
3155 if (op == Cut || op == Clear) {
3156 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3158 insert_result = freezelist.insert (pl);
3159 if (insert_result.second) {
3161 session->add_undo (pl->get_memento());
3167 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
3169 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3171 AudioRegionSelection::iterator tmp;
3178 PlaylistMapping::iterator pi = pmap.find (pl);
3180 if (pi == pmap.end()) {
3181 npl = new AudioPlaylist (*session, "cutlist", true);
3190 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3191 pl->remove_region (&((*x)->region));
3195 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3199 pl->remove_region (&((*x)->region));
3207 list<Playlist*> foo;
3209 for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3210 foo.push_back (i->second);
3214 cut_buffer->set (foo);
3217 for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3219 session->add_redo_no_execute ((*pl)->get_memento());
3224 Editor::cut_copy_ranges (CutCopyOp op)
3226 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3227 (*i)->cut_copy_clear (*selection, op);
3232 Editor::paste (float times)
3234 paste_internal (edit_cursor->current_frame, times);
3238 Editor::mouse_paste ()
3243 track_canvas.get_pointer (x, y);
3244 track_canvas.window_to_world (x, y, wx, wy);
3245 wx += horizontal_adjustment.get_value();
3246 wy += vertical_adjustment.get_value();
3249 event.type = GDK_BUTTON_RELEASE;
3250 event.button.x = wx;
3251 event.button.y = wy;
3253 jack_nframes_t where = event_frame (&event, 0, 0);
3255 paste_internal (where, 1);
3259 Editor::paste_internal (jack_nframes_t position, float times)
3261 bool commit = false;
3263 if (cut_buffer->empty() || selection->tracks.empty()) {
3267 if (position == max_frames) {
3268 position = edit_cursor->current_frame;
3271 begin_reversible_command (_("paste"));
3273 TrackSelection::iterator i;
3276 for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) {
3278 /* undo/redo is handled by individual tracks */
3280 if ((*i)->paste (position, times, *cut_buffer, nth)) {
3286 commit_reversible_command ();
3291 Editor::paste_named_selection (float times)
3293 TrackSelection::iterator t;
3295 Glib::RefPtr<TreeSelection> selected = named_selection_display.get_selection();
3297 if (selected->count_selected_rows() != 1 || selection->tracks.empty()) {
3301 TreeModel::iterator i = selected->get_selected();
3302 NamedSelection* ns = (*i)[named_selection_columns.selection];
3304 list<Playlist*>::iterator chunk;
3305 list<Playlist*>::iterator tmp;
3307 chunk = ns->playlists.begin();
3309 begin_reversible_command (_("paste chunk"));
3311 for (t = selection->tracks.begin(); t != selection->tracks.end(); ++t) {
3313 AudioTimeAxisView* atv;
3317 if ((atv = dynamic_cast<AudioTimeAxisView*> (*t)) == 0) {
3321 if ((pl = atv->playlist()) == 0) {
3325 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
3332 session->add_undo (apl->get_memento());
3333 apl->paste (**chunk, edit_cursor->current_frame, times);
3334 session->add_redo_no_execute (apl->get_memento());
3336 if (tmp != ns->playlists.end()) {
3341 commit_reversible_command();
3345 Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
3348 AudioRegionSelection sel = regions; // clear (below) will clear the argument list
3350 begin_reversible_command (_("duplicate region"));
3352 selection->clear_audio_regions ();
3354 for (AudioRegionSelection::iterator i = sel.begin(); i != sel.end(); ++i) {
3356 Region& r ((*i)->region);
3358 TimeAxisView& tv = (*i)->get_time_axis_view();
3359 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
3360 sigc::connection c = atv->view->AudioRegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
3362 playlist = (*i)->region.playlist();
3363 session->add_undo (playlist->get_memento());
3364 playlist->duplicate (r, r.last_frame(), times);
3365 session->add_redo_no_execute (playlist->get_memento());
3369 if (latest_regionview) {
3370 selection->add (latest_regionview);
3375 commit_reversible_command ();
3379 Editor::duplicate_selection (float times)
3381 if (selection->time.empty() || selection->tracks.empty()) {
3386 vector<AudioRegion*> new_regions;
3387 vector<AudioRegion*>::iterator ri;
3389 create_region_from_selection (new_regions);
3391 if (new_regions.empty()) {
3395 begin_reversible_command (_("duplicate selection"));
3397 ri = new_regions.begin();
3399 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3400 if ((playlist = (*i)->playlist()) == 0) {
3403 session->add_undo (playlist->get_memento());
3404 playlist->duplicate (**ri, selection->time[clicked_selection].end, times);
3405 session->add_redo_no_execute (playlist->get_memento());
3408 if (ri == new_regions.end()) {
3413 commit_reversible_command ();
3417 Editor::center_playhead ()
3419 float page = canvas_width * frames_per_unit;
3421 center_screen_internal (playhead_cursor->current_frame, page);
3425 Editor::center_edit_cursor ()
3427 float page = canvas_width * frames_per_unit;
3429 center_screen_internal (edit_cursor->current_frame, page);
3433 Editor::clear_playlist (Playlist& playlist)
3435 begin_reversible_command (_("clear playlist"));
3436 session->add_undo (playlist.get_memento());
3438 session->add_redo_no_execute (playlist.get_memento());
3439 commit_reversible_command ();
3443 Editor::nudge_track (bool use_edit_cursor, bool forwards)
3446 jack_nframes_t distance;
3447 jack_nframes_t next_distance;
3448 jack_nframes_t start;
3450 if (use_edit_cursor) {
3451 start = edit_cursor->current_frame;
3456 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
3460 if (selection->tracks.empty()) {
3464 begin_reversible_command (_("nudge track"));
3466 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3468 if ((playlist = (*i)->playlist()) == 0) {
3472 session->add_undo (playlist->get_memento());
3473 playlist->nudge_after (start, distance, forwards);
3474 session->add_redo_no_execute (playlist->get_memento());
3477 commit_reversible_command ();
3481 Editor::toggle_xfades_active ()
3484 session->set_crossfades_active (!session->get_crossfades_active());
3489 Editor::set_xfade_visibility (bool yn)
3495 Editor::toggle_xfade_visibility ()
3497 set_xfade_visibility (!xfade_visibility());
3501 Editor::remove_last_capture ()
3503 vector<string> choices;
3510 if (Config->get_verify_remove_last_capture()) {
3511 prompt = _("Do you really want to destroy the last capture?"
3512 "\n(This is destructive and cannot be undone)");
3514 choices.push_back (_("Yes, destroy it."));
3515 choices.push_back (_("No, do nothing."));
3517 Gtkmm2ext::Choice prompter (prompt, choices);
3518 prompter.chosen.connect (ptr_fun (Main::quit));
3519 prompter.show_all ();
3523 if (prompter.get_choice() == 0) {
3524 session->remove_last_capture ();
3528 session->remove_last_capture();
3533 Editor::normalize_region ()
3539 if (selection->audio_regions.empty()) {
3543 begin_reversible_command (_("normalize"));
3545 track_canvas.get_window()->set_cursor (*wait_cursor);
3548 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3549 session->add_undo ((*r)->region.get_memento());
3550 (*r)->region.normalize_to (0.0f);
3551 session->add_redo_no_execute ((*r)->region.get_memento());
3554 commit_reversible_command ();
3555 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
3560 Editor::denormalize_region ()
3566 if (selection->audio_regions.empty()) {
3570 begin_reversible_command ("denormalize");
3572 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3573 session->add_undo ((*r)->region.get_memento());
3574 (*r)->region.set_scale_amplitude (1.0f);
3575 session->add_redo_no_execute ((*r)->region.get_memento());
3578 commit_reversible_command ();
3583 Editor::reverse_region ()
3589 Reverse rev (*session);
3590 apply_filter (rev, _("reverse regions"));
3594 Editor::apply_filter (AudioFilter& filter, string command)
3596 if (selection->audio_regions.empty()) {
3600 begin_reversible_command (command);
3602 track_canvas.get_window()->set_cursor (*wait_cursor);
3605 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
3607 AudioRegion& region ((*r)->region);
3608 Playlist* playlist = region.playlist();
3610 AudioRegionSelection::iterator tmp;
3615 if (region.apply (filter) == 0) {
3617 session->add_undo (playlist->get_memento());
3618 playlist->replace_region (region, *(filter.results.front()), region.position());
3619 session->add_redo_no_execute (playlist->get_memento());
3627 commit_reversible_command ();
3628 selection->audio_regions.clear ();
3631 track_canvas.get_window()->set_cursor (*current_canvas_cursor);
3635 Editor::region_selection_op (void (Region::*pmf)(void))
3637 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3638 ((*i)->region.*pmf)();
3644 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
3646 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3647 ((*i)->region.*pmf)(arg);
3652 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
3654 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3655 ((*i)->region.*pmf)(yn);
3660 Editor::external_edit_region ()
3662 if (!clicked_regionview) {
3670 Editor::brush (jack_nframes_t pos)
3672 AudioRegionSelection sel;
3675 if (selection->audio_regions.empty()) {
3676 /* XXX get selection from region list */
3678 sel = selection->audio_regions;
3685 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3686 mouse_brush_insert_region ((*i), pos);
3691 Editor::toggle_gain_envelope_visibility ()
3693 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3694 (*i)->set_envelope_visible (!(*i)->envelope_visible());
3699 Editor::toggle_gain_envelope_active ()
3701 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3702 AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
3704 ar->set_envelope_active (true);