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.
20 /* Note: public Editor methods are documented in public_editor.h */
30 #include "pbd/error.h"
31 #include "pbd/basename.h"
32 #include "pbd/pthread_utils.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/whitespace.h"
35 #include "pbd/stateful_diff_command.h"
37 #include <gtkmm2ext/utils.h>
38 #include <gtkmm2ext/choice.h>
39 #include <gtkmm2ext/popup.h>
41 #include "ardour/audio_track.h"
42 #include "ardour/audioregion.h"
43 #include "ardour/dB.h"
44 #include "ardour/location.h"
45 #include "ardour/midi_region.h"
46 #include "ardour/operations.h"
47 #include "ardour/playlist_factory.h"
48 #include "ardour/quantize.h"
49 #include "ardour/region_factory.h"
50 #include "ardour/reverse.h"
51 #include "ardour/route_group.h"
52 #include "ardour/session.h"
53 #include "ardour/session_playlists.h"
54 #include "ardour/strip_silence.h"
55 #include "ardour/transient_detector.h"
56 #include "ardour/utils.h"
58 #include "ardour_ui.h"
61 #include "time_axis_view.h"
62 #include "route_time_axis.h"
63 #include "audio_time_axis.h"
64 #include "automation_time_axis.h"
65 #include "streamview.h"
66 #include "audio_streamview.h"
67 #include "audio_region_view.h"
68 #include "midi_region_view.h"
69 #include "rgb_macros.h"
70 #include "selection_templates.h"
71 #include "selection.h"
73 #include "gtk-custom-hruler.h"
74 #include "gui_thread.h"
77 #include "editor_drag.h"
78 #include "strip_silence_dialog.h"
79 #include "editor_routes.h"
80 #include "editor_regions.h"
81 #include "quantize_dialog.h"
82 #include "interthread_progress_window.h"
83 #include "insert_time_dialog.h"
84 #include "normalize_dialog.h"
85 #include "editor_cursors.h"
86 #include "mouse_cursors.h"
87 #include "patch_change_dialog.h"
88 #include "transpose_dialog.h"
93 using namespace ARDOUR;
96 using namespace Gtkmm2ext;
97 using namespace Editing;
98 using Gtkmm2ext::Keyboard;
100 /***********************************************************************
102 ***********************************************************************/
105 Editor::undo (uint32_t n)
107 if (_drags->active ()) {
117 Editor::redo (uint32_t n)
119 if (_drags->active ()) {
129 Editor::split_regions_at (framepos_t where, RegionSelection& regions)
133 list <boost::shared_ptr<Playlist > > used_playlists;
135 if (regions.empty()) {
139 begin_reversible_command (_("split"));
141 // if splitting a single region, and snap-to is using
142 // region boundaries, don't pay attention to them
144 if (regions.size() == 1) {
145 switch (_snap_type) {
146 case SnapToRegionStart:
147 case SnapToRegionSync:
148 case SnapToRegionEnd:
157 EditorFreeze(); /* Emit Signal */
160 for (RegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
162 RegionSelection::iterator tmp;
164 /* XXX this test needs to be more complicated, to make sure we really
165 have something to split.
168 if (!(*a)->region()->covers (where)) {
176 boost::shared_ptr<Playlist> pl = (*a)->region()->playlist();
184 /* we haven't seen this playlist before */
186 /* remember used playlists so we can thaw them later */
187 used_playlists.push_back(pl);
192 pl->clear_changes ();
193 pl->split_region ((*a)->region(), where);
194 _session->add_command (new StatefulDiffCommand (pl));
200 while (used_playlists.size() > 0) {
201 list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
203 used_playlists.pop_front();
206 commit_reversible_command ();
209 EditorThaw(); /* Emit Signal */
213 /** Move one extreme of the current range selection. If more than one range is selected,
214 * the start of the earliest range or the end of the latest range is moved.
216 * @param move_end true to move the end of the current range selection, false to move
218 * @param next true to move the extreme to the next region boundary, false to move to
222 Editor::move_range_selection_start_or_end_to_region_boundary (bool move_end, bool next)
224 if (selection->time.start() == selection->time.end_frame()) {
228 framepos_t start = selection->time.start ();
229 framepos_t end = selection->time.end_frame ();
231 /* the position of the thing we may move */
232 framepos_t pos = move_end ? end : start;
233 int dir = next ? 1 : -1;
235 /* so we don't find the current region again */
236 if (dir > 0 || pos > 0) {
240 framepos_t const target = get_region_boundary (pos, dir, true, false);
255 begin_reversible_command (_("alter selection"));
256 selection->set_preserving_all_ranges (start, end);
257 commit_reversible_command ();
261 Editor::nudge_forward_release (GdkEventButton* ev)
263 if (ev->state & Keyboard::PrimaryModifier) {
264 nudge_forward (false, true);
266 nudge_forward (false, false);
272 Editor::nudge_backward_release (GdkEventButton* ev)
274 if (ev->state & Keyboard::PrimaryModifier) {
275 nudge_backward (false, true);
277 nudge_backward (false, false);
284 Editor::nudge_forward (bool next, bool force_playhead)
287 framepos_t next_distance;
293 RegionSelection rs = get_regions_from_selection_and_entered ();
295 if (!force_playhead && !rs.empty()) {
297 begin_reversible_command (_("nudge regions forward"));
299 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
300 boost::shared_ptr<Region> r ((*i)->region());
302 distance = get_nudge_distance (r->position(), next_distance);
305 distance = next_distance;
309 r->set_position (r->position() + distance);
310 _session->add_command (new StatefulDiffCommand (r));
313 commit_reversible_command ();
316 } else if (!force_playhead && !selection->markers.empty()) {
320 begin_reversible_command (_("nudge location forward"));
322 for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) {
324 Location* loc = find_location_from_marker ((*i), is_start);
328 XMLNode& before (loc->get_state());
331 distance = get_nudge_distance (loc->start(), next_distance);
333 distance = next_distance;
335 if (max_framepos - distance > loc->start() + loc->length()) {
336 loc->set_start (loc->start() + distance);
338 loc->set_start (max_framepos - loc->length());
341 distance = get_nudge_distance (loc->end(), next_distance);
343 distance = next_distance;
345 if (max_framepos - distance > loc->end()) {
346 loc->set_end (loc->end() + distance);
348 loc->set_end (max_framepos);
351 XMLNode& after (loc->get_state());
352 _session->add_command (new MementoCommand<Location>(*loc, &before, &after));
356 commit_reversible_command ();
359 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
360 _session->request_locate (playhead_cursor->current_frame + distance);
365 Editor::nudge_backward (bool next, bool force_playhead)
368 framepos_t next_distance;
374 RegionSelection rs = get_regions_from_selection_and_entered ();
376 if (!force_playhead && !rs.empty()) {
378 begin_reversible_command (_("nudge regions backward"));
380 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
381 boost::shared_ptr<Region> r ((*i)->region());
383 distance = get_nudge_distance (r->position(), next_distance);
386 distance = next_distance;
391 if (r->position() > distance) {
392 r->set_position (r->position() - distance);
396 _session->add_command (new StatefulDiffCommand (r));
399 commit_reversible_command ();
401 } else if (!force_playhead && !selection->markers.empty()) {
405 begin_reversible_command (_("nudge location forward"));
407 for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) {
409 Location* loc = find_location_from_marker ((*i), is_start);
413 XMLNode& before (loc->get_state());
416 distance = get_nudge_distance (loc->start(), next_distance);
418 distance = next_distance;
420 if (distance < loc->start()) {
421 loc->set_start (loc->start() - distance);
426 distance = get_nudge_distance (loc->end(), next_distance);
429 distance = next_distance;
432 if (distance < loc->end() - loc->length()) {
433 loc->set_end (loc->end() - distance);
435 loc->set_end (loc->length());
439 XMLNode& after (loc->get_state());
440 _session->add_command (new MementoCommand<Location>(*loc, &before, &after));
444 commit_reversible_command ();
448 distance = get_nudge_distance (playhead_cursor->current_frame, next_distance);
450 if (playhead_cursor->current_frame > distance) {
451 _session->request_locate (playhead_cursor->current_frame - distance);
453 _session->goto_start();
459 Editor::nudge_forward_capture_offset ()
461 RegionSelection rs = get_regions_from_selection_and_entered ();
463 if (!_session || rs.empty()) {
467 begin_reversible_command (_("nudge forward"));
469 framepos_t const distance = _session->worst_output_latency();
471 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
472 boost::shared_ptr<Region> r ((*i)->region());
475 r->set_position (r->position() + distance);
476 _session->add_command(new StatefulDiffCommand (r));
479 commit_reversible_command ();
483 Editor::nudge_backward_capture_offset ()
485 RegionSelection rs = get_regions_from_selection_and_entered ();
487 if (!_session || rs.empty()) {
491 begin_reversible_command (_("nudge forward"));
493 framepos_t const distance = _session->worst_output_latency();
495 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
496 boost::shared_ptr<Region> r ((*i)->region());
500 if (r->position() > distance) {
501 r->set_position (r->position() - distance);
505 _session->add_command(new StatefulDiffCommand (r));
508 commit_reversible_command ();
514 Editor::move_to_start ()
516 _session->goto_start ();
520 Editor::move_to_end ()
523 _session->request_locate (_session->current_end_frame());
527 Editor::build_region_boundary_cache ()
530 vector<RegionPoint> interesting_points;
531 boost::shared_ptr<Region> r;
532 TrackViewList tracks;
535 region_boundary_cache.clear ();
541 switch (_snap_type) {
542 case SnapToRegionStart:
543 interesting_points.push_back (Start);
545 case SnapToRegionEnd:
546 interesting_points.push_back (End);
548 case SnapToRegionSync:
549 interesting_points.push_back (SyncPoint);
551 case SnapToRegionBoundary:
552 interesting_points.push_back (Start);
553 interesting_points.push_back (End);
556 fatal << string_compose (_("build_region_boundary_cache called with snap_type = %1"), _snap_type) << endmsg;
561 TimeAxisView *ontrack = 0;
564 if (!selection->tracks.empty()) {
565 tlist = selection->tracks.filter_to_unique_playlists ();
567 tlist = track_views.filter_to_unique_playlists ();
570 while (pos < _session->current_end_frame() && !at_end) {
573 framepos_t lpos = max_framepos;
575 for (vector<RegionPoint>::iterator p = interesting_points.begin(); p != interesting_points.end(); ++p) {
577 if ((r = find_next_region (pos, *p, 1, tlist, &ontrack)) == 0) {
578 if (*p == interesting_points.back()) {
581 /* move to next point type */
587 rpos = r->first_frame();
591 rpos = r->last_frame();
595 rpos = r->sync_position ();
603 RouteTimeAxisView *rtav;
605 if (ontrack != 0 && (rtav = dynamic_cast<RouteTimeAxisView*>(ontrack)) != 0 ) {
606 if (rtav->track() != 0) {
607 speed = rtav->track()->speed();
611 rpos = track_frame_to_session_frame (rpos, speed);
617 /* prevent duplicates, but we don't use set<> because we want to be able
621 vector<framepos_t>::iterator ri;
623 for (ri = region_boundary_cache.begin(); ri != region_boundary_cache.end(); ++ri) {
629 if (ri == region_boundary_cache.end()) {
630 region_boundary_cache.push_back (rpos);
637 /* finally sort to be sure that the order is correct */
639 sort (region_boundary_cache.begin(), region_boundary_cache.end());
642 boost::shared_ptr<Region>
643 Editor::find_next_region (framepos_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack)
645 TrackViewList::iterator i;
646 framepos_t closest = max_framepos;
647 boost::shared_ptr<Region> ret;
651 framepos_t track_frame;
652 RouteTimeAxisView *rtav;
654 for (i = tracks.begin(); i != tracks.end(); ++i) {
657 boost::shared_ptr<Region> r;
660 if ( (rtav = dynamic_cast<RouteTimeAxisView*>(*i)) != 0 ) {
661 if (rtav->track()!=0)
662 track_speed = rtav->track()->speed();
665 track_frame = session_frame_to_track_frame(frame, track_speed);
667 if ((r = (*i)->find_next_region (track_frame, point, dir)) == 0) {
673 rpos = r->first_frame ();
677 rpos = r->last_frame ();
681 rpos = r->sync_position ();
685 // rpos is a "track frame", converting it to "_session frame"
686 rpos = track_frame_to_session_frame(rpos, track_speed);
689 distance = rpos - frame;
691 distance = frame - rpos;
694 if (distance < closest) {
706 Editor::find_next_region_boundary (framepos_t pos, int32_t dir, const TrackViewList& tracks)
708 framecnt_t distance = max_framepos;
709 framepos_t current_nearest = -1;
711 for (TrackViewList::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
712 framepos_t contender;
715 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
721 if ((contender = rtv->find_next_region_boundary (pos, dir)) < 0) {
725 d = ::llabs (pos - contender);
728 current_nearest = contender;
733 return current_nearest;
737 Editor::get_region_boundary (framepos_t pos, int32_t dir, bool with_selection, bool only_onscreen)
742 if (with_selection && Config->get_region_boundaries_from_selected_tracks()) {
744 if (!selection->tracks.empty()) {
746 target = find_next_region_boundary (pos, dir, selection->tracks);
750 if (only_onscreen || Config->get_region_boundaries_from_onscreen_tracks()) {
751 get_onscreen_tracks (tvl);
752 target = find_next_region_boundary (pos, dir, tvl);
754 target = find_next_region_boundary (pos, dir, track_views);
760 if (only_onscreen || Config->get_region_boundaries_from_onscreen_tracks()) {
761 get_onscreen_tracks (tvl);
762 target = find_next_region_boundary (pos, dir, tvl);
764 target = find_next_region_boundary (pos, dir, track_views);
772 Editor::cursor_to_region_boundary (bool with_selection, int32_t dir)
774 framepos_t pos = playhead_cursor->current_frame;
781 // so we don't find the current region again..
782 if (dir > 0 || pos > 0) {
786 if ((target = get_region_boundary (pos, dir, with_selection, false)) < 0) {
790 _session->request_locate (target);
794 Editor::cursor_to_next_region_boundary (bool with_selection)
796 cursor_to_region_boundary (with_selection, 1);
800 Editor::cursor_to_previous_region_boundary (bool with_selection)
802 cursor_to_region_boundary (with_selection, -1);
806 Editor::cursor_to_region_point (EditorCursor* cursor, RegionPoint point, int32_t dir)
808 boost::shared_ptr<Region> r;
809 framepos_t pos = cursor->current_frame;
815 TimeAxisView *ontrack = 0;
817 // so we don't find the current region again..
821 if (!selection->tracks.empty()) {
823 r = find_next_region (pos, point, dir, selection->tracks, &ontrack);
825 } else if (clicked_axisview) {
828 t.push_back (clicked_axisview);
830 r = find_next_region (pos, point, dir, t, &ontrack);
834 r = find_next_region (pos, point, dir, track_views, &ontrack);
843 pos = r->first_frame ();
847 pos = r->last_frame ();
851 pos = r->sync_position ();
856 RouteTimeAxisView *rtav;
858 if ( ontrack != 0 && (rtav = dynamic_cast<RouteTimeAxisView*>(ontrack)) != 0 ) {
859 if (rtav->track() != 0) {
860 speed = rtav->track()->speed();
864 pos = track_frame_to_session_frame(pos, speed);
866 if (cursor == playhead_cursor) {
867 _session->request_locate (pos);
869 cursor->set_position (pos);
874 Editor::cursor_to_next_region_point (EditorCursor* cursor, RegionPoint point)
876 cursor_to_region_point (cursor, point, 1);
880 Editor::cursor_to_previous_region_point (EditorCursor* cursor, RegionPoint point)
882 cursor_to_region_point (cursor, point, -1);
886 Editor::cursor_to_selection_start (EditorCursor *cursor)
890 switch (mouse_mode) {
892 if (!selection->regions.empty()) {
893 pos = selection->regions.start();
898 if (!selection->time.empty()) {
899 pos = selection->time.start ();
907 if (cursor == playhead_cursor) {
908 _session->request_locate (pos);
910 cursor->set_position (pos);
915 Editor::cursor_to_selection_end (EditorCursor *cursor)
919 switch (mouse_mode) {
921 if (!selection->regions.empty()) {
922 pos = selection->regions.end_frame();
927 if (!selection->time.empty()) {
928 pos = selection->time.end_frame ();
936 if (cursor == playhead_cursor) {
937 _session->request_locate (pos);
939 cursor->set_position (pos);
944 Editor::selected_marker_to_region_boundary (bool with_selection, int32_t dir)
954 if (selection->markers.empty()) {
958 if (!mouse_frame (mouse, ignored)) {
962 add_location_mark (mouse);
965 if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) {
969 framepos_t pos = loc->start();
971 // so we don't find the current region again..
972 if (dir > 0 || pos > 0) {
976 if ((target = get_region_boundary (pos, dir, with_selection, false)) < 0) {
980 loc->move_to (target);
984 Editor::selected_marker_to_next_region_boundary (bool with_selection)
986 selected_marker_to_region_boundary (with_selection, 1);
990 Editor::selected_marker_to_previous_region_boundary (bool with_selection)
992 selected_marker_to_region_boundary (with_selection, -1);
996 Editor::selected_marker_to_region_point (RegionPoint point, int32_t dir)
998 boost::shared_ptr<Region> r;
1003 if (!_session || selection->markers.empty()) {
1007 if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) {
1011 TimeAxisView *ontrack = 0;
1015 // so we don't find the current region again..
1019 if (!selection->tracks.empty()) {
1021 r = find_next_region (pos, point, dir, selection->tracks, &ontrack);
1025 r = find_next_region (pos, point, dir, track_views, &ontrack);
1034 pos = r->first_frame ();
1038 pos = r->last_frame ();
1042 pos = r->adjust_to_sync (r->first_frame());
1047 RouteTimeAxisView *rtav;
1049 if (ontrack != 0 && (rtav = dynamic_cast<RouteTimeAxisView*>(ontrack)) != 0) {
1050 if (rtav->track() != 0) {
1051 speed = rtav->track()->speed();
1055 pos = track_frame_to_session_frame(pos, speed);
1061 Editor::selected_marker_to_next_region_point (RegionPoint point)
1063 selected_marker_to_region_point (point, 1);
1067 Editor::selected_marker_to_previous_region_point (RegionPoint point)
1069 selected_marker_to_region_point (point, -1);
1073 Editor::selected_marker_to_selection_start ()
1079 if (!_session || selection->markers.empty()) {
1083 if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) {
1087 switch (mouse_mode) {
1089 if (!selection->regions.empty()) {
1090 pos = selection->regions.start();
1095 if (!selection->time.empty()) {
1096 pos = selection->time.start ();
1108 Editor::selected_marker_to_selection_end ()
1114 if (!_session || selection->markers.empty()) {
1118 if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) {
1122 switch (mouse_mode) {
1124 if (!selection->regions.empty()) {
1125 pos = selection->regions.end_frame();
1130 if (!selection->time.empty()) {
1131 pos = selection->time.end_frame ();
1143 Editor::scroll_playhead (bool forward)
1145 framepos_t pos = playhead_cursor->current_frame;
1146 framecnt_t delta = (framecnt_t) floor (current_page_frames() / 0.8);
1149 if (pos == max_framepos) {
1153 if (pos < max_framepos - delta) {
1172 _session->request_locate (pos);
1176 Editor::cursor_align (bool playhead_to_edit)
1182 if (playhead_to_edit) {
1184 if (selection->markers.empty()) {
1188 _session->request_locate (selection->markers.front()->position(), _session->transport_rolling());
1191 /* move selected markers to playhead */
1193 for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) {
1196 Location* loc = find_location_from_marker (*i, ignored);
1198 if (loc->is_mark()) {
1199 loc->set_start (playhead_cursor->current_frame);
1201 loc->set (playhead_cursor->current_frame,
1202 playhead_cursor->current_frame + loc->length());
1209 Editor::scroll_backward (float pages)
1211 framepos_t const one_page = (framepos_t) rint (_canvas_width * frames_per_unit);
1212 framepos_t const cnt = (framepos_t) floor (pages * one_page);
1215 if (leftmost_frame < cnt) {
1218 frame = leftmost_frame - cnt;
1221 reset_x_origin (frame);
1225 Editor::scroll_forward (float pages)
1227 framepos_t const one_page = (framepos_t) rint (_canvas_width * frames_per_unit);
1228 framepos_t const cnt = (framepos_t) floor (pages * one_page);
1231 if (max_framepos - cnt < leftmost_frame) {
1232 frame = max_framepos - cnt;
1234 frame = leftmost_frame + cnt;
1237 reset_x_origin (frame);
1241 Editor::scroll_tracks_down ()
1243 double vert_value = vertical_adjustment.get_value() + vertical_adjustment.get_page_size();
1244 if (vert_value > vertical_adjustment.get_upper() - _canvas_height) {
1245 vert_value = vertical_adjustment.get_upper() - _canvas_height;
1248 vertical_adjustment.set_value (vert_value);
1252 Editor::scroll_tracks_up ()
1254 vertical_adjustment.set_value (vertical_adjustment.get_value() - vertical_adjustment.get_page_size());
1258 Editor::scroll_tracks_down_line ()
1260 double vert_value = vertical_adjustment.get_value() + 60;
1262 if (vert_value > vertical_adjustment.get_upper() - _canvas_height) {
1263 vert_value = vertical_adjustment.get_upper() - _canvas_height;
1266 vertical_adjustment.set_value (vert_value);
1270 Editor::scroll_tracks_up_line ()
1272 reset_y_origin (vertical_adjustment.get_value() - 60);
1278 Editor::tav_zoom_step (bool coarser)
1280 ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_step, coarser)
1282 _routes->suspend_redisplay ();
1284 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1285 TimeAxisView *tv = (static_cast<TimeAxisView*>(*i));
1286 tv->step_height (coarser);
1289 _routes->resume_redisplay ();
1293 Editor::temporal_zoom_step (bool coarser)
1295 ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_step, coarser)
1299 nfpu = frames_per_unit;
1304 nfpu = max(1.0,(nfpu/1.61803399));
1307 temporal_zoom (nfpu);
1311 Editor::temporal_zoom (gdouble fpu)
1313 if (!_session) return;
1315 framepos_t current_page = current_page_frames();
1316 framepos_t current_leftmost = leftmost_frame;
1317 framepos_t current_rightmost;
1318 framepos_t current_center;
1319 framepos_t new_page_size;
1320 framepos_t half_page_size;
1321 framepos_t leftmost_after_zoom = 0;
1323 bool in_track_canvas;
1327 /* XXX this limit is also in ::set_frames_per_unit() */
1329 if (frames_per_unit <= 1.0 && fpu <= frames_per_unit) {
1335 new_page_size = (framepos_t) floor (_canvas_width * nfpu);
1336 half_page_size = new_page_size / 2;
1338 switch (zoom_focus) {
1340 leftmost_after_zoom = current_leftmost;
1343 case ZoomFocusRight:
1344 current_rightmost = leftmost_frame + current_page;
1345 if (current_rightmost < new_page_size) {
1346 leftmost_after_zoom = 0;
1348 leftmost_after_zoom = current_rightmost - new_page_size;
1352 case ZoomFocusCenter:
1353 current_center = current_leftmost + (current_page/2);
1354 if (current_center < half_page_size) {
1355 leftmost_after_zoom = 0;
1357 leftmost_after_zoom = current_center - half_page_size;
1361 case ZoomFocusPlayhead:
1362 /* centre playhead */
1363 l = playhead_cursor->current_frame - (new_page_size * 0.5);
1366 leftmost_after_zoom = 0;
1367 } else if (l > max_framepos) {
1368 leftmost_after_zoom = max_framepos - new_page_size;
1370 leftmost_after_zoom = (framepos_t) l;
1374 case ZoomFocusMouse:
1375 /* try to keep the mouse over the same point in the display */
1377 if (!mouse_frame (where, in_track_canvas)) {
1378 /* use playhead instead */
1379 where = playhead_cursor->current_frame;
1381 if (where < half_page_size) {
1382 leftmost_after_zoom = 0;
1384 leftmost_after_zoom = where - half_page_size;
1389 l = - ((new_page_size * ((where - current_leftmost)/(double)current_page)) - where);
1392 leftmost_after_zoom = 0;
1393 } else if (l > max_framepos) {
1394 leftmost_after_zoom = max_framepos - new_page_size;
1396 leftmost_after_zoom = (framepos_t) l;
1403 /* try to keep the edit point in the same place */
1404 where = get_preferred_edit_position ();
1408 double l = - ((new_page_size * ((where - current_leftmost)/(double)current_page)) - where);
1411 leftmost_after_zoom = 0;
1412 } else if (l > max_framepos) {
1413 leftmost_after_zoom = max_framepos - new_page_size;
1415 leftmost_after_zoom = (framepos_t) l;
1419 /* edit point not defined */
1426 // leftmost_after_zoom = min (leftmost_after_zoom, _session->current_end_frame());
1428 reposition_and_zoom (leftmost_after_zoom, nfpu);
1432 Editor::temporal_zoom_region (bool both_axes)
1434 framepos_t start = max_framepos;
1436 set<TimeAxisView*> tracks;
1438 RegionSelection rs = get_regions_from_selection_and_entered ();
1444 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
1446 if ((*i)->region()->position() < start) {
1447 start = (*i)->region()->position();
1450 if ((*i)->region()->last_frame() + 1 > end) {
1451 end = (*i)->region()->last_frame() + 1;
1454 tracks.insert (&((*i)->get_time_axis_view()));
1457 /* now comes an "interesting" hack ... make sure we leave a little space
1458 at each end of the editor so that the zoom doesn't fit the region
1459 precisely to the screen.
1462 GdkScreen* screen = gdk_screen_get_default ();
1463 gint pixwidth = gdk_screen_get_width (screen);
1464 gint mmwidth = gdk_screen_get_width_mm (screen);
1465 double pix_per_mm = (double) pixwidth/ (double) mmwidth;
1466 double one_centimeter_in_pixels = pix_per_mm * 10.0;
1468 if ((start == 0 && end == 0) || end < start) {
1472 framepos_t range = end - start;
1473 double new_fpu = (double)range / (double)_canvas_width;
1474 framepos_t extra_samples = (framepos_t) floor (one_centimeter_in_pixels * new_fpu);
1476 if (start > extra_samples) {
1477 start -= extra_samples;
1482 if (max_framepos - extra_samples > end) {
1483 end += extra_samples;
1489 /* save visual state with track states included, and prevent
1490 set_frames_per_unit() from doing it again.
1492 undo_visual_stack.push_back (current_visual_state(true));
1493 no_save_visual = true;
1496 temporal_zoom_by_frame (start, end, "zoom to region");
1499 uint32_t per_track_height = (uint32_t) floor ((_canvas_height - canvas_timebars_vsize - 10.0) / tracks.size());
1501 /* set visible track heights appropriately */
1503 for (set<TimeAxisView*>::iterator t = tracks.begin(); t != tracks.end(); ++t) {
1504 (*t)->set_height (per_track_height);
1507 /* hide irrelevant tracks */
1509 _routes->suspend_redisplay ();
1511 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
1512 if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
1513 hide_track_in_display (*i);
1517 _routes->resume_redisplay ();
1519 vertical_adjustment.set_value (0.0);
1520 no_save_visual = false;
1523 redo_visual_stack.push_back (current_visual_state());
1527 Editor::zoom_to_region (bool both_axes)
1529 temporal_zoom_region (both_axes);
1533 Editor::temporal_zoom_selection ()
1535 if (!selection) return;
1537 if (selection->time.empty()) {
1541 framepos_t start = selection->time[clicked_selection].start;
1542 framepos_t end = selection->time[clicked_selection].end;
1544 temporal_zoom_by_frame (start, end, "zoom to selection");
1548 Editor::temporal_zoom_session ()
1550 ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_session)
1553 framecnt_t const l = _session->current_end_frame() - _session->current_start_frame();
1554 double s = _session->current_start_frame() - l * 0.01;
1558 framecnt_t const e = _session->current_end_frame() + l * 0.01;
1559 temporal_zoom_by_frame (framecnt_t (s), e, "zoom to _session");
1564 Editor::temporal_zoom_by_frame (framepos_t start, framepos_t end, const string & /*op*/)
1566 if (!_session) return;
1568 if ((start == 0 && end == 0) || end < start) {
1572 framepos_t range = end - start;
1574 double new_fpu = (double)range / (double)_canvas_width;
1576 framepos_t new_page = (framepos_t) floor (_canvas_width * new_fpu);
1577 framepos_t middle = (framepos_t) floor( (double)start + ((double)range / 2.0f ));
1578 framepos_t new_leftmost = (framepos_t) floor( (double)middle - ((double)new_page/2.0f));
1580 if (new_leftmost > middle) {
1584 reposition_and_zoom (new_leftmost, new_fpu);
1588 Editor::temporal_zoom_to_frame (bool coarser, framepos_t frame)
1593 double range_before = frame - leftmost_frame;
1596 new_fpu = frames_per_unit;
1599 new_fpu *= 1.61803399;
1600 range_before *= 1.61803399;
1602 new_fpu = max(1.0,(new_fpu/1.61803399));
1603 range_before /= 1.61803399;
1606 if (new_fpu == frames_per_unit) {
1610 framepos_t new_leftmost = frame - (framepos_t)range_before;
1612 if (new_leftmost > frame) {
1616 if (new_leftmost < 0) {
1620 reposition_and_zoom (new_leftmost, new_fpu);
1625 Editor::choose_new_marker_name(string &name) {
1627 if (!Config->get_name_new_markers()) {
1628 /* don't prompt user for a new name */
1632 ArdourPrompter dialog (true);
1634 dialog.set_prompt (_("New Name:"));
1636 dialog.set_title (_("New Location Marker"));
1638 dialog.set_name ("MarkNameWindow");
1639 dialog.set_size_request (250, -1);
1640 dialog.set_position (Gtk::WIN_POS_MOUSE);
1642 dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
1643 dialog.set_initial_text (name);
1647 switch (dialog.run ()) {
1648 case RESPONSE_ACCEPT:
1654 dialog.get_result(name);
1661 Editor::add_location_from_selection ()
1665 if (selection->time.empty()) {
1669 if (_session == 0 || clicked_axisview == 0) {
1673 framepos_t start = selection->time[clicked_selection].start;
1674 framepos_t end = selection->time[clicked_selection].end;
1676 _session->locations()->next_available_name(rangename,"selection");
1677 Location *location = new Location (*_session, start, end, rangename, Location::IsRangeMarker);
1679 _session->begin_reversible_command (_("add marker"));
1680 XMLNode &before = _session->locations()->get_state();
1681 _session->locations()->add (location, true);
1682 XMLNode &after = _session->locations()->get_state();
1683 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1684 _session->commit_reversible_command ();
1688 Editor::add_location_mark (framepos_t where)
1692 select_new_marker = true;
1694 _session->locations()->next_available_name(markername,"mark");
1695 if (!choose_new_marker_name(markername)) {
1698 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1699 _session->begin_reversible_command (_("add marker"));
1700 XMLNode &before = _session->locations()->get_state();
1701 _session->locations()->add (location, true);
1702 XMLNode &after = _session->locations()->get_state();
1703 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1704 _session->commit_reversible_command ();
1708 Editor::add_location_from_playhead_cursor ()
1710 add_location_mark (_session->audible_frame());
1713 /** Add a range marker around each selected region */
1715 Editor::add_locations_from_region ()
1717 RegionSelection rs = get_regions_from_selection_and_entered ();
1723 _session->begin_reversible_command (selection->regions.size () > 1 ? _("add markers") : _("add marker"));
1724 XMLNode &before = _session->locations()->get_state();
1726 for (RegionSelection::iterator i = rs.begin (); i != rs.end (); ++i) {
1728 boost::shared_ptr<Region> region = (*i)->region ();
1730 Location *location = new Location (*_session, region->position(), region->last_frame(), region->name(), Location::IsRangeMarker);
1732 _session->locations()->add (location, true);
1735 XMLNode &after = _session->locations()->get_state();
1736 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1737 _session->commit_reversible_command ();
1740 /** Add a single range marker around all selected regions */
1742 Editor::add_location_from_region ()
1744 RegionSelection rs = get_regions_from_selection_and_entered ();
1750 _session->begin_reversible_command (_("add marker"));
1751 XMLNode &before = _session->locations()->get_state();
1755 if (rs.size() > 1) {
1756 _session->locations()->next_available_name(markername, "regions");
1758 RegionView* rv = *(rs.begin());
1759 boost::shared_ptr<Region> region = rv->region();
1760 markername = region->name();
1763 if (!choose_new_marker_name(markername)) {
1767 // single range spanning all selected
1768 Location *location = new Location (*_session, selection->regions.start(), selection->regions.end_frame(), markername, Location::IsRangeMarker);
1769 _session->locations()->add (location, true);
1771 XMLNode &after = _session->locations()->get_state();
1772 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1773 _session->commit_reversible_command ();
1779 Editor::jump_forward_to_mark ()
1785 Location *location = _session->locations()->first_location_after (playhead_cursor->current_frame);
1788 _session->request_locate (location->start(), _session->transport_rolling());
1790 _session->request_locate (_session->current_end_frame());
1795 Editor::jump_backward_to_mark ()
1801 Location *location = _session->locations()->first_location_before (playhead_cursor->current_frame);
1804 _session->request_locate (location->start(), _session->transport_rolling());
1806 _session->goto_start ();
1813 framepos_t const pos = _session->audible_frame ();
1816 _session->locations()->next_available_name (markername, "mark");
1818 if (!choose_new_marker_name (markername)) {
1822 _session->locations()->add (new Location (*_session, pos, 0, markername, Location::IsMark), true);
1826 Editor::clear_markers ()
1829 _session->begin_reversible_command (_("clear markers"));
1830 XMLNode &before = _session->locations()->get_state();
1831 _session->locations()->clear_markers ();
1832 XMLNode &after = _session->locations()->get_state();
1833 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1834 _session->commit_reversible_command ();
1839 Editor::clear_ranges ()
1842 _session->begin_reversible_command (_("clear ranges"));
1843 XMLNode &before = _session->locations()->get_state();
1845 Location * looploc = _session->locations()->auto_loop_location();
1846 Location * punchloc = _session->locations()->auto_punch_location();
1847 Location * sessionloc = _session->locations()->session_range_location();
1849 _session->locations()->clear_ranges ();
1851 if (looploc) _session->locations()->add (looploc);
1852 if (punchloc) _session->locations()->add (punchloc);
1853 if (sessionloc) _session->locations()->add (sessionloc);
1855 XMLNode &after = _session->locations()->get_state();
1856 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1857 _session->commit_reversible_command ();
1862 Editor::clear_locations ()
1864 _session->begin_reversible_command (_("clear locations"));
1865 XMLNode &before = _session->locations()->get_state();
1866 _session->locations()->clear ();
1867 XMLNode &after = _session->locations()->get_state();
1868 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1869 _session->commit_reversible_command ();
1870 _session->locations()->clear ();
1874 Editor::unhide_markers ()
1876 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1877 Location *l = (*i).first;
1878 if (l->is_hidden() && l->is_mark()) {
1879 l->set_hidden(false, this);
1885 Editor::unhide_ranges ()
1887 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1888 Location *l = (*i).first;
1889 if (l->is_hidden() && l->is_range_marker()) {
1890 l->set_hidden(false, this);
1895 /* INSERT/REPLACE */
1898 Editor::insert_region_list_drag (boost::shared_ptr<Region> region, int x, int y)
1903 RouteTimeAxisView *rtv = 0;
1904 boost::shared_ptr<Playlist> playlist;
1906 track_canvas->window_to_world (x, y, wx, wy);
1909 event.type = GDK_BUTTON_RELEASE;
1910 event.button.x = wx;
1911 event.button.y = wy;
1913 where = event_frame (&event, &cx, &cy);
1915 if (where < leftmost_frame || where > leftmost_frame + current_page_frames()) {
1916 /* clearly outside canvas area */
1920 std::pair<TimeAxisView*, int> tv = trackview_by_y_position (cy);
1921 if (tv.first == 0) {
1925 if ((rtv = dynamic_cast<RouteTimeAxisView*> (tv.first)) == 0) {
1929 if ((playlist = rtv->playlist()) == 0) {
1935 begin_reversible_command (_("insert dragged region"));
1936 playlist->clear_changes ();
1937 playlist->add_region (RegionFactory::create (region, true), where, 1.0);
1938 _session->add_command(new StatefulDiffCommand (playlist));
1939 commit_reversible_command ();
1943 Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y)
1947 RouteTimeAxisView *dest_rtv = 0;
1948 RouteTimeAxisView *source_rtv = 0;
1950 track_canvas->window_to_world (x, y, wx, wy);
1951 wx += horizontal_position ();
1952 wy += vertical_adjustment.get_value();
1955 event.type = GDK_BUTTON_RELEASE;
1956 event.button.x = wx;
1957 event.button.y = wy;
1959 event_frame (&event, &cx, &cy);
1961 std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (cy);
1962 if (tv.first == 0) {
1966 if ((dest_rtv = dynamic_cast<RouteTimeAxisView*> (tv.first)) == 0) {
1970 /* use this drag source to add underlay to a track. But we really don't care
1971 about the Route, only the view of the route, so find it first */
1972 for(TrackViewList::iterator it = track_views.begin(); it != track_views.end(); ++it) {
1973 if((source_rtv = dynamic_cast<RouteTimeAxisView*>(*it)) == 0) {
1977 if(source_rtv->route() == route && source_rtv != dest_rtv) {
1978 dest_rtv->add_underlay(source_rtv->view());
1985 Editor::insert_region_list_selection (float times)
1987 RouteTimeAxisView *tv = 0;
1988 boost::shared_ptr<Playlist> playlist;
1990 if (clicked_routeview != 0) {
1991 tv = clicked_routeview;
1992 } else if (!selection->tracks.empty()) {
1993 if ((tv = dynamic_cast<RouteTimeAxisView*>(selection->tracks.front())) == 0) {
1996 } else if (entered_track != 0) {
1997 if ((tv = dynamic_cast<RouteTimeAxisView*>(entered_track)) == 0) {
2004 if ((playlist = tv->playlist()) == 0) {
2008 boost::shared_ptr<Region> region = _regions->get_single_selection ();
2013 begin_reversible_command (_("insert region"));
2014 playlist->clear_changes ();
2015 playlist->add_region ((RegionFactory::create (region, true)), get_preferred_edit_position(), times);
2016 _session->add_command(new StatefulDiffCommand (playlist));
2017 commit_reversible_command ();
2020 /* BUILT-IN EFFECTS */
2023 Editor::reverse_selection ()
2028 /* GAIN ENVELOPE EDITING */
2031 Editor::edit_envelope ()
2038 Editor::transition_to_rolling (bool fwd)
2044 if (_session->config.get_external_sync()) {
2045 switch (_session->config.get_sync_source()) {
2049 /* transport controlled by the master */
2054 if (_session->is_auditioning()) {
2055 _session->cancel_audition ();
2059 _session->request_transport_speed (fwd ? 1.0f : -1.0f);
2063 Editor::play_from_start ()
2065 _session->request_locate (_session->current_start_frame(), true);
2069 Editor::play_from_edit_point ()
2071 _session->request_locate (get_preferred_edit_position(), true);
2075 Editor::play_from_edit_point_and_return ()
2077 framepos_t start_frame;
2078 framepos_t return_frame;
2080 start_frame = get_preferred_edit_position (true);
2082 if (_session->transport_rolling()) {
2083 _session->request_locate (start_frame, false);
2087 /* don't reset the return frame if its already set */
2089 if ((return_frame = _session->requested_return_frame()) < 0) {
2090 return_frame = _session->audible_frame();
2093 if (start_frame >= 0) {
2094 _session->request_roll_at_and_return (start_frame, return_frame);
2099 Editor::play_selection ()
2101 if (selection->time.empty()) {
2105 _session->request_play_range (&selection->time, true);
2109 Editor::play_location (Location& location)
2111 if (location.start() <= location.end()) {
2115 _session->request_bounded_roll (location.start(), location.end());
2119 Editor::loop_location (Location& location)
2121 if (location.start() <= location.end()) {
2127 if ((tll = transport_loop_location()) != 0) {
2128 tll->set (location.start(), location.end());
2130 // enable looping, reposition and start rolling
2131 _session->request_play_loop (true);
2132 _session->request_locate (tll->start(), true);
2137 Editor::do_layer_operation (LayerOperation op)
2139 if (selection->regions.empty ()) {
2143 bool const multiple = selection->regions.size() > 1;
2147 begin_reversible_command (_("raise regions"));
2149 begin_reversible_command (_("raise region"));
2155 begin_reversible_command (_("raise regions to top"));
2157 begin_reversible_command (_("raise region to top"));
2163 begin_reversible_command (_("lower regions"));
2165 begin_reversible_command (_("lower region"));
2171 begin_reversible_command (_("lower regions to bottom"));
2173 begin_reversible_command (_("lower region"));
2178 set<boost::shared_ptr<Playlist> > playlists = selection->regions.playlists ();
2179 for (set<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2180 (*i)->clear_owned_changes ();
2183 for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
2184 boost::shared_ptr<Region> r = (*i)->region ();
2196 r->lower_to_bottom ();
2200 for (set<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2201 vector<Command*> cmds;
2203 _session->add_commands (cmds);
2206 commit_reversible_command ();
2210 Editor::raise_region ()
2212 do_layer_operation (Raise);
2216 Editor::raise_region_to_top ()
2218 do_layer_operation (RaiseToTop);
2222 Editor::lower_region ()
2224 do_layer_operation (Lower);
2228 Editor::lower_region_to_bottom ()
2230 do_layer_operation (LowerToBottom);
2233 /** Show the region editor for the selected regions */
2235 Editor::show_region_properties ()
2237 selection->foreach_regionview (&RegionView::show_region_editor);
2240 /** Show the midi list editor for the selected MIDI regions */
2242 Editor::show_midi_list_editor ()
2244 selection->foreach_midi_regionview (&MidiRegionView::show_list_editor);
2248 Editor::rename_region ()
2250 RegionSelection rs = get_regions_from_selection_and_entered ();
2256 ArdourDialog d (*this, _("Rename Region"), true, false);
2258 Label label (_("New name:"));
2261 hbox.set_spacing (6);
2262 hbox.pack_start (label, false, false);
2263 hbox.pack_start (entry, true, true);
2265 d.get_vbox()->set_border_width (12);
2266 d.get_vbox()->pack_start (hbox, false, false);
2268 d.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2269 d.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
2271 d.set_size_request (300, -1);
2272 d.set_position (Gtk::WIN_POS_MOUSE);
2274 entry.set_text (rs.front()->region()->name());
2275 entry.select_region (0, -1);
2277 entry.signal_activate().connect (sigc::bind (sigc::mem_fun (d, &Dialog::response), RESPONSE_OK));
2283 int const ret = d.run();
2287 if (ret != RESPONSE_OK) {
2291 std::string str = entry.get_text();
2292 strip_whitespace_edges (str);
2294 rs.front()->region()->set_name (str);
2295 _regions->redisplay ();
2300 Editor::audition_playlist_region_via_route (boost::shared_ptr<Region> region, Route& route)
2302 if (_session->is_auditioning()) {
2303 _session->cancel_audition ();
2306 // note: some potential for creativity here, because region doesn't
2307 // have to belong to the playlist that Route is handling
2309 // bool was_soloed = route.soloed();
2311 route.set_solo (true, this);
2313 _session->request_bounded_roll (region->position(), region->position() + region->length());
2315 /* XXX how to unset the solo state ? */
2318 /** Start an audition of the first selected region */
2320 Editor::play_edit_range ()
2322 framepos_t start, end;
2324 if (get_edit_op_range (start, end)) {
2325 _session->request_bounded_roll (start, end);
2330 Editor::play_selected_region ()
2332 framepos_t start = max_framepos;
2335 RegionSelection rs = get_regions_from_selection_and_entered ();
2341 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
2342 if ((*i)->region()->position() < start) {
2343 start = (*i)->region()->position();
2345 if ((*i)->region()->last_frame() + 1 > end) {
2346 end = (*i)->region()->last_frame() + 1;
2350 _session->request_bounded_roll (start, end);
2354 Editor::audition_playlist_region_standalone (boost::shared_ptr<Region> region)
2356 _session->audition_region (region);
2360 Editor::region_from_selection ()
2362 if (clicked_axisview == 0) {
2366 if (selection->time.empty()) {
2370 framepos_t start = selection->time[clicked_selection].start;
2371 framepos_t end = selection->time[clicked_selection].end;
2373 TrackViewList tracks = get_tracks_for_range_action ();
2375 framepos_t selection_cnt = end - start + 1;
2377 for (TrackSelection::iterator i = tracks.begin(); i != tracks.end(); ++i) {
2378 boost::shared_ptr<Region> current;
2379 boost::shared_ptr<Playlist> pl;
2380 framepos_t internal_start;
2383 if ((pl = (*i)->playlist()) == 0) {
2387 if ((current = pl->top_region_at (start)) == 0) {
2391 internal_start = start - current->position();
2392 RegionFactory::region_name (new_name, current->name(), true);
2396 plist.add (ARDOUR::Properties::start, current->start() + internal_start);
2397 plist.add (ARDOUR::Properties::length, selection_cnt);
2398 plist.add (ARDOUR::Properties::name, new_name);
2399 plist.add (ARDOUR::Properties::layer, 0);
2401 boost::shared_ptr<Region> region (RegionFactory::create (current, plist));
2406 Editor::create_region_from_selection (vector<boost::shared_ptr<Region> >& new_regions)
2408 if (selection->time.empty() || selection->tracks.empty()) {
2412 framepos_t start = selection->time[clicked_selection].start;
2413 framepos_t end = selection->time[clicked_selection].end;
2415 TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
2416 sort_track_selection (ts);
2418 for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
2419 boost::shared_ptr<Region> current;
2420 boost::shared_ptr<Playlist> playlist;
2421 framepos_t internal_start;
2424 if ((playlist = (*i)->playlist()) == 0) {
2428 if ((current = playlist->top_region_at(start)) == 0) {
2432 internal_start = start - current->position();
2433 RegionFactory::region_name (new_name, current->name(), true);
2437 plist.add (ARDOUR::Properties::start, current->start() + internal_start);
2438 plist.add (ARDOUR::Properties::length, end - start + 1);
2439 plist.add (ARDOUR::Properties::name, new_name);
2441 new_regions.push_back (RegionFactory::create (current, plist));
2446 Editor::split_multichannel_region ()
2448 RegionSelection rs = get_regions_from_selection_and_entered ();
2454 vector< boost::shared_ptr<Region> > v;
2456 for (list<RegionView*>::iterator x = rs.begin(); x != rs.end(); ++x) {
2457 (*x)->region()->separate_by_channel (*_session, v);
2462 Editor::new_region_from_selection ()
2464 region_from_selection ();
2465 cancel_selection ();
2469 add_if_covered (RegionView* rv, const AudioRange* ar, RegionSelection* rs)
2471 switch (rv->region()->coverage (ar->start, ar->end - 1)) {
2480 * - selected tracks, or if there are none...
2481 * - tracks containing selected regions, or if there are none...
2486 Editor::get_tracks_for_range_action () const
2490 if (selection->tracks.empty()) {
2492 /* use tracks with selected regions */
2494 RegionSelection rs = selection->regions;
2496 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
2497 TimeAxisView* tv = &(*i)->get_time_axis_view();
2499 if (!t.contains (tv)) {
2505 /* no regions and no tracks: use all tracks */
2511 t = selection->tracks;
2514 return t.filter_to_unique_playlists();
2518 Editor::separate_regions_between (const TimeSelection& ts)
2520 bool in_command = false;
2521 boost::shared_ptr<Playlist> playlist;
2522 RegionSelection new_selection;
2524 TrackViewList tmptracks = get_tracks_for_range_action ();
2525 sort_track_selection (tmptracks);
2527 for (TrackSelection::iterator i = tmptracks.begin(); i != tmptracks.end(); ++i) {
2529 RouteTimeAxisView* rtv;
2531 if ((rtv = dynamic_cast<RouteTimeAxisView*> ((*i))) != 0) {
2533 if (rtv->is_track()) {
2535 /* no edits to destructive tracks */
2537 if (rtv->track()->destructive()) {
2541 if ((playlist = rtv->playlist()) != 0) {
2543 playlist->clear_changes ();
2545 /* XXX need to consider musical time selections here at some point */
2547 double speed = rtv->track()->speed();
2550 for (list<AudioRange>::const_iterator t = ts.begin(); t != ts.end(); ++t) {
2552 sigc::connection c = rtv->view()->RegionViewAdded.connect (
2553 sigc::mem_fun(*this, &Editor::collect_new_region_view));
2555 latest_regionviews.clear ();
2557 playlist->partition ((framepos_t)((*t).start * speed),
2558 (framepos_t)((*t).end * speed), false);
2562 if (!latest_regionviews.empty()) {
2564 rtv->view()->foreach_regionview (sigc::bind (
2565 sigc::ptr_fun (add_if_covered),
2566 &(*t), &new_selection));
2569 begin_reversible_command (_("separate"));
2573 /* pick up changes to existing regions */
2575 vector<Command*> cmds;
2576 playlist->rdiff (cmds);
2577 _session->add_commands (cmds);
2579 /* pick up changes to the playlist itself (adds/removes)
2582 _session->add_command(new StatefulDiffCommand (playlist));
2591 selection->set (new_selection);
2592 set_mouse_mode (MouseObject);
2594 commit_reversible_command ();
2598 struct PlaylistState {
2599 boost::shared_ptr<Playlist> playlist;
2603 /** Take tracks from get_tracks_for_range_action and cut any regions
2604 * on those tracks so that the tracks are empty over the time
2608 Editor::separate_region_from_selection ()
2610 /* preferentially use *all* ranges in the time selection if we're in range mode
2611 to allow discontiguous operation, since get_edit_op_range() currently
2612 returns a single range.
2615 if (mouse_mode == MouseRange && !selection->time.empty()) {
2617 separate_regions_between (selection->time);
2624 if (get_edit_op_range (start, end)) {
2626 AudioRange ar (start, end, 1);
2630 separate_regions_between (ts);
2636 Editor::separate_region_from_punch ()
2638 Location* loc = _session->locations()->auto_punch_location();
2640 separate_regions_using_location (*loc);
2645 Editor::separate_region_from_loop ()
2647 Location* loc = _session->locations()->auto_loop_location();
2649 separate_regions_using_location (*loc);
2654 Editor::separate_regions_using_location (Location& loc)
2656 if (loc.is_mark()) {
2660 AudioRange ar (loc.start(), loc.end(), 1);
2665 separate_regions_between (ts);
2668 /** Separate regions under the selected region */
2670 Editor::separate_under_selected_regions ()
2672 vector<PlaylistState> playlists;
2676 rs = get_regions_from_selection_and_entered();
2678 if (!_session || rs.empty()) {
2682 begin_reversible_command (_("separate region under"));
2684 list<boost::shared_ptr<Region> > regions_to_remove;
2686 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
2687 // we can't just remove the region(s) in this loop because
2688 // this removes them from the RegionSelection, and they thus
2689 // disappear from underneath the iterator, and the ++i above
2690 // SEGVs in a puzzling fashion.
2692 // so, first iterate over the regions to be removed from rs and
2693 // add them to the regions_to_remove list, and then
2694 // iterate over the list to actually remove them.
2696 regions_to_remove.push_back ((*i)->region());
2699 for (list<boost::shared_ptr<Region> >::iterator rl = regions_to_remove.begin(); rl != regions_to_remove.end(); ++rl) {
2701 boost::shared_ptr<Playlist> playlist = (*rl)->playlist();
2704 // is this check necessary?
2708 vector<PlaylistState>::iterator i;
2710 //only take state if this is a new playlist.
2711 for (i = playlists.begin(); i != playlists.end(); ++i) {
2712 if ((*i).playlist == playlist) {
2717 if (i == playlists.end()) {
2719 PlaylistState before;
2720 before.playlist = playlist;
2721 before.before = &playlist->get_state();
2723 playlist->freeze ();
2724 playlists.push_back(before);
2727 //Partition on the region bounds
2728 playlist->partition ((*rl)->first_frame() - 1, (*rl)->last_frame() + 1, true);
2730 //Re-add region that was just removed due to the partition operation
2731 playlist->add_region( (*rl), (*rl)->first_frame() );
2734 vector<PlaylistState>::iterator pl;
2736 for (pl = playlists.begin(); pl != playlists.end(); ++pl) {
2737 (*pl).playlist->thaw ();
2738 _session->add_command(new MementoCommand<Playlist>(*(*pl).playlist, (*pl).before, &(*pl).playlist->get_state()));
2741 commit_reversible_command ();
2745 Editor::crop_region_to_selection ()
2747 if (!selection->time.empty()) {
2749 crop_region_to (selection->time.start(), selection->time.end_frame());
2756 if (get_edit_op_range (start, end)) {
2757 crop_region_to (start, end);
2764 Editor::crop_region_to (framepos_t start, framepos_t end)
2766 vector<boost::shared_ptr<Playlist> > playlists;
2767 boost::shared_ptr<Playlist> playlist;
2770 if (selection->tracks.empty()) {
2771 ts = track_views.filter_to_unique_playlists();
2773 ts = selection->tracks.filter_to_unique_playlists ();
2776 sort_track_selection (ts);
2778 for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
2780 RouteTimeAxisView* rtv;
2782 if ((rtv = dynamic_cast<RouteTimeAxisView*> ((*i))) != 0) {
2784 boost::shared_ptr<Track> t = rtv->track();
2786 if (t != 0 && ! t->destructive()) {
2788 if ((playlist = rtv->playlist()) != 0) {
2789 playlists.push_back (playlist);
2795 if (playlists.empty()) {
2799 framepos_t the_start;
2803 begin_reversible_command (_("trim to selection"));
2805 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
2807 boost::shared_ptr<Region> region;
2811 if ((region = (*i)->top_region_at(the_start)) == 0) {
2815 /* now adjust lengths to that we do the right thing
2816 if the selection extends beyond the region
2819 the_start = max (the_start, (framepos_t) region->position());
2820 if (max_framepos - the_start < region->length()) {
2821 the_end = the_start + region->length() - 1;
2823 the_end = max_framepos;
2825 the_end = min (end, the_end);
2826 cnt = the_end - the_start + 1;
2828 region->clear_changes ();
2829 region->trim_to (the_start, cnt);
2830 _session->add_command (new StatefulDiffCommand (region));
2833 commit_reversible_command ();
2837 Editor::region_fill_track ()
2839 RegionSelection rs = get_regions_from_selection_and_entered ();
2841 if (!_session || rs.empty()) {
2845 framepos_t const end = _session->current_end_frame ();
2847 begin_reversible_command (Operations::region_fill);
2849 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
2851 boost::shared_ptr<Region> region ((*i)->region());
2853 boost::shared_ptr<Playlist> pl = region->playlist();
2855 if (end <= region->last_frame()) {
2859 double times = (double) (end - region->last_frame()) / (double) region->length();
2865 pl->clear_changes ();
2866 pl->add_region (RegionFactory::create (region, true), region->last_frame(), times);
2867 _session->add_command (new StatefulDiffCommand (pl));
2870 commit_reversible_command ();
2874 Editor::region_fill_selection ()
2876 if (clicked_routeview == 0 || !clicked_routeview->is_audio_track()) {
2880 if (selection->time.empty()) {
2884 boost::shared_ptr<Region> region = _regions->get_single_selection ();
2889 framepos_t start = selection->time[clicked_selection].start;
2890 framepos_t end = selection->time[clicked_selection].end;
2892 boost::shared_ptr<Playlist> playlist;
2894 if (selection->tracks.empty()) {
2898 framepos_t selection_length = end - start;
2899 float times = (float)selection_length / region->length();
2901 begin_reversible_command (Operations::fill_selection);
2903 TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
2905 for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
2907 if ((playlist = (*i)->playlist()) == 0) {
2911 playlist->clear_changes ();
2912 playlist->add_region (RegionFactory::create (region, true), start, times);
2913 _session->add_command (new StatefulDiffCommand (playlist));
2916 commit_reversible_command ();
2920 Editor::set_region_sync_position ()
2922 set_sync_point (get_preferred_edit_position (), get_regions_from_selection_and_edit_point ());
2926 Editor::set_sync_point (framepos_t where, const RegionSelection& rs)
2928 bool in_command = false;
2930 for (RegionSelection::const_iterator r = rs.begin(); r != rs.end(); ++r) {
2932 if (!(*r)->region()->covers (where)) {
2936 boost::shared_ptr<Region> region ((*r)->region());
2939 begin_reversible_command (_("set sync point"));
2943 region->clear_changes ();
2944 region->set_sync_position (where);
2945 _session->add_command(new StatefulDiffCommand (region));
2949 commit_reversible_command ();
2953 /** Remove the sync positions of the selection */
2955 Editor::remove_region_sync ()
2957 RegionSelection rs = get_regions_from_selection_and_entered ();
2963 begin_reversible_command (_("remove region sync"));
2965 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
2967 (*i)->region()->clear_changes ();
2968 (*i)->region()->clear_sync_position ();
2969 _session->add_command(new StatefulDiffCommand ((*i)->region()));
2972 commit_reversible_command ();
2976 Editor::naturalize_region ()
2978 RegionSelection rs = get_regions_from_selection_and_entered ();
2984 if (rs.size() > 1) {
2985 begin_reversible_command (_("move regions to original position"));
2987 begin_reversible_command (_("move region to original position"));
2990 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
2991 (*i)->region()->clear_changes ();
2992 (*i)->region()->move_to_natural_position ();
2993 _session->add_command (new StatefulDiffCommand ((*i)->region()));
2996 commit_reversible_command ();
3000 Editor::align_regions (RegionPoint what)
3002 RegionSelection const rs = get_regions_from_selection_and_edit_point ();
3008 begin_reversible_command (_("align selection"));
3010 framepos_t const position = get_preferred_edit_position ();
3012 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
3013 align_region_internal ((*i)->region(), what, position);
3016 commit_reversible_command ();
3019 struct RegionSortByTime {
3020 bool operator() (const RegionView* a, const RegionView* b) {
3021 return a->region()->position() < b->region()->position();
3026 Editor::align_regions_relative (RegionPoint point)
3028 RegionSelection const rs = get_regions_from_selection_and_edit_point ();
3034 framepos_t const position = get_preferred_edit_position ();
3036 framepos_t distance = 0;
3040 list<RegionView*> sorted;
3041 rs.by_position (sorted);
3043 boost::shared_ptr<Region> r ((*sorted.begin())->region());
3048 if (position > r->position()) {
3049 distance = position - r->position();
3051 distance = r->position() - position;
3057 if (position > r->last_frame()) {
3058 distance = position - r->last_frame();
3059 pos = r->position() + distance;
3061 distance = r->last_frame() - position;
3062 pos = r->position() - distance;
3068 pos = r->adjust_to_sync (position);
3069 if (pos > r->position()) {
3070 distance = pos - r->position();
3072 distance = r->position() - pos;
3078 if (pos == r->position()) {
3082 begin_reversible_command (_("align selection (relative)"));
3084 /* move first one specially */
3086 r->clear_changes ();
3087 r->set_position (pos);
3088 _session->add_command(new StatefulDiffCommand (r));
3090 /* move rest by the same amount */
3094 for (list<RegionView*>::iterator i = sorted.begin(); i != sorted.end(); ++i) {
3096 boost::shared_ptr<Region> region ((*i)->region());
3098 region->clear_changes ();
3101 region->set_position (region->position() + distance);
3103 region->set_position (region->position() - distance);
3106 _session->add_command(new StatefulDiffCommand (region));
3110 commit_reversible_command ();
3114 Editor::align_region (boost::shared_ptr<Region> region, RegionPoint point, framepos_t position)
3116 begin_reversible_command (_("align region"));
3117 align_region_internal (region, point, position);
3118 commit_reversible_command ();
3122 Editor::align_region_internal (boost::shared_ptr<Region> region, RegionPoint point, framepos_t position)
3124 region->clear_changes ();
3128 region->set_position (region->adjust_to_sync (position));
3132 if (position > region->length()) {
3133 region->set_position (position - region->length());
3138 region->set_position (position);
3142 _session->add_command(new StatefulDiffCommand (region));
3146 Editor::trim_region_front ()
3152 Editor::trim_region_back ()
3154 trim_region (false);
3158 Editor::trim_region (bool front)
3160 framepos_t where = get_preferred_edit_position();
3161 RegionSelection rs = get_regions_from_selection_and_edit_point ();
3163 cerr << "trim regions\n";
3166 cerr << " no regions\n";
3170 cerr << "where = " << where << endl;
3172 begin_reversible_command (front ? _("trim front") : _("trim back"));
3174 for (list<RegionView*>::const_iterator i = rs.by_layer().begin(); i != rs.by_layer().end(); ++i) {
3175 if (!(*i)->region()->locked()) {
3177 (*i)->region()->clear_changes ();
3180 (*i)->region()->trim_front (where);
3182 (*i)->region()->trim_end (where);
3185 _session->add_command (new StatefulDiffCommand ((*i)->region()));
3189 commit_reversible_command ();
3192 /** Trim the end of the selected regions to the position of the edit cursor */
3194 Editor::trim_region_to_loop ()
3196 Location* loc = _session->locations()->auto_loop_location();
3200 trim_region_to_location (*loc, _("trim to loop"));
3204 Editor::trim_region_to_punch ()
3206 Location* loc = _session->locations()->auto_punch_location();
3210 trim_region_to_location (*loc, _("trim to punch"));
3214 Editor::trim_region_to_location (const Location& loc, const char* str)
3216 RegionSelection rs = get_regions_from_selection_and_entered ();
3218 begin_reversible_command (str);
3220 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
3221 RegionView* rv = (*x);
3223 /* require region to span proposed trim */
3224 switch (rv->region()->coverage (loc.start(), loc.end())) {
3225 case OverlapInternal:
3231 RouteTimeAxisView* tav = dynamic_cast<RouteTimeAxisView*> (&rv->get_time_axis_view());
3240 if (tav->track() != 0) {
3241 speed = tav->track()->speed();
3244 start = session_frame_to_track_frame (loc.start(), speed);
3245 end = session_frame_to_track_frame (loc.end(), speed);
3247 rv->region()->clear_changes ();
3248 rv->region()->trim_to (start, (end - start));
3249 _session->add_command(new StatefulDiffCommand (rv->region()));
3252 commit_reversible_command ();
3256 Editor::trim_region_to_previous_region_end ()
3258 return trim_to_region(false);
3262 Editor::trim_region_to_next_region_start ()
3264 return trim_to_region(true);
3268 Editor::trim_to_region(bool forward)
3270 RegionSelection rs = get_regions_from_selection_and_entered ();
3272 begin_reversible_command (_("trim to region"));
3274 boost::shared_ptr<Region> next_region;
3276 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
3278 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*x);
3284 AudioTimeAxisView* atav = dynamic_cast<AudioTimeAxisView*> (&arv->get_time_axis_view());
3292 if (atav->track() != 0) {
3293 speed = atav->track()->speed();
3297 boost::shared_ptr<Region> region = arv->region();
3298 boost::shared_ptr<Playlist> playlist (region->playlist());
3300 region->clear_changes ();
3304 next_region = playlist->find_next_region (region->first_frame(), Start, 1);
3310 region->trim_end((framepos_t) ( (next_region->first_frame() - 1) * speed));
3311 arv->region_changed (PropertyChange (ARDOUR::Properties::length));
3315 next_region = playlist->find_next_region (region->first_frame(), Start, 0);
3321 region->trim_front((framepos_t) ((next_region->last_frame() + 1) * speed));
3323 arv->region_changed (ARDOUR::bounds_change);
3326 _session->add_command(new StatefulDiffCommand (region));
3329 commit_reversible_command ();
3333 Editor::unfreeze_route ()
3335 if (clicked_routeview == 0 || !clicked_routeview->is_track()) {
3339 clicked_routeview->track()->unfreeze ();
3343 Editor::_freeze_thread (void* arg)
3345 SessionEvent::create_per_thread_pool ("freeze events", 64);
3347 return static_cast<Editor*>(arg)->freeze_thread ();
3351 Editor::freeze_thread ()
3353 clicked_routeview->audio_track()->freeze_me (*current_interthread_info);
3354 current_interthread_info->done = true;
3359 Editor::freeze_route ()
3365 /* stop transport before we start. this is important */
3367 _session->request_transport_speed (0.0);
3369 if (clicked_routeview == 0 || !clicked_routeview->is_audio_track()) {
3373 if (!clicked_routeview->track()->bounceable()) {
3374 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_routeview);
3375 if (rtv && !rtv->track()->bounceable()) {
3377 _("This route cannot be frozen because it has more outputs than inputs. "
3378 "You can fix this by increasing the number of inputs.")
3380 d.set_title (_("Cannot freeze"));
3386 InterThreadInfo itt;
3387 current_interthread_info = &itt;
3389 InterthreadProgressWindow ipw (current_interthread_info, _("Freeze"), _("Cancel Freeze"));
3391 pthread_create_and_store (X_("freezer"), &itt.thread, _freeze_thread, this);
3393 set_canvas_cursor (_cursors->wait);
3395 while (!itt.done && !itt.cancel) {
3396 gtk_main_iteration ();
3399 current_interthread_info = 0;
3400 set_canvas_cursor (current_canvas_cursor);
3404 Editor::bounce_range_selection (bool replace, bool enable_processing)
3406 if (selection->time.empty()) {
3410 TrackSelection views = selection->tracks;
3412 for (TrackViewList::iterator i = views.begin(); i != views.end(); ++i) {
3413 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
3414 if (rtv && rtv->track() && replace && enable_processing && !rtv->track()->bounceable()) {
3416 _("You can't perform this operation because the processing of the signal "
3417 "will cause one or more of the tracks will end up with a region with more channels than this track has inputs.\n\n"
3418 "You can do this without processing, which is a different operation.")
3420 d.set_title (_("Cannot bounce"));
3426 framepos_t start = selection->time[clicked_selection].start;
3427 framepos_t end = selection->time[clicked_selection].end;
3428 framepos_t cnt = end - start + 1;
3430 begin_reversible_command (_("bounce range"));
3432 for (TrackViewList::iterator i = views.begin(); i != views.end(); ++i) {
3434 RouteTimeAxisView* rtv;
3436 if ((rtv = dynamic_cast<RouteTimeAxisView*> (*i)) == 0) {
3440 boost::shared_ptr<Playlist> playlist;
3442 if ((playlist = rtv->playlist()) == 0) {
3446 InterThreadInfo itt;
3448 playlist->clear_changes ();
3449 playlist->clear_owned_changes ();
3451 boost::shared_ptr<Region> r = rtv->track()->bounce_range (start, start+cnt, itt, enable_processing);
3458 list<AudioRange> ranges;
3459 ranges.push_back (AudioRange (start, start+cnt, 0));
3460 playlist->cut (ranges); // discard result
3461 playlist->add_region (r, start);
3464 vector<Command*> cmds;
3465 playlist->rdiff (cmds);
3466 _session->add_commands (cmds);
3468 _session->add_command (new StatefulDiffCommand (playlist));
3471 commit_reversible_command ();
3474 /** Delete selected regions, automation points or a time range */
3481 /** Cut selected regions, automation points or a time range */
3488 /** Copy selected regions, automation points or a time range */
3496 /** @return true if a Cut, Copy or Clear is possible */
3498 Editor::can_cut_copy () const
3500 switch (current_mouse_mode()) {
3503 if (!selection->regions.empty() || !selection->points.empty()) {
3509 if (!selection->time.empty()) {
3522 /** Cut, copy or clear selected regions, automation points or a time range.
3523 * @param op Operation (Cut, Copy or Clear)
3526 Editor::cut_copy (CutCopyOp op)
3528 /* only cancel selection if cut/copy is successful.*/
3534 opname = _("delete");
3543 opname = _("clear");
3547 /* if we're deleting something, and the mouse is still pressed,
3548 the thing we started a drag for will be gone when we release
3549 the mouse button(s). avoid this. see part 2 at the end of
3553 if (op == Delete || op == Cut || op == Clear) {
3554 if (_drags->active ()) {
3559 cut_buffer->clear ();
3561 if (entered_marker) {
3563 /* cut/delete op while pointing at a marker */
3566 Location* loc = find_location_from_marker (entered_marker, ignored);
3568 if (_session && loc) {
3569 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
3576 if (internal_editing()) {
3578 switch (current_mouse_mode()) {
3591 /* we only want to cut regions if some are selected */
3593 switch (current_mouse_mode()) {
3595 rs = get_regions_from_selection ();
3596 if (!rs.empty() || !selection->points.empty()) {
3598 begin_reversible_command (opname + _(" objects"));
3601 cut_copy_regions (op, rs);
3603 if (op == Cut || op == Delete) {
3604 selection->clear_regions ();
3608 if (!selection->points.empty()) {
3609 cut_copy_points (op);
3611 if (op == Cut || op == Delete) {
3612 selection->clear_points ();
3615 commit_reversible_command ();
3616 break; // terminate case statement here
3618 if (!selection->time.empty()) {
3619 /* don't cause suprises */
3622 // fall thru if there was nothing selected
3625 if (selection->time.empty()) {
3626 framepos_t start, end;
3627 if (!get_edit_op_range (start, end)) {
3630 selection->set (start, end);
3633 begin_reversible_command (opname + _(" range"));
3634 cut_copy_ranges (op);
3635 commit_reversible_command ();
3637 if (op == Cut || op == Delete) {
3638 selection->clear_time ();
3648 if (op == Delete || op == Cut || op == Clear) {
3653 /** Cut, copy or clear selected automation points.
3654 * @param op Operation (Cut, Copy or Clear)
3657 Editor::cut_copy_points (CutCopyOp op)
3659 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
3661 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>((*i).track);
3662 _last_cut_copy_source_track = atv;
3665 atv->cut_copy_clear_objects (selection->points, op);
3670 /** Cut, copy or clear selected automation points.
3671 * @param op Operation (Cut, Copy or Clear)
3674 Editor::cut_copy_midi (CutCopyOp op)
3676 for (MidiRegionSelection::iterator i = selection->midi_regions.begin(); i != selection->midi_regions.end(); ++i) {
3677 MidiRegionView* mrv = *i;
3678 mrv->cut_copy_clear (op);
3684 struct lt_playlist {
3685 bool operator () (const PlaylistState& a, const PlaylistState& b) {
3686 return a.playlist < b.playlist;
3690 struct PlaylistMapping {
3692 boost::shared_ptr<Playlist> pl;
3694 PlaylistMapping (TimeAxisView* tvp) : tv (tvp) {}
3697 /** Remove `clicked_regionview' */
3699 Editor::remove_clicked_region ()
3701 if (clicked_routeview == 0 || clicked_regionview == 0) {
3705 boost::shared_ptr<Playlist> playlist = clicked_routeview->playlist();
3707 begin_reversible_command (_("remove region"));
3708 playlist->clear_changes ();
3709 playlist->remove_region (clicked_regionview->region());
3710 _session->add_command(new StatefulDiffCommand (playlist));
3711 commit_reversible_command ();
3715 /** Remove the selected regions */
3717 Editor::remove_selected_regions ()
3719 RegionSelection rs = get_regions_from_selection_and_entered ();
3721 if (!_session || rs.empty()) {
3725 begin_reversible_command (_("remove region"));
3727 list<boost::shared_ptr<Region> > regions_to_remove;
3729 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
3730 // we can't just remove the region(s) in this loop because
3731 // this removes them from the RegionSelection, and they thus
3732 // disappear from underneath the iterator, and the ++i above
3733 // SEGVs in a puzzling fashion.
3735 // so, first iterate over the regions to be removed from rs and
3736 // add them to the regions_to_remove list, and then
3737 // iterate over the list to actually remove them.
3739 regions_to_remove.push_back ((*i)->region());
3742 vector<boost::shared_ptr<Playlist> > playlists;
3744 for (list<boost::shared_ptr<Region> >::iterator rl = regions_to_remove.begin(); rl != regions_to_remove.end(); ++rl) {
3746 boost::shared_ptr<Playlist> playlist = (*rl)->playlist();
3749 // is this check necessary?
3753 /* get_regions_from_selection_and_entered() guarantees that
3754 the playlists involved are unique, so there is no need
3758 playlists.push_back (playlist);
3760 playlist->clear_changes ();
3761 playlist->freeze ();
3762 playlist->remove_region (*rl);
3765 vector<boost::shared_ptr<Playlist> >::iterator pl;
3767 for (pl = playlists.begin(); pl != playlists.end(); ++pl) {
3769 _session->add_command(new StatefulDiffCommand (*pl));
3772 commit_reversible_command ();
3775 /** Cut, copy or clear selected regions.
3776 * @param op Operation (Cut, Copy or Clear)
3779 Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
3781 /* we can't use a std::map here because the ordering is important, and we can't trivially sort
3782 a map when we want ordered access to both elements. i think.
3785 vector<PlaylistMapping> pmap;
3787 framepos_t first_position = max_framepos;
3789 typedef set<boost::shared_ptr<Playlist> > FreezeList;
3790 FreezeList freezelist;
3792 /* get ordering correct before we cut/copy */
3794 rs.sort_by_position_and_track ();
3796 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
3798 first_position = min ((framepos_t) (*x)->region()->position(), first_position);
3800 if (op == Cut || op == Clear || op == Delete) {
3801 boost::shared_ptr<Playlist> pl = (*x)->region()->playlist();
3804 FreezeList::iterator fl;
3806 // only take state if this is a new playlist.
3807 for (fl = freezelist.begin(); fl != freezelist.end(); ++fl) {
3813 if (fl == freezelist.end()) {
3814 pl->clear_changes();
3816 freezelist.insert (pl);
3821 TimeAxisView* tv = &(*x)->get_time_axis_view();
3822 vector<PlaylistMapping>::iterator z;
3824 for (z = pmap.begin(); z != pmap.end(); ++z) {
3825 if ((*z).tv == tv) {
3830 if (z == pmap.end()) {
3831 pmap.push_back (PlaylistMapping (tv));
3835 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ) {
3837 boost::shared_ptr<Playlist> pl = (*x)->region()->playlist();
3840 /* region not yet associated with a playlist (e.g. unfinished
3847 TimeAxisView& tv = (*x)->get_time_axis_view();
3848 boost::shared_ptr<Playlist> npl;
3849 RegionSelection::iterator tmp;
3856 vector<PlaylistMapping>::iterator z;
3858 for (z = pmap.begin(); z != pmap.end(); ++z) {
3859 if ((*z).tv == &tv) {
3864 assert (z != pmap.end());
3867 npl = PlaylistFactory::create (pl->data_type(), *_session, "cutlist", true);
3875 boost::shared_ptr<Region> r = (*x)->region();
3876 boost::shared_ptr<Region> _xx;
3882 pl->remove_region (r);
3886 _xx = RegionFactory::create (r);
3887 npl->add_region (_xx, r->position() - first_position);
3888 pl->remove_region (r);
3892 /* copy region before adding, so we're not putting same object into two different playlists */
3893 npl->add_region (RegionFactory::create (r), r->position() - first_position);
3897 pl->remove_region (r);
3906 list<boost::shared_ptr<Playlist> > foo;
3908 /* the pmap is in the same order as the tracks in which selected regions occured */
3910 for (vector<PlaylistMapping>::iterator i = pmap.begin(); i != pmap.end(); ++i) {
3913 foo.push_back ((*i).pl);
3918 cut_buffer->set (foo);
3922 _last_cut_copy_source_track = 0;
3924 _last_cut_copy_source_track = pmap.front().tv;
3928 for (FreezeList::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
3930 _session->add_command (new StatefulDiffCommand (*pl));
3935 Editor::cut_copy_ranges (CutCopyOp op)
3937 TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
3939 /* Sort the track selection now, so that it if is used, the playlists
3940 selected by the calls below to cut_copy_clear are in the order that
3941 their tracks appear in the editor. This makes things like paste
3942 of ranges work properly.
3945 sort_track_selection (ts);
3948 if (!entered_track) {
3951 ts.push_back (entered_track);
3954 for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
3955 (*i)->cut_copy_clear (*selection, op);
3960 Editor::paste (float times)
3962 DEBUG_TRACE (DEBUG::CutNPaste, "paste to preferred edit pos\n");
3963 paste_internal (get_preferred_edit_position(), times);
3967 Editor::mouse_paste ()
3972 if (!mouse_frame (where, ignored)) {
3977 paste_internal (where, 1);
3981 Editor::paste_internal (framepos_t position, float times)
3983 DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("apparent paste position is %1\n", position));
3985 if (internal_editing()) {
3986 if (cut_buffer->midi_notes.empty()) {
3990 if (cut_buffer->empty()) {
3995 if (position == max_framepos) {
3996 position = get_preferred_edit_position();
3997 DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("preferred edit position is %1\n", position));
4001 TrackViewList::iterator i;
4004 /* get everything in the correct order */
4006 if (!selection->tracks.empty()) {
4007 /* there are some selected tracks, so paste to them */
4008 ts = selection->tracks.filter_to_unique_playlists ();
4009 sort_track_selection (ts);
4010 } else if (_last_cut_copy_source_track) {
4011 /* otherwise paste to the track that the cut/copy came from;
4012 see discussion in mantis #3333.
4014 ts.push_back (_last_cut_copy_source_track);
4017 if (internal_editing ()) {
4019 /* undo/redo is handled by individual tracks/regions */
4021 for (nth = 0, i = ts.begin(); i != ts.end(); ++i, ++nth) {
4024 RegionSelection::iterator r;
4025 MidiNoteSelection::iterator cb;
4027 get_regions_at (rs, position, ts);
4029 for (cb = cut_buffer->midi_notes.begin(), r = rs.begin();
4030 cb != cut_buffer->midi_notes.end() && r != rs.end(); ++r) {
4031 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*r);
4033 mrv->paste (position, times, **cb);
4041 /* we do redo (do you do voodoo?) */
4043 begin_reversible_command (Operations::paste);
4045 for (nth = 0, i = ts.begin(); i != ts.end(); ++i, ++nth) {
4046 (*i)->paste (position, times, *cut_buffer, nth);
4049 commit_reversible_command ();
4054 Editor::duplicate_some_regions (RegionSelection& regions, float times)
4056 boost::shared_ptr<Playlist> playlist;
4057 RegionSelection sel = regions; // clear (below) may clear the argument list if its the current region selection
4058 RegionSelection foo;
4060 framepos_t const start_frame = regions.start ();
4061 framepos_t const end_frame = regions.end_frame ();
4063 begin_reversible_command (Operations::duplicate_region);
4065 selection->clear_regions ();
4067 for (RegionSelection::iterator i = sel.begin(); i != sel.end(); ++i) {
4069 boost::shared_ptr<Region> r ((*i)->region());
4071 TimeAxisView& tv = (*i)->get_time_axis_view();
4072 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
4073 latest_regionviews.clear ();
4074 sigc::connection c = rtv->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view));
4076 playlist = (*i)->region()->playlist();
4077 playlist->clear_changes ();
4078 playlist->duplicate (r, end_frame + (r->first_frame() - start_frame), times);
4079 _session->add_command(new StatefulDiffCommand (playlist));
4083 foo.insert (foo.end(), latest_regionviews.begin(), latest_regionviews.end());
4086 commit_reversible_command ();
4089 selection->set (foo);
4094 Editor::duplicate_selection (float times)
4096 if (selection->time.empty() || selection->tracks.empty()) {
4100 boost::shared_ptr<Playlist> playlist;
4101 vector<boost::shared_ptr<Region> > new_regions;
4102 vector<boost::shared_ptr<Region> >::iterator ri;
4104 create_region_from_selection (new_regions);
4106 if (new_regions.empty()) {
4110 begin_reversible_command (_("duplicate selection"));
4112 ri = new_regions.begin();
4114 TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
4116 for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
4117 if ((playlist = (*i)->playlist()) == 0) {
4120 playlist->clear_changes ();
4121 playlist->duplicate (*ri, selection->time[clicked_selection].end, times);
4122 _session->add_command (new StatefulDiffCommand (playlist));
4125 if (ri == new_regions.end()) {
4130 commit_reversible_command ();
4134 Editor::reset_point_selection ()
4136 /* reset all selected points to the relevant default value */
4138 for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
4140 AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>((*i).track);
4143 atv->reset_objects (selection->points);
4149 Editor::center_playhead ()
4151 float page = _canvas_width * frames_per_unit;
4152 center_screen_internal (playhead_cursor->current_frame, page);
4156 Editor::center_edit_point ()
4158 float page = _canvas_width * frames_per_unit;
4159 center_screen_internal (get_preferred_edit_position(), page);
4162 /** Caller must begin and commit a reversible command */
4164 Editor::clear_playlist (boost::shared_ptr<Playlist> playlist)
4166 playlist->clear_changes ();
4168 _session->add_command (new StatefulDiffCommand (playlist));
4172 Editor::nudge_track (bool use_edit, bool forwards)
4174 boost::shared_ptr<Playlist> playlist;
4175 framepos_t distance;
4176 framepos_t next_distance;
4180 start = get_preferred_edit_position();
4185 if ((distance = get_nudge_distance (start, next_distance)) == 0) {
4189 if (selection->tracks.empty()) {
4193 begin_reversible_command (_("nudge track"));
4195 TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
4197 for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
4199 if ((playlist = (*i)->playlist()) == 0) {
4203 playlist->clear_changes ();
4204 playlist->clear_owned_changes ();
4206 playlist->nudge_after (start, distance, forwards);
4208 vector<Command*> cmds;
4210 playlist->rdiff (cmds);
4211 _session->add_commands (cmds);
4213 _session->add_command (new StatefulDiffCommand (playlist));
4216 commit_reversible_command ();
4220 Editor::remove_last_capture ()
4222 vector<string> choices;
4229 if (Config->get_verify_remove_last_capture()) {
4230 prompt = _("Do you really want to destroy the last capture?"
4231 "\n(This is destructive and cannot be undone)");
4233 choices.push_back (_("No, do nothing."));
4234 choices.push_back (_("Yes, destroy it."));
4236 Gtkmm2ext::Choice prompter (_("Destroy last capture"), prompt, choices);
4238 if (prompter.run () == 1) {
4239 _session->remove_last_capture ();
4240 _regions->redisplay ();
4244 _session->remove_last_capture();
4245 _regions->redisplay ();
4250 Editor::normalize_region ()
4256 RegionSelection rs = get_regions_from_selection_and_entered ();
4262 NormalizeDialog dialog (rs.size() > 1);
4264 if (dialog.run () == RESPONSE_CANCEL) {
4268 set_canvas_cursor (_cursors->wait);
4271 /* XXX: should really only count audio regions here */
4272 int const regions = rs.size ();
4274 /* Make a list of the selected audio regions' maximum amplitudes, and also
4275 obtain the maximum amplitude of them all.
4277 list<double> max_amps;
4279 for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
4280 AudioRegionView const * arv = dynamic_cast<AudioRegionView const *> (*i);
4282 dialog.descend (1.0 / regions);
4283 double const a = arv->audio_region()->maximum_amplitude (&dialog);
4286 /* the user cancelled the operation */
4287 set_canvas_cursor (current_canvas_cursor);
4291 max_amps.push_back (a);
4292 max_amp = max (max_amp, a);
4297 begin_reversible_command (_("normalize"));
4299 list<double>::const_iterator a = max_amps.begin ();
4301 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
4302 AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (*r);
4307 arv->region()->clear_changes ();
4309 double const amp = dialog.normalize_individually() ? *a : max_amp;
4311 arv->audio_region()->normalize (amp, dialog.target ());
4312 _session->add_command (new StatefulDiffCommand (arv->region()));
4317 commit_reversible_command ();
4318 set_canvas_cursor (current_canvas_cursor);
4323 Editor::reset_region_scale_amplitude ()
4329 RegionSelection rs = get_regions_from_selection_and_entered ();
4335 begin_reversible_command ("reset gain");
4337 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
4338 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*r);
4341 arv->region()->clear_changes ();
4342 arv->audio_region()->set_scale_amplitude (1.0f);
4343 _session->add_command (new StatefulDiffCommand (arv->region()));
4346 commit_reversible_command ();
4350 Editor::adjust_region_gain (bool up)
4352 RegionSelection rs = get_regions_from_selection_and_entered ();
4354 if (!_session || rs.empty()) {
4358 begin_reversible_command ("adjust region gain");
4360 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
4361 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*r);
4366 arv->region()->clear_changes ();
4368 double dB = accurate_coefficient_to_dB (arv->audio_region()->scale_amplitude ());
4376 arv->audio_region()->set_scale_amplitude (dB_to_coefficient (dB));
4377 _session->add_command (new StatefulDiffCommand (arv->region()));
4380 commit_reversible_command ();
4385 Editor::reverse_region ()
4391 Reverse rev (*_session);
4392 apply_filter (rev, _("reverse regions"));
4396 Editor::strip_region_silence ()
4402 RegionSelection rs = get_regions_from_selection_and_entered ();
4408 std::list<RegionView*> audio_only;
4410 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
4411 AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (*i);
4413 audio_only.push_back (arv);
4417 StripSilenceDialog d (_session, audio_only);
4418 int const r = d.run ();
4422 if (r == Gtk::RESPONSE_OK) {
4423 ARDOUR::AudioIntervalMap silences;
4424 d.silences (silences);
4425 StripSilence s (*_session, silences, d.fade_length());
4426 apply_filter (s, _("strip silence"), &d);
4431 Editor::apply_midi_note_edit_op_to_region (MidiOperator& op, MidiRegionView& mrv)
4433 Evoral::Sequence<Evoral::MusicalTime>::Notes selected;
4434 mrv.selection_as_notelist (selected, true);
4436 vector<Evoral::Sequence<Evoral::MusicalTime>::Notes> v;
4437 v.push_back (selected);
4439 framepos_t pos_frames = mrv.midi_region()->position();
4440 double pos_beats = _session->tempo_map().framewalk_to_beats(0, pos_frames);
4442 return op (mrv.midi_region()->model(), pos_beats, v);
4446 Editor::apply_midi_note_edit_op (MidiOperator& op)
4450 RegionSelection rs = get_regions_from_selection_and_entered ();
4456 begin_reversible_command (op.name ());
4458 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ) {
4459 RegionSelection::iterator tmp = r;
4462 MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*r);
4465 cmd = apply_midi_note_edit_op_to_region (op, *mrv);
4468 _session->add_command (cmd);
4475 commit_reversible_command ();
4479 Editor::fork_region ()
4481 RegionSelection rs = get_regions_from_selection_and_entered ();
4487 begin_reversible_command (_("Fork Region(s)"));
4489 set_canvas_cursor (_cursors->wait);
4492 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ) {
4493 RegionSelection::iterator tmp = r;
4496 MidiRegionView* const mrv = dynamic_cast<MidiRegionView*>(*r);
4499 boost::shared_ptr<Playlist> playlist = mrv->region()->playlist();
4500 boost::shared_ptr<MidiRegion> newregion = mrv->midi_region()->clone ();
4502 playlist->clear_changes ();
4503 playlist->replace_region (mrv->region(), newregion, mrv->region()->position());
4504 _session->add_command(new StatefulDiffCommand (playlist));
4510 commit_reversible_command ();
4512 set_canvas_cursor (current_canvas_cursor);
4516 Editor::quantize_region ()
4518 int selected_midi_region_cnt = 0;
4524 RegionSelection rs = get_regions_from_selection_and_entered ();
4530 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
4531 MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*r);
4533 selected_midi_region_cnt++;
4537 if (selected_midi_region_cnt == 0) {
4541 QuantizeDialog* qd = new QuantizeDialog (*this);
4544 const int r = qd->run ();
4547 if (r == Gtk::RESPONSE_OK) {
4548 Quantize quant (*_session, Plain,
4549 qd->snap_start(), qd->snap_end(),
4550 qd->start_grid_size(), qd->end_grid_size(),
4551 qd->strength(), qd->swing(), qd->threshold());
4553 apply_midi_note_edit_op (quant);
4558 Editor::insert_patch_change (bool from_context)
4560 RegionSelection rs = get_regions_from_selection_and_entered ();
4568 if (!from_context || (_edit_point != EditAtMouse)) {
4569 p = get_preferred_edit_position (false);
4571 p = event_frame (&context_click_event, 0, 0);
4574 Evoral::PatchChange<Evoral::MusicalTime> empty (0, 0, 0, 0);
4575 PatchChangeDialog d (0, _session, empty, Gtk::Stock::ADD);
4577 if (d.run() == RESPONSE_CANCEL) {
4581 for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
4582 MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*i);
4584 if (p >= mrv->region()->first_frame() && p <= mrv->region()->last_frame()) {
4585 mrv->add_patch_change (p - mrv->region()->position(), d.patch ());
4592 Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress)
4594 RegionSelection rs = get_regions_from_selection_and_entered ();
4600 begin_reversible_command (command);
4602 set_canvas_cursor (_cursors->wait);
4606 int const N = rs.size ();
4608 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ) {
4609 RegionSelection::iterator tmp = r;
4612 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*r);
4614 boost::shared_ptr<Playlist> playlist = arv->region()->playlist();
4617 progress->descend (1.0 / N);
4620 if (arv->audio_region()->apply (filter, progress) == 0) {
4622 playlist->clear_changes ();
4624 if (filter.results.empty ()) {
4626 /* no regions returned; remove the old one */
4627 playlist->remove_region (arv->region ());
4631 std::vector<boost::shared_ptr<Region> >::iterator res = filter.results.begin ();
4633 /* first region replaces the old one */
4634 playlist->replace_region (arv->region(), *res, (*res)->position());
4638 while (res != filter.results.end()) {
4639 playlist->add_region (*res, (*res)->position());
4645 _session->add_command(new StatefulDiffCommand (playlist));
4651 progress->ascend ();
4659 commit_reversible_command ();
4662 set_canvas_cursor (current_canvas_cursor);
4666 Editor::external_edit_region ()
4672 Editor::reset_region_gain_envelopes ()
4674 RegionSelection rs = get_regions_from_selection_and_entered ();
4676 if (!_session || rs.empty()) {
4680 _session->begin_reversible_command (_("reset region gain"));
4682 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
4683 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
4685 boost::shared_ptr<AutomationList> alist (arv->audio_region()->envelope());
4686 XMLNode& before (alist->get_state());
4688 arv->audio_region()->set_default_envelope ();
4689 _session->add_command (new MementoCommand<AutomationList>(*arv->audio_region()->envelope().get(), &before, &alist->get_state()));
4693 _session->commit_reversible_command ();
4697 Editor::toggle_gain_envelope_visibility ()
4699 if (_ignore_region_action) {
4703 RegionSelection rs = get_regions_from_selection_and_entered ();
4705 if (!_session || rs.empty()) {
4709 _session->begin_reversible_command (_("region gain envelope visible"));
4711 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
4712 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
4714 arv->region()->clear_changes ();
4715 arv->set_envelope_visible (!arv->envelope_visible());
4716 _session->add_command (new StatefulDiffCommand (arv->region()));
4720 _session->commit_reversible_command ();
4724 Editor::toggle_gain_envelope_active ()
4726 if (_ignore_region_action) {
4730 RegionSelection rs = get_regions_from_selection_and_entered ();
4732 if (!_session || rs.empty()) {
4736 _session->begin_reversible_command (_("region gain envelope active"));
4738 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
4739 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
4741 arv->region()->clear_changes ();
4742 arv->audio_region()->set_envelope_active (!arv->audio_region()->envelope_active());
4743 _session->add_command (new StatefulDiffCommand (arv->region()));
4747 _session->commit_reversible_command ();
4751 Editor::toggle_region_lock ()
4753 if (_ignore_region_action) {
4757 RegionSelection rs = get_regions_from_selection_and_entered ();
4759 if (!_session || rs.empty()) {
4763 _session->begin_reversible_command (_("toggle region lock"));
4765 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
4766 (*i)->region()->clear_changes ();
4767 (*i)->region()->set_locked (!(*i)->region()->locked());
4768 _session->add_command (new StatefulDiffCommand ((*i)->region()));
4771 _session->commit_reversible_command ();
4775 Editor::toggle_region_lock_style ()
4777 if (_ignore_region_action) {
4781 RegionSelection rs = get_regions_from_selection_and_entered ();
4783 if (!_session || rs.empty()) {
4787 _session->begin_reversible_command (_("region lock style"));
4789 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
4790 (*i)->region()->clear_changes ();
4791 PositionLockStyle const ns = (*i)->region()->position_lock_style() == AudioTime ? MusicTime : AudioTime;
4792 (*i)->region()->set_position_lock_style (ns);
4793 _session->add_command (new StatefulDiffCommand ((*i)->region()));
4796 _session->commit_reversible_command ();
4800 Editor::toggle_opaque_region ()
4802 if (_ignore_region_action) {
4806 RegionSelection rs = get_regions_from_selection_and_entered ();
4808 if (!_session || rs.empty()) {
4812 _session->begin_reversible_command (_("change region opacity"));
4814 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
4815 (*i)->region()->clear_changes ();
4816 (*i)->region()->set_opaque (!(*i)->region()->opaque());
4817 _session->add_command (new StatefulDiffCommand ((*i)->region()));
4820 _session->commit_reversible_command ();
4824 Editor::toggle_record_enable ()
4826 bool new_state = false;
4828 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4829 RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView *>(*i);
4832 if (!rtav->is_track())
4836 new_state = !rtav->track()->record_enabled();
4840 rtav->track()->set_record_enabled (new_state, this);
4845 Editor::toggle_solo ()
4847 bool new_state = false;
4849 boost::shared_ptr<RouteList> rl (new RouteList);
4851 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4852 RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView *>(*i);
4859 new_state = !rtav->route()->soloed ();
4863 rl->push_back (rtav->route());
4866 _session->set_solo (rl, new_state, Session::rt_cleanup, true);
4870 Editor::toggle_mute ()
4872 bool new_state = false;
4874 boost::shared_ptr<RouteList> rl (new RouteList);
4876 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
4877 RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView *>(*i);
4884 new_state = !rtav->route()->muted();
4888 rl->push_back (rtav->route());
4891 _session->set_mute (rl, new_state, Session::rt_cleanup, true);
4895 Editor::toggle_solo_isolate ()
4900 Editor::set_fade_length (bool in)
4902 RegionSelection rs = get_regions_from_selection_and_entered ();
4908 /* we need a region to measure the offset from the start */
4910 RegionView* rv = rs.front ();
4912 framepos_t pos = get_preferred_edit_position();
4916 if (pos > rv->region()->last_frame() || pos < rv->region()->first_frame()) {
4917 /* edit point is outside the relevant region */
4922 if (pos <= rv->region()->position()) {
4926 len = pos - rv->region()->position();
4927 cmd = _("set fade in length");
4929 if (pos >= rv->region()->last_frame()) {
4933 len = rv->region()->last_frame() - pos;
4934 cmd = _("set fade out length");
4937 begin_reversible_command (cmd);
4939 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
4940 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*x);
4946 boost::shared_ptr<AutomationList> alist;
4948 alist = tmp->audio_region()->fade_in();
4950 alist = tmp->audio_region()->fade_out();
4953 XMLNode &before = alist->get_state();
4956 tmp->audio_region()->set_fade_in_length (len);
4957 tmp->audio_region()->set_fade_in_active (true);
4959 tmp->audio_region()->set_fade_out_length (len);
4960 tmp->audio_region()->set_fade_out_active (true);
4963 XMLNode &after = alist->get_state();
4964 _session->add_command(new MementoCommand<AutomationList>(*alist, &before, &after));
4967 commit_reversible_command ();
4971 Editor::set_fade_in_shape (FadeShape shape)
4973 RegionSelection rs = get_regions_from_selection_and_entered ();
4979 begin_reversible_command (_("set fade in shape"));
4981 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
4982 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*x);
4988 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_in();
4989 XMLNode &before = alist->get_state();
4991 tmp->audio_region()->set_fade_in_shape (shape);
4993 XMLNode &after = alist->get_state();
4994 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
4997 commit_reversible_command ();
5002 Editor::set_fade_out_shape (FadeShape shape)
5004 RegionSelection rs = get_regions_from_selection_and_entered ();
5010 begin_reversible_command (_("set fade out shape"));
5012 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
5013 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*x);
5019 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_out();
5020 XMLNode &before = alist->get_state();
5022 tmp->audio_region()->set_fade_out_shape (shape);
5024 XMLNode &after = alist->get_state();
5025 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
5028 commit_reversible_command ();
5032 Editor::set_fade_in_active (bool yn)
5034 RegionSelection rs = get_regions_from_selection_and_entered ();
5040 begin_reversible_command (_("set fade in active"));
5042 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
5043 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*x);
5050 boost::shared_ptr<AudioRegion> ar (tmp->audio_region());
5052 ar->clear_changes ();
5053 ar->set_fade_in_active (yn);
5054 _session->add_command (new StatefulDiffCommand (ar));
5057 commit_reversible_command ();
5061 Editor::set_fade_out_active (bool yn)
5063 RegionSelection rs = get_regions_from_selection_and_entered ();
5069 begin_reversible_command (_("set fade out active"));
5071 for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
5072 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*x);
5078 boost::shared_ptr<AudioRegion> ar (tmp->audio_region());
5080 ar->clear_changes ();
5081 ar->set_fade_out_active (yn);
5082 _session->add_command(new StatefulDiffCommand (ar));
5085 commit_reversible_command ();
5089 Editor::toggle_region_fades (int dir)
5091 boost::shared_ptr<AudioRegion> ar;
5094 RegionSelection rs = get_regions_from_selection_and_entered ();
5100 RegionSelection::iterator i;
5101 for (i = rs.begin(); i != rs.end(); ++i) {
5102 if ((ar = boost::dynamic_pointer_cast<AudioRegion>((*i)->region())) != 0) {
5104 yn = ar->fade_out_active ();
5106 yn = ar->fade_in_active ();
5112 if (i == rs.end()) {
5116 /* XXX should this undo-able? */
5118 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
5119 if ((ar = boost::dynamic_pointer_cast<AudioRegion>((*i)->region())) == 0) {
5122 if (dir == 1 || dir == 0) {
5123 ar->set_fade_in_active (!yn);
5126 if (dir == -1 || dir == 0) {
5127 ar->set_fade_out_active (!yn);
5133 /** Update region fade visibility after its configuration has been changed */
5135 Editor::update_region_fade_visibility ()
5137 bool _fade_visibility = _session->config.get_show_region_fades ();
5139 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5140 AudioTimeAxisView* v = dynamic_cast<AudioTimeAxisView*>(*i);
5142 if (_fade_visibility) {
5143 v->audio_view()->show_all_fades ();
5145 v->audio_view()->hide_all_fades ();
5151 /** Update crossfade visibility after its configuration has been changed */
5153 Editor::update_xfade_visibility ()
5155 _xfade_visibility = _session->config.get_xfades_visible ();
5157 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5158 AudioTimeAxisView* v = dynamic_cast<AudioTimeAxisView*>(*i);
5160 if (_xfade_visibility) {
5161 v->show_all_xfades ();
5163 v->hide_all_xfades ();
5170 Editor::set_edit_point ()
5175 if (!mouse_frame (where, ignored)) {
5181 if (selection->markers.empty()) {
5183 mouse_add_new_marker (where);
5188 Location* loc = find_location_from_marker (selection->markers.front(), ignored);
5191 loc->move_to (where);
5197 Editor::set_playhead_cursor ()
5199 if (entered_marker) {
5200 _session->request_locate (entered_marker->position(), _session->transport_rolling());
5205 if (!mouse_frame (where, ignored)) {
5212 _session->request_locate (where, _session->transport_rolling());
5218 Editor::split_region ()
5220 if (((mouse_mode == MouseRange) ||
5221 (mouse_mode != MouseObject && _join_object_range_state == JOIN_OBJECT_RANGE_RANGE)) &&
5222 !selection->time.empty()) {
5223 separate_regions_between (selection->time);
5227 RegionSelection rs = get_regions_from_selection_and_edit_point ();
5229 framepos_t where = get_preferred_edit_position ();
5235 split_regions_at (where, rs);
5239 Editor::ensure_entered_track_selected (bool op_really_wants_one_track_if_none_are_selected)
5241 if (entered_track && mouse_mode == MouseObject) {
5242 if (!selection->tracks.empty()) {
5243 if (!selection->selected (entered_track)) {
5244 selection->add (entered_track);
5247 /* there is no selection, but this operation requires/prefers selected objects */
5249 if (op_really_wants_one_track_if_none_are_selected) {
5250 selection->set (entered_track);
5256 struct EditorOrderRouteSorter {
5257 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
5258 /* use of ">" forces the correct sort order */
5259 return a->order_key ("editor") < b->order_key ("editor");
5264 Editor::select_next_route()
5266 if (selection->tracks.empty()) {
5267 selection->set (track_views.front());
5271 TimeAxisView* current = selection->tracks.front();
5275 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
5276 if (*i == current) {
5278 if (i != track_views.end()) {
5281 current = (*(track_views.begin()));
5282 //selection->set (*(track_views.begin()));
5287 rui = dynamic_cast<RouteUI *>(current);
5288 } while ( current->hidden() || (rui != NULL && !rui->route()->active()));
5290 selection->set(current);
5292 ensure_track_visible(current);
5296 Editor::select_prev_route()
5298 if (selection->tracks.empty()) {
5299 selection->set (track_views.front());
5303 TimeAxisView* current = selection->tracks.front();
5307 for (TrackViewList::reverse_iterator i = track_views.rbegin(); i != track_views.rend(); ++i) {
5308 if (*i == current) {
5310 if (i != track_views.rend()) {
5313 current = *(track_views.rbegin());
5318 rui = dynamic_cast<RouteUI *>(current);
5319 } while ( current->hidden() || (rui != NULL && !rui->route()->active()));
5321 selection->set (current);
5323 ensure_track_visible(current);
5327 Editor::ensure_track_visible(TimeAxisView *track)
5329 if (track->hidden())
5332 double const current_view_min_y = vertical_adjustment.get_value();
5333 double const current_view_max_y = vertical_adjustment.get_value() + vertical_adjustment.get_page_size() - canvas_timebars_vsize;
5335 double const track_min_y = track->y_position ();
5336 double const track_max_y = track->y_position () + track->effective_height ();
5338 if (track_min_y >= current_view_min_y &&
5339 track_max_y <= current_view_max_y) {
5345 if (track_min_y < current_view_min_y) {
5346 // Track is above the current view
5347 new_value = track_min_y;
5349 // Track is below the current view
5350 new_value = track->y_position () + track->effective_height() + canvas_timebars_vsize - vertical_adjustment.get_page_size();
5353 vertical_adjustment.set_value(new_value);
5357 Editor::set_loop_from_selection (bool play)
5359 if (_session == 0 || selection->time.empty()) {
5363 framepos_t start = selection->time[clicked_selection].start;
5364 framepos_t end = selection->time[clicked_selection].end;
5366 set_loop_range (start, end, _("set loop range from selection"));
5369 _session->request_play_loop (true);
5370 _session->request_locate (start, true);
5375 Editor::set_loop_from_edit_range (bool play)
5377 if (_session == 0) {
5384 if (!get_edit_op_range (start, end)) {
5388 set_loop_range (start, end, _("set loop range from edit range"));
5391 _session->request_play_loop (true);
5392 _session->request_locate (start, true);
5397 Editor::set_loop_from_region (bool play)
5399 framepos_t start = max_framepos;
5402 RegionSelection rs = get_regions_from_selection_and_entered ();
5408 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
5409 if ((*i)->region()->position() < start) {
5410 start = (*i)->region()->position();
5412 if ((*i)->region()->last_frame() + 1 > end) {
5413 end = (*i)->region()->last_frame() + 1;
5417 set_loop_range (start, end, _("set loop range from region"));
5420 _session->request_play_loop (true);
5421 _session->request_locate (start, true);
5426 Editor::set_punch_from_selection ()
5428 if (_session == 0 || selection->time.empty()) {
5432 framepos_t start = selection->time[clicked_selection].start;
5433 framepos_t end = selection->time[clicked_selection].end;
5435 set_punch_range (start, end, _("set punch range from selection"));
5439 Editor::set_punch_from_edit_range ()
5441 if (_session == 0) {
5448 if (!get_edit_op_range (start, end)) {
5452 set_punch_range (start, end, _("set punch range from edit range"));
5456 Editor::set_punch_from_region ()
5458 framepos_t start = max_framepos;
5461 RegionSelection rs = get_regions_from_selection_and_entered ();
5467 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
5468 if ((*i)->region()->position() < start) {
5469 start = (*i)->region()->position();
5471 if ((*i)->region()->last_frame() + 1 > end) {
5472 end = (*i)->region()->last_frame() + 1;
5476 set_punch_range (start, end, _("set punch range from region"));
5480 Editor::pitch_shift_region ()
5482 RegionSelection rs = get_regions_from_selection_and_entered ();
5484 RegionSelection audio_rs;
5485 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
5486 if (dynamic_cast<AudioRegionView*> (*i)) {
5487 audio_rs.push_back (*i);
5491 if (audio_rs.empty()) {
5495 pitch_shift (audio_rs, 1.2);
5499 Editor::transpose_region ()
5501 RegionSelection rs = get_regions_from_selection_and_entered ();
5503 list<MidiRegionView*> midi_region_views;
5504 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
5505 MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*i);
5507 midi_region_views.push_back (mrv);
5512 int const r = d.run ();
5513 if (r != RESPONSE_ACCEPT) {
5517 for (list<MidiRegionView*>::iterator i = midi_region_views.begin(); i != midi_region_views.end(); ++i) {
5518 (*i)->midi_region()->transpose (d.semitones ());
5523 Editor::set_tempo_from_region ()
5525 RegionSelection rs = get_regions_from_selection_and_entered ();
5527 if (!_session || rs.empty()) {
5531 RegionView* rv = rs.front();
5533 define_one_bar (rv->region()->position(), rv->region()->last_frame() + 1);
5537 Editor::use_range_as_bar ()
5539 framepos_t start, end;
5540 if (get_edit_op_range (start, end)) {
5541 define_one_bar (start, end);
5546 Editor::define_one_bar (framepos_t start, framepos_t end)
5548 framepos_t length = end - start;
5550 const Meter& m (_session->tempo_map().meter_at (start));
5552 /* length = 1 bar */
5554 /* now we want frames per beat.
5555 we have frames per bar, and beats per bar, so ...
5558 /* XXXX METER MATH */
5560 double frames_per_beat = length / m.divisions_per_bar();
5562 /* beats per minute = */
5564 double beats_per_minute = (_session->frame_rate() * 60.0) / frames_per_beat;
5566 /* now decide whether to:
5568 (a) set global tempo
5569 (b) add a new tempo marker
5573 const TempoSection& t (_session->tempo_map().tempo_section_at (start));
5575 bool do_global = false;
5577 if ((_session->tempo_map().n_tempos() == 1) && (_session->tempo_map().n_meters() == 1)) {
5579 /* only 1 tempo & 1 meter: ask if the user wants to set the tempo
5580 at the start, or create a new marker
5583 vector<string> options;
5584 options.push_back (_("Cancel"));
5585 options.push_back (_("Add new marker"));
5586 options.push_back (_("Set global tempo"));
5589 _("Define one bar"),
5590 _("Do you want to set the global tempo or add a new tempo marker?"),
5594 c.set_default_response (2);
5610 /* more than 1 tempo and/or meter section already, go ahead do the "usual":
5611 if the marker is at the region starter, change it, otherwise add
5616 begin_reversible_command (_("set tempo from region"));
5617 XMLNode& before (_session->tempo_map().get_state());
5620 _session->tempo_map().change_initial_tempo (beats_per_minute, t.note_type());
5621 } else if (t.frame() == start) {
5622 _session->tempo_map().change_existing_tempo_at (start, beats_per_minute, t.note_type());
5624 _session->tempo_map().add_tempo (Tempo (beats_per_minute, t.note_type()), start);
5627 XMLNode& after (_session->tempo_map().get_state());
5629 _session->add_command (new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
5630 commit_reversible_command ();
5634 Editor::split_region_at_transients ()
5636 AnalysisFeatureList positions;
5638 RegionSelection rs = get_regions_from_selection_and_entered ();
5640 if (!_session || rs.empty()) {
5644 _session->begin_reversible_command (_("split regions"));
5646 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ) {
5648 RegionSelection::iterator tmp;
5653 boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> ((*i)->region());
5655 if (ar && (ar->get_transients (positions) == 0)) {
5656 split_region_at_points ((*i)->region(), positions, true);
5663 _session->commit_reversible_command ();
5668 Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList& positions, bool can_ferret, bool select_new)
5670 bool use_rhythmic_rodent = false;
5672 boost::shared_ptr<Playlist> pl = r->playlist();
5674 list<boost::shared_ptr<Region> > new_regions;
5680 if (positions.empty()) {
5685 if (positions.size() > 20 && can_ferret) {
5686 std::string msgstr = string_compose (_("You are about to split\n%1\ninto %2 pieces.\nThis could take a long time."), r->name(), positions.size() + 1);
5687 MessageDialog msg (msgstr,
5690 Gtk::BUTTONS_OK_CANCEL);
5693 msg.add_button (_("Call for the Ferret!"), RESPONSE_APPLY);
5694 msg.set_secondary_text (_("Press OK to continue with this split operation\nor ask the Ferret dialog to tune the analysis"));
5696 msg.set_secondary_text (_("Press OK to continue with this split operation"));
5699 msg.set_title (_("Excessive split?"));
5702 int response = msg.run();
5708 case RESPONSE_APPLY:
5709 use_rhythmic_rodent = true;
5716 if (use_rhythmic_rodent) {
5717 show_rhythm_ferret ();
5721 AnalysisFeatureList::const_iterator x;
5723 pl->clear_changes ();
5725 x = positions.begin();
5727 if (x == positions.end()) {
5732 pl->remove_region (r);
5736 while (x != positions.end()) {
5738 /* deal with positons that are out of scope of present region bounds */
5739 if (*x <= 0 || *x > r->length()) {
5744 /* file start = original start + how far we from the initial position ?
5747 framepos_t file_start = r->start() + pos;
5749 /* length = next position - current position
5752 framepos_t len = (*x) - pos;
5754 /* XXX we do we really want to allow even single-sample regions?
5755 shouldn't we have some kind of lower limit on region size?
5764 if (RegionFactory::region_name (new_name, r->name())) {
5768 /* do NOT announce new regions 1 by one, just wait till they are all done */
5772 plist.add (ARDOUR::Properties::start, file_start);
5773 plist.add (ARDOUR::Properties::length, len);
5774 plist.add (ARDOUR::Properties::name, new_name);
5775 plist.add (ARDOUR::Properties::layer, 0);
5777 boost::shared_ptr<Region> nr = RegionFactory::create (r->sources(), plist, false);
5779 pl->add_region (nr, r->position() + pos);
5782 new_regions.push_front(nr);
5791 RegionFactory::region_name (new_name, r->name());
5793 /* Add the final region */
5796 plist.add (ARDOUR::Properties::start, r->start() + pos);
5797 plist.add (ARDOUR::Properties::length, r->last_frame() - (r->position() + pos) + 1);
5798 plist.add (ARDOUR::Properties::name, new_name);
5799 plist.add (ARDOUR::Properties::layer, 0);
5801 boost::shared_ptr<Region> nr = RegionFactory::create (r->sources(), plist, false);
5802 pl->add_region (nr, r->position() + pos);
5805 new_regions.push_front(nr);
5810 _session->add_command (new StatefulDiffCommand (pl));
5814 for (list<boost::shared_ptr<Region> >::iterator i = new_regions.begin(); i != new_regions.end(); ++i){
5815 set_selected_regionview_from_region_list ((*i), Selection::Add);
5821 Editor::place_transient()
5827 RegionSelection rs = get_regions_from_selection_and_edit_point ();
5833 framepos_t where = get_preferred_edit_position();
5835 _session->begin_reversible_command (_("place transient"));
5837 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
5838 framepos_t position = (*r)->region()->position();
5839 (*r)->region()->add_transient(where - position);
5842 _session->commit_reversible_command ();
5846 Editor::remove_transient(ArdourCanvas::Item* item)
5852 ArdourCanvas::Line* _line = reinterpret_cast<ArdourCanvas::Line*> (item);
5855 AudioRegionView* _arv = reinterpret_cast<AudioRegionView*> (item->get_data ("regionview"));
5856 _arv->remove_transient (*(float*) _line->get_data ("position"));
5860 Editor::snap_regions_to_grid ()
5862 list <boost::shared_ptr<Playlist > > used_playlists;
5864 RegionSelection rs = get_regions_from_selection_and_entered ();
5866 if (!_session || rs.empty()) {
5870 _session->begin_reversible_command (_("snap regions to grid"));
5872 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
5874 boost::shared_ptr<Playlist> pl = (*r)->region()->playlist();
5876 if (!pl->frozen()) {
5877 /* we haven't seen this playlist before */
5879 /* remember used playlists so we can thaw them later */
5880 used_playlists.push_back(pl);
5884 framepos_t start_frame = (*r)->region()->first_frame ();
5885 snap_to (start_frame);
5886 (*r)->region()->set_position (start_frame);
5889 while (used_playlists.size() > 0) {
5890 list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
5892 used_playlists.pop_front();
5895 _session->commit_reversible_command ();
5899 Editor::close_region_gaps ()
5901 list <boost::shared_ptr<Playlist > > used_playlists;
5903 RegionSelection rs = get_regions_from_selection_and_entered ();
5905 if (!_session || rs.empty()) {
5909 Dialog dialog (_("Close Region Gaps"));
5912 table.set_spacings (12);
5913 table.set_border_width (12);
5914 Label* l = manage (new Label (_("Crossfade length")));
5915 l->set_alignment (0, 0.5);
5916 table.attach (*l, 0, 1, 0, 1);
5918 SpinButton spin_crossfade (1, 0);
5919 spin_crossfade.set_range (0, 15);
5920 spin_crossfade.set_increments (1, 1);
5921 spin_crossfade.set_value (5);
5922 table.attach (spin_crossfade, 1, 2, 0, 1);
5924 table.attach (*manage (new Label (_("ms"))), 2, 3, 0, 1);
5926 l = manage (new Label (_("Pull-back length")));
5927 l->set_alignment (0, 0.5);
5928 table.attach (*l, 0, 1, 1, 2);
5930 SpinButton spin_pullback (1, 0);
5931 spin_pullback.set_range (0, 100);
5932 spin_pullback.set_increments (1, 1);
5933 spin_pullback.set_value(30);
5934 table.attach (spin_pullback, 1, 2, 1, 2);
5936 table.attach (*manage (new Label (_("ms"))), 2, 3, 1, 2);
5938 dialog.get_vbox()->pack_start (table);
5939 dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL);
5940 dialog.add_button (_("Ok"), RESPONSE_ACCEPT);
5943 if (dialog.run () == RESPONSE_CANCEL) {
5947 framepos_t crossfade_len = spin_crossfade.get_value();
5948 framepos_t pull_back_frames = spin_pullback.get_value();
5950 crossfade_len = lrintf (crossfade_len * _session->frame_rate()/1000);
5951 pull_back_frames = lrintf (pull_back_frames * _session->frame_rate()/1000);
5953 /* Iterate over the region list and make adjacent regions overlap by crossfade_len_ms */
5955 _session->begin_reversible_command (_("close region gaps"));
5958 boost::shared_ptr<Region> last_region;
5960 rs.sort_by_position_and_track();
5962 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
5964 boost::shared_ptr<Playlist> pl = (*r)->region()->playlist();
5966 if (!pl->frozen()) {
5967 /* we haven't seen this playlist before */
5969 /* remember used playlists so we can thaw them later */
5970 used_playlists.push_back(pl);
5974 framepos_t position = (*r)->region()->position();
5976 if (idx == 0 || position < last_region->position()){
5977 last_region = (*r)->region();
5982 (*r)->region()->trim_front( (position - pull_back_frames));
5983 last_region->trim_end( (position - pull_back_frames + crossfade_len));
5985 last_region = (*r)->region();
5990 while (used_playlists.size() > 0) {
5991 list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
5993 used_playlists.pop_front();
5996 _session->commit_reversible_command ();
6000 Editor::tab_to_transient (bool forward)
6002 AnalysisFeatureList positions;
6004 RegionSelection rs = get_regions_from_selection_and_entered ();
6010 framepos_t pos = _session->audible_frame ();
6012 if (!selection->tracks.empty()) {
6014 /* don't waste time searching for transients in duplicate playlists.
6017 TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
6019 for (TrackViewList::iterator t = ts.begin(); t != ts.end(); ++t) {
6021 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*t);
6024 boost::shared_ptr<Track> tr = rtv->track();
6026 boost::shared_ptr<Playlist> pl = tr->playlist ();
6028 framepos_t result = pl->find_next_transient (pos, forward ? 1 : -1);
6031 positions.push_back (result);
6044 for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
6045 (*r)->region()->get_transients (positions);
6049 TransientDetector::cleanup_transients (positions, _session->frame_rate(), 3.0);
6052 AnalysisFeatureList::iterator x;
6054 for (x = positions.begin(); x != positions.end(); ++x) {
6060 if (x != positions.end ()) {
6061 _session->request_locate (*x);
6065 AnalysisFeatureList::reverse_iterator x;
6067 for (x = positions.rbegin(); x != positions.rend(); ++x) {
6073 if (x != positions.rend ()) {
6074 _session->request_locate (*x);
6080 Editor::playhead_forward_to_grid ()
6082 if (!_session) return;
6083 framepos_t pos = playhead_cursor->current_frame;
6084 if (pos < max_framepos - 1) {
6086 snap_to_internal (pos, 1, false);
6087 _session->request_locate (pos);
6093 Editor::playhead_backward_to_grid ()
6095 if (!_session) return;
6096 framepos_t pos = playhead_cursor->current_frame;
6099 snap_to_internal (pos, -1, false);
6100 _session->request_locate (pos);
6105 Editor::set_track_height (Height h)
6107 TrackSelection& ts (selection->tracks);
6109 for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) {
6110 (*x)->set_height_enum (h);
6115 Editor::toggle_tracks_active ()
6117 TrackSelection& ts (selection->tracks);
6119 bool target = false;
6125 for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) {
6126 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(*x);
6130 target = !rtv->_route->active();
6133 rtv->_route->set_active (target, this);
6139 Editor::remove_tracks ()
6141 TrackSelection& ts (selection->tracks);
6147 vector<string> choices;
6151 const char* trackstr;
6153 vector<boost::shared_ptr<Route> > routes;
6154 bool special_bus = false;
6156 for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) {
6157 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*x);
6159 if (rtv->is_track()) {
6165 routes.push_back (rtv->_route);
6167 if (rtv->route()->is_master() || rtv->route()->is_monitor()) {
6172 if (special_bus && !Config->get_allow_special_bus_removal()) {
6173 MessageDialog msg (_("That would be bad news ...."),
6177 msg.set_secondary_text (string_compose (_(
6178 "Removing the master or monitor bus is such a bad idea\n\
6179 that %1 is not going to allow it.\n\
6181 If you really want to do this sort of thing\n\
6182 edit your ardour.rc file to set the\n\
6183 \"allow-special-bus-removal\" option to be \"yes\""), PROGRAM_NAME));
6190 if (ntracks + nbusses == 0) {
6195 trackstr = _("tracks");
6197 trackstr = _("track");
6201 busstr = _("busses");
6208 prompt = string_compose (_("Do you really want to remove %1 %2 and %3 %4?\n"
6209 "(You may also lose the playlists associated with the %2)\n\n"
6210 "This action cannot be undone, and the session file will be overwritten!"),
6211 ntracks, trackstr, nbusses, busstr);
6213 prompt = string_compose (_("Do you really want to remove %1 %2?\n"
6214 "(You may also lose the playlists associated with the %2)\n\n"
6215 "This action cannot be undone, and the session file will be overwritten!"),
6218 } else if (nbusses) {
6219 prompt = string_compose (_("Do you really want to remove %1 %2?\n\n"
6220 "This action cannot be undon, and the session file will be overwritten"),
6224 choices.push_back (_("No, do nothing."));
6225 if (ntracks + nbusses > 1) {
6226 choices.push_back (_("Yes, remove them."));
6228 choices.push_back (_("Yes, remove it."));
6233 title = string_compose (_("Remove %1"), trackstr);
6235 title = string_compose (_("Remove %1"), busstr);
6238 Choice prompter (title, prompt, choices);
6240 if (prompter.run () != 1) {
6244 for (vector<boost::shared_ptr<Route> >::iterator x = routes.begin(); x != routes.end(); ++x) {
6245 _session->remove_route (*x);
6250 Editor::do_insert_time ()
6252 if (selection->tracks.empty()) {
6256 InsertTimeDialog d (*this);
6257 int response = d.run ();
6259 if (response != RESPONSE_OK) {
6263 if (d.distance() == 0) {
6267 InsertTimeOption opt = d.intersected_region_action ();
6270 get_preferred_edit_position(),
6276 d.move_glued_markers(),
6277 d.move_locked_markers(),
6283 Editor::insert_time (
6284 framepos_t pos, framecnt_t frames, InsertTimeOption opt,
6285 bool all_playlists, bool ignore_music_glue, bool markers_too, bool glued_markers_too, bool locked_markers_too, bool tempo_too
6288 bool commit = false;
6290 if (Config->get_edit_mode() == Lock) {
6294 begin_reversible_command (_("insert time"));
6296 TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
6298 for (TrackViewList::iterator x = ts.begin(); x != ts.end(); ++x) {
6302 /* don't operate on any playlist more than once, which could
6303 * happen if "all playlists" is enabled, but there is more
6304 * than 1 track using playlists "from" a given track.
6307 set<boost::shared_ptr<Playlist> > pl;
6309 if (all_playlists) {
6310 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
6312 vector<boost::shared_ptr<Playlist> > all = _session->playlists->playlists_for_track (rtav->track ());
6313 for (vector<boost::shared_ptr<Playlist> >::iterator p = all.begin(); p != all.end(); ++p) {
6318 if ((*x)->playlist ()) {
6319 pl.insert ((*x)->playlist ());
6323 for (set<boost::shared_ptr<Playlist> >::iterator i = pl.begin(); i != pl.end(); ++i) {
6325 (*i)->clear_changes ();
6326 (*i)->clear_owned_changes ();
6328 if (opt == SplitIntersected) {
6332 (*i)->shift (pos, frames, (opt == MoveIntersected), ignore_music_glue);
6334 vector<Command*> cmds;
6336 _session->add_commands (cmds);
6338 _session->add_command (new StatefulDiffCommand (*i));
6343 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
6345 rtav->route ()->shift (pos, frames);
6353 XMLNode& before (_session->locations()->get_state());
6354 Locations::LocationList copy (_session->locations()->list());
6356 for (Locations::LocationList::iterator i = copy.begin(); i != copy.end(); ++i) {
6358 Locations::LocationList::const_iterator tmp;
6360 bool const was_locked = (*i)->locked ();
6361 if (locked_markers_too) {
6365 if ((*i)->position_lock_style() == AudioTime || glued_markers_too) {
6367 if ((*i)->start() >= pos) {
6368 (*i)->set_start ((*i)->start() + frames);
6369 if (!(*i)->is_mark()) {
6370 (*i)->set_end ((*i)->end() + frames);
6383 XMLNode& after (_session->locations()->get_state());
6384 _session->add_command (new MementoCommand<Locations>(*_session->locations(), &before, &after));
6389 _session->tempo_map().insert_time (pos, frames);
6393 commit_reversible_command ();
6398 Editor::fit_selected_tracks ()
6400 if (!selection->tracks.empty()) {
6401 fit_tracks (selection->tracks);
6405 /* no selected tracks - use tracks with selected regions */
6407 if (!selection->regions.empty()) {
6408 for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ++r) {
6409 tvl.push_back (&(*r)->get_time_axis_view ());
6415 } else if (internal_editing()) {
6416 /* no selected tracks, or regions, but in internal edit mode, so follow the mouse and use
6419 if (entered_track) {
6420 tvl.push_back (entered_track);
6428 Editor::fit_tracks (TrackViewList & tracks)
6430 if (tracks.empty()) {
6434 uint32_t child_heights = 0;
6435 int visible_tracks = 0;
6437 for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
6439 if (!(*t)->marked_for_display()) {
6443 child_heights += (*t)->effective_height() - (*t)->current_height();
6447 uint32_t h = (uint32_t) floor ((_canvas_height - child_heights - canvas_timebars_vsize) / visible_tracks);
6448 double first_y_pos = DBL_MAX;
6450 if (h < TimeAxisView::preset_height (HeightSmall)) {
6451 MessageDialog msg (*this, _("There are too many tracks to fit in the current window"));
6452 /* too small to be displayed */
6456 undo_visual_stack.push_back (current_visual_state());
6458 /* build a list of all tracks, including children */
6461 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
6463 TimeAxisView::Children c = (*i)->get_child_list ();
6464 for (TimeAxisView::Children::iterator j = c.begin(); j != c.end(); ++j) {
6465 all.push_back (j->get());
6469 /* operate on all tracks, hide unselected ones that are in the middle of selected ones */
6471 bool prev_was_selected = false;
6472 bool is_selected = tracks.contains (all.front());
6473 bool next_is_selected;
6475 for (TrackViewList::iterator t = all.begin(); t != all.end(); ++t) {
6477 TrackViewList::iterator next;
6482 if (next != all.end()) {
6483 next_is_selected = tracks.contains (*next);
6485 next_is_selected = false;
6488 if ((*t)->marked_for_display ()) {
6490 (*t)->set_height (h);
6491 first_y_pos = std::min ((*t)->y_position (), first_y_pos);
6493 if (prev_was_selected && next_is_selected) {
6494 hide_track_in_display (*t);
6499 prev_was_selected = is_selected;
6500 is_selected = next_is_selected;
6504 set the controls_layout height now, because waiting for its size
6505 request signal handler will cause the vertical adjustment setting to fail
6508 controls_layout.property_height () = full_canvas_height - canvas_timebars_vsize;
6509 vertical_adjustment.set_value (first_y_pos);
6511 redo_visual_stack.push_back (current_visual_state());
6515 Editor::save_visual_state (uint32_t n)
6517 while (visual_states.size() <= n) {
6518 visual_states.push_back (0);
6521 delete visual_states[n];
6523 visual_states[n] = current_visual_state (true);
6528 Editor::goto_visual_state (uint32_t n)
6530 if (visual_states.size() <= n) {
6534 if (visual_states[n] == 0) {
6538 use_visual_state (*visual_states[n]);
6542 Editor::start_visual_state_op (uint32_t n)
6544 if (visual_state_op_connection.empty()) {
6545 visual_state_op_connection = Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun (*this, &Editor::end_visual_state_op), n), 1000);
6550 Editor::cancel_visual_state_op (uint32_t n)
6552 if (!visual_state_op_connection.empty()) {
6553 visual_state_op_connection.disconnect();
6554 goto_visual_state (n);
6556 //we land here if called from the menu OR if end_visual_state_op has been called
6557 //so check if we are already in visual state n
6558 // XXX not yet checking it at all, but redoing does not hurt
6559 goto_visual_state (n);
6564 Editor::end_visual_state_op (uint32_t n)
6566 visual_state_op_connection.disconnect();
6567 save_visual_state (n);
6569 PopUp* pup = new PopUp (WIN_POS_MOUSE, 1000, true);
6571 snprintf (buf, sizeof (buf), _("Saved view %u"), n+1);
6572 pup->set_text (buf);
6575 return false; // do not call again
6579 Editor::toggle_region_mute ()
6581 if (_ignore_region_action) {
6585 RegionSelection rs = get_regions_from_selection_and_entered ();
6591 if (rs.size() > 1) {
6592 begin_reversible_command (_("mute regions"));
6594 begin_reversible_command (_("mute region"));
6597 for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
6599 (*i)->region()->playlist()->clear_changes ();
6600 (*i)->region()->set_muted (!(*i)->region()->muted ());
6601 _session->add_command (new StatefulDiffCommand ((*i)->region()->playlist()));
6605 commit_reversible_command ();
6609 Editor::combine_regions ()
6611 /* foreach track with selected regions, take all selected regions
6612 and join them into a new region containing the subregions (as a
6616 typedef set<RouteTimeAxisView*> RTVS;
6619 if (selection->regions.empty()) {
6623 for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
6624 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&(*i)->get_time_axis_view());
6627 tracks.insert (rtv);
6631 begin_reversible_command (_("combine regions"));
6633 vector<RegionView*> new_selection;
6635 for (RTVS::iterator i = tracks.begin(); i != tracks.end(); ++i) {
6638 if ((rv = (*i)->combine_regions ()) != 0) {
6639 new_selection.push_back (rv);
6643 selection->clear_regions ();
6644 for (vector<RegionView*>::iterator i = new_selection.begin(); i != new_selection.end(); ++i) {
6645 selection->add (*i);
6648 commit_reversible_command ();
6652 Editor::uncombine_regions ()
6654 typedef set<RouteTimeAxisView*> RTVS;
6657 if (selection->regions.empty()) {
6661 for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
6662 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&(*i)->get_time_axis_view());
6665 tracks.insert (rtv);
6669 begin_reversible_command (_("uncombine regions"));
6671 for (RTVS::iterator i = tracks.begin(); i != tracks.end(); ++i) {
6672 (*i)->uncombine_regions ();
6675 commit_reversible_command ();