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 "extra_bind.h"
61 #include "selection_templates.h"
62 #include "selection.h"
63 #include "library_ui.h"
65 #include "gtk-custom-hruler.h"
70 using namespace ARDOUR;
73 using namespace Editing;
75 /***********************************************************************
77 ***********************************************************************/
80 Editor::undo (uint32_t n)
88 Editor::redo (uint32_t n)
96 Editor::ensure_cursor (jack_nframes_t *pos)
98 *pos = edit_cursor->current_frame;
103 Editor::split_region ()
105 split_region_at (edit_cursor->current_frame);
109 Editor::split_region_at (jack_nframes_t where)
111 split_regions_at (where, selection->audio_regions);
115 Editor::split_regions_at (jack_nframes_t where, AudioRegionSelection& regions)
117 begin_reversible_command (_("split"));
120 for (AudioRegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
122 AudioRegionSelection::iterator tmp;
127 Playlist* pl = (*a)->region.playlist();
129 _new_regionviews_show_envelope = (*a)->envelope_visible();
132 session->add_undo (pl->get_memento());
133 pl->split_region ((*a)->region, where);
134 session->add_redo_no_execute (pl->get_memento());
140 commit_reversible_command ();
141 _new_regionviews_show_envelope = false;
145 Editor::remove_clicked_region ()
147 if (clicked_audio_trackview == 0 || clicked_regionview == 0) {
151 Playlist* playlist = clicked_audio_trackview->playlist();
153 begin_reversible_command (_("remove region"));
154 session->add_undo (playlist->get_memento());
155 playlist->remove_region (&clicked_regionview->region);
156 session->add_redo_no_execute (playlist->get_memento());
157 commit_reversible_command ();
161 Editor::destroy_clicked_region ()
163 int32_t selected = selection->audio_regions.size();
165 if (!session || clicked_regionview == 0 && selected == 0) {
169 vector<string> choices;
172 prompt = string_compose (_(" This is destructive, will possibly delete audio files\n\
173 It cannot be undone\n\
174 Do you really want to destroy %1 ?"),
176 _("these regions") : _("this region")));
179 choices.push_back (_("Yes, destroy them."));
181 choices.push_back (_("Yes, destroy it."));
184 choices.push_back (_("No, do nothing."));
186 Gtkmm2ext::Choice prompter (prompt, choices);
188 prompter.chosen.connect (Gtk::Main::quit.slot());
189 prompter.show_all ();
193 if (prompter.get_choice() != 0) {
200 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
201 r.push_back (&(*i)->region);
204 session->destroy_regions (r);
206 } else if (clicked_regionview) {
207 session->destroy_region (&clicked_regionview->region);
212 Editor::select_region_for_operation (int dir, TimeAxisView **tv)
216 jack_nframes_t start = 0;
218 if (selection->time.start () == selection->time.end_frame ()) {
220 /* no current selection-> is there a selected regionview? */
222 if (selection->audio_regions.empty()) {
230 if (!selection->audio_regions.empty()) {
232 rv = *(selection->audio_regions.begin());
233 (*tv) = &rv->get_time_axis_view();
234 region = &rv->region;
236 } else if (!selection->tracks.empty()) {
238 (*tv) = selection->tracks.front();
240 AudioTimeAxisView* atv;
242 if ((atv = dynamic_cast<AudioTimeAxisView*> (*tv)) != 0) {
245 if ((pl = atv->playlist()) == 0) {
249 region = dynamic_cast<AudioRegion*> (pl->top_region_at (start));
257 Editor::extend_selection_to_end_of_region (bool next)
261 jack_nframes_t start;
263 if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) {
267 if (region && selection->time.start () == selection->time.end_frame ()) {
268 start = region->position();
270 start = selection->time.start ();
273 /* Try to leave the selection with the same route if possible */
275 if ((tv = selection->time.track) == 0) {
279 begin_reversible_command (_("extend selection"));
280 selection->set (tv, start, region->position() + region->length());
281 commit_reversible_command ();
285 Editor::extend_selection_to_start_of_region (bool previous)
291 if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) {
295 if (region && selection->time.start () == selection->time.end_frame ()) {
296 end = region->position() + region->length();
298 end = selection->time.end_frame ();
301 /* Try to leave the selection with the same route if possible */
303 if ((tv = selection->time.track) == 0) {
307 begin_reversible_command (_("extend selection"));
308 selection->set (tv, region->position(), end);
309 commit_reversible_command ();
314 Editor::nudge_forward (bool next)
316 jack_nframes_t distance;
317 jack_nframes_t next_distance;
319 if (!session) return;
321 if (!selection->audio_regions.empty()) {
323 begin_reversible_command (_("nudge forward"));
325 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
326 AudioRegion& r ((*i)->region);
328 distance = get_nudge_distance (r.position(), next_distance);
331 distance = next_distance;
334 session->add_undo (r.playlist()->get_memento());
335 r.set_position (r.position() + distance, this);
336 session->add_redo_no_execute (r.playlist()->get_memento());
339 commit_reversible_command ();
342 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
343 session->request_locate (playhead_cursor->current_frame + distance);
348 Editor::nudge_backward (bool next)
350 jack_nframes_t distance;
351 jack_nframes_t next_distance;
353 if (!session) return;
355 if (!selection->audio_regions.empty()) {
357 begin_reversible_command (_("nudge forward"));
359 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
360 AudioRegion& r ((*i)->region);
362 distance = get_nudge_distance (r.position(), next_distance);
365 distance = next_distance;
368 session->add_undo (r.playlist()->get_memento());
370 if (r.position() > distance) {
371 r.set_position (r.position() - distance, this);
373 r.set_position (0, this);
375 session->add_redo_no_execute (r.playlist()->get_memento());
378 commit_reversible_command ();
382 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
384 if (playhead_cursor->current_frame > distance) {
385 session->request_locate (playhead_cursor->current_frame - distance);
387 session->request_locate (0);
393 Editor::nudge_forward_capture_offset ()
395 jack_nframes_t distance;
397 if (!session) return;
399 if (!selection->audio_regions.empty()) {
401 begin_reversible_command (_("nudge forward"));
403 distance = session->worst_output_latency();
405 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
406 AudioRegion& r ((*i)->region);
408 session->add_undo (r.playlist()->get_memento());
409 r.set_position (r.position() + distance, this);
410 session->add_redo_no_execute (r.playlist()->get_memento());
413 commit_reversible_command ();
419 Editor::nudge_backward_capture_offset ()
421 jack_nframes_t distance;
423 if (!session) return;
425 if (!selection->audio_regions.empty()) {
427 begin_reversible_command (_("nudge forward"));
429 distance = session->worst_output_latency();
431 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
432 AudioRegion& r ((*i)->region);
434 session->add_undo (r.playlist()->get_memento());
436 if (r.position() > distance) {
437 r.set_position (r.position() - distance, this);
439 r.set_position (0, this);
441 session->add_redo_no_execute (r.playlist()->get_memento());
444 commit_reversible_command ();
451 Editor::move_to_start ()
453 session->request_locate (0);
457 Editor::move_to_end ()
460 session->request_locate (session->current_end_frame());
464 Editor::build_region_boundary_cache ()
466 jack_nframes_t pos = 0;
469 TrackViewList tracks;
471 region_boundary_cache.clear ();
478 case SnapToRegionStart:
481 case SnapToRegionEnd:
484 case SnapToRegionSync:
487 case SnapToRegionBoundary:
491 fatal << string_compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type) << endmsg;
496 TimeAxisView *ontrack = 0;
498 while (pos < session->current_end_frame()) {
500 if (!selection->tracks.empty()) {
502 if ((r = find_next_region (pos, point, 1, selection->tracks, &ontrack)) == 0) {
506 } else if (clicked_trackview) {
509 t.push_back (clicked_trackview);
511 if ((r = find_next_region (pos, point, 1, t, &ontrack)) == 0) {
517 if ((r = find_next_region (pos, point, 1, track_views, &ontrack)) == 0) {
525 case SnapToRegionStart:
526 rpos = r->first_frame();
528 case SnapToRegionEnd:
529 rpos = r->last_frame();
531 case SnapToRegionSync:
532 rpos = r->adjust_to_sync (r->first_frame());
535 case SnapToRegionBoundary:
536 rpos = r->last_frame();
543 AudioTimeAxisView *atav;
545 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
546 if (atav->get_diskstream() != 0) {
547 speed = atav->get_diskstream()->speed();
551 rpos = (jack_nframes_t) floor ( (float) rpos / speed );
553 if (region_boundary_cache.empty() || rpos != region_boundary_cache.back()) {
554 if (snap_type == SnapToRegionBoundary) {
555 region_boundary_cache.push_back (r->first_frame());
557 region_boundary_cache.push_back (rpos);
565 Editor::find_next_region (jack_nframes_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack)
567 TrackViewList::iterator i;
568 jack_nframes_t closest = max_frames;
570 jack_nframes_t rpos = 0;
573 jack_nframes_t track_frame;
574 AudioTimeAxisView *atav;
576 for (i = tracks.begin(); i != tracks.end(); ++i) {
578 jack_nframes_t distance;
582 if ( (atav = dynamic_cast<AudioTimeAxisView*>(*i)) != 0 ) {
583 if (atav->get_diskstream()!=0)
584 track_speed = atav->get_diskstream()->speed();
587 track_frame = (jack_nframes_t) floor ( (float) frame * track_speed );
589 if ((r = (*i)->find_next_region (track_frame, point, dir)) == 0) {
595 rpos = r->first_frame ();
599 rpos = r->last_frame ();
603 rpos = r->adjust_to_sync (r->first_frame());
606 // rpos is a "track frame", converting it to "time frame"
607 rpos = (jack_nframes_t) floor ( (float) rpos / track_speed );
610 distance = rpos - frame;
612 distance = frame - rpos;
615 if (distance < closest) {
627 Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir)
630 jack_nframes_t pos = cursor->current_frame;
636 TimeAxisView *ontrack = 0;
638 // so we don't find the current region again..
642 if (!selection->tracks.empty()) {
644 r = find_next_region (pos, point, dir, selection->tracks, &ontrack);
646 } else if (clicked_trackview) {
649 t.push_back (clicked_trackview);
651 r = find_next_region (pos, point, dir, t, &ontrack);
655 r = find_next_region (pos, point, dir, track_views, &ontrack);
664 pos = r->first_frame ();
668 pos = r->last_frame ();
672 pos = r->adjust_to_sync (r->first_frame());
677 AudioTimeAxisView *atav;
679 if ( ontrack != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(ontrack)) != 0 ) {
680 if (atav->get_diskstream() != 0) {
681 speed = atav->get_diskstream()->speed();
685 pos = (jack_nframes_t) floor ( (float) pos / speed );
688 if (cursor == playhead_cursor) {
689 session->request_locate (pos);
691 cursor->set_position (pos);
696 Editor::cursor_to_next_region_point (Cursor* cursor, RegionPoint point)
698 cursor_to_region_point (cursor, point, 1);
702 Editor::cursor_to_previous_region_point (Cursor* cursor, RegionPoint point)
704 cursor_to_region_point (cursor, point, -1);
708 Editor::cursor_to_selection_start (Cursor *cursor)
710 jack_nframes_t pos = 0;
711 switch (mouse_mode) {
713 if (!selection->audio_regions.empty()) {
714 pos = selection->audio_regions.start();
719 if (!selection->time.empty()) {
720 pos = selection->time.start ();
728 if (cursor == playhead_cursor) {
729 session->request_locate (pos);
731 cursor->set_position (pos);
736 Editor::cursor_to_selection_end (Cursor *cursor)
738 jack_nframes_t pos = 0;
740 switch (mouse_mode) {
742 if (!selection->audio_regions.empty()) {
743 pos = selection->audio_regions.end_frame();
748 if (!selection->time.empty()) {
749 pos = selection->time.end_frame ();
757 if (cursor == playhead_cursor) {
758 session->request_locate (pos);
760 cursor->set_position (pos);
765 Editor::playhead_backward ()
772 if (get_prefix (prefix, was_floating)) {
776 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
778 cnt = (jack_nframes_t) prefix;
782 pos = playhead_cursor->current_frame;
784 if ((jack_nframes_t) pos < cnt) {
790 /* XXX this is completely insane. with the current buffering
791 design, we'll force a complete track buffer flush and
792 reload, just to move 1 sample !!!
795 session->request_locate (pos);
799 Editor::playhead_forward ()
806 if (get_prefix (prefix, was_floating)) {
810 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
812 cnt = (jack_nframes_t) floor (prefix);
816 pos = playhead_cursor->current_frame;
818 /* XXX this is completely insane. with the current buffering
819 design, we'll force a complete track buffer flush and
820 reload, just to move 1 sample !!!
823 session->request_locate (pos+cnt);
827 Editor::cursor_align (bool playhead_to_edit)
829 if (playhead_to_edit) {
831 session->request_locate (edit_cursor->current_frame);
834 edit_cursor->set_position (playhead_cursor->current_frame);
839 Editor::edit_cursor_backward ()
846 if (get_prefix (prefix, was_floating)) {
850 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
852 cnt = (jack_nframes_t) prefix;
856 pos = edit_cursor->current_frame;
858 if ((jack_nframes_t) pos < cnt) {
864 edit_cursor->set_position (pos);
868 Editor::edit_cursor_forward ()
875 if (get_prefix (prefix, was_floating)) {
879 cnt = (jack_nframes_t) floor (prefix * session->frame_rate ());
881 cnt = (jack_nframes_t) floor (prefix);
885 pos = edit_cursor->current_frame;
886 edit_cursor->set_position (pos+cnt);
890 Editor::goto_frame ()
894 jack_nframes_t frame;
896 if (get_prefix (prefix, was_floating)) {
901 frame = (jack_nframes_t) floor (prefix * session->frame_rate());
903 frame = (jack_nframes_t) floor (prefix);
906 session->request_locate (frame);
910 Editor::scroll_backward (float pages)
912 jack_nframes_t frame;
913 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
918 if (get_prefix (prefix, was_floating)) {
919 cnt = (jack_nframes_t) floor (pages * one_page);
922 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
924 cnt = (jack_nframes_t) floor (prefix * one_page);
928 if (leftmost_frame < cnt) {
931 frame = leftmost_frame - cnt;
934 reposition_x_origin (frame);
938 Editor::scroll_forward (float pages)
940 jack_nframes_t frame;
941 jack_nframes_t one_page = (jack_nframes_t) rint (canvas_width * frames_per_unit);
946 if (get_prefix (prefix, was_floating)) {
947 cnt = (jack_nframes_t) floor (pages * one_page);
950 cnt = (jack_nframes_t) floor (prefix * session->frame_rate());
952 cnt = (jack_nframes_t) floor (prefix * one_page);
956 if (ULONG_MAX - cnt < leftmost_frame) {
957 frame = ULONG_MAX - cnt;
959 frame = leftmost_frame + cnt;
962 reposition_x_origin (frame);
966 Editor::scroll_tracks_down ()
972 if (get_prefix (prefix, was_floating)) {
975 cnt = (int) floor (prefix);
978 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
979 adj->set_value (adj->get_value() + (cnt * adj->get_page_size()));
983 Editor::scroll_tracks_up ()
989 if (get_prefix (prefix, was_floating)) {
992 cnt = (int) floor (prefix);
995 Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
996 adj->set_value (adj->get_value() - (cnt * adj->get_page_size()));
1000 Editor::scroll_tracks_down_line ()
1002 edit_vscrollbar.default_vmotion (0, 10);
1006 Editor::scroll_tracks_up_line ()
1008 edit_vscrollbar.default_vmotion (0, -10);
1014 Editor::temporal_zoom_step (bool coarser)
1018 nfpu = frames_per_unit;
1023 nfpu = max(1.0,(nfpu/2.0));
1026 temporal_zoom (nfpu);
1030 Editor::temporal_zoom (gdouble fpu)
1032 if (!session) return;
1034 jack_nframes_t current_page = current_page_frames();
1035 jack_nframes_t current_leftmost = leftmost_frame;
1036 jack_nframes_t current_rightmost;
1037 jack_nframes_t current_center;
1038 jack_nframes_t new_page;
1039 jack_nframes_t leftmost_after_zoom = 0;
1044 new_page = (jack_nframes_t) floor (canvas_width * nfpu);
1046 switch (zoom_focus) {
1048 leftmost_after_zoom = current_leftmost;
1051 case ZoomFocusRight:
1052 current_rightmost = leftmost_frame + current_page;
1053 if (current_rightmost > new_page) {
1054 leftmost_after_zoom = current_rightmost - new_page;
1056 leftmost_after_zoom = 0;
1060 case ZoomFocusCenter:
1061 current_center = current_leftmost + (current_page/2);
1062 if (current_center > (new_page/2)) {
1063 leftmost_after_zoom = current_center - (new_page / 2);
1065 leftmost_after_zoom = 0;
1069 case ZoomFocusPlayhead:
1070 /* try to keep the playhead in the center */
1071 if (playhead_cursor->current_frame > new_page/2) {
1072 leftmost_after_zoom = playhead_cursor->current_frame - (new_page/2);
1074 leftmost_after_zoom = 0;
1079 /* try to keep the edit cursor in the center */
1080 if (edit_cursor->current_frame > leftmost_frame + (new_page/2)) {
1081 leftmost_after_zoom = edit_cursor->current_frame - (new_page/2);
1083 leftmost_after_zoom = 0;
1089 // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
1091 // begin_reversible_command (_("zoom"));
1092 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
1093 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
1094 // commit_reversible_command ();
1096 reposition_and_zoom (leftmost_after_zoom, nfpu);
1100 Editor::temporal_zoom_selection ()
1102 if (!selection) return;
1104 if (selection->time.empty()) {
1108 jack_nframes_t start = selection->time[clicked_selection].start;
1109 jack_nframes_t end = selection->time[clicked_selection].end;
1111 temporal_zoom_by_frame (start, end, "zoom to selection");
1115 Editor::temporal_zoom_session ()
1118 temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
1123 Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, string op)
1125 if (!session) return;
1127 if ((start == 0 && end == 0) || end < start) {
1131 jack_nframes_t range = end - start;
1133 double new_fpu = (double)range / (double)canvas_width;
1136 // while (p2 < new_fpu) {
1141 jack_nframes_t new_page = (jack_nframes_t) floor (canvas_width * new_fpu);
1142 jack_nframes_t middle = (jack_nframes_t) floor( (double)start + ((double)range / 2.0f ));
1143 jack_nframes_t new_leftmost = (jack_nframes_t) floor( (double)middle - ((double)new_page/2.0f));
1145 if (new_leftmost > middle) new_leftmost = 0;
1147 // begin_reversible_command (op);
1148 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1149 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1150 // commit_reversible_command ();
1152 reposition_and_zoom (new_leftmost, new_fpu);
1156 Editor::temporal_zoom_to_frame (bool coarser, jack_nframes_t frame)
1158 if (!session) return;
1160 jack_nframes_t range_before = frame - leftmost_frame;
1163 new_fpu = frames_per_unit;
1169 new_fpu = max(1.0,(new_fpu/2.0));
1173 if (new_fpu == frames_per_unit) return;
1175 jack_nframes_t new_leftmost = frame - range_before;
1177 if (new_leftmost > frame) new_leftmost = 0;
1179 // begin_reversible_command (_("zoom to frame"));
1180 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1181 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1182 // commit_reversible_command ();
1184 reposition_and_zoom (new_leftmost, new_fpu);
1188 Editor::select_all_in_track (bool add)
1190 list<Selectable *> touched;
1192 if (!clicked_trackview) {
1196 clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1199 selection->add (touched);
1201 selection->set (touched);
1206 Editor::select_all (bool add)
1208 list<Selectable *> touched;
1210 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1211 if ((*iter)->hidden()) {
1214 (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
1218 selection->add (touched);
1220 selection->set (touched);
1226 Editor::invert_selection_in_track ()
1228 list<Selectable *> touched;
1230 if (!clicked_trackview) {
1234 clicked_trackview->get_inverted_selectables (*selection, touched);
1235 selection->set (touched);
1239 Editor::invert_selection ()
1241 list<Selectable *> touched;
1243 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1244 if ((*iter)->hidden()) {
1247 (*iter)->get_inverted_selectables (*selection, touched);
1250 selection->set (touched);
1254 Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
1256 list<Selectable *> touched;
1258 for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
1259 if ((*iter)->hidden()) {
1262 (*iter)->get_selectables (start, end, top, bot, touched);
1266 selection->add (touched);
1268 selection->set (touched);
1271 return !touched.empty();
1275 Editor::set_selection_from_punch()
1279 if ((location = session->locations()->auto_punch_location()) == 0) {
1283 set_selection_from_range (*location);
1287 Editor::set_selection_from_loop()
1291 if ((location = session->locations()->auto_loop_location()) == 0) {
1295 set_selection_from_range (*location);
1299 Editor::set_selection_from_range (Location& range)
1301 if (clicked_trackview == 0) {
1305 begin_reversible_command (_("set selection from range"));
1306 selection->set (0, range.start(), range.end());
1307 commit_reversible_command ();
1311 Editor::amplitude_zoom_step (bool in)
1325 #ifdef FIX_FOR_CANVAS
1326 /* XXX DO SOMETHING */
1335 Editor::delete_sample_forward ()
1340 Editor::delete_sample_backward ()
1345 Editor::delete_screen ()
1352 Editor::search_backwards ()
1358 Editor::search_forwards ()
1366 Editor::jump_forward_to_mark ()
1372 Location *location = session->locations()->first_location_after (playhead_cursor->current_frame);
1375 session->request_locate (location->start(), session->transport_rolling());
1377 session->request_locate (session->current_end_frame());
1382 Editor::jump_backward_to_mark ()
1388 Location *location = session->locations()->first_location_before (playhead_cursor->current_frame);
1391 session->request_locate (location->start(), session->transport_rolling());
1393 session->request_locate (0);
1404 if (get_prefix (prefix, was_floating)) {
1405 pos = session->audible_frame ();
1408 pos = (jack_nframes_t) floor (prefix * session->frame_rate ());
1410 pos = (jack_nframes_t) floor (prefix);
1414 session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true);
1418 Editor::clear_markers ()
1421 session->begin_reversible_command (_("clear markers"));
1422 session->add_undo (session->locations()->get_memento());
1423 session->locations()->clear_markers ();
1424 session->add_redo_no_execute (session->locations()->get_memento());
1425 session->commit_reversible_command ();
1430 Editor::clear_ranges ()
1433 session->begin_reversible_command (_("clear ranges"));
1434 session->add_undo (session->locations()->get_memento());
1436 Location * looploc = session->locations()->auto_loop_location();
1437 Location * punchloc = session->locations()->auto_punch_location();
1439 session->locations()->clear_ranges ();
1441 if (looploc) session->locations()->add (looploc);
1442 if (punchloc) session->locations()->add (punchloc);
1444 session->add_redo_no_execute (session->locations()->get_memento());
1445 session->commit_reversible_command ();
1450 Editor::clear_locations ()
1452 session->begin_reversible_command (_("clear locations"));
1453 session->add_undo (session->locations()->get_memento());
1454 session->locations()->clear ();
1455 session->add_redo_no_execute (session->locations()->get_memento());
1456 session->commit_reversible_command ();
1457 session->locations()->clear ();
1460 /* INSERT/REPLACE */
1463 Editor::insert_region_list_drag (AudioRegion& region)
1469 jack_nframes_t where;
1470 AudioTimeAxisView *atv = 0;
1473 track_canvas->get_pointer (x, y);
1475 gnome_canvas_window_to_world (GNOME_CANVAS(track_gnome_canvas), x, y, &wx, &wy);
1478 event.type = GDK_BUTTON_RELEASE;
1479 event.button.x = wx;
1480 event.button.y = wy;
1482 where = event_frame (&event, &cx, &cy);
1484 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1485 /* clearly outside canvas area */
1489 if ((tv = trackview_by_y_position (cy)) == 0) {
1493 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) == 0) {
1497 if ((playlist = atv->playlist()) == 0) {
1503 begin_reversible_command (_("insert dragged region"));
1504 session->add_undo (playlist->get_memento());
1505 playlist->add_region (*(new AudioRegion (region)), where, 1.0);
1506 session->add_redo_no_execute (playlist->get_memento());
1507 commit_reversible_command ();
1511 Editor::insert_region_list_selection (float times)
1513 AudioTimeAxisView *tv = 0;
1516 if (clicked_audio_trackview != 0) {
1517 tv = clicked_audio_trackview;
1518 } else if (!selection->tracks.empty()) {
1519 if ((tv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.front())) == 0) {
1526 if ((playlist = tv->playlist()) == 0) {
1530 Gtk::CTree_Helpers::SelectionList& selected = region_list_display.selection();
1532 if (selected.empty()) {
1536 Region* region = reinterpret_cast<Region *> (selected.front().get_data ());
1538 begin_reversible_command (_("insert region"));
1539 session->add_undo (playlist->get_memento());
1540 playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times);
1541 session->add_redo_no_execute (playlist->get_memento());
1542 commit_reversible_command ();
1546 /* BUILT-IN EFFECTS */
1549 Editor::reverse_selection ()
1554 /* GAIN ENVELOPE EDITING */
1557 Editor::edit_envelope ()
1564 Editor::toggle_playback (bool with_abort)
1570 switch (session->slave_source()) {
1575 /* transport controlled by the master */
1579 if (session->is_auditioning()) {
1580 session->cancel_audition ();
1584 if (session->transport_rolling()) {
1585 session->request_stop (with_abort);
1586 if (session->get_auto_loop()) {
1587 session->request_auto_loop (false);
1590 session->request_transport_speed (1.0f);
1595 Editor::play_from_start ()
1597 session->request_locate (0, true);
1601 Editor::play_selection ()
1603 if (selection->time.empty()) {
1607 session->request_play_range (true);
1611 Editor::play_selected_region ()
1613 if (!selection->audio_regions.empty()) {
1614 AudioRegionView *rv = *(selection->audio_regions.begin());
1616 session->request_bounded_roll (rv->region.position(), rv->region.last_frame());
1621 Editor::toggle_loop_playback ()
1624 session->request_auto_loop (true);
1629 Editor::loop_selected_region ()
1631 if (!selection->audio_regions.empty()) {
1632 AudioRegionView *rv = *(selection->audio_regions.begin());
1635 if ((tll = transport_loop_location()) != 0) {
1637 tll->set (rv->region.position(), rv->region.last_frame());
1639 // enable looping, reposition and start rolling
1641 session->request_auto_loop (true);
1642 session->request_locate (tll->start(), false);
1643 session->request_transport_speed (1.0f);
1649 Editor::play_location (Location& location)
1651 if (location.start() <= location.end()) {
1655 session->request_bounded_roll (location.start(), location.end());
1659 Editor::loop_location (Location& location)
1661 if (location.start() <= location.end()) {
1667 if ((tll = transport_loop_location()) != 0) {
1668 tll->set (location.start(), location.end());
1670 // enable looping, reposition and start rolling
1671 session->request_auto_loop (true);
1672 session->request_locate (tll->start(), true);
1677 Editor::toggle_region_mute ()
1679 if (clicked_regionview) {
1680 clicked_regionview->region.set_muted (!clicked_regionview->region.muted());
1681 } else if (!selection->audio_regions.empty()) {
1682 bool yn = ! (*selection->audio_regions.begin())->region.muted();
1683 selection->foreach_audio_region (&AudioRegion::set_muted, yn);
1688 Editor::toggle_region_opaque ()
1690 if (clicked_regionview) {
1691 clicked_regionview->region.set_opaque (!clicked_regionview->region.opaque());
1692 } else if (!selection->audio_regions.empty()) {
1693 bool yn = ! (*selection->audio_regions.begin())->region.opaque();
1694 selection->foreach_audio_region (&Region::set_opaque, yn);
1699 Editor::raise_region ()
1701 selection->foreach_audio_region (&Region::raise);
1705 Editor::raise_region_to_top ()
1707 selection->foreach_audio_region (&Region::raise_to_top);
1711 Editor::lower_region ()
1713 selection->foreach_audio_region (&Region::lower);
1717 Editor::lower_region_to_bottom ()
1719 selection->foreach_audio_region (&Region::lower_to_bottom);
1723 Editor::edit_region ()
1725 if (clicked_regionview == 0) {
1729 clicked_regionview->show_region_editor ();
1733 Editor::rename_region ()
1737 Button ok_button (_("OK"));
1738 Button cancel_button (_("Cancel"));
1740 if (selection->audio_regions.empty()) {
1744 dialog.set_title (_("ardour: rename region"));
1745 dialog.set_name ("RegionRenameWindow");
1746 dialog.set_size_request (300, -1);
1747 dialog.set_position (Gtk::WIN_POS_MOUSE);
1748 dialog.set_modal (true);
1750 dialog.get_vbox()->set_border_width (10);
1751 dialog.get_vbox()->pack_start (entry);
1752 dialog.get_action_area()->pack_start (ok_button);
1753 dialog.get_action_area()->pack_start (cancel_button);
1755 entry.set_name ("RegionNameDisplay");
1756 ok_button.set_name ("EditorGTKButton");
1757 cancel_button.set_name ("EditorGTKButton");
1759 region_renamed = false;
1761 entry.activate.connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1762 ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
1763 cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
1768 ARDOUR_UI::instance()->allow_focus (true);
1770 ARDOUR_UI::instance()->allow_focus (false);
1772 if (region_renamed) {
1773 (*selection->audio_regions.begin())->region.set_name (entry.get_text());
1774 redisplay_regions ();
1779 Editor::rename_region_finished (bool status)
1782 region_renamed = status;
1787 Editor::audition_playlist_region_via_route (AudioRegion& region, Route& route)
1789 if (session->is_auditioning()) {
1790 session->cancel_audition ();
1793 // note: some potential for creativity here, because region doesn't
1794 // have to belong to the playlist that Route is handling
1796 // bool was_soloed = route.soloed();
1798 route.set_solo (true, this);
1800 session->request_bounded_roll (region.position(), region.position() + region.length());
1802 /* XXX how to unset the solo state ? */
1806 Editor::audition_selected_region ()
1808 if (!selection->audio_regions.empty()) {
1809 AudioRegionView* rv = *(selection->audio_regions.begin());
1810 session->audition_region (rv->region);
1815 Editor::audition_playlist_region_standalone (AudioRegion& region)
1817 session->audition_region (region);
1821 Editor::build_interthread_progress_window ()
1823 interthread_progress_window = new ArdourDialog (X_("interthread progress"));
1825 interthread_progress_bar.set_orientation (GTK_PROGRESS_LEFT_TO_RIGHT);
1827 interthread_progress_vbox.set_border_width (10);
1828 interthread_progress_vbox.set_spacing (5);
1829 interthread_progress_vbox.pack_start (interthread_progress_label, false, false);
1830 interthread_progress_vbox.pack_start (interthread_progress_bar,false, false);
1831 interthread_progress_vbox.pack_start (interthread_cancel_button,false, false);
1833 interthread_cancel_button.add (interthread_cancel_label);
1835 interthread_cancel_button.signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
1837 interthread_progress_window->set_modal (true);
1838 interthread_progress_window->set_default_size (200, 100);
1839 interthread_progress_window->add (interthread_progress_vbox);
1843 Editor::interthread_cancel_clicked ()
1845 if (current_interthread_info) {
1846 current_interthread_info->cancel = true;
1851 Editor::_import_thread (void *arg)
1853 PBD::ThreadCreated (pthread_self(), X_("Import"));
1855 Editor *ed = (Editor *) arg;
1856 return ed->import_thread ();
1860 Editor::import_thread ()
1862 session->import_audiofile (import_status);
1867 Editor::import_progress_timeout (void *arg)
1869 interthread_progress_label.set_text (import_status.doing_what);
1871 if (import_status.freeze) {
1872 interthread_cancel_button.set_sensitive(false);
1874 interthread_cancel_button.set_sensitive(true);
1877 if (import_status.doing_what == "building peak files") {
1878 interthread_progress_bar.set_activity_mode (true);
1881 interthread_progress_bar.set_percentage (import_status.progress);
1884 return !(import_status.done || import_status.cancel);
1888 Editor::import_audio (bool as_tracks)
1891 warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
1895 SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
1900 c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_import), true));
1901 str =_("Import selected as tracks");
1903 c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_import), false));
1904 str = _("Import selected to region list");
1907 sfdb.run (str, true);
1912 Editor::catch_new_audio_region (AudioRegion* ar)
1914 last_audio_region = ar;
1918 Editor::do_import (vector<string> paths, bool split, bool as_tracks)
1922 /* SFDB sets "multichan" to true to indicate "split channels"
1923 so reverse the setting to match the way libardour
1927 import_status.multichan = !split;
1929 if (interthread_progress_window == 0) {
1930 build_interthread_progress_window ();
1933 interthread_progress_window->set_title (_("ardour: audio import in progress"));
1934 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
1935 interthread_progress_window->show_all ();
1936 interthread_progress_bar.set_percentage (0.0f);
1937 interthread_cancel_label.set_text (_("Cancel Import"));
1938 current_interthread_info = &import_status;
1940 c = session->AudioRegionAdded.connect (mem_fun(*this, &Editor::catch_new_audio_region));
1942 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
1944 interthread_progress_window->set_title (string_compose (_("ardour: importing %1"), (*i)));
1946 import_status.pathname = (*i);
1947 import_status.done = false;
1948 import_status.cancel = false;
1949 import_status.freeze = false;
1950 import_status.done = 0.0;
1952 interthread_progress_connection =
1953 Gtk::Main::timeout.connect (bind (mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
1955 last_audio_region = 0;
1957 pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
1958 pthread_detach (import_status.thread);
1960 while (!(import_status.done || import_status.cancel)) {
1961 gtk_main_iteration ();
1964 import_status.done = true;
1965 interthread_progress_connection.disconnect ();
1967 if (as_tracks && last_audio_region != 0) {
1968 uint32_t channels = last_audio_region->n_channels();
1970 AudioTrack* at = session->new_audio_track (channels, channels);
1971 AudioRegion* copy = new AudioRegion (*last_audio_region);
1972 at->disk_stream().playlist()->add_region (*copy, 0);
1977 interthread_progress_window->hide_all ();
1981 Editor::reject_because_rate_differs (string path, SF_INFO& finfo, string action, bool multiple_pending)
1987 if (finfo.samplerate != (int) session->frame_rate()) {
1988 vector<string> choices;
1990 choices.push_back (string_compose (_("%1 it anyway"), action));
1992 if (multiple_pending) {
1993 /* XXX assumptions about sentence structure
1994 here for translators. Sorry.
1996 choices.push_back (string_compose (_("Don't %1 it"), action));
1997 choices.push_back (string_compose (_("%1 all without questions"), action));
1998 choices.push_back (_("Cancel entire import"));
2000 choices.push_back (_("Cancel"));
2003 Gtkmm2ext::Choice rate_choice (
2004 string_compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
2007 rate_choice.chosen.connect (Main::quit.slot());
2008 rate_choice.show_all ();
2012 switch (rate_choice.get_choice()) {
2013 case 0: /* do it anyway */
2015 case 1: /* don't import this one */
2017 case 2: /* do the rest without asking */
2019 case 3: /* stop a multi-file import */
2029 Editor::embed_audio ()
2032 warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
2036 SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2037 sigc::connection c = sfdb.Action.connect (mem_fun(*this, &Editor::do_embed_sndfiles));
2039 sfdb.run (_("Add to External Region list"), true);
2045 Editor::do_embed_sndfiles (vector<string> paths, bool split)
2047 bool multiple_files = paths.size() > 1;
2048 bool check_sample_rate = true;
2050 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
2051 embed_sndfile (*i, split, multiple_files, check_sample_rate);
2054 session->save_state ("");
2058 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
2060 SndFileSource *source = 0; /* keep g++ quiet */
2061 AudioRegion::SourceList sources;
2067 /* lets see if we can link it into the session */
2069 linked_path = session->sound_dir();
2070 linked_path += PBD::basename (path);
2072 if (link (path.c_str(), linked_path.c_str()) == 0) {
2074 /* there are many reasons why link(2) might have failed.
2075 but if it succeeds, we now have a link in the
2076 session sound dir that will protect against
2077 unlinking of the original path. nice.
2083 memset (&finfo, 0, sizeof(finfo));
2085 /* note that we temporarily truncated _id at the colon */
2087 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2089 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2090 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
2096 if (check_sample_rate) {
2097 switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
2103 check_sample_rate = false;
2112 track_canvas_scroller.get_window().set_cursor (GDK_WATCH);
2113 ARDOUR_UI::instance()->flush_pending ();
2115 /* make the proper number of channels in the region */
2117 for (int n=0; n < finfo.channels; ++n)
2120 idspec += string_compose(":%1", n);
2123 source = new SndFileSource (idspec.c_str());
2124 sources.push_back(source);
2127 catch (failed_constructor& err) {
2128 error << string_compose(_("could not open %1"), path) << endmsg;
2132 ARDOUR_UI::instance()->flush_pending ();
2135 if (sources.size() > 0) {
2137 string region_name = PBD::basename_nosuffix (path);
2138 region_name += "-0";
2140 /* The created region isn't dropped. It emits a signal
2141 that is picked up by the session.
2144 new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
2145 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2147 /* make sure we can see it in the list */
2149 Gtk::CTree_Helpers::RowList::iterator external_node;
2150 external_node = region_list_display.rows().begin();
2151 ++external_node; /* its the second node, always */
2152 external_node->expand_recursive ();
2154 ARDOUR_UI::instance()->flush_pending ();
2158 track_canvas_scroller.get_window().set_cursor (current_canvas_cursor);
2162 Editor::insert_sndfile (bool as_tracks)
2164 SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
2170 c = sfdb.Action.connect (mem_fun(*this, &Editor::insert_paths_as_new_tracks));
2171 str = _("Insert selected as new tracks");
2177 if (clicked_audio_trackview == 0) {
2181 if (ensure_cursor (&pos)) {
2185 c = sfdb.Action.connect (bind (mem_fun(*this, &Editor::do_insert_sndfile), pos));
2186 str = _("Insert selected");
2189 sfdb.run (str, false);
2194 Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
2198 bool multiple_files;
2199 bool check_sample_rate = true;
2201 multiple_files = paths.size() > 1;
2203 for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
2205 memset (&finfo, 0, sizeof(finfo));
2207 if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
2209 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2210 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
2217 /* add a new track */
2219 if (check_sample_rate) {
2220 switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
2226 check_sample_rate = false;
2234 uint32_t input_chan = finfo.channels;
2235 uint32_t output_chan;
2237 if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
2238 output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
2240 output_chan = input_chan;
2243 (void) session->new_audio_track (input_chan, output_chan);
2246 /* get the last (most recently added) track view */
2248 AudioTimeAxisView* tv;
2250 if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
2251 fatal << _("programming error: ")
2252 << X_("last trackview after new_audio_track is not an audio track!")
2257 jack_nframes_t pos = 0;
2258 insert_sndfile_into (*p, true, tv, pos, false);
2263 Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
2265 for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
2266 insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
2271 Editor::insert_sndfile_into (string path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
2273 SndFileSource *source = 0; /* keep g++ quiet */
2274 AudioRegion::SourceList sources;
2279 memset (&finfo, 0, sizeof(finfo));
2281 /* note that we temporarily truncated _id at the colon */
2283 if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
2285 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
2286 error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
2292 if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
2296 track_canvas_scroller.get_window().set_cursor (GDK_WATCH);
2297 ARDOUR_UI::instance()->flush_pending ();
2299 /* make the proper number of channels in the region */
2301 for (int n=0; n < finfo.channels; ++n)
2304 idspec += string_compose(":%1", n);
2307 source = new SndFileSource (idspec.c_str());
2308 sources.push_back(source);
2311 catch (failed_constructor& err) {
2312 error << string_compose(_("could not open %1"), path) << endmsg;
2316 ARDOUR_UI::instance()->flush_pending ();
2319 if (sources.size() > 0) {
2321 string region_name = region_name_from_path (PBD::basename (path));
2323 AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
2324 0, /* irrelevant these days */
2325 Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
2327 begin_reversible_command (_("insert sndfile"));
2328 session->add_undo (tv->playlist()->get_memento());
2329 tv->playlist()->add_region (*region, pos);
2330 session->add_redo_no_execute (tv->playlist()->get_memento());
2331 commit_reversible_command ();
2333 pos += sources[0]->length();
2335 ARDOUR_UI::instance()->flush_pending ();
2339 track_canvas_scroller.get_window().set_cursor (current_canvas_cursor);
2344 Editor::region_from_selection ()
2346 if (clicked_trackview == 0) {
2350 if (selection->time.empty()) {
2354 jack_nframes_t start = selection->time[clicked_selection].start;
2355 jack_nframes_t end = selection->time[clicked_selection].end;
2357 jack_nframes_t selection_cnt = end - start + 1;
2359 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2361 AudioRegion *region;
2362 AudioRegion *current;
2366 jack_nframes_t internal_start;
2369 if ((pl = (*i)->playlist()) == 0) {
2373 if ((current_r = pl->top_region_at (start)) == 0) {
2377 if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
2378 internal_start = start - current->position();
2379 session->region_name (new_name, current->name(), true);
2380 region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
2386 Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
2388 if (selection->time.empty() || selection->tracks.empty()) {
2392 jack_nframes_t start = selection->time[clicked_selection].start;
2393 jack_nframes_t end = selection->time[clicked_selection].end;
2395 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2397 AudioRegion* current;
2400 jack_nframes_t internal_start;
2403 if ((playlist = (*i)->playlist()) == 0) {
2407 if ((current_r = playlist->top_region_at(start)) == 0) {
2411 if ((current = dynamic_cast<AudioRegion*>(current_r)) == 0) {
2415 internal_start = start - current->position();
2416 session->region_name (new_name, current->name(), true);
2418 new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name));
2423 Editor::split_multichannel_region ()
2425 vector<AudioRegion*> v;
2427 if (!clicked_regionview || clicked_regionview->region.n_channels() < 2) {
2431 clicked_regionview->region.separate_by_channel (*session, v);
2433 /* nothing else to do, really */
2437 Editor::new_region_from_selection ()
2439 region_from_selection ();
2440 cancel_selection ();
2444 Editor::separate_region_from_selection ()
2446 bool doing_undo = false;
2448 if (selection->time.empty()) {
2454 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2456 AudioTimeAxisView* atv;
2458 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2460 if (atv->is_audio_track()) {
2462 if ((playlist = atv->playlist()) != 0) {
2464 begin_reversible_command (_("separate"));
2467 if (doing_undo) session->add_undo ((playlist)->get_memento());
2469 /* XXX need to consider musical time selections here at some point */
2471 double speed = atv->get_diskstream()->speed();
2473 for (list<AudioRange>::iterator t = selection->time.begin(); t != selection->time.end(); ++t) {
2474 playlist->partition ((jack_nframes_t)((*t).start * speed), (jack_nframes_t)((*t).end * speed), true);
2477 if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
2483 if (doing_undo) commit_reversible_command ();
2487 Editor::crop_region_to_selection ()
2489 if (selection->time.empty()) {
2493 vector<Playlist*> playlists;
2496 if (clicked_trackview != 0) {
2498 if ((playlist = clicked_trackview->playlist()) == 0) {
2502 playlists.push_back (playlist);
2506 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2508 AudioTimeAxisView* atv;
2510 if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
2512 if (atv->is_audio_track()) {
2514 if ((playlist = atv->playlist()) != 0) {
2515 playlists.push_back (playlist);
2522 if (!playlists.empty()) {
2524 jack_nframes_t start;
2528 begin_reversible_command (_("trim to selection"));
2530 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2534 start = selection->time.start();
2536 if ((region = (*i)->top_region_at(start)) == 0) {
2540 /* now adjust lengths to that we do the right thing
2541 if the selection extends beyond the region
2544 start = max (start, region->position());
2545 end = min (selection->time.end_frame(), start + region->length() - 1);
2546 cnt = end - start + 1;
2548 session->add_undo ((*i)->get_memento());
2549 region->trim_to (start, cnt, this);
2550 session->add_redo_no_execute ((*i)->get_memento());
2553 commit_reversible_command ();
2558 Editor::region_fill_track ()
2562 if (!session || selection->audio_regions.empty()) {
2566 end = session->current_end_frame ();
2568 begin_reversible_command (_("region fill"));
2570 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2572 AudioRegion& region ((*i)->region);
2573 Playlist* pl = region.playlist();
2575 if (end <= region.last_frame()) {
2579 double times = (double) (end - region.last_frame()) / (double) region.length();
2585 session->add_undo (pl->get_memento());
2586 pl->add_region (*(new AudioRegion (region)), region.last_frame(), times);
2587 session->add_redo_no_execute (pl->get_memento());
2590 commit_reversible_command ();
2594 Editor::region_fill_selection ()
2596 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2600 if (selection->time.empty()) {
2606 Gtk::CTree_Helpers::SelectionList& selected = region_list_display.selection();
2608 if (selected.empty()) {
2612 region = reinterpret_cast<Region *> (selected.front().get_data());
2614 jack_nframes_t start = selection->time[clicked_selection].start;
2615 jack_nframes_t end = selection->time[clicked_selection].end;
2619 if (selection->tracks.empty()) {
2623 jack_nframes_t selection_length = end - start;
2624 float times = (float)selection_length / region->length();
2626 begin_reversible_command (_("fill selection"));
2628 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
2630 if ((playlist = (*i)->playlist()) == 0) {
2634 session->add_undo (playlist->get_memento());
2635 playlist->add_region (*(createRegion (*region)), start, times);
2636 session->add_redo_no_execute (playlist->get_memento());
2639 commit_reversible_command ();
2643 Editor::set_region_sync_from_edit_cursor ()
2645 if (clicked_regionview == 0) {
2649 if (!clicked_regionview->region.covers (edit_cursor->current_frame)) {
2650 error << _("Place the edit cursor at the desired sync point") << endmsg;
2654 Region& region (clicked_regionview->region);
2656 begin_reversible_command (_("set sync from edit cursor"));
2657 session->add_undo (region.playlist()->get_memento());
2658 region.set_sync_position (edit_cursor->current_frame);
2659 session->add_redo_no_execute (region.playlist()->get_memento());
2660 commit_reversible_command ();
2664 Editor::remove_region_sync ()
2666 if (clicked_regionview) {
2667 Region& region (clicked_regionview->region);
2668 begin_reversible_command (_("remove sync"));
2669 session->add_undo (region.playlist()->get_memento());
2670 region.clear_sync_position ();
2671 session->add_redo_no_execute (region.playlist()->get_memento());
2672 commit_reversible_command ();
2677 Editor::naturalize ()
2679 if (selection->audio_regions.empty()) {
2682 begin_reversible_command (_("naturalize"));
2683 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2684 session->add_undo ((*i)->region.get_memento());
2685 (*i)->region.move_to_natural_position (this);
2686 session->add_redo_no_execute ((*i)->region.get_memento());
2688 commit_reversible_command ();
2692 Editor::align (RegionPoint what)
2694 align_selection (what, edit_cursor->current_frame);
2698 Editor::align_relative (RegionPoint what)
2700 align_selection_relative (what, edit_cursor->current_frame);
2703 struct RegionSortByTime {
2704 bool operator() (const AudioRegionView* a, const AudioRegionView* b) {
2705 return a->region.position() < b->region.position();
2710 Editor::align_selection_relative (RegionPoint point, jack_nframes_t position)
2712 if (selection->audio_regions.empty()) {
2716 jack_nframes_t distance;
2717 jack_nframes_t pos = 0;
2720 list<AudioRegionView*> sorted;
2721 selection->audio_regions.by_position (sorted);
2722 Region& r ((*sorted.begin())->region);
2726 pos = r.first_frame ();
2730 pos = r.last_frame();
2734 pos = r.adjust_to_sync (r.first_frame());
2738 if (pos > position) {
2739 distance = pos - position;
2742 distance = position - pos;
2746 begin_reversible_command (_("align selection (relative)"));
2748 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2750 Region& region ((*i)->region);
2752 session->add_undo (region.playlist()->get_memento());
2755 region.set_position (region.position() + distance, this);
2757 region.set_position (region.position() - distance, this);
2760 session->add_redo_no_execute (region.playlist()->get_memento());
2764 commit_reversible_command ();
2768 Editor::align_selection (RegionPoint point, jack_nframes_t position)
2770 if (selection->audio_regions.empty()) {
2774 begin_reversible_command (_("align selection"));
2776 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
2777 align_region_internal ((*i)->region, point, position);
2780 commit_reversible_command ();
2784 Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position)
2786 begin_reversible_command (_("align region"));
2787 align_region_internal (region, point, position);
2788 commit_reversible_command ();
2792 Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position)
2794 session->add_undo (region.playlist()->get_memento());
2798 region.set_position (region.adjust_to_sync (position), this);
2802 if (position > region.length()) {
2803 region.set_position (position - region.length(), this);
2808 region.set_position (position, this);
2812 session->add_redo_no_execute (region.playlist()->get_memento());
2816 Editor::trim_region_to_edit_cursor ()
2818 if (clicked_regionview == 0) {
2822 Region& region (clicked_regionview->region);
2825 AudioTimeAxisView *atav;
2827 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2828 if (atav->get_diskstream() != 0) {
2829 speed = atav->get_diskstream()->speed();
2833 begin_reversible_command (_("trim to edit"));
2834 session->add_undo (region.playlist()->get_memento());
2835 region.trim_end ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
2836 session->add_redo_no_execute (region.playlist()->get_memento());
2837 commit_reversible_command ();
2841 Editor::trim_region_from_edit_cursor ()
2843 if (clicked_regionview == 0) {
2847 Region& region (clicked_regionview->region);
2850 AudioTimeAxisView *atav;
2852 if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
2853 if (atav->get_diskstream() != 0) {
2854 speed = atav->get_diskstream()->speed();
2858 begin_reversible_command (_("trim to edit"));
2859 session->add_undo (region.playlist()->get_memento());
2860 region.trim_front ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
2861 session->add_redo_no_execute (region.playlist()->get_memento());
2862 commit_reversible_command ();
2866 Editor::unfreeze_route ()
2868 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2872 clicked_audio_trackview->audio_track()->unfreeze ();
2876 Editor::_freeze_thread (void* arg)
2878 PBD::ThreadCreated (pthread_self(), X_("Freeze"));
2879 return static_cast<Editor*>(arg)->freeze_thread ();
2883 Editor::freeze_thread ()
2885 clicked_audio_trackview->audio_track()->freeze (*current_interthread_info);
2890 Editor::freeze_progress_timeout (void *arg)
2892 interthread_progress_bar.set_percentage (current_interthread_info->progress);
2893 return !(current_interthread_info->done || current_interthread_info->cancel);
2897 Editor::freeze_route ()
2899 if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) {
2903 InterThreadInfo itt;
2905 if (interthread_progress_window == 0) {
2906 build_interthread_progress_window ();
2909 interthread_progress_window->set_title (_("ardour: freeze"));
2910 interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
2911 interthread_progress_window->show_all ();
2912 interthread_progress_bar.set_percentage (0.0f);
2913 interthread_progress_label.set_text ("");
2914 interthread_cancel_label.set_text (_("Cancel Freeze"));
2915 current_interthread_info = &itt;
2917 interthread_progress_connection =
2918 Gtk::Main::timeout.connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
2922 itt.progress = 0.0f;
2924 pthread_create (&itt.thread, 0, _freeze_thread, this);
2926 track_canvas_scroller.get_window().set_cursor (GDK_WATCH);
2928 while (!itt.done && !itt.cancel) {
2929 gtk_main_iteration ();
2932 interthread_progress_connection.disconnect ();
2933 interthread_progress_window->hide_all ();
2934 current_interthread_info = 0;
2935 track_canvas_scroller.get_window().set_cursor (current_canvas_cursor);
2939 Editor::bounce_range_selection ()
2941 if (selection->time.empty()) {
2945 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
2947 jack_nframes_t start = selection->time[clicked_selection].start;
2948 jack_nframes_t end = selection->time[clicked_selection].end;
2949 jack_nframes_t cnt = end - start + 1;
2951 begin_reversible_command (_("bounce range"));
2953 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
2955 AudioTimeAxisView* atv;
2957 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
2963 if ((playlist = atv->playlist()) == 0) {
2967 InterThreadInfo itt;
2971 itt.progress = false;
2973 session->add_undo (playlist->get_memento());
2974 atv->audio_track()->bounce_range (start, cnt, itt);
2975 session->add_redo_no_execute (playlist->get_memento());
2978 commit_reversible_command ();
2996 Editor::cut_copy (CutCopyOp op)
2998 /* only cancel selection if cut/copy is successful.*/
3010 opname = _("clear");
3014 cut_buffer->clear ();
3016 switch (current_mouse_mode()) {
3018 if (!selection->audio_regions.empty() || !selection->points.empty()) {
3020 begin_reversible_command (opname + _(" objects"));
3022 if (!selection->audio_regions.empty()) {
3024 cut_copy_regions (op);
3027 selection->clear_audio_regions ();
3031 if (!selection->points.empty()) {
3032 cut_copy_points (op);
3035 selection->clear_points ();
3039 commit_reversible_command ();
3044 if (!selection->time.empty()) {
3046 begin_reversible_command (opname + _(" range"));
3047 cut_copy_ranges (op);
3048 commit_reversible_command ();
3051 selection->clear_time ();
3063 Editor::cut_copy_points (CutCopyOp op)
3065 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3067 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>(&(*i).track);
3070 atv->cut_copy_clear_objects (selection->points, op);
3076 Editor::cut_copy_regions (CutCopyOp op)
3078 typedef map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
3079 PlaylistMapping pmap;
3080 jack_nframes_t first_position = max_frames;
3081 set<Playlist*> freezelist;
3082 pair<set<Playlist*>::iterator,bool> insert_result;
3084 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ++x) {
3085 first_position = min ((*x)->region.position(), first_position);
3087 if (op == Cut || op == Clear) {
3088 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3090 insert_result = freezelist.insert (pl);
3091 if (insert_result.second) {
3093 session->add_undo (pl->get_memento());
3099 for (AudioRegionSelection::iterator x = selection->audio_regions.begin(); x != selection->audio_regions.end(); ) {
3101 AudioPlaylist *pl = dynamic_cast<AudioPlaylist*>((*x)->region.playlist());
3103 AudioRegionSelection::iterator tmp;
3110 PlaylistMapping::iterator pi = pmap.find (pl);
3112 if (pi == pmap.end()) {
3113 npl = new AudioPlaylist (*session, "cutlist", true);
3122 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3123 pl->remove_region (&((*x)->region));
3127 npl->add_region (*(new AudioRegion ((*x)->region)), (*x)->region.position() - first_position);
3131 pl->remove_region (&((*x)->region));
3139 list<Playlist*> foo;
3141 for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3142 foo.push_back (i->second);
3146 cut_buffer->set (foo);
3149 for (set<Playlist*>::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3151 session->add_redo_no_execute ((*pl)->get_memento());
3156 Editor::cut_copy_ranges (CutCopyOp op)
3158 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3159 (*i)->cut_copy_clear (*selection, op);
3164 Editor::paste (float times)
3166 paste_internal (edit_cursor->current_frame, times);
3170 Editor::mouse_paste ()
3174 track_canvas->get_pointer (x, y);
3176 gnome_canvas_window_to_world (GNOME_CANVAS(track_gnome_canvas), x, y, &wx, &wy);
3179 event.type = GDK_BUTTON_RELEASE;
3180 event.button.x = wx;
3181 event.button.y = wy;
3183 jack_nframes_t where = event_frame (&event, 0, 0);
3185 paste_internal (where, 1);
3189 Editor::paste_internal (jack_nframes_t position, float times)
3191 bool commit = false;
3193 if (cut_buffer->empty() || selection->tracks.empty()) {
3197 if (position == max_frames) {
3198 position = edit_cursor->current_frame;
3201 begin_reversible_command (_("paste"));
3203 TrackSelection::iterator i;
3206 for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) {
3208 /* undo/redo is handled by individual tracks */
3210 if ((*i)->paste (position, times, *cut_buffer, nth)) {
3216 commit_reversible_command ();
3221 Editor::paste_named_selection (float times)
3223 Gtk::CList_Helpers::SelectionList& selected = named_selection_display.selection();
3224 TrackSelection::iterator i;
3226 if (selected.empty() || selection->tracks.empty()) {
3230 NamedSelection* ns = static_cast<NamedSelection*> (selected.front()->get_data ());
3231 list<Playlist*>::iterator chunk;
3232 list<Playlist*>::iterator tmp;
3234 chunk = ns->playlists.begin();
3236 begin_reversible_command (_("paste chunk"));
3238 for (i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3240 AudioTimeAxisView* atv;
3244 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
3248 if ((pl = atv->playlist()) == 0) {
3252 if ((apl = dynamic_cast<AudioPlaylist*> (pl)) == 0) {
3259 session->add_undo (apl->get_memento());
3260 apl->paste (**chunk, edit_cursor->current_frame, times);
3261 session->add_redo_no_execute (apl->get_memento());
3263 if (tmp != ns->playlists.end()) {
3268 commit_reversible_command();
3272 Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
3276 begin_reversible_command (_("duplicate region"));
3278 for (AudioRegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
3280 Region& r ((*i)->region);
3282 playlist = (*i)->region.playlist();
3283 session->add_undo (playlist->get_memento());
3284 playlist->duplicate (r, r.last_frame(), times);
3285 session->add_redo_no_execute (playlist->get_memento());
3289 commit_reversible_command ();
3293 Editor::duplicate_selection (float times)
3295 if (selection->time.empty() || selection->tracks.empty()) {
3300 vector<AudioRegion*> new_regions;
3301 vector<AudioRegion*>::iterator ri;
3303 create_region_from_selection (new_regions);
3305 if (new_regions.empty()) {
3309 begin_reversible_command (_("duplicate selection"));
3311 ri = new_regions.begin();
3313 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3314 if ((playlist = (*i)->playlist()) == 0) {
3317 session->add_undo (playlist->get_memento());
3318 playlist->duplicate (**ri, selection->time[clicked_selection].end, times);
3319 session->add_redo_no_execute (playlist->get_memento());
3322 if (ri == new_regions.end()) {
3327 commit_reversible_command ();
3331 Editor::center_playhead ()
3333 float page = canvas_width * frames_per_unit;
3335 center_screen_internal (playhead_cursor->current_frame, page);
3339 Editor::center_edit_cursor ()
3341 float page = canvas_width * frames_per_unit;
3343 center_screen_internal (edit_cursor->current_frame, page);
3347 Editor::clear_playlist (Playlist& playlist)
3349 begin_reversible_command (_("clear playlist"));
3350 session->add_undo (playlist.get_memento());
3352 session->add_redo_no_execute (playlist.get_memento());
3353 commit_reversible_command ();
3357 Editor::nudge_track (bool use_edit_cursor, bool forwards)
3360 jack_nframes_t distance;
3361 jack_nframes_t next_distance;
3362 jack_nframes_t start;
3364 if (use_edit_cursor) {
3365 start = edit_cursor->current_frame;
3370 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
3374 if (selection->tracks.empty()) {
3378 begin_reversible_command (_("nudge track"));
3380 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
3382 if ((playlist = (*i)->playlist()) == 0) {
3386 session->add_undo (playlist->get_memento());
3387 playlist->nudge_after (start, distance, forwards);
3388 session->add_redo_no_execute (playlist->get_memento());
3391 commit_reversible_command ();
3395 Editor::toggle_xfades_active ()
3398 session->set_crossfades_active (!session->get_crossfades_active());
3403 Editor::toggle_follow_playhead ()
3405 set_follow_playhead (!_follow_playhead);
3409 Editor::set_xfade_visibility (bool yn)
3415 Editor::toggle_xfade_visibility ()
3417 set_xfade_visibility (!xfade_visibility());
3421 Editor::remove_last_capture ()
3423 vector<string> choices;
3430 if (Config->get_verify_remove_last_capture()) {
3431 prompt = _("Do you really want to destroy the last capture?"
3432 "\n(This is destructive and cannot be undone)");
3434 choices.push_back (_("Yes, destroy it."));
3435 choices.push_back (_("No, do nothing."));
3437 Gtkmm2ext::Choice prompter (prompt, choices);
3439 prompter.chosen.connect (Gtk::Main::quit.slot());
3440 prompter.show_all ();
3444 if (prompter.get_choice() == 0) {
3445 session->remove_last_capture ();
3448 session->remove_last_capture();
3453 Editor::normalize_region ()
3459 if (selection->audio_regions.empty()) {
3463 begin_reversible_command (_("normalize"));
3465 track_canvas_scroller.get_window().set_cursor (wait_cursor);
3468 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3469 session->add_undo ((*r)->region.get_memento());
3470 (*r)->region.normalize_to (0.0f);
3471 session->add_redo_no_execute ((*r)->region.get_memento());
3474 commit_reversible_command ();
3475 gdk_window_set_cursor (track_canvas_scroller.get_window(), current_canvas_cursor);
3480 Editor::denormalize_region ()
3486 if (selection->audio_regions.empty()) {
3490 begin_reversible_command ("denormalize");
3492 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
3493 session->add_undo ((*r)->region.get_memento());
3494 (*r)->region.set_scale_amplitude (1.0f);
3495 session->add_redo_no_execute ((*r)->region.get_memento());
3498 commit_reversible_command ();
3503 Editor::reverse_region ()
3509 Reverse rev (*session);
3510 apply_filter (rev, _("reverse regions"));
3514 Editor::apply_filter (AudioFilter& filter, string command)
3516 if (selection->audio_regions.empty()) {
3520 begin_reversible_command (command);
3522 track_canvas_scroller.get_window().set_cursor (wait_cursor);
3525 for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
3527 AudioRegion& region ((*r)->region);
3528 Playlist* playlist = region.playlist();
3530 AudioRegionSelection::iterator tmp;
3535 if (region.apply (filter) == 0) {
3537 session->add_undo (playlist->get_memento());
3538 playlist->replace_region (region, *(filter.results.front()), region.position());
3539 session->add_redo_no_execute (playlist->get_memento());
3547 commit_reversible_command ();
3548 selection->audio_regions.clear ();
3551 gdk_window_set_cursor (track_canvas_scroller.get_window(), current_canvas_cursor);
3555 Editor::region_selection_op (void (Region::*pmf)(void))
3557 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3558 ((*i)->region.*pmf)();
3564 Editor::region_selection_op (void (Region::*pmf)(void*), void *arg)
3566 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3567 ((*i)->region.*pmf)(arg);
3572 Editor::region_selection_op (void (Region::*pmf)(bool), bool yn)
3574 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3575 ((*i)->region.*pmf)(yn);
3580 Editor::external_edit_region ()
3582 if (!clicked_regionview) {
3590 Editor::brush (jack_nframes_t pos)
3592 AudioRegionSelection sel;
3595 if (selection->audio_regions.empty()) {
3596 /* XXX get selection from region list */
3598 sel = selection->audio_regions;
3605 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3606 mouse_brush_insert_region ((*i), pos);
3611 Editor::toggle_gain_envelope_visibility ()
3613 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3614 (*i)->set_envelope_visible (!(*i)->envelope_visible());
3619 Editor::toggle_gain_envelope_active ()
3621 for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
3622 AudioRegion* ar = dynamic_cast<AudioRegion*>(&(*i)->region);
3624 ar->set_envelope_active (true);