-
Notifications
You must be signed in to change notification settings - Fork 716
/
Copy patheditor_ops.cc
9531 lines (7490 loc) · 227 KB
/
editor_ops.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2006 Taybin Rutkin <[email protected]>
* Copyright (C) 2005-2009 Sampo Savolainen <[email protected]>
* Copyright (C) 2005-2018 Paul Davis <[email protected]>
* Copyright (C) 2005 Karsten Wiese <[email protected]>
* Copyright (C) 2006-2015 David Robillard <[email protected]>
* Copyright (C) 2007-2012 Carl Hetherington <[email protected]>
* Copyright (C) 2007-2017 Tim Mayberry <[email protected]>
* Copyright (C) 2013-2016 Colin Fletcher <[email protected]>
* Copyright (C) 2013-2017 John Emmas <[email protected]>
* Copyright (C) 2013-2017 Nick Mainsbridge <[email protected]>
* Copyright (C) 2013-2019 Robin Gareus <[email protected]>
* Copyright (C) 2014-2019 Ben Loftis <[email protected]>
* Copyright (C) 2015 André Nusser <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* Note: public Editor methods are documented in public_editor.h */
#include <unistd.h>
#include <cstdlib>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <gtkmm/messagedialog.h>
#include "pbd/error.h"
#include "pbd/basename.h"
#include "pbd/pthread_utils.h"
#include "pbd/memento_command.h"
#include "pbd/unwind.h"
#include "pbd/whitespace.h"
#include "pbd/stateful_diff_command.h"
#include "temporal/tempo.h"
#include "gtkmm2ext/utils.h"
#include "widgets/choice.h"
#include "widgets/popup.h"
#include "widgets/prompter.h"
#include "ardour/audioengine.h"
#include "ardour/audio_track.h"
#include "ardour/audioregion.h"
#include "ardour/boost_debug.h"
#include "ardour/clip_library.h"
#include "ardour/dB.h"
#include "ardour/location.h"
#include "ardour/midi_region.h"
#include "ardour/midi_track.h"
#include "ardour/operations.h"
#include "ardour/playlist_factory.h"
#include "ardour/profile.h"
#include "ardour/quantize.h"
#include "ardour/legatize.h"
#include "ardour/region_factory.h"
#include "ardour/reverse.h"
#include "ardour/selection.h"
#include "ardour/session.h"
#include "ardour/session_playlists.h"
#include "ardour/source.h"
#include "ardour/strip_silence.h"
#include "ardour/transient_detector.h"
#include "ardour/transport_master_manager.h"
#include "ardour/transpose.h"
#include "ardour/triggerbox.h"
#include "ardour/vca_manager.h"
#include "actions.h"
#include "ardour_message.h"
#include "ardour_ui.h"
#include "audio_region_view.h"
#include "audio_streamview.h"
#include "audio_time_axis.h"
#include "automation_time_axis.h"
#include "control_point.h"
#include "debug.h"
#include "editing.h"
#include "editor.h"
#include "editor_cursors.h"
#include "editor_drag.h"
#include "editor_regions.h"
#include "editor_sources.h"
#include "editor_routes.h"
#include "gui_thread.h"
#include "insert_remove_time_dialog.h"
#include "interthread_progress_window.h"
#include "item_counts.h"
#include "keyboard.h"
#include "midi_region_view.h"
#include "mixer_ui.h"
#include "mixer_strip.h"
#include "normalize_dialog.h"
#include "note.h"
#include "paste_context.h"
#include "patch_change_dialog.h"
#include "quantize_dialog.h"
#include "region_gain_line.h"
#include "route_time_axis.h"
#include "selection.h"
#include "selection_templates.h"
#include "streamview.h"
#include "strip_silence_dialog.h"
#include "time_axis_view.h"
#include "timers.h"
#include "transpose_dialog.h"
#include "transform_dialog.h"
#include "triggerbox_ui.h"
#include "ui_config.h"
#include "utils.h"
#include "vca_time_axis.h"
#include "pbd/i18n.h"
using namespace std;
using namespace ARDOUR;
using namespace PBD;
using namespace Gtk;
using namespace Gtkmm2ext;
using namespace ArdourWidgets;
using namespace Editing;
using namespace Temporal;
using Gtkmm2ext::Keyboard;
/***********************************************************************
Editor operations
***********************************************************************/
void
Editor::undo (uint32_t n)
{
if (_session && _session->actively_recording()) {
/* no undo allowed while recording. Session will check also,
but we don't even want to get to that.
*/
return;
}
if (_drags->active ()) {
_drags->abort ();
}
paste_count = 0;
if (_session) {
_session->undo (n);
if (_session->undo_depth() == 0) {
undo_action->set_sensitive(false);
}
redo_action->set_sensitive(true);
begin_selection_op_history ();
}
}
void
Editor::redo (uint32_t n)
{
if (_session && _session->actively_recording()) {
/* no redo allowed while recording. Session will check also,
but we don't even want to get to that.
*/
return;
}
if (_drags->active ()) {
_drags->abort ();
}
paste_count = 0;
if (_session) {
_session->redo (n);
if (_session->redo_depth() == 0) {
redo_action->set_sensitive(false);
}
undo_action->set_sensitive(true);
begin_selection_op_history ();
}
}
void
Editor::split_regions_at (timepos_t const & where, RegionSelection& regions)
{
bool frozen = false;
list<boost::shared_ptr<Playlist> > used_playlists;
list<RouteTimeAxisView*> used_trackviews;
if (regions.empty()) {
return;
}
begin_reversible_command (_("split"));
if (regions.size() == 1) {
/* TODO: if splitting a single region, and snap-to is using
region boundaries, maybe we shouldn't pay attention to them? */
} else {
frozen = true;
EditorFreeze(); /* Emit Signal */
}
for (RegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
RegionSelection::iterator tmp;
/* XXX this test needs to be more complicated, to make sure we really
have something to split.
*/
if (!(*a)->region()->covers (where)) {
++a;
continue;
}
tmp = a;
++tmp;
boost::shared_ptr<Playlist> pl = (*a)->region()->playlist();
if (!pl) {
a = tmp;
continue;
}
if (!pl->frozen()) {
/* we haven't seen this playlist before */
/* remember used playlists so we can thaw them later */
used_playlists.push_back(pl);
TimeAxisView& tv = (*a)->get_time_axis_view();
RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
if (rtv) {
used_trackviews.push_back (rtv);
}
pl->freeze();
}
if (pl) {
pl->clear_changes ();
pl->split_region ((*a)->region(), where);
_session->add_command (new StatefulDiffCommand (pl));
}
a = tmp;
}
latest_regionviews.clear ();
vector<sigc::connection> region_added_connections;
for (list<RouteTimeAxisView*>::iterator i = used_trackviews.begin(); i != used_trackviews.end(); ++i) {
region_added_connections.push_back ((*i)->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view)));
}
while (used_playlists.size() > 0) {
list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
(*i)->thaw();
used_playlists.pop_front();
}
for (vector<sigc::connection>::iterator c = region_added_connections.begin(); c != region_added_connections.end(); ++c) {
(*c).disconnect ();
}
if (frozen){
EditorThaw(); /* Emit Signal */
}
if (_session->abort_empty_reversible_command ()) {
/* no change was made */
return;
}
RegionSelectionAfterSplit rsas = Config->get_region_selection_after_split();
//if the user has "Clear Selection" as their post-split behavior, then clear the selection
if (!latest_regionviews.empty() && (rsas == None)) {
selection->clear_objects();
selection->clear_time();
//but leave track selection intact
}
//if the user doesn't want to preserve the "Existing" selection, then clear the selection
if (!(rsas & Existing)) {
selection->clear_objects();
selection->clear_time();
}
//if the user wants newly-created regions to be selected, then select them:
if (mouse_mode == MouseObject) {
for (RegionSelection::iterator ri = latest_regionviews.begin(); ri != latest_regionviews.end(); ri++) {
if ((*ri)->region()->position() < where) {
// new regions created before the split
if (rsas & NewlyCreatedLeft) {
selection->add (*ri);
}
} else {
// new regions created after the split
if (rsas & NewlyCreatedRight) {
selection->add (*ri);
}
}
}
}
commit_reversible_command ();
}
/** Move one extreme of the current range selection. If more than one range is selected,
* the start of the earliest range or the end of the latest range is moved.
*
* @param move_end true to move the end of the current range selection, false to move
* the start.
* @param next true to move the extreme to the next region boundary, false to move to
* the previous.
*/
void
Editor::move_range_selection_start_or_end_to_region_boundary (bool move_end, bool next)
{
if (selection->time.start_time() == selection->time.end_time()) {
return;
}
timepos_t start = selection->time.start_time ();
timepos_t end = selection->time.end_time ();
/* the position of the thing we may move */
timepos_t pos = move_end ? end : start;
int dir = next ? 1 : -1;
/* so we don't find the current region again */
if (dir > 0 || pos.is_positive()) {
pos.increment ();
}
timepos_t const target = get_region_boundary (pos, dir, true, false);
if (target.is_negative ()) {
return;
}
if (move_end) {
end = target;
} else {
start = target;
}
if (end < start) {
return;
}
begin_reversible_selection_op (_("alter selection"));
selection->set_preserving_all_ranges (start, end);
commit_reversible_selection_op ();
}
bool
Editor::nudge_forward_release (GdkEventButton* ev)
{
if (ev->state & Keyboard::PrimaryModifier) {
nudge_forward (false, true);
} else {
nudge_forward (false, false);
}
return false;
}
bool
Editor::nudge_backward_release (GdkEventButton* ev)
{
if (ev->state & Keyboard::PrimaryModifier) {
nudge_backward (false, true);
} else {
nudge_backward (false, false);
}
return false;
}
void
Editor::nudge_forward (bool next, bool force_playhead)
{
timecnt_t distance;
timecnt_t next_distance;
if (!_session) {
return;
}
RegionSelection rs = get_regions_from_selection_and_entered ();
if (!force_playhead && !rs.empty()) {
begin_reversible_command (_("nudge regions forward"));
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
boost::shared_ptr<Region> r ((*i)->region());
distance = get_nudge_distance (r->position(), next_distance);
if (next) {
distance = next_distance;
}
r->clear_changes ();
r->set_position (r->position() + distance);
_session->add_command (new StatefulDiffCommand (r));
}
commit_reversible_command ();
} else if (!force_playhead && !selection->markers.empty()) {
bool is_start;
bool in_command = false;
for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) {
Location* loc = find_location_from_marker ((*i), is_start);
if (loc) {
XMLNode& before (loc->get_state());
if (is_start) {
distance = get_nudge_distance (loc->start(), next_distance);
if (next) {
distance = next_distance;
}
if (timepos_t (timecnt_t::max (distance.time_domain()) - distance) > loc->start() + loc->length()) {
loc->set_start (loc->start() + distance, false);
} else {
loc->set_start (timepos_t::max (loc->length().time_domain()).earlier (loc->length()), false);
}
} else {
distance = get_nudge_distance (loc->end(), next_distance);
if (next) {
distance = next_distance;
}
if (timepos_t (timecnt_t::max (distance.time_domain()) - distance) > loc->end()) {
loc->set_end (loc->end() + distance, false);
} else {
loc->set_end (timepos_t::max (loc->end().time_domain()), false);
}
if (loc->is_session_range()) {
_session->set_session_range_is_free (false);
}
}
if (!in_command) {
begin_reversible_command (_("nudge location forward"));
in_command = true;
}
XMLNode& after (loc->get_state());
_session->add_command (new MementoCommand<Location>(*loc, &before, &after));
}
}
if (in_command) {
commit_reversible_command ();
}
} else {
distance = get_nudge_distance (timepos_t (playhead_cursor()->current_sample ()), next_distance);
_session->request_locate ((timepos_t (playhead_cursor()->current_sample ()) + distance).samples());
}
}
void
Editor::nudge_backward (bool next, bool force_playhead)
{
timecnt_t distance;
timecnt_t next_distance;
if (!_session) {
return;
}
RegionSelection rs = get_regions_from_selection_and_entered ();
if (!force_playhead && !rs.empty()) {
begin_reversible_command (_("nudge regions backward"));
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
boost::shared_ptr<Region> r ((*i)->region());
distance = get_nudge_distance (r->position(), next_distance);
if (next) {
distance = next_distance;
}
r->clear_changes ();
if (r->position() > distance) {
r->set_position (r->position().earlier (distance));
} else {
r->set_position (timepos_t());
}
_session->add_command (new StatefulDiffCommand (r));
}
commit_reversible_command ();
} else if (!force_playhead && !selection->markers.empty()) {
bool is_start;
bool in_command = false;
for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) {
Location* loc = find_location_from_marker ((*i), is_start);
if (loc) {
XMLNode& before (loc->get_state());
if (is_start) {
distance = get_nudge_distance (loc->start(), next_distance);
if (next) {
distance = next_distance;
}
if (timepos_t (distance) < loc->start()) {
loc->set_start (loc->start().earlier (distance), false);
} else {
loc->set_start (timepos_t(), false);
}
} else {
distance = get_nudge_distance (loc->end(), next_distance);
if (next) {
distance = next_distance;
}
if (timepos_t (distance + loc->length()) < loc->end()) {
loc->set_end (loc->end().earlier (distance), false);
} else {
loc->set_end (timepos_t (loc->length()), false);
}
if (loc->is_session_range()) {
_session->set_session_range_is_free (false);
}
}
if (!in_command) {
begin_reversible_command (_("nudge location forward"));
in_command = true;
}
XMLNode& after (loc->get_state());
_session->add_command (new MementoCommand<Location>(*loc, &before, &after));
}
}
if (in_command) {
commit_reversible_command ();
}
} else {
distance = get_nudge_distance (timepos_t (playhead_cursor()->current_sample ()), next_distance);
if (_playhead_cursor->current_sample () > distance.samples()) {
_session->request_locate ((timepos_t (_playhead_cursor->current_sample ()).earlier (distance)).samples());
} else {
_session->goto_start();
}
}
}
void
Editor::nudge_forward_capture_offset ()
{
RegionSelection rs = get_regions_from_selection_and_entered ();
if (!_session || rs.empty()) {
return;
}
begin_reversible_command (_("nudge forward"));
samplepos_t const distance = _session->worst_output_latency();
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
boost::shared_ptr<Region> r ((*i)->region());
r->clear_changes ();
r->set_position (r->position() + timecnt_t (distance));
_session->add_command(new StatefulDiffCommand (r));
}
commit_reversible_command ();
}
void
Editor::nudge_backward_capture_offset ()
{
RegionSelection rs = get_regions_from_selection_and_entered ();
if (!_session || rs.empty()) {
return;
}
begin_reversible_command (_("nudge backward"));
timepos_t const distance (_session->worst_output_latency());
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
boost::shared_ptr<Region> r ((*i)->region());
r->clear_changes ();
if (r->position() > distance) {
r->set_position (r->position().earlier (distance));
} else {
r->set_position (timepos_t ());
}
_session->add_command(new StatefulDiffCommand (r));
}
commit_reversible_command ();
}
struct RegionSelectionPositionSorter {
bool operator() (RegionView* a, RegionView* b) {
return a->region()->position() < b->region()->position();
}
};
void
Editor::sequence_regions ()
{
timepos_t r_end;
timepos_t r_end_prev;
int iCount=0;
if (!_session) {
return;
}
RegionSelection rs = get_regions_from_selection_and_entered ();
rs.sort(RegionSelectionPositionSorter());
if (!rs.empty()) {
bool in_command = false;
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
boost::shared_ptr<Region> r ((*i)->region());
r->clear_changes();
if(r->locked())
{
continue;
}
if(r->position_locked())
{
continue;
}
if(iCount>0)
{
r_end_prev=r_end;
r->set_position(r_end_prev);
}
if (!in_command) {
begin_reversible_command (_("sequence regions"));
in_command = true;
}
_session->add_command (new StatefulDiffCommand (r));
r_end=r->position() + r->length();
iCount++;
}
if (in_command) {
commit_reversible_command ();
}
}
}
/* DISPLAY MOTION */
void
Editor::move_to_start ()
{
_session->goto_start ();
}
void
Editor::move_to_end ()
{
_session->request_locate (_session->current_end_sample());
}
void
Editor::build_region_boundary_cache ()
{
/* TODO: maybe set a timer so we don't recalutate when lots of changes are coming in */
/* TODO: maybe somehow defer this until session is fully loaded. */
if (!_region_boundary_cache_dirty)
return;
timepos_t pos;
vector<RegionPoint> interesting_points;
boost::shared_ptr<Region> r;
TrackViewList tracks;
bool at_end = false;
region_boundary_cache.clear ();
if (_session == 0) {
return;
}
bool maybe_first_sample = false;
if (UIConfiguration::instance().get_snap_to_region_start()) {
interesting_points.push_back (Start);
maybe_first_sample = true;
}
if (UIConfiguration::instance().get_snap_to_region_end()) {
interesting_points.push_back (End);
}
if (UIConfiguration::instance().get_snap_to_region_sync()) {
interesting_points.push_back (SyncPoint);
}
/* if no snap selections are set, boundary cache should be left empty */
if ( interesting_points.empty() ) {
_region_boundary_cache_dirty = false;
return;
}
TimeAxisView *ontrack = 0;
TrackViewList tlist;
tlist = track_views.filter_to_unique_playlists ();
if (maybe_first_sample) {
TrackViewList::const_iterator i;
for (i = tlist.begin(); i != tlist.end(); ++i) {
boost::shared_ptr<Playlist> pl = (*i)->playlist();
if (pl && pl->count_regions_at (timepos_t())) {
region_boundary_cache.push_back (timepos_t());
break;
}
}
}
/* allow regions to snap to the video start (if any) as if it were a "region" */
if (ARDOUR_UI::instance()->video_timeline) {
ARDOUR::samplepos_t vo = ARDOUR_UI::instance()->video_timeline->get_video_start_offset();
if (std::find (region_boundary_cache.begin(), region_boundary_cache.end(), vo) == region_boundary_cache.end()) {
region_boundary_cache.push_back (timepos_t (ARDOUR_UI::instance()->video_timeline->get_video_start_offset()));
}
}
std::pair<timepos_t, timepos_t> ext = session_gui_extents (false);
timepos_t session_end = ext.second;
while (pos < session_end && !at_end) {
timepos_t rpos;
timepos_t lpos = session_end;
for (vector<RegionPoint>::iterator p = interesting_points.begin(); p != interesting_points.end(); ++p) {
if ((r = find_next_region (pos, *p, 1, tlist, &ontrack)) == 0) {
if (*p == interesting_points.back()) {
at_end = true;
}
/* move to next point type */
continue;
}
switch (*p) {
case Start:
rpos = r->position();
break;
case End:
rpos = r->end();
break;
case SyncPoint:
rpos = r->sync_position ();
break;
default:
break;
}
if (rpos < lpos) {
lpos = rpos;
}
/* prevent duplicates, but we don't use set<> because we want to be able
to sort later.
*/
vector<timepos_t>::iterator ri;
for (ri = region_boundary_cache.begin(); ri != region_boundary_cache.end(); ++ri) {
if (*ri == rpos) {
break;
}
}
if (ri == region_boundary_cache.end()) {
region_boundary_cache.push_back (rpos);
}
}
pos = lpos.increment();
}
/* finally sort to be sure that the order is correct */
sort (region_boundary_cache.begin(), region_boundary_cache.end());
_region_boundary_cache_dirty = false;
}
boost::shared_ptr<Region>
Editor::find_next_region (timepos_t const & pos, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack)
{
TrackViewList::iterator i;
timecnt_t closest = timecnt_t::max (pos.time_domain());
boost::shared_ptr<Region> ret;
timepos_t rpos;
timepos_t track_pos;
for (i = tracks.begin(); i != tracks.end(); ++i) {
timecnt_t distance;
boost::shared_ptr<Region> r;
track_pos = pos;
if ((r = (*i)->find_next_region (track_pos, point, dir)) == 0) {
continue;
}
switch (point) {
case Start:
rpos = r->position ();
break;
case End:
rpos = r->end ();
break;
case SyncPoint:
rpos = r->sync_position ();
break;
}
if (rpos > pos) {
distance = pos.distance (rpos);
} else {
distance = rpos.distance (pos);
}
if (distance < closest) {
closest = distance;
if (ontrack != 0) {
*ontrack = (*i);
}
ret = r;
}
}
return ret;
}
timepos_t
Editor::find_next_region_boundary (timepos_t const & pos, int32_t dir, const TrackViewList& tracks)
{
timecnt_t distance = timecnt_t::max (pos.time_domain());
timepos_t current_nearest = timepos_t::max (pos.time_domain());
for (TrackViewList::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
timepos_t contender;
timecnt_t d;
RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
if (!rtv) {
continue;
}
if ((contender = rtv->find_next_region_boundary (pos, dir)) < 0) {
continue;
}
d = contender.distance (pos);
if (d < distance) {
current_nearest = contender;
distance = d;
}
}
return current_nearest;
}
timepos_t
Editor::get_region_boundary (timepos_t const & pos, int32_t dir, bool with_selection, bool only_onscreen)
{
timepos_t target;
TrackViewList tvl;
if (with_selection && Config->get_region_boundaries_from_selected_tracks()) {
if (!selection->tracks.empty()) {
target = find_next_region_boundary (pos, dir, selection->tracks);
} else {
if (only_onscreen || Config->get_region_boundaries_from_onscreen_tracks()) {
get_onscreen_tracks (tvl);
target = find_next_region_boundary (pos, dir, tvl);
} else {
target = find_next_region_boundary (pos, dir, track_views);
}
}
} else {
if (only_onscreen || Config->get_region_boundaries_from_onscreen_tracks()) {
get_onscreen_tracks (tvl);
target = find_next_region_boundary (pos, dir, tvl);
} else {
target = find_next_region_boundary (pos, dir, track_views);
}
}
return target;
}
void
Editor::cursor_to_region_boundary (bool with_selection, int32_t dir)
{
timepos_t pos (_playhead_cursor->current_sample ());
timepos_t target;
if (!_session) {
return;
}
// so we don't find the current region again..
if (dir > 0 || pos > 0) {
pos = pos.increment();
}
if ((target = get_region_boundary (pos, dir, with_selection, false)) < 0) {
return;
}
_session->request_locate (target.samples());
}
void
Editor::cursor_to_next_region_boundary (bool with_selection)
{
cursor_to_region_boundary (with_selection, 1);
}
void
Editor::cursor_to_previous_region_boundary (bool with_selection)
{
cursor_to_region_boundary (with_selection, -1);
}