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.
28 #include <pbd/error.h>
29 #include <pbd/basename.h>
30 #include <pbd/pthread_utils.h>
31 #include <pbd/memento_command.h>
32 #include <pbd/whitespace.h>
34 #include <gtkmm2ext/utils.h>
35 #include <gtkmm2ext/choice.h>
36 #include <gtkmm2ext/window_title.h>
37 #include <gtkmm2ext/popup.h>
39 #include <ardour/audioengine.h>
40 #include <ardour/session.h>
41 #include <ardour/audioplaylist.h>
42 #include <ardour/audioregion.h>
43 #include <ardour/audio_diskstream.h>
44 #include <ardour/utils.h>
45 #include <ardour/location.h>
46 #include <ardour/named_selection.h>
47 #include <ardour/audio_track.h>
48 #include <ardour/audiofilesource.h>
49 #include <ardour/audioplaylist.h>
50 #include <ardour/region_factory.h>
51 #include <ardour/playlist_factory.h>
52 #include <ardour/reverse.h>
53 #include <ardour/transient_detector.h>
54 #include <ardour/dB.h>
56 #include "ardour_ui.h"
58 #include "time_axis_view.h"
59 #include "route_time_axis.h"
60 #include "audio_time_axis.h"
61 #include "automation_time_axis.h"
62 #include "streamview.h"
63 #include "audio_streamview.h"
64 #include "audio_region_view.h"
65 #include "rgb_macros.h"
66 #include "selection_templates.h"
67 #include "selection.h"
69 #include "gtk-custom-hruler.h"
70 #include "gui_thread.h"
77 using namespace ARDOUR
;
81 using namespace Gtkmm2ext
;
82 using namespace Editing
;
84 /***********************************************************************
86 ***********************************************************************/
89 Editor::undo (uint32_t n
)
97 Editor::redo (uint32_t n
)
105 Editor::split_region ()
107 split_region_at (get_preferred_edit_position());
111 Editor::split_region_at (nframes64_t where
)
115 get_regions_for_action (rs
);
116 split_regions_at (where
, selection
->regions
);
120 Editor::split_regions_at (nframes64_t where
, RegionSelection
& regions
)
122 if (regions
.empty()) {
126 begin_reversible_command (_("split"));
128 // if splitting a single region, and snap-to is using
129 // region boundaries, don't pay attention to them
131 if (regions
.size() == 1) {
133 case SnapToRegionStart
:
134 case SnapToRegionSync
:
135 case SnapToRegionEnd
:
144 for (RegionSelection::iterator a
= regions
.begin(); a
!= regions
.end(); ) {
146 RegionSelection::iterator tmp
;
148 /* XXX this test needs to be more complicated, to make sure we really
149 have something to split.
152 if (!(*a
)->region()->covers (where
)) {
160 boost::shared_ptr
<Playlist
> pl
= (*a
)->region()->playlist();
162 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*a
);
165 _new_regionviews_show_envelope
= arv
->envelope_visible();
169 XMLNode
&before
= pl
->get_state();
170 pl
->split_region ((*a
)->region(), where
);
171 XMLNode
&after
= pl
->get_state();
172 session
->add_command(new MementoCommand
<Playlist
>(*pl
, &before
, &after
));
178 commit_reversible_command ();
179 _new_regionviews_show_envelope
= false;
183 Editor::remove_clicked_region ()
185 if (clicked_audio_trackview
== 0 || clicked_regionview
== 0) {
189 boost::shared_ptr
<Playlist
> playlist
= clicked_audio_trackview
->playlist();
191 begin_reversible_command (_("remove region"));
192 XMLNode
&before
= playlist
->get_state();
193 playlist
->remove_region (clicked_regionview
->region());
194 XMLNode
&after
= playlist
->get_state();
195 session
->add_command(new MementoCommand
<Playlist
>(*playlist
, &before
, &after
));
196 commit_reversible_command ();
200 Editor::remove_region ()
204 get_regions_for_action (rs
);
214 begin_reversible_command (_("remove region"));
216 list
<boost::shared_ptr
<Region
> > regions_to_remove
;
218 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
219 // we can't just remove the region(s) in this loop because
220 // this removes them from the RegionSelection, and they thus
221 // disappear from underneath the iterator, and the ++i above
222 // SEGVs in a puzzling fashion.
224 // so, first iterate over the regions to be removed from rs and
225 // add them to the regions_to_remove list, and then
226 // iterate over the list to actually remove them.
228 regions_to_remove
.push_back ((*i
)->region());
231 for (list
<boost::shared_ptr
<Region
> >::iterator rl
= regions_to_remove
.begin(); rl
!= regions_to_remove
.end(); ++rl
) {
232 boost::shared_ptr
<Playlist
> playlist
= (*rl
)->playlist();
234 // is this check necessary?
238 XMLNode
&before
= playlist
->get_state();
239 playlist
->remove_region (*rl
);
240 XMLNode
&after
= playlist
->get_state();
241 session
->add_command(new MementoCommand
<Playlist
>(*playlist
, &before
, &after
));
243 commit_reversible_command ();
246 boost::shared_ptr
<Region
>
247 Editor::select_region_for_operation (int dir
, TimeAxisView
**tv
)
250 boost::shared_ptr
<Region
> region
;
251 nframes64_t start
= 0;
253 if (selection
->time
.start () == selection
->time
.end_frame ()) {
255 /* no current selection-> is there a selected regionview? */
257 if (selection
->regions
.empty()) {
263 if (!selection
->regions
.empty()) {
265 rv
= *(selection
->regions
.begin());
266 (*tv
) = &rv
->get_time_axis_view();
267 region
= rv
->region();
269 } else if (!selection
->tracks
.empty()) {
271 (*tv
) = selection
->tracks
.front();
273 RouteTimeAxisView
* rtv
;
275 if ((rtv
= dynamic_cast<RouteTimeAxisView
*> (*tv
)) != 0) {
276 boost::shared_ptr
<Playlist
> pl
;
278 if ((pl
= rtv
->playlist()) == 0) {
282 region
= pl
->top_region_at (start
);
290 Editor::extend_selection_to_end_of_region (bool next
)
293 boost::shared_ptr
<Region
> region
;
296 if ((region
= select_region_for_operation (next
? 1 : 0, &tv
)) == 0) {
300 if (region
&& selection
->time
.start () == selection
->time
.end_frame ()) {
301 start
= region
->position();
303 start
= selection
->time
.start ();
306 /* Try to leave the selection with the same route if possible */
308 if ((tv
= selection
->time
.track
) == 0) {
312 begin_reversible_command (_("extend selection"));
313 selection
->set (tv
, start
, region
->position() + region
->length());
314 commit_reversible_command ();
318 Editor::extend_selection_to_start_of_region (bool previous
)
321 boost::shared_ptr
<Region
> region
;
324 if ((region
= select_region_for_operation (previous
? -1 : 0, &tv
)) == 0) {
328 if (region
&& selection
->time
.start () == selection
->time
.end_frame ()) {
329 end
= region
->position() + region
->length();
331 end
= selection
->time
.end_frame ();
334 /* Try to leave the selection with the same route if possible */
336 if ((tv
= selection
->time
.track
) == 0) {
340 begin_reversible_command (_("extend selection"));
341 selection
->set (tv
, region
->position(), end
);
342 commit_reversible_command ();
346 Editor::nudge_forward_release (GdkEventButton
* ev
)
348 if (ev
->state
& Keyboard::PrimaryModifier
) {
349 nudge_forward (false, true);
351 nudge_forward (false, false);
357 Editor::nudge_backward_release (GdkEventButton
* ev
)
359 if (ev
->state
& Keyboard::PrimaryModifier
) {
360 nudge_backward (false, true);
362 nudge_backward (false, false);
369 Editor::nudge_forward (bool next
, bool force_playhead
)
371 nframes64_t distance
;
372 nframes64_t next_distance
;
375 get_regions_for_action (rs
);
377 if (!session
) return;
379 if (!force_playhead
&& !rs
.empty()) {
381 begin_reversible_command (_("nudge regions forward"));
383 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
384 boost::shared_ptr
<Region
> r ((*i
)->region());
386 distance
= get_nudge_distance (r
->position(), next_distance
);
389 distance
= next_distance
;
392 XMLNode
&before
= r
->playlist()->get_state();
393 r
->set_position (r
->position() + distance
, this);
394 XMLNode
&after
= r
->playlist()->get_state();
395 session
->add_command (new MementoCommand
<Playlist
>(*(r
->playlist()), &before
, &after
));
398 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 (max_frames
- distance
> loc
->start() + loc
->length()) {
421 loc
->set_start (loc
->start() + distance
);
423 loc
->set_start (max_frames
- loc
->length());
426 distance
= get_nudge_distance (loc
->end(), next_distance
);
428 distance
= next_distance
;
430 if (max_frames
- distance
> loc
->end()) {
431 loc
->set_end (loc
->end() + distance
);
433 loc
->set_end (max_frames
);
436 XMLNode
& after (loc
->get_state());
437 session
->add_command (new MementoCommand
<Location
>(*loc
, &before
, &after
));
441 commit_reversible_command ();
444 distance
= get_nudge_distance (playhead_cursor
->current_frame
, next_distance
);
445 session
->request_locate (playhead_cursor
->current_frame
+ distance
);
450 Editor::nudge_backward (bool next
, bool force_playhead
)
452 nframes64_t distance
;
453 nframes64_t next_distance
;
456 get_regions_for_action (rs
);
458 if (!session
) return;
460 if (!force_playhead
&& !rs
.empty()) {
462 begin_reversible_command (_("nudge regions backward"));
464 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
465 boost::shared_ptr
<Region
> r ((*i
)->region());
467 distance
= get_nudge_distance (r
->position(), next_distance
);
470 distance
= next_distance
;
473 XMLNode
&before
= r
->playlist()->get_state();
475 if (r
->position() > distance
) {
476 r
->set_position (r
->position() - distance
, this);
478 r
->set_position (0, this);
480 XMLNode
&after
= r
->playlist()->get_state();
481 session
->add_command(new MementoCommand
<Playlist
>(*(r
->playlist()), &before
, &after
));
484 commit_reversible_command ();
486 } else if (!force_playhead
&& !selection
->markers
.empty()) {
490 begin_reversible_command (_("nudge location forward"));
492 for (MarkerSelection::iterator i
= selection
->markers
.begin(); i
!= selection
->markers
.end(); ++i
) {
494 Location
* loc
= find_location_from_marker ((*i
), is_start
);
498 XMLNode
& before (loc
->get_state());
501 distance
= get_nudge_distance (loc
->start(), next_distance
);
503 distance
= next_distance
;
505 if (distance
< loc
->start()) {
506 loc
->set_start (loc
->start() - distance
);
511 distance
= get_nudge_distance (loc
->end(), next_distance
);
514 distance
= next_distance
;
517 if (distance
< loc
->end() - loc
->length()) {
518 loc
->set_end (loc
->end() - distance
);
520 loc
->set_end (loc
->length());
524 XMLNode
& after (loc
->get_state());
525 session
->add_command (new MementoCommand
<Location
>(*loc
, &before
, &after
));
529 commit_reversible_command ();
533 distance
= get_nudge_distance (playhead_cursor
->current_frame
, next_distance
);
535 if (playhead_cursor
->current_frame
> distance
) {
536 session
->request_locate (playhead_cursor
->current_frame
- distance
);
538 session
->goto_start();
544 Editor::nudge_forward_capture_offset ()
546 nframes64_t distance
;
549 get_regions_for_action (rs
);
551 if (!session
) return;
555 begin_reversible_command (_("nudge forward"));
557 distance
= session
->worst_output_latency();
559 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
560 boost::shared_ptr
<Region
> r ((*i
)->region());
562 XMLNode
&before
= r
->playlist()->get_state();
563 r
->set_position (r
->position() + distance
, this);
564 XMLNode
&after
= r
->playlist()->get_state();
565 session
->add_command(new MementoCommand
<Playlist
>(*(r
->playlist()), &before
, &after
));
568 commit_reversible_command ();
574 Editor::nudge_backward_capture_offset ()
576 nframes64_t distance
;
579 get_regions_for_action (rs
);
581 if (!session
) return;
585 begin_reversible_command (_("nudge forward"));
587 distance
= session
->worst_output_latency();
589 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
590 boost::shared_ptr
<Region
> r ((*i
)->region());
592 XMLNode
&before
= r
->playlist()->get_state();
594 if (r
->position() > distance
) {
595 r
->set_position (r
->position() - distance
, this);
597 r
->set_position (0, this);
599 XMLNode
&after
= r
->playlist()->get_state();
600 session
->add_command(new MementoCommand
<Playlist
>(*(r
->playlist()), &before
, &after
));
603 commit_reversible_command ();
610 Editor::move_to_start ()
612 session
->goto_start ();
616 Editor::move_to_end ()
619 session
->request_locate (session
->current_end_frame());
623 Editor::build_region_boundary_cache ()
626 vector
<RegionPoint
> interesting_points
;
627 boost::shared_ptr
<Region
> r
;
628 TrackViewList tracks
;
631 region_boundary_cache
.clear ();
638 case SnapToRegionStart
:
639 interesting_points
.push_back (Start
);
641 case SnapToRegionEnd
:
642 interesting_points
.push_back (End
);
644 case SnapToRegionSync
:
645 interesting_points
.push_back (SyncPoint
);
647 case SnapToRegionBoundary
:
648 interesting_points
.push_back (Start
);
649 interesting_points
.push_back (End
);
652 fatal
<< string_compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type
) << endmsg
;
657 TimeAxisView
*ontrack
= 0;
660 if (!selection
->tracks
.empty()) {
661 tlist
= selection
->tracks
;
666 while (pos
< session
->current_end_frame() && !at_end
) {
669 nframes64_t lpos
= max_frames
;
671 for (vector
<RegionPoint
>::iterator p
= interesting_points
.begin(); p
!= interesting_points
.end(); ++p
) {
673 if ((r
= find_next_region (pos
, *p
, 1, tlist
, &ontrack
)) == 0) {
674 if (*p
== interesting_points
.back()) {
677 /* move to next point type */
683 rpos
= r
->first_frame();
687 rpos
= r
->last_frame();
691 rpos
= r
->sync_position ();
692 //r->adjust_to_sync (r->first_frame());
700 AudioTimeAxisView
*atav
;
702 if (ontrack
!= 0 && (atav
= dynamic_cast<AudioTimeAxisView
*>(ontrack
)) != 0 ) {
703 if (atav
->get_diskstream() != 0) {
704 speed
= atav
->get_diskstream()->speed();
708 rpos
= track_frame_to_session_frame (rpos
, speed
);
714 /* prevent duplicates, but we don't use set<> because we want to be able
718 vector
<nframes64_t
>::iterator ri
;
720 for (ri
= region_boundary_cache
.begin(); ri
!= region_boundary_cache
.end(); ++ri
) {
726 if (ri
== region_boundary_cache
.end()) {
727 region_boundary_cache
.push_back (rpos
);
734 /* finally sort to be sure that the order is correct */
736 sort (region_boundary_cache
.begin(), region_boundary_cache
.end());
739 boost::shared_ptr
<Region
>
740 Editor::find_next_region (nframes64_t frame
, RegionPoint point
, int32_t dir
, TrackViewList
& tracks
, TimeAxisView
**ontrack
)
742 TrackViewList::iterator i
;
743 nframes64_t closest
= max_frames
;
744 boost::shared_ptr
<Region
> ret
;
745 nframes64_t rpos
= 0;
748 nframes64_t track_frame
;
749 AudioTimeAxisView
*atav
;
751 for (i
= tracks
.begin(); i
!= tracks
.end(); ++i
) {
753 nframes64_t distance
;
754 boost::shared_ptr
<Region
> r
;
757 if ( (atav
= dynamic_cast<AudioTimeAxisView
*>(*i
)) != 0 ) {
758 if (atav
->get_diskstream()!=0)
759 track_speed
= atav
->get_diskstream()->speed();
762 track_frame
= session_frame_to_track_frame(frame
, track_speed
);
764 if ((r
= (*i
)->find_next_region (track_frame
, point
, dir
)) == 0) {
770 rpos
= r
->first_frame ();
774 rpos
= r
->last_frame ();
778 rpos
= r
->sync_position ();
779 // r->adjust_to_sync (r->first_frame());
783 // rpos is a "track frame", converting it to "session frame"
784 rpos
= track_frame_to_session_frame(rpos
, track_speed
);
787 distance
= rpos
- frame
;
789 distance
= frame
- rpos
;
792 if (distance
< closest
) {
804 Editor::find_next_region_boundary (nframes64_t pos
, int32_t dir
, const TrackViewList
& tracks
)
806 nframes64_t distance
= max_frames
;
807 nframes64_t current_nearest
= -1;
810 for (TrackViewList::const_iterator i
= tracks
.begin(); i
!= tracks
.end(); ++i
) {
811 nframes64_t contender
;
814 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*> (*i
);
820 if ((contender
= rtv
->find_next_region_boundary (pos
, dir
)) < 0) {
824 d
= ::llabs (pos
- contender
);
827 current_nearest
= contender
;
832 return current_nearest
;
836 Editor::get_region_boundary (nframes64_t pos
, int32_t dir
, bool with_selection
, bool only_onscreen
)
841 if (with_selection
&& Config
->get_region_boundaries_from_selected_tracks()) {
843 if (!selection
->tracks
.empty()) {
845 target
= find_next_region_boundary (pos
, dir
, selection
->tracks
);
849 if (only_onscreen
|| Config
->get_region_boundaries_from_onscreen_tracks()) {
850 get_onscreen_tracks (tvl
);
851 target
= find_next_region_boundary (pos
, dir
, tvl
);
853 target
= find_next_region_boundary (pos
, dir
, track_views
);
859 if (only_onscreen
|| Config
->get_region_boundaries_from_onscreen_tracks()) {
860 get_onscreen_tracks (tvl
);
861 target
= find_next_region_boundary (pos
, dir
, tvl
);
863 target
= find_next_region_boundary (pos
, dir
, track_views
);
871 Editor::cursor_to_region_boundary (bool with_selection
, int32_t dir
)
873 nframes64_t pos
= playhead_cursor
->current_frame
;
880 // so we don't find the current region again..
881 if (dir
> 0 || pos
> 0) {
885 if ((target
= get_region_boundary (pos
, dir
, with_selection
, false)) < 0) {
890 session
->request_locate (target
);
894 Editor::cursor_to_next_region_boundary (bool with_selection
)
896 cursor_to_region_boundary (with_selection
, 1);
900 Editor::cursor_to_previous_region_boundary (bool with_selection
)
902 cursor_to_region_boundary (with_selection
, -1);
906 Editor::cursor_to_region_point (Cursor
* cursor
, RegionPoint point
, int32_t dir
)
908 boost::shared_ptr
<Region
> r
;
909 nframes64_t pos
= cursor
->current_frame
;
915 TimeAxisView
*ontrack
= 0;
917 // so we don't find the current region again..
921 if (!selection
->tracks
.empty()) {
923 r
= find_next_region (pos
, point
, dir
, selection
->tracks
, &ontrack
);
925 } else if (clicked_trackview
) {
928 t
.push_back (clicked_trackview
);
930 r
= find_next_region (pos
, point
, dir
, t
, &ontrack
);
934 r
= find_next_region (pos
, point
, dir
, track_views
, &ontrack
);
943 pos
= r
->first_frame ();
947 pos
= r
->last_frame ();
951 pos
= r
->sync_position ();
952 // r->adjust_to_sync (r->first_frame());
957 AudioTimeAxisView
*atav
;
959 if ( ontrack
!= 0 && (atav
= dynamic_cast<AudioTimeAxisView
*>(ontrack
)) != 0 ) {
960 if (atav
->get_diskstream() != 0) {
961 speed
= atav
->get_diskstream()->speed();
965 pos
= track_frame_to_session_frame(pos
, speed
);
967 if (cursor
== playhead_cursor
) {
968 session
->request_locate (pos
);
970 cursor
->set_position (pos
);
975 Editor::cursor_to_next_region_point (Cursor
* cursor
, RegionPoint point
)
977 cursor_to_region_point (cursor
, point
, 1);
981 Editor::cursor_to_previous_region_point (Cursor
* cursor
, RegionPoint point
)
983 cursor_to_region_point (cursor
, point
, -1);
987 Editor::cursor_to_selection_start (Cursor
*cursor
)
992 get_regions_for_action (rs
);
994 switch (mouse_mode
) {
1002 if (!selection
->time
.empty()) {
1003 pos
= selection
->time
.start ();
1011 if (cursor
== playhead_cursor
) {
1012 session
->request_locate (pos
);
1014 cursor
->set_position (pos
);
1019 Editor::cursor_to_selection_end (Cursor
*cursor
)
1021 nframes64_t pos
= 0;
1024 get_regions_for_action (rs
);
1026 switch (mouse_mode
) {
1029 pos
= rs
.end_frame();
1034 if (!selection
->time
.empty()) {
1035 pos
= selection
->time
.end_frame ();
1043 if (cursor
== playhead_cursor
) {
1044 session
->request_locate (pos
);
1046 cursor
->set_position (pos
);
1051 Editor::selected_marker_to_region_boundary (bool with_selection
, int32_t dir
)
1061 if (selection
->markers
.empty()) {
1065 if (!mouse_frame (mouse
, ignored
)) {
1069 add_location_mark (mouse
);
1072 if ((loc
= find_location_from_marker (selection
->markers
.front(), ignored
)) == 0) {
1076 nframes64_t pos
= loc
->start();
1078 // so we don't find the current region again..
1079 if (dir
> 0 || pos
> 0) {
1083 if ((target
= get_region_boundary (pos
, dir
, with_selection
, false)) < 0) {
1087 loc
->move_to (target
);
1091 Editor::selected_marker_to_next_region_boundary (bool with_selection
)
1093 selected_marker_to_region_boundary (with_selection
, 1);
1097 Editor::selected_marker_to_previous_region_boundary (bool with_selection
)
1099 selected_marker_to_region_boundary (with_selection
, -1);
1103 Editor::selected_marker_to_region_point (RegionPoint point
, int32_t dir
)
1105 boost::shared_ptr
<Region
> r
;
1110 if (!session
|| selection
->markers
.empty()) {
1114 if ((loc
= find_location_from_marker (selection
->markers
.front(), ignored
)) == 0) {
1118 TimeAxisView
*ontrack
= 0;
1122 // so we don't find the current region again..
1126 if (!selection
->tracks
.empty()) {
1128 r
= find_next_region (pos
, point
, dir
, selection
->tracks
, &ontrack
);
1130 } else if (clicked_trackview
) {
1133 t
.push_back (clicked_trackview
);
1135 r
= find_next_region (pos
, point
, dir
, t
, &ontrack
);
1139 r
= find_next_region (pos
, point
, dir
, track_views
, &ontrack
);
1148 pos
= r
->first_frame ();
1152 pos
= r
->last_frame ();
1156 pos
= r
->adjust_to_sync (r
->first_frame());
1161 AudioTimeAxisView
*atav
;
1163 if ( ontrack
!= 0 && (atav
= dynamic_cast<AudioTimeAxisView
*>(ontrack
)) != 0 ) {
1164 if (atav
->get_diskstream() != 0) {
1165 speed
= atav
->get_diskstream()->speed();
1169 pos
= track_frame_to_session_frame(pos
, speed
);
1175 Editor::selected_marker_to_next_region_point (RegionPoint point
)
1177 selected_marker_to_region_point (point
, 1);
1181 Editor::selected_marker_to_previous_region_point (RegionPoint point
)
1183 selected_marker_to_region_point (point
, -1);
1187 Editor::selected_marker_to_selection_start ()
1189 nframes64_t pos
= 0;
1193 if (!session
|| selection
->markers
.empty()) {
1197 if ((loc
= find_location_from_marker (selection
->markers
.front(), ignored
)) == 0) {
1203 get_regions_for_action (rs
);
1205 switch (mouse_mode
) {
1213 if (!selection
->time
.empty()) {
1214 pos
= selection
->time
.start ();
1226 Editor::selected_marker_to_selection_end ()
1228 nframes64_t pos
= 0;
1232 if (!session
|| selection
->markers
.empty()) {
1236 if ((loc
= find_location_from_marker (selection
->markers
.front(), ignored
)) == 0) {
1242 get_regions_for_action (rs
);
1244 switch (mouse_mode
) {
1247 pos
= rs
.end_frame();
1252 if (!selection
->time
.empty()) {
1253 pos
= selection
->time
.end_frame ();
1265 Editor::scroll_playhead (bool forward
)
1267 nframes64_t pos
= playhead_cursor
->current_frame
;
1268 nframes64_t delta
= (nframes64_t
) floor (current_page_frames() / 0.8);
1271 if (pos
== max_frames
) {
1275 if (pos
< max_frames
- delta
) {
1294 session
->request_locate (pos
);
1298 Editor::playhead_backward ()
1305 if (get_prefix (prefix
, was_floating
)) {
1309 cnt
= (nframes64_t
) floor (prefix
* session
->frame_rate ());
1311 cnt
= (nframes64_t
) prefix
;
1315 pos
= playhead_cursor
->current_frame
;
1317 if ((nframes64_t
) pos
< cnt
) {
1323 /* XXX this is completely insane. with the current buffering
1324 design, we'll force a complete track buffer flush and
1325 reload, just to move 1 sample !!!
1328 session
->request_locate (pos
);
1332 Editor::playhead_forward ()
1339 if (get_prefix (prefix
, was_floating
)) {
1343 cnt
= (nframes64_t
) floor (prefix
* session
->frame_rate ());
1345 cnt
= (nframes64_t
) floor (prefix
);
1349 pos
= playhead_cursor
->current_frame
;
1351 /* XXX this is completely insane. with the current buffering
1352 design, we'll force a complete track buffer flush and
1353 reload, just to move 1 sample !!!
1356 session
->request_locate (pos
+cnt
);
1360 Editor::cursor_align (bool playhead_to_edit
)
1366 if (playhead_to_edit
) {
1368 if (selection
->markers
.empty()) {
1372 session
->request_locate (selection
->markers
.front()->position(), session
->transport_rolling());
1376 /* move selected markers to playhead */
1378 for (MarkerSelection::iterator i
= selection
->markers
.begin(); i
!= selection
->markers
.end(); ++i
) {
1381 Location
* loc
= find_location_from_marker (*i
, ignored
);
1383 if (loc
->is_mark()) {
1384 loc
->set_start (playhead_cursor
->current_frame
);
1386 loc
->set (playhead_cursor
->current_frame
,
1387 playhead_cursor
->current_frame
+ loc
->length());
1394 Editor::edit_cursor_backward ()
1401 if (get_prefix (prefix
, was_floating
)) {
1405 cnt
= (nframes64_t
) floor (prefix
* session
->frame_rate ());
1407 cnt
= (nframes64_t
) prefix
;
1411 if ((pos
= get_preferred_edit_position()) < 0) {
1421 // EDIT CURSOR edit_cursor->set_position (pos);
1425 Editor::edit_cursor_forward ()
1432 if (get_prefix (prefix
, was_floating
)) {
1436 cnt
= (nframes64_t
) floor (prefix
* session
->frame_rate ());
1438 cnt
= (nframes64_t
) floor (prefix
);
1442 // pos = edit_cursor->current_frame;
1443 // EDIT CURSOR edit_cursor->set_position (pos+cnt);
1447 Editor::goto_frame ()
1453 if (get_prefix (prefix
, was_floating
)) {
1458 frame
= (nframes64_t
) floor (prefix
* session
->frame_rate());
1460 frame
= (nframes64_t
) floor (prefix
);
1463 session
->request_locate (frame
);
1467 Editor::scroll_backward (float pages
)
1470 nframes64_t one_page
= (nframes64_t
) rint (canvas_width
* frames_per_unit
);
1475 if (get_prefix (prefix
, was_floating
)) {
1476 cnt
= (nframes64_t
) floor (pages
* one_page
);
1479 cnt
= (nframes64_t
) floor (prefix
* session
->frame_rate());
1481 cnt
= (nframes64_t
) floor (prefix
* one_page
);
1485 if (leftmost_frame
< cnt
) {
1488 frame
= leftmost_frame
- cnt
;
1491 reset_x_origin (frame
);
1495 Editor::scroll_forward (float pages
)
1498 nframes64_t one_page
= (nframes64_t
) rint (canvas_width
* frames_per_unit
);
1503 if (get_prefix (prefix
, was_floating
)) {
1504 cnt
= (nframes64_t
) floor (pages
* one_page
);
1507 cnt
= (nframes64_t
) floor (prefix
* session
->frame_rate());
1509 cnt
= (nframes64_t
) floor (prefix
* one_page
);
1513 if (max_frames
- cnt
< leftmost_frame
) {
1514 frame
= max_frames
- cnt
;
1516 frame
= leftmost_frame
+ cnt
;
1519 reset_x_origin (frame
);
1523 Editor::scroll_tracks_down ()
1529 if (get_prefix (prefix
, was_floating
)) {
1532 cnt
= (int) floor (prefix
);
1535 double vert_value
= vertical_adjustment
.get_value() + (cnt
*
1536 vertical_adjustment
.get_page_size());
1537 if (vert_value
> vertical_adjustment
.get_upper() - canvas_height
) {
1538 vert_value
= vertical_adjustment
.get_upper() - canvas_height
;
1540 vertical_adjustment
.set_value (vert_value
);
1544 Editor::scroll_tracks_up ()
1550 if (get_prefix (prefix
, was_floating
)) {
1553 cnt
= (int) floor (prefix
);
1556 vertical_adjustment
.set_value (vertical_adjustment
.get_value() - (cnt
* vertical_adjustment
.get_page_size()));
1560 Editor::scroll_tracks_down_line ()
1563 Gtk::Adjustment
* adj
= edit_vscrollbar
.get_adjustment();
1564 double vert_value
= adj
->get_value() + 60;
1566 if (vert_value
>adj
->get_upper() - canvas_height
) {
1567 vert_value
= adj
->get_upper() - canvas_height
;
1569 adj
->set_value (vert_value
);
1573 Editor::scroll_tracks_up_line ()
1575 Gtk::Adjustment
* adj
= edit_vscrollbar
.get_adjustment();
1576 adj
->set_value (adj
->get_value() - 60);
1582 Editor::temporal_zoom_step (bool coarser
)
1584 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::temporal_zoom_step
), coarser
));
1588 nfpu
= frames_per_unit
;
1593 nfpu
= max(1.0,(nfpu
/1.61803399));
1596 temporal_zoom (nfpu
);
1600 Editor::temporal_zoom (gdouble fpu
)
1602 if (!session
) return;
1604 nframes64_t current_page
= current_page_frames();
1605 nframes64_t current_leftmost
= leftmost_frame
;
1606 nframes64_t current_rightmost
;
1607 nframes64_t current_center
;
1608 nframes64_t new_page_size
;
1609 nframes64_t half_page_size
;
1610 nframes64_t leftmost_after_zoom
= 0;
1612 bool in_track_canvas
;
1616 /* XXX this limit is also in ::set_frames_per_unit() */
1618 if (frames_per_unit
< 1.0 && fpu
<= frames_per_unit
) {
1624 new_page_size
= (nframes64_t
) floor (canvas_width
* nfpu
);
1625 half_page_size
= new_page_size
/ 2;
1627 switch (zoom_focus
) {
1629 leftmost_after_zoom
= current_leftmost
;
1632 case ZoomFocusRight
:
1633 current_rightmost
= leftmost_frame
+ current_page
;
1634 if (current_rightmost
< new_page_size
) {
1635 leftmost_after_zoom
= 0;
1637 leftmost_after_zoom
= current_rightmost
- new_page_size
;
1641 case ZoomFocusCenter
:
1642 current_center
= current_leftmost
+ (current_page
/2);
1643 if (current_center
< half_page_size
) {
1644 leftmost_after_zoom
= 0;
1646 leftmost_after_zoom
= current_center
- half_page_size
;
1650 case ZoomFocusPlayhead
:
1651 /* try to keep the playhead in the same place */
1653 where
= playhead_cursor
->current_frame
;
1655 l
= - ((new_page_size
* ((where
- current_leftmost
)/(double)current_page
)) - where
);
1658 leftmost_after_zoom
= 0;
1659 } else if (l
> max_frames
) {
1660 leftmost_after_zoom
= max_frames
- new_page_size
;
1662 leftmost_after_zoom
= (nframes64_t
) l
;
1666 case ZoomFocusMouse
:
1667 /* try to keep the mouse over the same point in the display */
1669 if (!mouse_frame (where
, in_track_canvas
)) {
1670 /* use playhead instead */
1671 where
= playhead_cursor
->current_frame
;
1673 if (where
< half_page_size
) {
1674 leftmost_after_zoom
= 0;
1676 leftmost_after_zoom
= where
- half_page_size
;
1681 l
= - ((new_page_size
* ((where
- current_leftmost
)/(double)current_page
)) - where
);
1684 leftmost_after_zoom
= 0;
1685 } else if (l
> max_frames
) {
1686 leftmost_after_zoom
= max_frames
- new_page_size
;
1688 leftmost_after_zoom
= (nframes64_t
) l
;
1695 /* try to keep the edit point in the same place */
1696 where
= get_preferred_edit_position ();
1700 double l
= - ((new_page_size
* ((where
- current_leftmost
)/(double)current_page
)) - where
);
1703 leftmost_after_zoom
= 0;
1704 } else if (l
> max_frames
) {
1705 leftmost_after_zoom
= max_frames
- new_page_size
;
1707 leftmost_after_zoom
= (nframes64_t
) l
;
1711 /* edit point not defined */
1718 // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
1720 reposition_and_zoom (leftmost_after_zoom
, nfpu
);
1724 Editor::temporal_zoom_region (bool both_axes
)
1727 nframes64_t start
= max_frames
;
1728 nframes64_t end
= 0;
1730 set
<TimeAxisView
*> tracks
;
1732 get_regions_for_action (rs
);
1738 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
1740 if ((*i
)->region()->position() < start
) {
1741 start
= (*i
)->region()->position();
1744 if ((*i
)->region()->last_frame() + 1 > end
) {
1745 end
= (*i
)->region()->last_frame() + 1;
1748 tracks
.insert (&((*i
)->get_time_axis_view()));
1751 /* now comes an "interesting" hack ... make sure we leave a little space
1752 at each end of the editor so that the zoom doesn't fit the region
1753 precisely to the screen.
1756 GdkScreen
* screen
= gdk_screen_get_default ();
1757 gint pixwidth
= gdk_screen_get_width (screen
);
1758 gint mmwidth
= gdk_screen_get_width_mm (screen
);
1759 double pix_per_mm
= (double) pixwidth
/ (double) mmwidth
;
1760 double one_centimeter_in_pixels
= pix_per_mm
* 10.0;
1762 if ((start
== 0 && end
== 0) || end
< start
) {
1766 nframes64_t range
= end
- start
;
1767 double new_fpu
= (double)range
/ (double)canvas_width
;
1768 nframes64_t extra_samples
= (nframes64_t
) floor (one_centimeter_in_pixels
* new_fpu
);
1770 if (start
> extra_samples
) {
1771 start
-= extra_samples
;
1776 if (max_frames
- extra_samples
> end
) {
1777 end
+= extra_samples
;
1783 /* save visual state with track states included, and prevent
1784 set_frames_per_unit() from doing it again.
1786 undo_visual_stack
.push_back (current_visual_state(true));
1787 no_save_visual
= true;
1790 temporal_zoom_by_frame (start
, end
, "zoom to region");
1793 uint32_t per_track_height
= (uint32_t) floor ((canvas_height
- canvas_timebars_vsize
- 10.0) / tracks
.size());
1795 /* set visible track heights appropriately */
1797 for (set
<TimeAxisView
*>::iterator t
= tracks
.begin(); t
!= tracks
.end(); ++t
) {
1798 (*t
)->set_height (per_track_height
);
1801 /* hide irrelevant tracks */
1803 no_route_list_redisplay
= true;
1805 for (TrackViewList::iterator i
= track_views
.begin(); i
!= track_views
.end(); ++i
) {
1806 if (find (tracks
.begin(), tracks
.end(), (*i
)) == tracks
.end()) {
1807 hide_track_in_display (**i
, true);
1811 no_route_list_redisplay
= false;
1812 redisplay_route_list ();
1814 vertical_adjustment
.set_value (0);
1815 no_save_visual
= false;
1818 zoomed_to_region
= true;
1819 redo_visual_stack
.push_back (current_visual_state());
1823 Editor::toggle_zoom_region (bool both_axes
)
1825 if (zoomed_to_region
) {
1826 swap_visual_state ();
1828 temporal_zoom_region (both_axes
);
1833 Editor::temporal_zoom_selection ()
1835 if (!selection
) return;
1837 if (selection
->time
.empty()) {
1841 nframes64_t start
= selection
->time
[clicked_selection
].start
;
1842 nframes64_t end
= selection
->time
[clicked_selection
].end
;
1844 temporal_zoom_by_frame (start
, end
, "zoom to selection");
1848 Editor::temporal_zoom_session ()
1850 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::temporal_zoom_session
));
1853 temporal_zoom_by_frame (session
->current_start_frame(), session
->current_end_frame(), "zoom to session");
1858 Editor::temporal_zoom_by_frame (nframes64_t start
, nframes64_t end
, const string
& op
)
1860 if (!session
) return;
1862 if ((start
== 0 && end
== 0) || end
< start
) {
1866 nframes64_t range
= end
- start
;
1868 double new_fpu
= (double)range
/ (double)canvas_width
;
1870 nframes64_t new_page
= (nframes64_t
) floor (canvas_width
* new_fpu
);
1871 nframes64_t middle
= (nframes64_t
) floor( (double)start
+ ((double)range
/ 2.0f
));
1872 nframes64_t new_leftmost
= (nframes64_t
) floor( (double)middle
- ((double)new_page
/2.0f
));
1874 if (new_leftmost
> middle
) {
1878 reposition_and_zoom (new_leftmost
, new_fpu
);
1882 Editor::temporal_zoom_to_frame (bool coarser
, nframes64_t frame
)
1887 double range_before
= frame
- leftmost_frame
;
1890 new_fpu
= frames_per_unit
;
1893 new_fpu
*= 1.61803399;
1894 range_before
*= 1.61803399;
1896 new_fpu
= max(1.0,(new_fpu
/1.61803399));
1897 range_before
/= 1.61803399;
1900 if (new_fpu
== frames_per_unit
) {
1904 nframes64_t new_leftmost
= frame
- (nframes64_t
)range_before
;
1906 if (new_leftmost
> frame
) {
1909 // begin_reversible_command (_("zoom to frame"));
1910 // session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
1911 // session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
1912 // commit_reversible_command ();
1914 reposition_and_zoom (new_leftmost
, new_fpu
);
1919 Editor::choose_new_marker_name(string
&name
) {
1921 if (!Config
->get_name_new_markers()) {
1922 /* don't prompt user for a new name */
1926 ArdourPrompter
dialog (true);
1928 dialog
.set_prompt (_("New Name:"));
1930 WindowTitle
title(Glib::get_application_name());
1931 title
+= _("Name New Location Marker");
1933 dialog
.set_title(title
.get_string());
1935 dialog
.set_name ("MarkNameWindow");
1936 dialog
.set_size_request (250, -1);
1937 dialog
.set_position (Gtk::WIN_POS_MOUSE
);
1939 dialog
.add_button (Stock::OK
, RESPONSE_ACCEPT
);
1940 dialog
.set_initial_text (name
);
1944 switch (dialog
.run ()) {
1945 case RESPONSE_ACCEPT
:
1951 dialog
.get_result(name
);
1958 Editor::add_location_from_selection ()
1962 if (selection
->time
.empty()) {
1966 if (session
== 0 || clicked_trackview
== 0) {
1970 nframes64_t start
= selection
->time
[clicked_selection
].start
;
1971 nframes64_t end
= selection
->time
[clicked_selection
].end
;
1973 session
->locations()->next_available_name(rangename
,"selection");
1974 Location
*location
= new Location (start
, end
, rangename
, Location::IsRangeMarker
);
1976 session
->begin_reversible_command (_("add marker"));
1977 XMLNode
&before
= session
->locations()->get_state();
1978 session
->locations()->add (location
, true);
1979 XMLNode
&after
= session
->locations()->get_state();
1980 session
->add_command(new MementoCommand
<Locations
>(*(session
->locations()), &before
, &after
));
1981 session
->commit_reversible_command ();
1985 Editor::add_location_mark (nframes64_t where
)
1989 select_new_marker
= true;
1991 session
->locations()->next_available_name(markername
,"mark");
1992 if (!choose_new_marker_name(markername
)) {
1995 Location
*location
= new Location (where
, where
, markername
, Location::IsMark
);
1996 session
->begin_reversible_command (_("add marker"));
1997 XMLNode
&before
= session
->locations()->get_state();
1998 session
->locations()->add (location
, true);
1999 XMLNode
&after
= session
->locations()->get_state();
2000 session
->add_command(new MementoCommand
<Locations
>(*(session
->locations()), &before
, &after
));
2001 session
->commit_reversible_command ();
2005 Editor::add_location_from_playhead_cursor ()
2007 add_location_mark (session
->audible_frame());
2011 Editor::add_locations_from_audio_region ()
2015 get_regions_for_action (rs
);
2021 session
->begin_reversible_command (rs
.size () > 1 ? _("add markers") : _("add marker"));
2022 XMLNode
&before
= session
->locations()->get_state();
2024 cerr
<< "Add locations\n";
2026 for (RegionSelection::iterator i
= rs
.begin (); i
!= rs
.end (); ++i
) {
2028 boost::shared_ptr
<Region
> region
= (*i
)->region ();
2030 Location
*location
= new Location (region
->position(), region
->last_frame(), region
->name(), Location::IsRangeMarker
);
2032 session
->locations()->add (location
, true);
2035 XMLNode
&after
= session
->locations()->get_state();
2036 session
->add_command (new MementoCommand
<Locations
>(*(session
->locations()), &before
, &after
));
2037 session
->commit_reversible_command ();
2041 Editor::add_location_from_audio_region ()
2045 get_regions_for_action (rs
);
2051 session
->begin_reversible_command (_("add marker"));
2052 XMLNode
&before
= session
->locations()->get_state();
2056 if (rs
.size() > 1) { // more than one region selected
2057 session
->locations()->next_available_name(markername
, "regions");
2059 RegionView
* rv
= *(rs
.begin());
2060 boost::shared_ptr
<Region
> region
= rv
->region();
2061 markername
= region
->name();
2064 if (!choose_new_marker_name(markername
)) {
2068 cerr
<< "Add location\n";
2070 // single range spanning all selected
2071 Location
*location
= new Location (rs
.start(), rs
.end_frame(), markername
, Location::IsRangeMarker
);
2072 session
->locations()->add (location
, true);
2074 XMLNode
&after
= session
->locations()->get_state();
2075 session
->add_command (new MementoCommand
<Locations
>(*(session
->locations()), &before
, &after
));
2076 session
->commit_reversible_command ();
2080 Editor::amplitude_zoom_step (bool in
)
2094 #ifdef FIX_FOR_CANVAS
2095 /* XXX DO SOMETHING */
2104 Editor::delete_sample_forward ()
2109 Editor::delete_sample_backward ()
2114 Editor::delete_screen ()
2121 Editor::search_backwards ()
2127 Editor::search_forwards ()
2135 Editor::jump_forward_to_mark ()
2141 Location
*location
= session
->locations()->first_location_after (playhead_cursor
->current_frame
);
2144 session
->request_locate (location
->start(), session
->transport_rolling());
2146 session
->request_locate (session
->current_end_frame());
2151 Editor::jump_backward_to_mark ()
2157 Location
*location
= session
->locations()->first_location_before (playhead_cursor
->current_frame
);
2160 session
->request_locate (location
->start(), session
->transport_rolling());
2162 session
->goto_start ();
2174 if (get_prefix (prefix
, was_floating
)) {
2175 pos
= session
->audible_frame ();
2178 pos
= (nframes64_t
) floor (prefix
* session
->frame_rate ());
2180 pos
= (nframes64_t
) floor (prefix
);
2184 session
->locations()->next_available_name(markername
,"mark");
2185 if (!choose_new_marker_name(markername
)) {
2188 session
->locations()->add (new Location (pos
, 0, markername
, Location::IsMark
), true);
2192 Editor::clear_markers ()
2195 session
->begin_reversible_command (_("clear markers"));
2196 XMLNode
&before
= session
->locations()->get_state();
2197 session
->locations()->clear_markers ();
2198 XMLNode
&after
= session
->locations()->get_state();
2199 session
->add_command(new MementoCommand
<Locations
>(*(session
->locations()), &before
, &after
));
2200 session
->commit_reversible_command ();
2205 Editor::clear_ranges ()
2208 session
->begin_reversible_command (_("clear ranges"));
2209 XMLNode
&before
= session
->locations()->get_state();
2211 Location
* looploc
= session
->locations()->auto_loop_location();
2212 Location
* punchloc
= session
->locations()->auto_punch_location();
2214 session
->locations()->clear_ranges ();
2216 if (looploc
) session
->locations()->add (looploc
);
2217 if (punchloc
) session
->locations()->add (punchloc
);
2219 XMLNode
&after
= session
->locations()->get_state();
2220 session
->add_command(new MementoCommand
<Locations
>(*(session
->locations()), &before
, &after
));
2221 session
->commit_reversible_command ();
2226 Editor::clear_locations ()
2228 session
->begin_reversible_command (_("clear locations"));
2229 XMLNode
&before
= session
->locations()->get_state();
2230 session
->locations()->clear ();
2231 XMLNode
&after
= session
->locations()->get_state();
2232 session
->add_command(new MementoCommand
<Locations
>(*(session
->locations()), &before
, &after
));
2233 session
->commit_reversible_command ();
2234 session
->locations()->clear ();
2238 Editor::unhide_markers ()
2240 for (LocationMarkerMap::iterator i
= location_markers
.begin(); i
!= location_markers
.end(); ++i
) {
2241 Location
*l
= (*i
).first
;
2242 if (l
->is_hidden() && l
->is_mark()) {
2243 l
->set_hidden(false, this);
2249 Editor::unhide_ranges ()
2251 for (LocationMarkerMap::iterator i
= location_markers
.begin(); i
!= location_markers
.end(); ++i
) {
2252 Location
*l
= (*i
).first
;
2253 if (l
->is_hidden() && l
->is_range_marker()) {
2254 l
->set_hidden(false, this);
2259 /* INSERT/REPLACE */
2262 Editor::insert_region_list_drag (boost::shared_ptr
<AudioRegion
> region
, int x
, int y
)
2268 AudioTimeAxisView
*atv
= 0;
2269 boost::shared_ptr
<Playlist
> playlist
;
2271 track_canvas
->window_to_world (x
, y
, wx
, wy
);
2272 //wx += horizontal_adjustment.get_value();
2273 //wy += vertical_adjustment.get_value();
2276 event
.type
= GDK_BUTTON_RELEASE
;
2277 event
.button
.x
= wx
;
2278 event
.button
.y
= wy
;
2280 where
= event_frame (&event
, &cx
, &cy
);
2282 if (where
< leftmost_frame
|| where
> leftmost_frame
+ current_page_frames()) {
2283 /* clearly outside canvas area */
2287 if ((tv
= trackview_by_y_position (cy
)) == 0) {
2291 if ((atv
= dynamic_cast<AudioTimeAxisView
*>(tv
)) == 0) {
2295 if ((playlist
= atv
->playlist()) == 0) {
2301 begin_reversible_command (_("insert dragged region"));
2302 XMLNode
&before
= playlist
->get_state();
2303 playlist
->add_region (RegionFactory::create (region
), where
, 1.0);
2304 session
->add_command(new MementoCommand
<Playlist
>(*playlist
, &before
, &playlist
->get_state()));
2305 commit_reversible_command ();
2309 Editor::insert_region_list_selection (float times
)
2311 RouteTimeAxisView
*tv
= 0;
2312 boost::shared_ptr
<Playlist
> playlist
;
2314 if (clicked_audio_trackview
!= 0) {
2315 tv
= clicked_audio_trackview
;
2316 } else if (!selection
->tracks
.empty()) {
2317 if ((tv
= dynamic_cast<RouteTimeAxisView
*>(selection
->tracks
.front())) == 0) {
2320 } else if (entered_track
!= 0) {
2321 if ((tv
= dynamic_cast<RouteTimeAxisView
*>(entered_track
)) == 0) {
2328 if ((playlist
= tv
->playlist()) == 0) {
2332 Glib::RefPtr
<TreeSelection
> selected
= region_list_display
.get_selection();
2334 if (selected
->count_selected_rows() != 1) {
2338 TreeView::Selection::ListHandle_Path rows
= selected
->get_selected_rows ();
2340 /* only one row selected, so rows.begin() is it */
2344 if ((iter
= region_list_model
->get_iter (*rows
.begin()))) {
2346 boost::shared_ptr
<Region
> region
= (*iter
)[region_list_columns
.region
];
2348 begin_reversible_command (_("insert region"));
2349 XMLNode
&before
= playlist
->get_state();
2350 playlist
->add_region ((RegionFactory::create (region
)), get_preferred_edit_position(), times
);
2351 session
->add_command(new MementoCommand
<Playlist
>(*playlist
, &before
, &playlist
->get_state()));
2352 commit_reversible_command ();
2356 /* BUILT-IN EFFECTS */
2359 Editor::reverse_selection ()
2364 /* GAIN ENVELOPE EDITING */
2367 Editor::edit_envelope ()
2374 Editor::transition_to_rolling (bool fwd
)
2380 switch (Config
->get_slave_source()) {
2385 /* transport controlled by the master */
2389 if (session
->is_auditioning()) {
2390 session
->cancel_audition ();
2394 session
->request_transport_speed (fwd
? 1.0f
: -1.0f
);
2398 Editor::toggle_playback (bool with_abort
)
2404 switch (Config
->get_slave_source()) {
2409 /* transport controlled by the master */
2413 if (session
->is_auditioning()) {
2414 session
->cancel_audition ();
2418 if (session
->transport_rolling()) {
2419 session
->request_stop (with_abort
);
2420 if (session
->get_play_loop()) {
2421 session
->request_play_loop (false);
2424 session
->request_transport_speed (1.0f
);
2429 Editor::play_from_start ()
2431 session
->request_locate (session
->current_start_frame(), true);
2435 Editor::play_from_edit_point ()
2437 session
->request_locate (get_preferred_edit_position(), true);
2441 Editor::play_from_edit_point_and_return ()
2443 nframes64_t start_frame
;
2444 nframes64_t return_frame
;
2446 start_frame
= get_preferred_edit_position (true);
2448 if (session
->transport_rolling()) {
2449 session
->request_locate (start_frame
, false);
2453 /* don't reset the return frame if its already set */
2455 if ((return_frame
= session
->requested_return_frame()) < 0) {
2456 return_frame
= session
->audible_frame();
2459 if (start_frame
>= 0) {
2460 session
->request_roll_at_and_return (start_frame
, return_frame
);
2465 Editor::play_selection ()
2467 if (selection
->time
.empty()) {
2471 session
->request_play_range (true);
2475 Editor::loop_selected_region ()
2479 get_regions_for_action (rs
);
2482 RegionView
*rv
= *(rs
.begin());
2485 if ((tll
= transport_loop_location()) != 0) {
2487 tll
->set (rv
->region()->position(), rv
->region()->last_frame());
2489 // enable looping, reposition and start rolling
2491 session
->request_play_loop (true);
2492 session
->request_locate (tll
->start(), false);
2493 session
->request_transport_speed (1.0f
);
2499 Editor::play_location (Location
& location
)
2501 if (location
.start() <= location
.end()) {
2505 session
->request_bounded_roll (location
.start(), location
.end());
2509 Editor::loop_location (Location
& location
)
2511 if (location
.start() <= location
.end()) {
2517 if ((tll
= transport_loop_location()) != 0) {
2518 tll
->set (location
.start(), location
.end());
2520 // enable looping, reposition and start rolling
2521 session
->request_play_loop (true);
2522 session
->request_locate (tll
->start(), true);
2527 Editor::raise_region ()
2529 selection
->foreach_region (&Region::raise
);
2533 Editor::raise_region_to_top ()
2535 selection
->foreach_region (&Region::raise_to_top
);
2539 Editor::lower_region ()
2541 selection
->foreach_region (&Region::lower
);
2545 Editor::lower_region_to_bottom ()
2547 selection
->foreach_region (&Region::lower_to_bottom
);
2551 Editor::edit_region ()
2553 if (clicked_regionview
== 0) {
2557 clicked_regionview
->show_region_editor ();
2561 Editor::rename_region()
2565 get_regions_for_action (rs
);
2571 WindowTitle
title (Glib::get_application_name());
2572 title
+= _("Rename Region");
2574 ArdourDialog
d (*this, title
.get_string(), true, false);
2576 Label
label (_("New name:"));
2579 hbox
.set_spacing (6);
2580 hbox
.pack_start (label
, false, false);
2581 hbox
.pack_start (entry
, true, true);
2583 d
.get_vbox()->set_border_width (12);
2584 d
.get_vbox()->pack_start (hbox
, false, false);
2586 d
.add_button(Gtk::Stock::CANCEL
, Gtk::RESPONSE_CANCEL
);
2587 d
.add_button(Gtk::Stock::OK
, Gtk::RESPONSE_OK
);
2589 d
.set_size_request (300, -1);
2590 d
.set_position (Gtk::WIN_POS_MOUSE
);
2592 entry
.set_text (rs
.front()->region()->name());
2593 entry
.select_region (0, -1);
2595 entry
.signal_activate().connect (bind (mem_fun (d
, &Dialog::response
), RESPONSE_OK
));
2605 if (ret
== RESPONSE_OK
) {
2606 std::string str
= entry
.get_text();
2607 strip_whitespace_edges (str
);
2609 rs
.front()->region()->set_name (str
);
2610 redisplay_regions ();
2616 Editor::audition_playlist_region_via_route (boost::shared_ptr
<Region
> region
, Route
& route
)
2618 if (session
->is_auditioning()) {
2619 session
->cancel_audition ();
2622 // note: some potential for creativity here, because region doesn't
2623 // have to belong to the playlist that Route is handling
2625 // bool was_soloed = route.soloed();
2627 route
.set_solo (true, this);
2629 session
->request_bounded_roll (region
->position(), region
->position() + region
->length());
2631 /* XXX how to unset the solo state ? */
2635 Editor::play_edit_range ()
2637 nframes64_t start
, end
;
2639 if (get_edit_op_range (start
, end
)) {
2640 session
->request_bounded_roll (start
, end
);
2645 Editor::play_selected_region ()
2647 nframes64_t start
= max_frames
;
2648 nframes64_t end
= 0;
2651 get_regions_for_action (rs
);
2657 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
2658 if ((*i
)->region()->position() < start
) {
2659 start
= (*i
)->region()->position();
2661 if ((*i
)->region()->last_frame() + 1 > end
) {
2662 end
= (*i
)->region()->last_frame() + 1;
2666 session
->request_stop ();
2667 session
->request_bounded_roll (start
, end
);
2671 Editor::audition_playlist_region_standalone (boost::shared_ptr
<Region
> region
)
2673 session
->audition_region (region
);
2677 Editor::build_interthread_progress_window ()
2679 interthread_progress_window
= new ArdourDialog (X_("interthread progress"), true);
2681 interthread_progress_bar
.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT
);
2683 interthread_progress_window
->set_border_width (12);
2684 interthread_progress_window
->get_vbox()->set_spacing (6);
2686 interthread_progress_label
.set_alignment (0.5, 0.5);
2688 interthread_progress_window
->get_vbox()->pack_start (interthread_progress_label
, false, false);
2689 interthread_progress_window
->get_vbox()->pack_start (interthread_progress_bar
,false, false);
2691 // GTK2FIX: this button needs a modifiable label
2693 Button
* b
= interthread_progress_window
->add_button (Stock::CANCEL
, RESPONSE_CANCEL
);
2694 b
->signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked
));
2696 interthread_cancel_button
.add (interthread_cancel_label
);
2698 interthread_progress_window
->set_default_size (200, 100);
2702 Editor::interthread_cancel_clicked ()
2704 if (current_interthread_info
) {
2705 current_interthread_info
->cancel
= true;
2710 Editor::region_from_selection ()
2712 if (clicked_trackview
== 0) {
2716 if (selection
->time
.empty()) {
2720 nframes64_t start
= selection
->time
[clicked_selection
].start
;
2721 nframes64_t end
= selection
->time
[clicked_selection
].end
;
2723 nframes64_t selection_cnt
= end
- start
+ 1;
2725 for (TrackSelection::iterator i
= selection
->tracks
.begin(); i
!= selection
->tracks
.end(); ++i
) {
2726 boost::shared_ptr
<AudioRegion
> current
;
2727 boost::shared_ptr
<Region
> current_r
;
2728 boost::shared_ptr
<Playlist
> pl
;
2730 nframes64_t internal_start
;
2733 if ((pl
= (*i
)->playlist()) == 0) {
2737 if ((current_r
= pl
->top_region_at (start
)) == 0) {
2741 current
= boost::dynamic_pointer_cast
<AudioRegion
> (current_r
);
2742 // FIXME: audio only
2744 internal_start
= start
- current
->position();
2745 session
->region_name (new_name
, current
->name(), true);
2746 boost::shared_ptr
<Region
> region (RegionFactory::create (current
, internal_start
, selection_cnt
, new_name
));
2752 Editor::create_region_from_selection (vector
<boost::shared_ptr
<AudioRegion
> >& new_regions
)
2754 if (selection
->time
.empty() || selection
->tracks
.empty()) {
2758 nframes64_t start
= selection
->time
[clicked_selection
].start
;
2759 nframes64_t end
= selection
->time
[clicked_selection
].end
;
2761 sort_track_selection ();
2763 for (TrackSelection::iterator i
= selection
->tracks
.begin(); i
!= selection
->tracks
.end(); ++i
) {
2765 boost::shared_ptr
<AudioRegion
> current
;
2766 boost::shared_ptr
<Region
> current_r
;
2767 boost::shared_ptr
<Playlist
> playlist
;
2768 nframes64_t internal_start
;
2771 if ((playlist
= (*i
)->playlist()) == 0) {
2775 if ((current_r
= playlist
->top_region_at(start
)) == 0) {
2779 if ((current
= boost::dynamic_pointer_cast
<AudioRegion
>(current_r
)) == 0) {
2783 internal_start
= start
- current
->position();
2784 session
->region_name (new_name
, current
->name(), true);
2786 new_regions
.push_back (boost::dynamic_pointer_cast
<AudioRegion
> (RegionFactory::create (current
, internal_start
, end
- start
+ 1, new_name
)));
2791 Editor::split_multichannel_region ()
2795 get_regions_for_action (rs
);
2801 vector
<boost::shared_ptr
<AudioRegion
> > v
;
2803 for (list
<RegionView
*>::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
2805 AudioRegionView
* arv
= dynamic_cast<AudioRegionView
*>(*x
);
2807 if (!arv
|| arv
->audio_region()->n_channels() < 2) {
2811 (arv
)->audio_region()->separate_by_channel (*session
, v
);
2816 Editor::new_region_from_selection ()
2818 region_from_selection ();
2819 cancel_selection ();
2823 add_if_covered (RegionView
* rv
, const AudioRange
* ar
, RegionSelection
* rs
)
2825 switch (rv
->region()->coverage (ar
->start
, ar
->end
- 1)) {
2834 Editor::separate_regions_between (const TimeSelection
& ts
)
2836 bool in_command
= false;
2837 boost::shared_ptr
<Playlist
> playlist
;
2838 RegionSelection new_selection
;
2839 TrackSelection tmptracks
;
2841 if (selection
->tracks
.empty()) {
2843 /* use tracks with selected regions */
2847 get_regions_for_action (rs
);
2849 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
2850 TimeAxisView
* tv
= &(*i
)->get_time_axis_view();
2852 if (find (tmptracks
.begin(), tmptracks
.end(), tv
) == tmptracks
.end()) {
2853 tmptracks
.push_back (tv
);
2857 if (tmptracks
.empty()) {
2858 /* no regions selected: do nothing */
2864 tmptracks
= selection
->tracks
;
2868 sort_track_selection (&tmptracks
);
2870 for (TrackSelection::iterator i
= tmptracks
.begin(); i
!= tmptracks
.end(); ++i
) {
2872 AudioTimeAxisView
* atv
;
2874 if ((atv
= dynamic_cast<AudioTimeAxisView
*> ((*i
))) != 0) {
2876 if (atv
->is_audio_track()) {
2878 /* no edits to destructive tracks */
2880 if (atv
->audio_track()->audio_diskstream()->destructive()) {
2884 if ((playlist
= atv
->playlist()) != 0) {
2890 before
= &(playlist
->get_state());
2893 /* XXX need to consider musical time selections here at some point */
2895 double speed
= atv
->get_diskstream()->speed();
2898 for (list
<AudioRange
>::const_iterator t
= ts
.begin(); t
!= ts
.end(); ++t
) {
2900 sigc::connection c
= atv
->view()->RegionViewAdded
.connect (mem_fun(*this, &Editor::collect_new_region_view
));
2901 latest_regionviews
.clear ();
2903 playlist
->partition ((nframes64_t
)((*t
).start
* speed
), (nframes64_t
)((*t
).end
* speed
), true);
2907 if (!latest_regionviews
.empty()) {
2911 atv
->view()->foreach_regionview (bind (sigc::ptr_fun (add_if_covered
), &(*t
), &new_selection
));
2914 begin_reversible_command (_("separate"));
2918 session
->add_command(new MementoCommand
<Playlist
>(*playlist
, before
, &playlist
->get_state()));
2932 selection
->set (new_selection
);
2933 set_mouse_mode (MouseObject
);
2935 commit_reversible_command ();
2940 Editor::separate_region_from_selection ()
2942 /* preferentially use *all* ranges in the time selection if we're in range mode
2943 to allow discontiguous operation, since get_edit_op_range() currently
2944 returns a single range.
2947 if (mouse_mode
== MouseRange
&& !selection
->time
.empty()) {
2949 separate_regions_between (selection
->time
);
2956 if (get_edit_op_range (start
, end
)) {
2958 AudioRange
ar (start
, end
, 1);
2962 separate_regions_between (ts
);
2968 Editor::separate_region_from_punch ()
2970 Location
* loc
= session
->locations()->auto_punch_location();
2972 separate_regions_using_location (*loc
);
2977 Editor::separate_region_from_loop ()
2979 Location
* loc
= session
->locations()->auto_loop_location();
2981 separate_regions_using_location (*loc
);
2986 Editor::separate_regions_using_location (Location
& loc
)
2988 if (loc
.is_mark()) {
2992 AudioRange
ar (loc
.start(), loc
.end(), 1);
2997 separate_regions_between (ts
);
3001 Editor::crop_region_to_selection ()
3003 if (!selection
->time
.empty()) {
3005 crop_region_to (selection
->time
.start(), selection
->time
.end_frame());
3012 if (get_edit_op_range (start
, end
)) {
3013 crop_region_to (start
, end
);
3020 Editor::crop_region_to (nframes64_t start
, nframes64_t end
)
3022 vector
<boost::shared_ptr
<Playlist
> > playlists
;
3023 boost::shared_ptr
<Playlist
> playlist
;
3026 if (selection
->tracks
.empty()) {
3029 sort_track_selection ();
3030 ts
= &selection
->tracks
;
3033 for (TrackSelection::iterator i
= ts
->begin(); i
!= ts
->end(); ++i
) {
3035 AudioTimeAxisView
* atv
;
3037 if ((atv
= dynamic_cast<AudioTimeAxisView
*> ((*i
))) != 0) {
3039 if (atv
->is_audio_track()) {
3041 /* no edits to destructive tracks */
3043 if (atv
->audio_track()->audio_diskstream()->destructive()) {
3047 if ((playlist
= atv
->playlist()) != 0) {
3048 playlists
.push_back (playlist
);
3054 if (playlists
.empty()) {
3058 nframes64_t the_start
;
3059 nframes64_t the_end
;
3062 begin_reversible_command (_("trim to selection"));
3064 for (vector
<boost::shared_ptr
<Playlist
> >::iterator i
= playlists
.begin(); i
!= playlists
.end(); ++i
) {
3066 boost::shared_ptr
<Region
> region
;
3070 if ((region
= (*i
)->top_region_at(the_start
)) == 0) {
3074 /* now adjust lengths to that we do the right thing
3075 if the selection extends beyond the region
3078 the_start
= max (the_start
, (nframes64_t
) region
->position());
3079 if (max_frames
- the_start
< region
->length()) {
3080 the_end
= the_start
+ region
->length() - 1;
3082 the_end
= max_frames
;
3084 the_end
= min (end
, the_end
);
3085 cnt
= the_end
- the_start
+ 1;
3087 XMLNode
&before
= (*i
)->get_state();
3088 region
->trim_to (the_start
, cnt
, this);
3089 XMLNode
&after
= (*i
)->get_state();
3090 session
->add_command (new MementoCommand
<Playlist
>(*(*i
), &before
, &after
));
3093 commit_reversible_command ();
3097 Editor::region_fill_track ()
3102 get_regions_for_action (rs
);
3104 if (!session
|| rs
.empty()) {
3108 end
= session
->current_end_frame ();
3110 begin_reversible_command (_("region fill"));
3112 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
3114 boost::shared_ptr
<Region
> region ((*i
)->region());
3117 boost::shared_ptr
<AudioRegion
> ar
= boost::dynamic_pointer_cast
<AudioRegion
>(region
);
3121 boost::shared_ptr
<Playlist
> pl
= region
->playlist();
3123 if (end
<= region
->last_frame()) {
3127 double times
= (double) (end
- region
->last_frame()) / (double) region
->length();
3133 XMLNode
&before
= pl
->get_state();
3134 pl
->add_region (RegionFactory::create (ar
), ar
->last_frame(), times
);
3135 session
->add_command (new MementoCommand
<Playlist
>(*pl
, &before
, &pl
->get_state()));
3138 commit_reversible_command ();
3142 Editor::region_fill_selection ()
3144 if (clicked_audio_trackview
== 0 || !clicked_audio_trackview
->is_audio_track()) {
3148 if (selection
->time
.empty()) {
3153 Glib::RefPtr
<TreeSelection
> selected
= region_list_display
.get_selection();
3155 if (selected
->count_selected_rows() != 1) {
3159 TreeModel::iterator i
= region_list_display
.get_selection()->get_selected();
3160 boost::shared_ptr
<Region
> region
= (*i
)[region_list_columns
.region
];
3162 nframes64_t start
= selection
->time
[clicked_selection
].start
;
3163 nframes64_t end
= selection
->time
[clicked_selection
].end
;
3165 boost::shared_ptr
<Playlist
> playlist
;
3167 if (selection
->tracks
.empty()) {
3171 nframes64_t selection_length
= end
- start
;
3172 float times
= (float)selection_length
/ region
->length();
3174 begin_reversible_command (_("fill selection"));
3176 for (TrackSelection::iterator i
= selection
->tracks
.begin(); i
!= selection
->tracks
.end(); ++i
) {
3178 if ((playlist
= (*i
)->playlist()) == 0) {
3182 XMLNode
&before
= playlist
->get_state();
3183 playlist
->add_region (RegionFactory::create (region
), start
, times
);
3184 session
->add_command (new MementoCommand
<Playlist
>(*playlist
, &before
, &playlist
->get_state()));
3187 commit_reversible_command ();
3191 Editor::set_region_sync_from_edit_point ()
3193 nframes64_t where
= get_preferred_edit_position ();
3195 get_regions_for_action (rs
);
3196 set_sync_point (where
, rs
);
3200 Editor::set_sync_point (nframes64_t where
, const RegionSelection
& rs
)
3202 bool in_command
= false;
3204 for (RegionSelection::const_iterator r
= rs
.begin(); r
!= rs
.end(); ++r
) {
3206 if (!(*r
)->region()->covers (where
)) {
3210 boost::shared_ptr
<Region
> region ((*r
)->region());
3213 begin_reversible_command (_("set sync point"));
3217 XMLNode
&before
= region
->playlist()->get_state();
3218 region
->set_sync_position (get_preferred_edit_position());
3219 XMLNode
&after
= region
->playlist()->get_state();
3220 session
->add_command(new MementoCommand
<Playlist
>(*(region
->playlist()), &before
, &after
));
3224 commit_reversible_command ();
3229 Editor::remove_region_sync ()
3233 get_regions_for_action (rs
);
3239 begin_reversible_command (_("remove sync"));
3240 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
3242 XMLNode
&before
= (*i
)->region()->playlist()->get_state();
3243 (*i
)->region()->clear_sync_position ();
3244 XMLNode
&after
= (*i
)->region()->playlist()->get_state();
3245 session
->add_command(new MementoCommand
<Playlist
>(*((*i
)->region()->playlist()), &before
, &after
));
3247 commit_reversible_command ();
3251 Editor::naturalize ()
3255 get_regions_for_action (rs
);
3261 begin_reversible_command (_("naturalize"));
3262 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
3263 XMLNode
&before
= (*i
)->region()->get_state();
3264 (*i
)->region()->move_to_natural_position (this);
3265 XMLNode
&after
= (*i
)->region()->get_state();
3266 session
->add_command (new MementoCommand
<Region
>(*((*i
)->region().get()), &before
, &after
));
3268 commit_reversible_command ();
3272 Editor::align (RegionPoint what
)
3276 get_regions_for_action (rs
);
3277 nframes64_t where
= get_preferred_edit_position();
3280 align_selection (what
, where
, rs
);
3284 get_regions_at (rs
, where
, selection
->tracks
);
3285 align_selection (what
, where
, rs
);
3290 Editor::align_relative (RegionPoint what
)
3292 nframes64_t where
= get_preferred_edit_position();
3295 get_regions_for_action (rs
);
3298 align_selection_relative (what
, where
, rs
);
3302 struct RegionSortByTime
{
3303 bool operator() (const AudioRegionView
* a
, const AudioRegionView
* b
) {
3304 return a
->region()->position() < b
->region()->position();
3309 Editor::align_selection_relative (RegionPoint point
, nframes64_t position
, const RegionSelection
& rs
)
3315 nframes64_t distance
= 0;
3316 nframes64_t pos
= 0;
3319 list
<RegionView
*> sorted
;
3320 rs
.by_position (sorted
);
3322 boost::shared_ptr
<Region
> r ((*sorted
.begin())->region());
3327 if (position
> r
->position()) {
3328 distance
= position
- r
->position();
3330 distance
= r
->position() - position
;
3336 if (position
> r
->last_frame()) {
3337 distance
= position
- r
->last_frame();
3338 pos
= r
->position() + distance
;
3340 distance
= r
->last_frame() - position
;
3341 pos
= r
->position() - distance
;
3347 pos
= r
->adjust_to_sync (position
);
3348 if (pos
> r
->position()) {
3349 distance
= pos
- r
->position();
3351 distance
= r
->position() - pos
;
3357 if (pos
== r
->position()) {
3361 begin_reversible_command (_("align selection (relative)"));
3363 /* move first one specially */
3365 XMLNode
&before
= r
->playlist()->get_state();
3366 r
->set_position (pos
, this);
3367 XMLNode
&after
= r
->playlist()->get_state();
3368 session
->add_command(new MementoCommand
<Playlist
>(*(r
->playlist()), &before
, &after
));
3370 /* move rest by the same amount */
3374 for (list
<RegionView
*>::iterator i
= sorted
.begin(); i
!= sorted
.end(); ++i
) {
3376 boost::shared_ptr
<Region
> region ((*i
)->region());
3378 XMLNode
&before
= region
->playlist()->get_state();
3381 region
->set_position (region
->position() + distance
, this);
3383 region
->set_position (region
->position() - distance
, this);
3386 XMLNode
&after
= region
->playlist()->get_state();
3387 session
->add_command(new MementoCommand
<Playlist
>(*(region
->playlist()), &before
, &after
));
3391 commit_reversible_command ();
3395 Editor::align_selection (RegionPoint point
, nframes64_t position
, const RegionSelection
& rs
)
3401 begin_reversible_command (_("align selection"));
3403 for (RegionSelection::const_iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
3404 align_region_internal ((*i
)->region(), point
, position
);
3407 commit_reversible_command ();
3411 Editor::align_region (boost::shared_ptr
<Region
> region
, RegionPoint point
, nframes64_t position
)
3413 begin_reversible_command (_("align region"));
3414 align_region_internal (region
, point
, position
);
3415 commit_reversible_command ();
3419 Editor::align_region_internal (boost::shared_ptr
<Region
> region
, RegionPoint point
, nframes64_t position
)
3421 XMLNode
&before
= region
->playlist()->get_state();
3425 region
->set_position (region
->adjust_to_sync (position
), this);
3429 if (position
> region
->length()) {
3430 region
->set_position (position
- region
->length(), this);
3435 region
->set_position (position
, this);
3439 XMLNode
&after
= region
->playlist()->get_state();
3440 session
->add_command(new MementoCommand
<Playlist
>(*(region
->playlist()), &before
, &after
));
3444 Editor::trim_region_to_loop ()
3446 Location
* loc
= session
->locations()->auto_loop_location();
3450 trim_region_to_location (*loc
, _("trim to loop"));
3454 Editor::trim_region_to_punch ()
3456 Location
* loc
= session
->locations()->auto_punch_location();
3460 trim_region_to_location (*loc
, _("trim to punch"));
3464 Editor::trim_region_to_location (const Location
& loc
, const char* str
)
3468 get_regions_for_action (rs
);
3470 begin_reversible_command (str
);
3472 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
3473 AudioRegionView
* arv
= dynamic_cast<AudioRegionView
*> (*x
);
3479 /* require region to span proposed trim */
3481 switch (arv
->region()->coverage (loc
.start(), loc
.end())) {
3482 case OverlapInternal
:
3488 AudioTimeAxisView
* atav
= dynamic_cast<AudioTimeAxisView
*> (&arv
->get_time_axis_view());
3498 if (atav
->get_diskstream() != 0) {
3499 speed
= atav
->get_diskstream()->speed();
3502 start
= session_frame_to_track_frame (loc
.start(), speed
);
3503 end
= session_frame_to_track_frame (loc
.end(), speed
);
3505 XMLNode
&before
= arv
->region()->playlist()->get_state();
3506 arv
->region()->trim_to (start
, (end
- start
), this);
3507 XMLNode
&after
= arv
->region()->playlist()->get_state();
3508 session
->add_command(new MementoCommand
<Playlist
>(*(arv
->region()->playlist()), &before
, &after
));
3511 commit_reversible_command ();
3515 Editor::trim_region_to_edit_point ()
3519 get_regions_for_action (rs
);
3521 nframes64_t where
= get_preferred_edit_position();
3523 begin_reversible_command (_("trim region start to edit point"));
3525 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
3526 AudioRegionView
* arv
= dynamic_cast<AudioRegionView
*> (*x
);
3532 /* require region to cover trim */
3534 if (!arv
->region()->covers (where
)) {
3538 AudioTimeAxisView
* atav
= dynamic_cast<AudioTimeAxisView
*> (&arv
->get_time_axis_view());
3546 if (atav
->get_diskstream() != 0) {
3547 speed
= atav
->get_diskstream()->speed();
3550 XMLNode
&before
= arv
->region()->playlist()->get_state();
3551 arv
->region()->trim_end( session_frame_to_track_frame(where
, speed
), this);
3552 XMLNode
&after
= arv
->region()->playlist()->get_state();
3553 session
->add_command(new MementoCommand
<Playlist
>(*(arv
->region()->playlist()), &before
, &after
));
3556 commit_reversible_command ();
3560 Editor::trim_region_from_edit_point ()
3564 get_regions_for_action (rs
);
3566 nframes64_t where
= get_preferred_edit_position();
3568 begin_reversible_command (_("trim region end to edit point"));
3570 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
3571 AudioRegionView
* arv
= dynamic_cast<AudioRegionView
*> (*x
);
3577 /* require region to cover trim */
3579 if (!arv
->region()->covers (where
)) {
3583 AudioTimeAxisView
* atav
= dynamic_cast<AudioTimeAxisView
*> (&arv
->get_time_axis_view());
3591 if (atav
->get_diskstream() != 0) {
3592 speed
= atav
->get_diskstream()->speed();
3595 XMLNode
&before
= arv
->region()->playlist()->get_state();
3596 arv
->region()->trim_front ( session_frame_to_track_frame(where
, speed
), this);
3597 XMLNode
&after
= arv
->region()->playlist()->get_state();
3598 session
->add_command(new MementoCommand
<Playlist
>(*(arv
->region()->playlist()), &before
, &after
));
3601 commit_reversible_command ();
3605 Editor::unfreeze_route ()
3607 if (clicked_audio_trackview
== 0 || !clicked_audio_trackview
->is_audio_track()) {
3611 clicked_audio_trackview
->audio_track()->unfreeze ();
3615 Editor::_freeze_thread (void* arg
)
3617 PBD::notify_gui_about_thread_creation (pthread_self(), X_("Freeze"));
3618 return static_cast<Editor
*>(arg
)->freeze_thread ();
3622 Editor::freeze_thread ()
3624 clicked_audio_trackview
->audio_track()->freeze (*current_interthread_info
);
3629 Editor::freeze_progress_timeout (void *arg
)
3631 interthread_progress_bar
.set_fraction (current_interthread_info
->progress
);
3632 return !(current_interthread_info
->done
|| current_interthread_info
->cancel
);
3636 Editor::freeze_route ()
3638 if (clicked_audio_trackview
== 0 || !clicked_audio_trackview
->is_audio_track()) {
3642 InterThreadInfo itt
;
3644 if (interthread_progress_window
== 0) {
3645 build_interthread_progress_window ();
3648 WindowTitle
title(Glib::get_application_name());
3649 title
+= _("Freeze");
3650 interthread_progress_window
->set_title (title
.get_string());
3651 interthread_progress_window
->set_position (Gtk::WIN_POS_MOUSE
);
3652 interthread_progress_window
->show_all ();
3653 interthread_progress_bar
.set_fraction (0.0f
);
3654 interthread_progress_label
.set_text ("");
3655 interthread_cancel_label
.set_text (_("Cancel Freeze"));
3656 current_interthread_info
= &itt
;
3658 interthread_progress_connection
=
3659 Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout
), (gpointer
) 0), 100);
3663 itt
.progress
= 0.0f
;
3665 pthread_attr_t attr
;
3666 pthread_attr_init(&attr
);
3667 pthread_attr_setstacksize(&attr
, 500000);
3669 pthread_create_and_store (X_("freezer"), &itt
.thread
, &attr
, _freeze_thread
, this);
3671 pthread_attr_destroy(&attr
);
3673 track_canvas
->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH
));
3675 while (!itt
.done
&& !itt
.cancel
) {
3676 gtk_main_iteration ();
3679 interthread_progress_connection
.disconnect ();
3680 interthread_progress_window
->hide_all ();
3681 current_interthread_info
= 0;
3682 track_canvas
->get_window()->set_cursor (*current_canvas_cursor
);
3686 Editor::bounce_range_selection (bool replace
, bool enable_processing
)
3688 if (selection
->time
.empty()) {
3692 TrackSelection views
= selection
->tracks
;
3694 nframes64_t start
= selection
->time
[clicked_selection
].start
;
3695 nframes64_t end
= selection
->time
[clicked_selection
].end
;
3696 nframes64_t cnt
= end
- start
+ 1;
3698 begin_reversible_command (_("bounce range"));
3700 for (TrackViewList::iterator i
= views
.begin(); i
!= views
.end(); ++i
) {
3702 AudioTimeAxisView
* atv
;
3704 if ((atv
= dynamic_cast<AudioTimeAxisView
*> (*i
)) == 0) {
3708 boost::shared_ptr
<Playlist
> playlist
;
3710 if ((playlist
= atv
->playlist()) == 0) {
3714 InterThreadInfo itt
;
3718 itt
.progress
= false;
3720 XMLNode
&before
= playlist
->get_state();
3721 boost::shared_ptr
<Region
> r
= atv
->audio_track()->bounce_range (start
, start
+cnt
, itt
, enable_processing
);
3724 list
<AudioRange
> ranges
;
3725 ranges
.push_back (AudioRange (start
, start
+cnt
, 0));
3726 playlist
->cut (ranges
); // discard result
3727 playlist
->add_region (r
, start
);
3730 XMLNode
&after
= playlist
->get_state();
3731 session
->add_command (new MementoCommand
<Playlist
> (*playlist
, &before
, &after
));
3734 commit_reversible_command ();
3750 Editor::cut_copy (CutCopyOp op
)
3752 /* only cancel selection if cut/copy is successful.*/
3764 opname
= _("clear");
3768 /* if we're deleting something, and the mouse is still pressed,
3769 the thing we started a drag for will be gone when we release
3770 the mouse button(s). avoid this. see part 2 at the end of
3774 if (op
== Cut
|| op
== Clear
) {
3775 if (drag_info
.item
) {
3776 drag_info
.item
->ungrab (0);
3781 cut_buffer
->clear ();
3783 if (entered_marker
) {
3785 /* cut/delete op while pointing at a marker */
3788 Location
* loc
= find_location_from_marker (entered_marker
, ignored
);
3790 if (session
&& loc
) {
3791 Glib::signal_idle().connect (bind (mem_fun(*this, &Editor::really_remove_marker
), loc
));
3801 /* we only want to cut regions if some are selected */
3803 if (!selection
->regions
.empty()) {
3804 get_regions_for_action (rs
);
3807 switch (current_mouse_mode()) {
3809 if (!rs
.empty() || !selection
->points
.empty()) {
3811 begin_reversible_command (opname
+ _(" objects"));
3814 cut_copy_regions (op
, rs
);
3817 selection
->clear_regions ();
3821 if (!selection
->points
.empty()) {
3822 cut_copy_points (op
);
3825 selection
->clear_points ();
3829 commit_reversible_command ();
3830 break; // terminate case statement here
3832 if (!selection
->time
.empty()) {
3833 /* don't cause suprises */
3836 // fall thru if there was nothing selected
3839 if (selection
->time
.empty()) {
3840 nframes64_t start
, end
;
3841 if (!get_edit_op_range (start
, end
)) {
3844 selection
->set ((TimeAxisView
*) 0, start
, end
);
3847 begin_reversible_command (opname
+ _(" range"));
3848 cut_copy_ranges (op
);
3849 commit_reversible_command ();
3852 selection
->clear_time ();
3862 if (op
== Cut
|| op
== Clear
) {
3868 Editor::cut_copy_points (CutCopyOp op
)
3870 for (PointSelection::iterator i
= selection
->points
.begin(); i
!= selection
->points
.end(); ++i
) {
3872 AutomationTimeAxisView
* atv
= dynamic_cast<AutomationTimeAxisView
*>(&(*i
).track
);
3875 atv
->cut_copy_clear_objects (selection
->points
, op
);
3880 struct PlaylistState
{
3881 boost::shared_ptr
<Playlist
> playlist
;
3885 struct lt_playlist
{
3886 bool operator () (const PlaylistState
& a
, const PlaylistState
& b
) {
3887 return a
.playlist
< b
.playlist
;
3891 struct PlaylistMapping
{
3893 boost::shared_ptr
<AudioPlaylist
> pl
;
3895 PlaylistMapping (TimeAxisView
* tvp
) : tv (tvp
) {}
3899 Editor::cut_copy_regions (CutCopyOp op
, RegionSelection
& rs
)
3901 /* we can't use a std::map here because the ordering is important, and we can't trivially sort
3902 a map when we want ordered access to both elements. i think.
3905 vector
<PlaylistMapping
> pmap
;
3907 nframes64_t first_position
= max_frames
;
3909 set
<PlaylistState
, lt_playlist
> freezelist
;
3910 pair
<set
<PlaylistState
, lt_playlist
>::iterator
,bool> insert_result
;
3912 /* get ordering correct before we cut/copy */
3914 rs
.sort_by_position_and_track ();
3916 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
3918 first_position
= min ((nframes64_t
) (*x
)->region()->position(), first_position
);
3920 if (op
== Cut
|| op
== Clear
) {
3921 boost::shared_ptr
<AudioPlaylist
> pl
= boost::dynamic_pointer_cast
<AudioPlaylist
>((*x
)->region()->playlist());
3925 PlaylistState before
;
3926 before
.playlist
= pl
;
3927 before
.before
= &pl
->get_state();
3929 insert_result
= freezelist
.insert (before
);
3931 if (insert_result
.second
) {
3937 TimeAxisView
* tv
= &(*x
)->get_trackview();
3938 vector
<PlaylistMapping
>::iterator z
;
3940 for (z
= pmap
.begin(); z
!= pmap
.end(); ++z
) {
3941 if ((*z
).tv
== tv
) {
3946 if (z
== pmap
.end()) {
3947 pmap
.push_back (PlaylistMapping (tv
));
3951 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ) {
3953 boost::shared_ptr
<AudioPlaylist
> pl
= boost::dynamic_pointer_cast
<AudioPlaylist
>((*x
)->region()->playlist());
3956 /* impossible, but this handles it for the future */
3960 TimeAxisView
& tv
= (*x
)->get_trackview();
3961 boost::shared_ptr
<AudioPlaylist
> npl
;
3962 RegionSelection::iterator tmp
;
3967 vector
<PlaylistMapping
>::iterator z
;
3969 for (z
= pmap
.begin(); z
!= pmap
.end(); ++z
) {
3970 if ((*z
).tv
== &tv
) {
3975 assert (z
!= pmap
.end());
3978 npl
= boost::dynamic_pointer_cast
<AudioPlaylist
> (PlaylistFactory::create (*session
, "cutlist", true));
3985 boost::shared_ptr
<AudioRegion
> ar
= boost::dynamic_pointer_cast
<AudioRegion
>((*x
)->region());
3986 boost::shared_ptr
<Region
> _xx
;
3992 _xx
= RegionFactory::create ((*x
)->region());
3993 npl
->add_region (_xx
, (*x
)->region()->position() - first_position
);
3994 pl
->remove_region (((*x
)->region()));
4000 /* copy region before adding, so we're not putting same object into two different playlists */
4001 npl
->add_region (RegionFactory::create ((*x
)->region()), (*x
)->region()->position() - first_position
);
4005 pl
->remove_region (((*x
)->region()));
4012 list
<boost::shared_ptr
<Playlist
> > foo
;
4014 /* the pmap is in the same order as the tracks in which selected regions occured */
4016 for (vector
<PlaylistMapping
>::iterator i
= pmap
.begin(); i
!= pmap
.end(); ++i
) {
4018 foo
.push_back ((*i
).pl
);
4023 cut_buffer
->set (foo
);
4026 for (set
<PlaylistState
, lt_playlist
>::iterator pl
= freezelist
.begin(); pl
!= freezelist
.end(); ++pl
) {
4027 (*pl
).playlist
->thaw ();
4028 session
->add_command (new MementoCommand
<Playlist
>(*(*pl
).playlist
, (*pl
).before
, &(*pl
).playlist
->get_state()));
4033 Editor::cut_copy_ranges (CutCopyOp op
)
4036 TrackSelection entered
;
4038 if (selection
->tracks
.empty()) {
4039 if (!entered_track
) {
4042 entered
.push_back (entered_track
);
4045 ts
= &selection
->tracks
;
4048 for (TrackSelection::iterator i
= ts
->begin(); i
!= ts
->end(); ++i
) {
4049 (*i
)->cut_copy_clear (*selection
, op
);
4054 Editor::paste (float times
)
4056 paste_internal (get_preferred_edit_position(), times
);
4060 Editor::mouse_paste ()
4065 if (!mouse_frame (where
, ignored
)) {
4070 paste_internal (where
, 1);
4074 Editor::paste_internal (nframes64_t position
, float times
)
4076 bool commit
= false;
4078 if (cut_buffer
->empty()) {
4082 if (position
== max_frames
) {
4083 position
= get_preferred_edit_position();
4086 begin_reversible_command (_("paste"));
4089 TrackSelection::iterator i
;
4092 /* get everything in the correct order */
4095 if (!selection
->tracks
.empty()) {
4096 sort_track_selection ();
4097 ts
= selection
->tracks
;
4098 } else if (entered_track
) {
4099 ts
.push_back (entered_track
);
4102 for (nth
= 0, i
= ts
.begin(); i
!= ts
.end(); ++i
, ++nth
) {
4104 /* undo/redo is handled by individual tracks */
4106 if ((*i
)->paste (position
, times
, *cut_buffer
, nth
)) {
4112 commit_reversible_command ();
4117 Editor::paste_named_selection (float times
)
4119 TrackSelection::iterator t
;
4121 Glib::RefPtr
<TreeSelection
> selected
= named_selection_display
.get_selection();
4123 if (selected
->count_selected_rows() != 1 || selection
->tracks
.empty()) {
4127 TreeModel::iterator i
= selected
->get_selected();
4128 NamedSelection
* ns
= (*i
)[named_selection_columns
.selection
];
4130 list
<boost::shared_ptr
<Playlist
> >::iterator chunk
;
4131 list
<boost::shared_ptr
<Playlist
> >::iterator tmp
;
4133 chunk
= ns
->playlists
.begin();
4135 begin_reversible_command (_("paste chunk"));
4137 sort_track_selection ();
4139 for (t
= selection
->tracks
.begin(); t
!= selection
->tracks
.end(); ++t
) {
4141 AudioTimeAxisView
* atv
;
4142 boost::shared_ptr
<Playlist
> pl
;
4143 boost::shared_ptr
<AudioPlaylist
> apl
;
4145 if ((atv
= dynamic_cast<AudioTimeAxisView
*> (*t
)) == 0) {
4149 if ((pl
= atv
->playlist()) == 0) {
4153 if ((apl
= boost::dynamic_pointer_cast
<AudioPlaylist
> (pl
)) == 0) {
4160 XMLNode
&before
= apl
->get_state();
4161 apl
->paste (*chunk
, get_preferred_edit_position(), times
);
4162 session
->add_command(new MementoCommand
<AudioPlaylist
>(*apl
, &before
, &apl
->get_state()));
4164 if (tmp
!= ns
->playlists
.end()) {
4169 commit_reversible_command();
4173 Editor::duplicate_some_regions (RegionSelection
& regions
, float times
)
4175 boost::shared_ptr
<Playlist
> playlist
;
4176 RegionSelection sel
= regions
; // clear (below) may clear the argument list if its the current region selection
4177 RegionSelection foo
;
4179 begin_reversible_command (_("duplicate region"));
4181 selection
->clear_regions ();
4183 for (RegionSelection::iterator i
= sel
.begin(); i
!= sel
.end(); ++i
) {
4185 boost::shared_ptr
<Region
> r ((*i
)->region());
4187 TimeAxisView
& tv
= (*i
)->get_time_axis_view();
4188 AudioTimeAxisView
* atv
= dynamic_cast<AudioTimeAxisView
*> (&tv
);
4190 latest_regionviews
.clear ();
4191 sigc::connection c
= atv
->view()->RegionViewAdded
.connect (mem_fun(*this, &Editor::collect_new_region_view
));
4193 playlist
= (*i
)->region()->playlist();
4194 XMLNode
&before
= playlist
->get_state();
4195 playlist
->duplicate (r
, r
->last_frame() + 1, times
);
4196 session
->add_command(new MementoCommand
<Playlist
>(*playlist
, &before
, &playlist
->get_state()));
4200 foo
.insert (foo
.end(), latest_regionviews
.begin(), latest_regionviews
.end());
4203 commit_reversible_command ();
4206 selection
->set (foo
);
4211 Editor::duplicate_selection (float times
)
4213 if (selection
->time
.empty() || selection
->tracks
.empty()) {
4217 boost::shared_ptr
<Playlist
> playlist
;
4218 vector
<boost::shared_ptr
<AudioRegion
> > new_regions
;
4219 vector
<boost::shared_ptr
<AudioRegion
> >::iterator ri
;
4221 create_region_from_selection (new_regions
);
4223 if (new_regions
.empty()) {
4227 begin_reversible_command (_("duplicate selection"));
4229 ri
= new_regions
.begin();
4231 for (TrackSelection::iterator i
= selection
->tracks
.begin(); i
!= selection
->tracks
.end(); ++i
) {
4232 if ((playlist
= (*i
)->playlist()) == 0) {
4235 XMLNode
&before
= playlist
->get_state();
4236 playlist
->duplicate (*ri
, selection
->time
[clicked_selection
].end
, times
);
4237 XMLNode
&after
= playlist
->get_state();
4238 session
->add_command (new MementoCommand
<Playlist
>(*playlist
, &before
, &after
));
4241 if (ri
== new_regions
.end()) {
4246 commit_reversible_command ();
4250 Editor::reset_point_selection ()
4252 /* reset all selected points to the relevant default value */
4254 for (PointSelection::iterator i
= selection
->points
.begin(); i
!= selection
->points
.end(); ++i
) {
4256 AutomationTimeAxisView
* atv
= dynamic_cast<AutomationTimeAxisView
*>(&(*i
).track
);
4259 atv
->reset_objects (selection
->points
);
4265 Editor::center_playhead ()
4267 float page
= canvas_width
* frames_per_unit
;
4268 center_screen_internal (playhead_cursor
->current_frame
, page
);
4272 Editor::center_edit_point ()
4274 float page
= canvas_width
* frames_per_unit
;
4275 center_screen_internal (get_preferred_edit_position(), page
);
4279 Editor::clear_playlist (boost::shared_ptr
<Playlist
> playlist
)
4281 begin_reversible_command (_("clear playlist"));
4282 XMLNode
&before
= playlist
->get_state();
4284 XMLNode
&after
= playlist
->get_state();
4285 session
->add_command (new MementoCommand
<Playlist
>(*playlist
.get(), &before
, &after
));
4286 commit_reversible_command ();
4290 Editor::nudge_track (bool use_edit
, bool forwards
)
4292 boost::shared_ptr
<Playlist
> playlist
;
4293 nframes64_t distance
;
4294 nframes64_t next_distance
;
4298 start
= get_preferred_edit_position();
4303 if ((distance
= get_nudge_distance (start
, next_distance
)) == 0) {
4307 if (selection
->tracks
.empty()) {
4311 begin_reversible_command (_("nudge track"));
4313 for (TrackSelection::iterator i
= selection
->tracks
.begin(); i
!= selection
->tracks
.end(); ++i
) {
4315 if ((playlist
= (*i
)->playlist()) == 0) {
4319 XMLNode
&before
= playlist
->get_state();
4320 playlist
->nudge_after (start
, distance
, forwards
);
4321 XMLNode
&after
= playlist
->get_state();
4322 session
->add_command (new MementoCommand
<Playlist
>(*playlist
, &before
, &after
));
4325 commit_reversible_command ();
4329 Editor::remove_last_capture ()
4331 vector
<string
> choices
;
4338 if (Config
->get_verify_remove_last_capture()) {
4339 prompt
= _("Do you really want to destroy the last capture?"
4340 "\n(This is destructive and cannot be undone)");
4342 choices
.push_back (_("No, do nothing."));
4343 choices
.push_back (_("Yes, destroy it."));
4345 Gtkmm2ext::Choice
prompter (prompt
, choices
);
4347 if (prompter
.run () == 1) {
4348 session
->remove_last_capture ();
4352 session
->remove_last_capture();
4357 Editor::normalize_region ()
4361 get_regions_for_action (rs
);
4371 begin_reversible_command (_("normalize"));
4373 track_canvas
->get_window()->set_cursor (*wait_cursor
);
4376 for (RegionSelection::iterator r
= rs
.begin(); r
!= rs
.end(); ++r
) {
4377 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*r
);
4380 XMLNode
&before
= arv
->region()->get_state();
4381 arv
->audio_region()->normalize_to (0.0f
);
4382 session
->add_command (new MementoCommand
<Region
>(*(arv
->region().get()), &before
, &arv
->region()->get_state()));
4385 commit_reversible_command ();
4386 track_canvas
->get_window()->set_cursor (*current_canvas_cursor
);
4391 Editor::denormalize_region ()
4399 get_regions_for_action (rs
);
4405 begin_reversible_command ("denormalize");
4407 for (RegionSelection::iterator r
= rs
.begin(); r
!= rs
.end(); ++r
) {
4408 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*r
);
4411 XMLNode
&before
= arv
->region()->get_state();
4412 arv
->audio_region()->set_scale_amplitude (1.0f
);
4413 session
->add_command (new MementoCommand
<Region
>(*(arv
->region().get()), &before
, &arv
->region()->get_state()));
4416 commit_reversible_command ();
4420 Editor::adjust_region_scale_amplitude (bool up
)
4428 get_regions_for_action (rs
);
4434 begin_reversible_command ("denormalize");
4436 for (RegionSelection::iterator r
= rs
.begin(); r
!= rs
.end(); ++r
) {
4437 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*r
);
4440 XMLNode
&before
= arv
->region()->get_state();
4442 double fraction
= gain_to_slider_position (arv
->audio_region()->scale_amplitude ());
4446 fraction
= min (fraction
, 1.0);
4449 fraction
= max (fraction
, 0.0);
4452 if (!up
&& fraction
<= 0) {
4456 fraction
= slider_position_to_gain (fraction
);
4457 fraction
= coefficient_to_dB (fraction
);
4458 fraction
= dB_to_coefficient (fraction
);
4460 if (up
&& fraction
>= 2.0) {
4464 arv
->audio_region()->set_scale_amplitude (fraction
);
4465 session
->add_command (new MementoCommand
<Region
>(*(arv
->region().get()), &before
, &arv
->region()->get_state()));
4468 commit_reversible_command ();
4473 Editor::reverse_region ()
4479 Reverse
rev (*session
);
4480 apply_filter (rev
, _("reverse regions"));
4484 Editor::apply_filter (AudioFilter
& filter
, string command
)
4488 get_regions_for_action (rs
);
4494 begin_reversible_command (command
);
4496 track_canvas
->get_window()->set_cursor (*wait_cursor
);
4499 for (RegionSelection::iterator r
= rs
.begin(); r
!= rs
.end(); ) {
4500 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*r
);
4504 boost::shared_ptr
<Playlist
> playlist
= arv
->region()->playlist();
4506 RegionSelection::iterator tmp
;
4511 if (arv
->audio_region()->apply (filter
) == 0) {
4513 XMLNode
&before
= playlist
->get_state();
4514 playlist
->replace_region (arv
->region(), filter
.results
.front(), arv
->region()->position());
4515 XMLNode
&after
= playlist
->get_state();
4516 session
->add_command(new MementoCommand
<Playlist
>(*playlist
, &before
, &after
));
4524 commit_reversible_command ();
4528 track_canvas
->get_window()->set_cursor (*current_canvas_cursor
);
4532 Editor::region_selection_op (void (Region::*pmf
)(void))
4534 for (RegionSelection::iterator i
= selection
->regions
.begin(); i
!= selection
->regions
.end(); ++i
) {
4535 Region
* region
= (*i
)->region().get();
4542 Editor::region_selection_op (void (Region::*pmf
)(void*), void *arg
)
4544 for (RegionSelection::iterator i
= selection
->regions
.begin(); i
!= selection
->regions
.end(); ++i
) {
4545 Region
* region
= (*i
)->region().get();
4546 (region
->*pmf
)(arg
);
4551 Editor::region_selection_op (void (Region::*pmf
)(bool), bool yn
)
4553 for (RegionSelection::iterator i
= selection
->regions
.begin(); i
!= selection
->regions
.end(); ++i
) {
4554 Region
* region
= (*i
)->region().get();
4560 Editor::external_edit_region ()
4562 // XXX shouldn't this use get_regions_for_action(rs) too?
4563 if (!clicked_regionview
) {
4571 Editor::brush (nframes64_t pos
)
4573 RegionSelection sel
;
4576 get_regions_for_action (rs
);
4584 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4585 mouse_brush_insert_region ((*i
), pos
);
4590 Editor::reset_region_gain_envelopes ()
4594 get_regions_for_action (rs
);
4596 if (!session
|| rs
.empty()) {
4600 session
->begin_reversible_command (_("reset region gain"));
4602 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4603 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*i
);
4605 AutomationList
& alist (arv
->audio_region()->envelope());
4606 XMLNode
& before (alist
.get_state());
4608 arv
->audio_region()->set_default_envelope ();
4609 session
->add_command (new MementoCommand
<AutomationList
>(arv
->audio_region()->envelope(), &before
, &alist
.get_state()));
4613 session
->commit_reversible_command ();
4617 Editor::toggle_gain_envelope_visibility ()
4621 get_regions_for_action (rs
);
4623 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4624 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*i
);
4626 arv
->set_envelope_visible (!arv
->envelope_visible());
4632 Editor::toggle_gain_envelope_active ()
4636 get_regions_for_action (rs
);
4638 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4639 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*i
);
4641 arv
->audio_region()->set_envelope_active (!arv
->audio_region()->envelope_active());
4647 Editor::toggle_region_lock ()
4651 get_regions_for_action (rs
);
4653 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4654 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*i
);
4656 arv
->audio_region()->set_locked (!arv
->audio_region()->locked());
4662 Editor::set_region_lock_style (Region::PositionLockStyle ps
)
4666 get_regions_for_action (rs
);
4668 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4669 (*i
)->region()->set_position_lock_style (ps
);
4675 Editor::toggle_region_mute ()
4679 get_regions_for_action (rs
);
4681 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4682 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*i
);
4684 arv
->audio_region()->set_muted (!arv
->audio_region()->muted());
4690 Editor::toggle_region_opaque ()
4694 get_regions_for_action (rs
);
4696 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
4697 AudioRegionView
* const arv
= dynamic_cast<AudioRegionView
*>(*i
);
4699 arv
->audio_region()->set_opaque (!arv
->audio_region()->opaque());
4705 Editor::toggle_record_enable ()
4707 bool new_state
= false;
4709 for (TrackSelection::iterator i
= selection
->tracks
.begin(); i
!= selection
->tracks
.end(); ++i
) {
4710 RouteTimeAxisView
*rtav
= dynamic_cast<RouteTimeAxisView
*>(*i
);
4713 if (!rtav
->is_track())
4717 new_state
= !rtav
->track()->record_enabled();
4721 rtav
->track()->set_record_enable(new_state
, this);
4727 Editor::set_fade_length (bool in
)
4731 get_regions_for_action (rs
);
4733 /* we need a region to measure the offset from the start */
4739 } else if (entered_regionview
) {
4740 rv
= entered_regionview
;
4745 nframes64_t pos
= get_preferred_edit_position();
4749 if (pos
> rv
->region()->last_frame() || pos
< rv
->region()->first_frame()) {
4750 /* edit point is outside the relevant region */
4755 if (pos
<= rv
->region()->position()) {
4759 len
= pos
- rv
->region()->position();
4760 cmd
= _("set fade in length");
4762 if (pos
>= rv
->region()->last_frame()) {
4766 len
= rv
->region()->last_frame() - pos
;
4767 cmd
= _("set fade out length");
4770 begin_reversible_command (cmd
);
4772 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
4773 AudioRegionView
* tmp
= dynamic_cast<AudioRegionView
*> (*x
);
4779 AutomationList
* alist
;
4781 alist
= &tmp
->audio_region()->fade_in();
4783 alist
= &tmp
->audio_region()->fade_out();
4786 XMLNode
&before
= alist
->get_state();
4789 tmp
->audio_region()->set_fade_in_length (len
);
4790 tmp
->audio_region()->set_fade_in_active (true);
4792 tmp
->audio_region()->set_fade_out_length (len
);
4793 tmp
->audio_region()->set_fade_out_active (true);
4796 XMLNode
&after
= alist
->get_state();
4797 session
->add_command(new MementoCommand
<AutomationList
>(*alist
, &before
, &after
));
4800 commit_reversible_command ();
4805 Editor::toggle_fade_active (bool in
)
4809 get_regions_for_action (rs
);
4815 const char* cmd
= (in
? _("toggle fade in active") : _("toggle fade out active"));
4816 bool have_switch
= false;
4819 begin_reversible_command (cmd
);
4821 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
4822 AudioRegionView
* tmp
= dynamic_cast<AudioRegionView
*> (*x
);
4828 boost::shared_ptr
<AudioRegion
> region (tmp
->audio_region());
4830 /* make the behaviour consistent across all regions */
4834 yn
= region
->fade_in_active();
4836 yn
= region
->fade_out_active();
4841 XMLNode
&before
= region
->get_state();
4843 region
->set_fade_in_active (!yn
);
4845 region
->set_fade_out_active (!yn
);
4847 XMLNode
&after
= region
->get_state();
4848 session
->add_command(new MementoCommand
<AudioRegion
>(*region
.get(), &before
, &after
));
4851 commit_reversible_command ();
4855 Editor::set_fade_in_shape (AudioRegion::FadeShape shape
)
4859 get_regions_for_action (rs
);
4865 begin_reversible_command (_("set fade in shape"));
4867 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
4868 AudioRegionView
* tmp
= dynamic_cast<AudioRegionView
*> (*x
);
4874 AutomationList
& alist
= tmp
->audio_region()->fade_in();
4875 XMLNode
&before
= alist
.get_state();
4877 tmp
->audio_region()->set_fade_in_shape (shape
);
4879 XMLNode
&after
= alist
.get_state();
4880 session
->add_command(new MementoCommand
<AutomationList
>(alist
, &before
, &after
));
4883 commit_reversible_command ();
4888 Editor::set_fade_out_shape (AudioRegion::FadeShape shape
)
4892 get_regions_for_action (rs
);
4898 begin_reversible_command (_("set fade out shape"));
4900 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
4901 AudioRegionView
* tmp
= dynamic_cast<AudioRegionView
*> (*x
);
4907 AutomationList
& alist
= tmp
->audio_region()->fade_out();
4908 XMLNode
&before
= alist
.get_state();
4910 tmp
->audio_region()->set_fade_out_shape (shape
);
4912 XMLNode
&after
= alist
.get_state();
4913 session
->add_command(new MementoCommand
<AutomationList
>(alist
, &before
, &after
));
4916 commit_reversible_command ();
4920 Editor::set_fade_in_active (bool yn
)
4924 get_regions_for_action (rs
);
4930 begin_reversible_command (_("set fade in active"));
4932 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
4933 AudioRegionView
* tmp
= dynamic_cast<AudioRegionView
*> (*x
);
4940 boost::shared_ptr
<AudioRegion
> ar (tmp
->audio_region());
4942 XMLNode
&before
= ar
->get_state();
4944 ar
->set_fade_in_active (yn
);
4946 XMLNode
&after
= ar
->get_state();
4947 session
->add_command(new MementoCommand
<AudioRegion
>(*ar
, &before
, &after
));
4950 commit_reversible_command ();
4954 Editor::set_fade_out_active (bool yn
)
4958 get_regions_for_action (rs
);
4964 begin_reversible_command (_("set fade out active"));
4966 for (RegionSelection::iterator x
= rs
.begin(); x
!= rs
.end(); ++x
) {
4967 AudioRegionView
* tmp
= dynamic_cast<AudioRegionView
*> (*x
);
4973 boost::shared_ptr
<AudioRegion
> ar (tmp
->audio_region());
4975 XMLNode
&before
= ar
->get_state();
4977 ar
->set_fade_out_active (yn
);
4979 XMLNode
&after
= ar
->get_state();
4980 session
->add_command(new MementoCommand
<AudioRegion
>(*ar
, &before
, &after
));
4983 commit_reversible_command ();
4987 Editor::toggle_selected_region_fades (int dir
)
4990 RegionSelection::iterator i
;
4991 boost::shared_ptr
<AudioRegion
> ar
;
4994 get_regions_for_action (rs
);
5000 for (i
= rs
.begin(); i
!= rs
.end(); ++i
) {
5001 if ((ar
= boost::dynamic_pointer_cast
<AudioRegion
>((*i
)->region())) != 0) {
5003 yn
= ar
->fade_out_active ();
5005 yn
= ar
->fade_in_active ();
5011 if (i
== rs
.end()) {
5015 /* XXX should this undo-able? */
5017 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
5018 if ((ar
= boost::dynamic_pointer_cast
<AudioRegion
>((*i
)->region())) == 0) {
5021 if (dir
== 1 || dir
== 0) {
5022 ar
->set_fade_in_active (!yn
);
5025 if (dir
== -1 || dir
== 0) {
5026 ar
->set_fade_out_active (!yn
);
5032 /** Update region fade visibility after its configuration has been changed */
5034 Editor::update_region_fade_visibility ()
5036 bool _fade_visibility
= Config
->get_show_region_fades ();
5038 for (TrackViewList::iterator i
= track_views
.begin(); i
!= track_views
.end(); ++i
) {
5039 AudioTimeAxisView
* v
= dynamic_cast<AudioTimeAxisView
*>(*i
);
5041 if (_fade_visibility
) {
5042 v
->audio_view()->show_all_fades ();
5044 v
->audio_view()->hide_all_fades ();
5050 /** Update crossfade visibility after its configuration has been changed */
5052 Editor::update_xfade_visibility ()
5054 _xfade_visibility
= Config
->get_xfades_visible ();
5056 for (TrackViewList::iterator i
= track_views
.begin(); i
!= track_views
.end(); ++i
) {
5057 AudioTimeAxisView
* v
= dynamic_cast<AudioTimeAxisView
*>(*i
);
5059 if (_xfade_visibility
) {
5060 v
->show_all_xfades ();
5062 v
->hide_all_xfades ();
5069 Editor::set_edit_point ()
5074 if (!mouse_frame (where
, ignored
)) {
5080 if (selection
->markers
.empty()) {
5082 mouse_add_new_marker (where
);
5087 Location
* loc
= find_location_from_marker (selection
->markers
.front(), ignored
);
5090 loc
->move_to (where
);
5096 Editor::set_playhead_cursor ()
5098 if (entered_marker
) {
5099 session
->request_locate (entered_marker
->position(), session
->transport_rolling());
5104 if (!mouse_frame (where
, ignored
)) {
5111 session
->request_locate (where
, session
->transport_rolling());
5121 get_regions_for_action (rs
);
5123 nframes64_t where
= get_preferred_edit_position();
5129 split_regions_at (where
, rs
);
5133 Editor::ensure_entered_track_selected (bool op_really_wants_one_track_if_none_are_selected
)
5135 if (entered_track
&& mouse_mode
== MouseObject
) {
5136 if (!selection
->tracks
.empty()) {
5137 if (!selection
->selected (entered_track
)) {
5138 selection
->add (entered_track
);
5141 /* there is no selection, but this operation requires/prefers selected objects */
5143 if (op_really_wants_one_track_if_none_are_selected
) {
5144 selection
->set (entered_track
);
5151 Editor::trim_region_front ()
5157 Editor::trim_region_back ()
5159 trim_region (false);
5163 Editor::trim_region (bool front
)
5165 nframes64_t where
= get_preferred_edit_position();
5168 get_regions_for_action (rs
);
5174 begin_reversible_command (front
? _("trim front") : _("trim back"));
5176 for (list
<RegionView
*>::const_iterator i
= rs
.by_layer().begin(); i
!= rs
.by_layer().end(); ++i
) {
5177 if (!(*i
)->region()->locked()) {
5178 boost::shared_ptr
<Playlist
> pl
= (*i
)->region()->playlist();
5179 XMLNode
&before
= pl
->get_state();
5181 (*i
)->region()->trim_front (where
, this);
5183 (*i
)->region()->trim_end (where
, this);
5185 XMLNode
&after
= pl
->get_state();
5186 session
->add_command(new MementoCommand
<Playlist
>(*pl
.get(), &before
, &after
));
5190 commit_reversible_command ();
5193 struct EditorOrderRouteSorter
{
5194 bool operator() (boost::shared_ptr
<Route
> a
, boost::shared_ptr
<Route
> b
) {
5195 /* use of ">" forces the correct sort order */
5196 return a
->order_key ("editor") < b
->order_key ("editor");
5201 Editor::select_next_route()
5203 if (selection
->tracks
.empty()) {
5204 selection
->set (track_views
.front());
5208 TimeAxisView
* current
= selection
->tracks
.front();
5212 for (TrackViewList::iterator i
= track_views
.begin(); i
!= track_views
.end(); ++i
) {
5213 if (*i
== current
) {
5215 if (i
!= track_views
.end()) {
5218 current
= (*(track_views
.begin()));
5219 //selection->set (*(track_views.begin()));
5224 rui
= dynamic_cast<RouteUI
*>(current
);
5225 } while ( current
->hidden() || (rui
!= NULL
&& !rui
->route()->active()));
5227 selection
->set(current
);
5229 ensure_track_visible(current
);
5233 Editor::select_prev_route()
5235 if (selection
->tracks
.empty()) {
5236 selection
->set (track_views
.front());
5240 TimeAxisView
* current
= selection
->tracks
.front();
5244 for (TrackViewList::reverse_iterator i
= track_views
.rbegin(); i
!= track_views
.rend(); ++i
) {
5245 if (*i
== current
) {
5247 if (i
!= track_views
.rend()) {
5250 current
= *(track_views
.rbegin());
5255 rui
= dynamic_cast<RouteUI
*>(current
);
5256 } while ( current
->hidden() || (rui
!= NULL
&& !rui
->route()->active()));
5258 selection
->set (current
);
5260 ensure_track_visible(current
);
5264 Editor::ensure_track_visible(TimeAxisView
*track
)
5266 if (track
->hidden())
5269 double current_view_min_y
= vertical_adjustment
.get_value();
5270 double current_view_max_y
= vertical_adjustment
.get_value() + vertical_adjustment
.get_page_size() - canvas_timebars_vsize
;
5272 double track_min_y
= track
->y_position
;
5273 double track_max_y
= track
->y_position
+ (double)track
->effective_height
;
5275 if (track_min_y
>= current_view_min_y
&&
5276 track_max_y
<= current_view_max_y
) {
5282 if (track_min_y
< current_view_min_y
) {
5283 // Track is above the current view
5284 new_value
= track_min_y
;
5286 // Track is below the current view
5287 new_value
= track
->y_position
+ (double)track
->effective_height
+ canvas_timebars_vsize
- vertical_adjustment
.get_page_size();
5290 vertical_adjustment
.set_value(new_value
);
5294 Editor::set_loop_from_selection (bool play
)
5296 if (session
== 0 || selection
->time
.empty()) {
5300 nframes64_t start
= selection
->time
[clicked_selection
].start
;
5301 nframes64_t end
= selection
->time
[clicked_selection
].end
;
5303 set_loop_range (start
, end
, _("set loop range from selection"));
5306 session
->request_play_loop (true);
5307 session
->request_locate (start
, true);
5312 Editor::set_loop_from_edit_range (bool play
)
5321 if (!get_edit_op_range (start
, end
)) {
5325 set_loop_range (start
, end
, _("set loop range from edit range"));
5328 session
->request_play_loop (true);
5329 session
->request_locate (start
, true);
5334 Editor::set_loop_from_region (bool play
)
5336 nframes64_t start
= max_frames
;
5337 nframes64_t end
= 0;
5341 get_regions_for_action (rs
);
5347 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
5348 if ((*i
)->region()->position() < start
) {
5349 start
= (*i
)->region()->position();
5351 if ((*i
)->region()->last_frame() + 1 > end
) {
5352 end
= (*i
)->region()->last_frame() + 1;
5356 set_loop_range (start
, end
, _("set loop range from region"));
5359 session
->request_play_loop (true);
5360 session
->request_locate (start
, true);
5365 Editor::set_punch_from_selection ()
5367 if (session
== 0 || selection
->time
.empty()) {
5371 nframes64_t start
= selection
->time
[clicked_selection
].start
;
5372 nframes64_t end
= selection
->time
[clicked_selection
].end
;
5374 set_punch_range (start
, end
, _("set punch range from selection"));
5378 Editor::set_punch_from_edit_range ()
5387 if (!get_edit_op_range (start
, end
)) {
5391 set_punch_range (start
, end
, _("set punch range from edit range"));
5395 Editor::set_punch_from_region ()
5397 nframes64_t start
= max_frames
;
5398 nframes64_t end
= 0;
5402 get_regions_for_action (rs
);
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_punch_range (start
, end
, _("set punch range from region"));
5421 Editor::pitch_shift_regions ()
5425 get_regions_for_action (rs
);
5431 pitch_shift (rs
, 1.2);
5435 Editor::use_region_as_bar ()
5443 get_regions_for_action (rs
);
5449 RegionView
* rv
= rs
.front();
5451 define_one_bar (rv
->region()->position(), rv
->region()->last_frame() + 1);
5455 Editor::use_range_as_bar ()
5457 nframes64_t start
, end
;
5458 if (get_edit_op_range (start
, end
)) {
5459 define_one_bar (start
, end
);
5464 Editor::define_one_bar (nframes64_t start
, nframes64_t end
)
5466 nframes64_t length
= end
- start
;
5468 const Meter
& m (session
->tempo_map().meter_at (start
));
5470 /* length = 1 bar */
5472 /* now we want frames per beat.
5473 we have frames per bar, and beats per bar, so ...
5476 double frames_per_beat
= length
/ m
.beats_per_bar();
5478 /* beats per minute = */
5480 double beats_per_minute
= (session
->frame_rate() * 60.0) / frames_per_beat
;
5482 /* now decide whether to:
5484 (a) set global tempo
5485 (b) add a new tempo marker
5489 const TempoSection
& t (session
->tempo_map().tempo_section_at (start
));
5491 bool do_global
= false;
5493 if ((session
->tempo_map().n_tempos() == 1) && (session
->tempo_map().n_meters() == 1)) {
5495 /* only 1 tempo & 1 meter: ask if the user wants to set the tempo
5496 at the start, or create a new marker
5499 vector
<string
> options
;
5500 options
.push_back (_("Cancel"));
5501 options
.push_back (_("Add new marker"));
5502 options
.push_back (_("Set global tempo"));
5503 Choice
c (_("Do you want to set the global tempo or add new tempo marker?"),
5505 c
.set_default_response (2);
5521 /* more than 1 tempo and/or meter section already, go ahead do the "usual":
5522 if the marker is at the region starter, change it, otherwise add
5527 begin_reversible_command (_("set tempo from region"));
5528 XMLNode
& before (session
->tempo_map().get_state());
5531 session
->tempo_map().change_initial_tempo (beats_per_minute
, t
.note_type());
5532 } else if (t
.frame() == start
) {
5533 session
->tempo_map().change_existing_tempo_at (start
, beats_per_minute
, t
.note_type());
5535 session
->tempo_map().add_tempo (Tempo (beats_per_minute
, t
.note_type()), start
);
5538 XMLNode
& after (session
->tempo_map().get_state());
5540 session
->add_command (new MementoCommand
<TempoMap
>(session
->tempo_map(), &before
, &after
));
5541 commit_reversible_command ();
5545 Editor::split_region_at_transients ()
5547 AnalysisFeatureList positions
;
5555 get_regions_for_action (rs
);
5561 session
->begin_reversible_command (_("split regions"));
5563 for (RegionSelection::iterator i
= rs
.begin(); i
!= rs
.end(); ) {
5565 RegionSelection::iterator tmp
;
5570 boost::shared_ptr
<AudioRegion
> ar
= boost::dynamic_pointer_cast
<AudioRegion
> ((*i
)->region());
5572 if (ar
&& (ar
->get_transients (positions
) == 0)) {
5573 split_region_at_points ((*i
)->region(), positions
, true);
5580 session
->commit_reversible_command ();
5585 Editor::split_region_at_points (boost::shared_ptr
<Region
> r
, AnalysisFeatureList
& positions
, bool can_ferret
)
5587 boost::shared_ptr
<AudioRegion
> ar
= boost::dynamic_pointer_cast
<AudioRegion
> (r
);
5588 bool use_rhythmic_rodent
= false;
5594 boost::shared_ptr
<Playlist
> pl
= ar
->playlist();
5600 if (positions
.empty()) {
5605 if (positions
.size() > 20) {
5606 Glib::ustring msgstr
= string_compose (_("You are about to split\n%1\ninto %2 pieces.\nThis could take a long time."), ar
->name(), positions
.size() + 1);
5607 MessageDialog
msg (msgstr
,
5610 Gtk::BUTTONS_OK_CANCEL
);
5613 msg
.add_button (_("Call for the Ferret!"), RESPONSE_APPLY
);
5614 msg
.set_secondary_text (_("Press OK to continue with this split operation\nor ask the Ferret dialog to tune the analysis"));
5616 msg
.set_secondary_text (_("Press OK to continue with this split operation"));
5619 msg
.set_title (_("Excessive split?"));
5622 int response
= msg
.run();
5627 case RESPONSE_APPLY
:
5628 use_rhythmic_rodent
= true;
5635 if (use_rhythmic_rodent
) {
5636 show_rhythm_ferret ();
5640 AnalysisFeatureList::const_iterator x
;
5642 nframes64_t pos
= ar
->position();
5644 XMLNode
& before (pl
->get_state());
5646 x
= positions
.begin();
5648 while (x
!= positions
.end()) {
5655 if (x
== positions
.end()) {
5660 pl
->remove_region (ar
);
5662 while (x
!= positions
.end()) {
5664 /* file start = original start + how far we from the initial position ?
5667 nframes64_t file_start
= ar
->start() + (pos
- ar
->position());
5669 /* length = next position - current position
5672 nframes64_t len
= (*x
) - pos
;
5674 /* XXX we do we really want to allow even single-sample regions?
5675 shouldn't we have some kind of lower limit on region size?
5684 if (session
->region_name (new_name
, ar
->name())) {
5688 /* do NOT announce new regions 1 by one, just wait till they are all done */
5690 boost::shared_ptr
<Region
> r
= RegionFactory::create (ar
->get_sources(), file_start
, len
, new_name
, 0, Region::DefaultFlags
, false);
5691 pl
->add_region (r
, pos
);
5696 if (*x
> ar
->last_frame()) {
5698 /* add final fragment */
5700 file_start
= ar
->start() + (pos
- ar
->position());
5701 len
= ar
->last_frame() - pos
;
5703 boost::shared_ptr
<Region
> r
= RegionFactory::create (ar
->get_sources(), file_start
, len
, new_name
, 0, Region::DefaultFlags
);
5704 pl
->add_region (r
, pos
);
5712 XMLNode
& after (pl
->get_state());
5714 session
->add_command (new MementoCommand
<Playlist
>(*pl
, &before
, &after
));
5718 Editor::tab_to_transient (bool forward
)
5720 AnalysisFeatureList positions
;
5726 nframes64_t pos
= session
->audible_frame ();
5728 if (!selection
->tracks
.empty()) {
5730 for (TrackSelection::iterator t
= selection
->tracks
.begin(); t
!= selection
->tracks
.end(); ++t
) {
5732 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*> (*t
);
5735 boost::shared_ptr
<Diskstream
> ds
= rtv
->get_diskstream();
5737 boost::shared_ptr
<Playlist
> pl
= rtv
->get_diskstream()->playlist ();
5739 nframes64_t result
= pl
->find_next_transient (pos
, forward
? 1 : -1);
5742 positions
.push_back (result
);
5753 get_regions_for_action (rs
);
5759 for (RegionSelection::iterator r
= rs
.begin(); r
!= rs
.end(); ++r
) {
5760 (*r
)->region()->get_transients (positions
);
5764 TransientDetector::cleanup_transients (positions
, session
->frame_rate(), 3.0);
5767 AnalysisFeatureList::iterator x
;
5769 for (x
= positions
.begin(); x
!= positions
.end(); ++x
) {
5775 if (x
!= positions
.end ()) {
5776 session
->request_locate (*x
);
5780 AnalysisFeatureList::reverse_iterator x
;
5782 for (x
= positions
.rbegin(); x
!= positions
.rend(); ++x
) {
5788 if (x
!= positions
.rend ()) {
5789 session
->request_locate (*x
);
5795 Editor::playhead_forward_to_grid ()
5797 if (!session
) return;
5798 nframes64_t pos
= playhead_cursor
->current_frame
;
5799 if (pos
< max_frames
- 1) {
5801 snap_to_internal (pos
, 1, false);
5802 session
->request_locate (pos
);
5808 Editor::playhead_backward_to_grid ()
5810 if (!session
) return;
5811 nframes64_t pos
= playhead_cursor
->current_frame
;
5814 snap_to_internal (pos
, -1, false);
5815 session
->request_locate (pos
);
5820 Editor::set_track_height (uint32_t h
)
5822 TrackSelection
& ts (selection
->tracks
);
5828 for (TrackSelection::iterator x
= ts
.begin(); x
!= ts
.end(); ++x
) {
5829 (*x
)->set_height (h
);
5834 Editor::set_track_height_largest ()
5836 set_track_height (TimeAxisView::hLargest
);
5839 Editor::set_track_height_large ()
5841 set_track_height (TimeAxisView::hLarge
);
5844 Editor::set_track_height_larger ()
5846 set_track_height (TimeAxisView::hLarger
);
5849 Editor::set_track_height_normal ()
5851 set_track_height (TimeAxisView::hNormal
);
5854 Editor::set_track_height_smaller ()
5856 set_track_height (TimeAxisView::hSmaller
);
5859 Editor::set_track_height_small ()
5861 set_track_height (TimeAxisView::hSmall
);
5865 Editor::toggle_tracks_active ()
5867 TrackSelection
& ts (selection
->tracks
);
5869 bool target
= false;
5875 for (TrackSelection::iterator x
= ts
.begin(); x
!= ts
.end(); ++x
) {
5876 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*>(*x
);
5880 target
= !rtv
->_route
->active();
5883 rtv
->_route
->set_active (target
);
5889 Editor::remove_tracks ()
5891 TrackSelection
& ts (selection
->tracks
);
5897 vector
<string
> choices
;
5901 const char* trackstr
;
5903 vector
<boost::shared_ptr
<Route
> > routes
;
5905 for (TrackSelection::iterator x
= ts
.begin(); x
!= ts
.end(); ++x
) {
5906 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*> (*x
);
5908 if (rtv
->is_track()) {
5914 routes
.push_back (rtv
->_route
);
5917 if (ntracks
+ nbusses
== 0) {
5922 trackstr
= _("tracks");
5924 trackstr
= _("track");
5928 busstr
= _("busses");
5935 prompt
= string_compose (_("Do you really want to remove %1 %2 and %3 %4?\n"
5936 "(You may also lose the playlists associated with the %2)\n\n"
5937 "This action cannot be undone!"),
5938 ntracks
, trackstr
, nbusses
, busstr
);
5940 prompt
= string_compose (_("Do you really want to remove %1 %2?\n"
5941 "(You may also lose the playlists associated with the %2)\n\n"
5942 "This action cannot be undone!"),
5945 } else if (nbusses
) {
5946 prompt
= string_compose (_("Do you really want to remove %1 %2?"),
5950 choices
.push_back (_("No, do nothing."));
5951 if (ntracks
+ nbusses
> 1) {
5952 choices
.push_back (_("Yes, remove them."));
5954 choices
.push_back (_("Yes, remove it."));
5957 Choice
prompter (prompt
, choices
);
5959 if (prompter
.run () != 1) {
5963 for (vector
<boost::shared_ptr
<Route
> >::iterator x
= routes
.begin(); x
!= routes
.end(); ++x
) {
5964 session
->remove_route (*x
);
5969 Editor::set_waveform_scale (WaveformScale ws
)
5971 TrackSelection
& ts (selection
->tracks
);
5977 for (TrackSelection::iterator x
= ts
.begin(); x
!= ts
.end(); ++x
) {
5978 AudioTimeAxisView
* atv
= dynamic_cast<AudioTimeAxisView
*> (*x
);
5980 atv
->set_waveform_scale (ws
);
5986 Editor::do_insert_time ()
5988 if (selection
->tracks
.empty()) {
5992 nframes64_t pos
= get_preferred_edit_position ();
5993 ArdourDialog
d (*this, _("Insert Time"));
5994 VButtonBox button_box
;
5996 RadioButtonGroup group
;
5997 RadioButton
leave_button (group
, _("Stay in position"));
5998 RadioButton
move_button (group
, _("Move"));
5999 RadioButton
split_button (group
, _("Split & Later Section Moves"));
6000 Label
intersect_option_label (_("Intersected regions should:"));
6001 CheckButton
glue_button (_("Move Glued Regions"));
6002 CheckButton
marker_button (_("Move Markers"));
6003 CheckButton
tempo_button (_("Move Tempo & Meters"));
6004 AudioClock
clock ("insertTimeClock", true, X_("InsertTimeClock"), true, true, true);
6008 clock
.set_session (session
);
6009 clock
.set_bbt_reference (pos
);
6011 clock_box
.pack_start (clock
, false, true);
6013 option_box
.set_spacing (6);
6014 option_box
.pack_start (intersect_option_label
, false, false);
6015 option_box
.pack_start (button_box
, false, false);
6016 option_box
.pack_start (glue_button
, false, false);
6017 option_box
.pack_start (marker_button
, false, false);
6018 option_box
.pack_start (tempo_button
, false, false);
6020 button_box
.pack_start (leave_button
, false, false);
6021 button_box
.pack_start (move_button
, false, false);
6022 button_box
.pack_start (split_button
, false, false);
6024 d
.get_vbox()->set_border_width (12);
6025 d
.get_vbox()->pack_start (clock_box
, false, false);
6026 d
.get_vbox()->pack_start (option_box
, false, false);
6028 leave_button
.show ();
6029 move_button
.show ();
6030 split_button
.show ();
6031 intersect_option_label
.show ();
6034 glue_button
.show ();
6037 marker_button
.show ();
6038 tempo_button
.show ();
6040 d
.add_button (Gtk::Stock::CANCEL
, Gtk::RESPONSE_CANCEL
);
6041 d
.add_button (Gtk::Stock::OK
, Gtk::RESPONSE_OK
);
6044 int response
= d
.run ();
6046 if (response
!= RESPONSE_OK
) {
6050 nframes64_t distance
= clock
.current_duration (pos
);
6052 if (distance
== 0) {
6056 InsertTimeOption opt
;
6058 if (leave_button
.get_active()) {
6059 opt
= LeaveIntersected
;
6060 } else if (move_button
.get_active()) {
6061 opt
= MoveIntersected
;
6063 opt
= SplitIntersected
;
6066 insert_time (pos
, distance
, opt
, glue_button
.get_active(), marker_button
.get_active(), tempo_button
.get_active());
6070 Editor::insert_time (nframes64_t pos
, nframes64_t frames
, InsertTimeOption opt
,
6071 bool ignore_music_glue
, bool markers_too
, bool tempo_too
)
6073 bool commit
= false;
6075 if (Config
->get_edit_mode() == Lock
) {
6079 begin_reversible_command (_("insert time"));
6081 for (TrackSelection::iterator x
= selection
->tracks
.begin(); x
!= selection
->tracks
.end(); ++x
) {
6083 boost::shared_ptr
<Playlist
> pl
= (*x
)->playlist();
6087 XMLNode
&before
= pl
->get_state();
6089 if (opt
== SplitIntersected
) {
6093 pl
->shift (pos
, frames
, (opt
== MoveIntersected
), ignore_music_glue
);
6095 XMLNode
&after
= pl
->get_state();
6097 session
->add_command (new MementoCommand
<Playlist
> (*pl
, &before
, &after
));
6102 RouteTimeAxisView
* rtav
= dynamic_cast<RouteTimeAxisView
*> (*x
);
6104 rtav
->route ()->shift (pos
, frames
);
6112 XMLNode
& before (session
->locations()->get_state());
6113 Locations::LocationList
copy (session
->locations()->list());
6115 for (Locations::LocationList::iterator i
= copy
.begin(); i
!= copy
.end(); ++i
) {
6117 Locations::LocationList::const_iterator tmp
;
6119 if ((*i
)->start() >= pos
) {
6120 (*i
)->set_start ((*i
)->start() + frames
);
6121 if (!(*i
)->is_mark()) {
6122 (*i
)->set_end ((*i
)->end() + frames
);
6129 XMLNode
& after (session
->locations()->get_state());
6130 session
->add_command (new MementoCommand
<Locations
>(*session
->locations(), &before
, &after
));
6135 session
->tempo_map().insert_time (pos
, frames
);
6138 commit_reversible_command ();
6143 Editor::fit_tracks ()
6145 if (selection
->tracks
.empty()) {
6149 uint32_t child_heights
= 0;
6151 for (TrackSelection::iterator t
= selection
->tracks
.begin(); t
!= selection
->tracks
.end(); ++t
) {
6153 if (!(*t
)->marked_for_display()) {
6157 child_heights
+= ((*t
)->effective_height
- (*t
)->current_height());
6160 uint32_t h
= (uint32_t) floor ((canvas_height
- child_heights
- canvas_timebars_vsize
)/selection
->tracks
.size());
6161 double first_y_pos
= DBL_MAX
;
6163 if (h
< TimeAxisView::hSmall
) {
6164 MessageDialog
msg (*this, _("There are too many selected tracks to fit in the current window"));
6165 /* too small to be displayed */
6169 undo_visual_stack
.push_back (current_visual_state());
6171 /* operate on all tracks, hide unselected ones that are in the middle of selected ones */
6173 bool prev_was_selected
= false;
6174 bool is_selected
= selection
->selected (track_views
.front());
6175 bool next_is_selected
;
6177 for (TrackViewList::iterator t
= track_views
.begin(); t
!= track_views
.end(); ++t
) {
6179 TrackViewList::iterator next
;
6184 if (next
!= track_views
.end()) {
6185 next_is_selected
= selection
->selected (*next
);
6187 next_is_selected
= false;
6191 (*t
)->set_height (h
);
6192 first_y_pos
= std::min ((*t
)->y_position
, first_y_pos
);
6194 if (prev_was_selected
&& next_is_selected
) {
6195 hide_track_in_display (**t
);
6199 prev_was_selected
= is_selected
;
6200 is_selected
= next_is_selected
;
6204 set the controls_layout height now, because waiting for its size
6205 request signal handler will cause the vertical adjustment setting to fail
6208 controls_layout
.property_height () = full_canvas_height
- canvas_timebars_vsize
;
6209 vertical_adjustment
.set_value (first_y_pos
);
6211 redo_visual_stack
.push_back (current_visual_state());
6215 Editor::save_visual_state (uint32_t n
)
6217 while (visual_states
.size() <= n
) {
6218 visual_states
.push_back (0);
6221 if (visual_states
[n
] != 0) {
6222 delete visual_states
[n
];
6225 visual_states
[n
] = current_visual_state (true);
6230 Editor::goto_visual_state (uint32_t n
)
6232 if (visual_states
.size() <= n
) {
6236 if (visual_states
[n
] == 0) {
6240 use_visual_state (*visual_states
[n
]);
6244 Editor::start_visual_state_op (uint32_t n
)
6246 cerr
<< "Start visual op\n";
6247 if (visual_state_op_connection
.empty()) {
6248 visual_state_op_connection
= Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::end_visual_state_op
), n
), 1000);
6249 cerr
<< "\tqueued new timeout\n";
6254 Editor::cancel_visual_state_op (uint32_t n
)
6256 if (!visual_state_op_connection
.empty()) {
6257 cerr
<< "cancel visual op, time to goto\n";
6258 visual_state_op_connection
.disconnect();
6259 goto_visual_state (n
);
6261 cerr
<< "cancel visual op, do nothing\n";
6266 Editor::end_visual_state_op (uint32_t n
)
6268 visual_state_op_connection
.disconnect();
6269 save_visual_state (n
);
6271 PopUp
* pup
= new PopUp (WIN_POS_MOUSE
, 1000, true);
6273 snprintf (buf
, sizeof (buf
), _("Saved view %u"), n
+1);
6274 pup
->set_text (buf
);
6277 return false; // do not call again