-
Notifications
You must be signed in to change notification settings - Fork 716
/
Copy patheditor_mouse.cc
3151 lines (2599 loc) · 83.6 KB
/
editor_mouse.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-2018 Paul Davis <[email protected]>
* Copyright (C) 2006-2015 David Robillard <[email protected]>
* Copyright (C) 2006-2016 Tim Mayberry <[email protected]>
* Copyright (C) 2006 Sampo Savolainen <[email protected]>
* Copyright (C) 2007-2012 Carl Hetherington <[email protected]>
* Copyright (C) 2007 Doug McLain <[email protected]>
* Copyright (C) 2013-2014 Colin Fletcher <[email protected]>
* Copyright (C) 2013-2019 Robin Gareus <[email protected]>
* Copyright (C) 2014-2017 Nick Mainsbridge <[email protected]>
* Copyright (C) 2014-2018 Ben Loftis <[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.
*/
#include <cassert>
#include <cstdlib>
#include <stdint.h>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <bitset>
#include "pbd/error.h"
#include "pbd/enumwriter.h"
#include "pbd/memento_command.h"
#include "pbd/basename.h"
#include "pbd/stateful_diff_command.h"
#include "gtkmm2ext/bindings.h"
#include "gtkmm2ext/utils.h"
#include "canvas/canvas.h"
#include "ardour/audioplaylist.h"
#include "ardour/audioregion.h"
#include "ardour/operations.h"
#include "ardour/playlist.h"
#include "ardour/profile.h"
#include "ardour/region_factory.h"
#include "ardour/route.h"
#include "ardour/session.h"
#include "ardour/types.h"
#include "widgets/prompter.h"
#include "actions.h"
#include "ardour_ui.h"
#include "editor.h"
#include "time_axis_view.h"
#include "audio_time_axis.h"
#include "audio_region_view.h"
#include "midi_region_view.h"
#include "marker.h"
#include "streamview.h"
#include "region_gain_line.h"
#include "rc_option_editor.h"
#include "automation_time_axis.h"
#include "control_point.h"
#include "selection.h"
#include "keyboard.h"
#include "editing.h"
#include "rgb_macros.h"
#include "control_point_dialog.h"
#include "editor_drag.h"
#include "automation_region_view.h"
#include "edit_note_dialog.h"
#include "mouse_cursors.h"
#include "editor_cursors.h"
#include "region_peak_cursor.h"
#include "velocity_ghost_region.h"
#include "verbose_cursor.h"
#include "note.h"
#include "pbd/i18n.h"
using namespace std;
using namespace ARDOUR;
using namespace PBD;
using namespace Gtk;
using namespace Editing;
using namespace Temporal;
using Gtkmm2ext::Keyboard;
bool
Editor::mouse_sample (samplepos_t& where, bool& in_track_canvas) const
{
/* gdk_window_get_pointer() has X11's XQueryPointer semantics in that it only
* pays attentions to subwindows. this means that menu windows are ignored, and
* if the pointer is in a menu, the return window from the call will be the
* the regular subwindow *under* the menu.
*
* this matters quite a lot if the pointer is moving around in a menu that overlaps
* the track canvas because we will believe that we are within the track canvas
* when we are not. therefore, we track enter/leave events for the track canvas
* and allow that to override the result of gdk_window_get_pointer().
*/
if (!within_track_canvas) {
return false;
}
int x, y;
Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->_track_canvas->get_window();
if (!canvas_window) {
return false;
}
Glib::RefPtr<const Gdk::Window> pointer_window = Gdk::Display::get_default()->get_window_at_pointer (x, y);
if (!pointer_window) {
return false;
}
if (pointer_window != canvas_window) {
in_track_canvas = false;
return false;
}
in_track_canvas = true;
GdkEvent event;
event.type = GDK_BUTTON_RELEASE;
event.button.x = x;
event.button.y = y;
where = window_event_sample (&event, 0, 0);
return true;
}
samplepos_t
Editor::window_event_sample (GdkEvent const * event, double* pcx, double* pcy) const
{
ArdourCanvas::Duple d;
if (!gdk_event_get_coords (event, &d.x, &d.y)) {
return 0;
}
/* event coordinates are in window units, so convert to canvas
*/
d = _track_canvas->window_to_canvas (d);
if (pcx) {
*pcx = d.x;
}
if (pcy) {
*pcy = d.y;
}
return pixel_to_sample (d.x);
}
timepos_t
Editor::canvas_event_time (GdkEvent const * event, double* pcx, double* pcy) const
{
timepos_t pos (canvas_event_sample (event, pcx, pcy));
if (default_time_domain() == Temporal::AudioTime) {
return pos;
}
return timepos_t (pos.beats());
}
samplepos_t
Editor::canvas_event_sample (GdkEvent const * event, double* pcx, double* pcy) const
{
double x;
double y;
/* event coordinates are already in canvas units */
if (!gdk_event_get_coords (event, &x, &y)) {
cerr << "!NO c COORDS for event type " << event->type << endl;
return 0;
}
if (pcx) {
*pcx = x;
}
if (pcy) {
*pcy = y;
}
/* note that pixel_to_sample_from_event() never returns less than zero, so even if the pixel
position is negative (as can be the case with motion events in particular),
the sample location is always positive.
*/
return pixel_to_sample_from_event (x);
}
void
Editor::set_current_trimmable (std::shared_ptr<Trimmable> t)
{
std::shared_ptr<Trimmable> st = _trimmable.lock();
if (!st || st == t) {
_trimmable = t;
}
}
void
Editor::set_current_movable (std::shared_ptr<Movable> m)
{
std::shared_ptr<Movable> sm = _movable.lock();
if (!sm || sm != m) {
_movable = m;
}
}
void
Editor::mouse_mode_object_range_toggled()
{
set_mouse_mode (mouse_mode, true); /* updates set-mouse-mode-range */
}
bool
Editor::snap_mode_button_clicked (GdkEventButton* ev)
{
if (ev->button != 3) {
cycle_snap_mode();
return true;
}
RCOptionEditor* rc_option_editor = ARDOUR_UI::instance()->get_rc_option_editor();
if (rc_option_editor) {
ARDOUR_UI::instance()->show_tabbable (rc_option_editor);
rc_option_editor->set_current_page (_("Editor/Snap"));
}
return true;
}
Glib::RefPtr<Action>
Editor::get_mouse_mode_action(MouseMode m) const
{
switch (m) {
case MouseRange:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-range"));
case MouseObject:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-object"));
case MouseCut:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-cut"));
case MouseDraw:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-draw"));
case MouseTimeFX:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-timefx"));
case MouseGrid:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-grid"));
case MouseContent:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-content"));
case MouseAudition:
return ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-audition"));
}
return Glib::RefPtr<Action>();
}
void
Editor::set_mouse_mode (MouseMode m, bool force)
{
if (_drags->active ()) {
return;
}
if (!force && m == mouse_mode) {
return;
}
if (ARDOUR::Profile->get_mixbus()) {
if (m == MouseAudition) {
m = MouseRange;
}
}
Glib::RefPtr<Action> act = get_mouse_mode_action(m);
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
/* go there and back to ensure that the toggled handler is called to set up mouse_mode */
tact->set_active (false);
tact->set_active (true);
/* NOTE: this will result in a call to mouse_mode_toggled which does the heavy lifting */
}
void
Editor::mouse_mode_toggled (MouseMode m)
{
if (ARDOUR::Profile->get_mixbus()) {
if (m == MouseAudition) {
m = MouseRange;
}
}
Glib::RefPtr<Action> act = get_mouse_mode_action(m);
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
if (!tact->get_active()) {
/* this was just the notification that the old mode has been
* left. we'll get called again with the new mode active in a
* jiffy.
*/
return;
}
if (_session && mouse_mode == MouseAudition) {
/* stop transport and reset default speed to avoid oddness with
auditioning */
_session->request_stop ();
_session->reset_transport_speed ();
}
const bool was_internal = internal_editing();
mouse_mode = m;
/* Ben ToDo: once we have a dedicated 'region edit panel', we can store
* one snap mode in the editor canvas and another one in the editor,
* relieving the complexity here */
/* Switch snap type/mode if we're moving to/from an internal tool. Note
this must toggle the actions and not call set_snap_*() directly,
otherwise things get out of sync and the combo box stops working. */
if (!UIConfiguration::instance().get_grid_follows_internal()) {
grid_type_action(pre_internal_grid_type)->set_active(true);
snap_mode_action(pre_internal_snap_mode)->set_active(true);
} else if (!was_internal && internal_editing()) {
grid_type_action(internal_grid_type)->set_active(true);
snap_mode_action(internal_snap_mode)->set_active(true);
} else if (was_internal && !internal_editing()) {
grid_type_action(pre_internal_grid_type)->set_active(true);
snap_mode_action(pre_internal_snap_mode)->set_active(true);
}
instant_save ();
/* this should generate a new enter event which will
trigger the appropriate cursor.
*/
if (_track_canvas) {
_track_canvas->re_enter ();
}
set_gain_envelope_visibility ();
update_time_selection_display ();
if (mouse_mode == MouseDraw) {
draw_box.show();
_draw_box_spacer.show();
} else {
draw_box.hide();
_draw_box_spacer.hide();
}
if (mouse_mode == MouseGrid) {
grid_box.show();
_grid_box_spacer.show ();
_canvas_grid_zone->set_ignore_events (false);
} else {
grid_box.hide ();
_grid_box_spacer.hide ();
_canvas_grid_zone->set_ignore_events (true);
}
if (internal_editing()) {
/* reinstate any existing MIDI note (and by extension, MIDI
* region) selection for internal edit mode. This allows a user
* to enter/exit/enter this mode without losing a selection of
* notes.
*/
catch_up_on_midi_selection ();
/* ensure that the track canvas has focus, so that key events
will get directed to the correct place.
*/
_track_canvas->grab_focus ();
/* enable MIDI editing actions, which in turns enables their
bindings
*/
ActionManager::set_sensitive (_midi_actions, true);
/* mark "magic widget focus" so that we handle key events
* correctly
*/
Keyboard::magic_widget_grab_focus ();
} else {
/* undo some of the above actions, since we're not in internal
edit mode.
*/
ActionManager::set_sensitive (_midi_actions, false);
Keyboard::magic_widget_drop_focus ();
}
if (was_internal && !internal_editing()) {
/* drop any selected regions so that they in turn
* redraw any selected notes. This essentially the
* opposite of ::catch_up_on_midi_selection() called
* above.
*/
get_selection().clear_regions ();
}
update_all_enter_cursors ();
MouseModeChanged (); /* EMIT SIGNAL */
if ((was_internal && !internal_editing()) ||
(!was_internal && internal_editing())) {
queue_redisplay_track_views ();
}
}
bool
Editor::internal_editing() const
{
return mouse_mode == Editing::MouseContent || mouse_mode == Editing::MouseDraw;
}
void
Editor::update_time_selection_display ()
{
switch (mouse_mode) {
case MouseRange:
selection->clear_objects ();
selection->clear_midi_notes ();
break;
case MouseObject:
selection->clear_time ();
selection->clear_midi_notes ();
break;
case MouseDraw:
/* Clear regions, but not time or tracks, since that
* would destroy the range selection rectangle, which we need to stick
* around for AutomationRangeDrag. */
selection->clear_regions ();
selection->clear_playlists ();
/* .. unless there is no track selection (i.e. arrangement section
* selection). In which case time is cleared too.
*/
if (selection->tracks.empty ()) {
selection->clear_time ();
}
break;
case MouseContent:
/* This handles internal edit.
Clear everything except points and notes.
*/
selection->clear_regions();
selection->clear_lines();
selection->clear_playlists ();
selection->clear_time ();
selection->clear_tracks ();
break;
case MouseTimeFX:
/* We probably want to keep region selection */
selection->clear_points ();
selection->clear_lines();
selection->clear_playlists ();
selection->clear_time ();
selection->clear_tracks ();
break;
case MouseAudition:
/*Don't lose lines or points if no action in this mode */
selection->clear_regions ();
selection->clear_playlists ();
selection->clear_time ();
selection->clear_tracks ();
break;
case MouseGrid:
default:
/*Clear everything */
selection->clear_objects();
selection->clear_time ();
selection->clear_tracks ();
break;
}
}
void
Editor::step_mouse_mode (bool next)
{
const int n_mouse_modes = (int)MouseContent + 1;
int current = (int)current_mouse_mode();
if (next) {
set_mouse_mode((MouseMode)((current + 1) % n_mouse_modes));
} else {
set_mouse_mode((MouseMode)((current + n_mouse_modes - 1) % n_mouse_modes));
}
}
void
Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
{
/* in object/audition/timefx/gain-automation mode,
* any button press sets the selection if the object
* can be selected. this is a bit of hack, because
* we want to avoid this if the mouse operation is a
* region alignment.
*
* note: not dbl-click or triple-click
*
* Also note that there is no region selection in internal edit mode, otherwise
* for operations operating on the selection (e.g. cut) it is not obvious whether
* to cut notes or regions.
*/
MouseMode eff_mouse_mode = effective_mouse_mode ();
if (eff_mouse_mode == MouseCut) {
/* never change selection in cut mode */
return;
}
if (get_smart_mode() && eff_mouse_mode == MouseRange && event->button.button == 3 && item_type == RegionItem) {
/* context clicks are always about object properties, even if
* we're in range mode within smart mode.
*/
eff_mouse_mode = MouseObject;
}
/* special case: allow drag of region fade in/out in object mode with join object/range enabled */
if (get_smart_mode()) {
switch (item_type) {
case FadeInHandleItem:
case FadeInTrimHandleItem:
case FadeOutHandleItem:
case FadeOutTrimHandleItem:
eff_mouse_mode = MouseObject;
break;
default:
break;
}
}
if (((mouse_mode != MouseObject) &&
(mouse_mode != MouseAudition || item_type != RegionItem) &&
(mouse_mode != MouseTimeFX || item_type != RegionItem) &&
(mouse_mode != MouseDraw) &&
(mouse_mode != MouseContent || item_type == RegionItem)) ||
((event->type != GDK_BUTTON_PRESS && event->type != GDK_BUTTON_RELEASE) || event->button.button > 3)) {
return;
}
if (event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) {
if ((event->button.state & Keyboard::RelevantModifierKeyMask) && event->button.button != 1) {
/* almost no selection action on modified button-2 or button-3 events */
if ((item_type != RegionItem && event->button.button != 2)
/* for selection of control points prior to delete (shift-right click) */
&& !(item_type == ControlPointItem && event->button.button == 3 && event->type == GDK_BUTTON_PRESS)) {
return;
}
}
}
Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
bool press = (event->type == GDK_BUTTON_PRESS);
if (press) {
_mouse_changed_selection = false;
}
switch (item_type) {
case RegionItem:
if (eff_mouse_mode == MouseDraw) {
break;
}
if (press) {
if (eff_mouse_mode != MouseRange) {
_mouse_changed_selection = set_selected_regionview_from_click (press, op);
} else {
/* don't change the selection unless the
* clicked track is not currently selected. if
* so, "collapse" the selection to just this track
*/
if (!selection->selected (clicked_axisview)) {
set_selected_track_as_side_effect (Selection::Set);
}
}
} else {
if (eff_mouse_mode != MouseRange) {
_mouse_changed_selection |= set_selected_regionview_from_click (press, op);
}
}
break;
case RegionViewNameHighlight:
case RegionViewName:
case LeftFrameHandle:
case RightFrameHandle:
case FadeInHandleItem:
case FadeInTrimHandleItem:
case FadeInItem:
case FadeOutHandleItem:
case FadeOutTrimHandleItem:
case FadeOutItem:
case StartCrossFadeItem:
case EndCrossFadeItem:
if (get_smart_mode() || eff_mouse_mode != MouseRange) {
_mouse_changed_selection |= set_selected_regionview_from_click (press, op);
} else if (event->type == GDK_BUTTON_PRESS) {
set_selected_track_as_side_effect (op);
}
break;
case ControlPointItem:
/* for object/track exclusivity, we don't call set_selected_track_as_side_effect (op); */
if (eff_mouse_mode == MouseContent) {
if (event->button.button != 3) {
_mouse_changed_selection |= set_selected_control_point_from_click (press, op);
} else {
_mouse_changed_selection |= set_selected_control_point_from_click (press, Selection::Set);
}
}
break;
case GainLineItem:
if (eff_mouse_mode != MouseRange) {
AutomationLine* argl = reinterpret_cast<AutomationLine*> (item->get_data ("line"));
std::list<Selectable*> selectables;
uint32_t before, after;
samplecnt_t const where = (samplecnt_t) floor (event->button.x * samples_per_pixel) - clicked_regionview->region ()->position_sample ();
if (!argl || !argl->control_points_adjacent (where, before, after)) {
break;
}
selectables.push_back (argl->nth (before));
selectables.push_back (argl->nth (after));
switch (op) {
case Selection::Set:
if (press) {
selection->set (selectables);
_mouse_changed_selection = true;
}
break;
case Selection::Add:
if (press) {
selection->add (selectables);
_mouse_changed_selection = true;
}
break;
case Selection::Toggle:
if (press) {
selection->toggle (selectables);
_mouse_changed_selection = true;
}
break;
case Selection::Extend:
/* XXX */
break;
}
}
break;
case AutomationLineItem:
if (eff_mouse_mode != MouseRange) {
AutomationLine* al = reinterpret_cast<AutomationLine*> (item->get_data ("line"));
std::list<Selectable*> selectables;
double mx = event->button.x;
double my = event->button.y;
al->grab_item().canvas_to_item (mx, my);
uint32_t before, after;
samplecnt_t const where = (samplecnt_t) floor (mx * samples_per_pixel);
if (!al || !al->control_points_adjacent (where, before, after)) {
break;
}
selectables.push_back (al->nth (before));
selectables.push_back (al->nth (after));
switch (op) {
case Selection::Set:
if (press) {
selection->set (selectables);
_mouse_changed_selection = true;
}
break;
case Selection::Add:
if (press) {
selection->add (selectables);
_mouse_changed_selection = true;
}
break;
case Selection::Toggle:
if (press) {
selection->toggle (selectables);
_mouse_changed_selection = true;
}
break;
case Selection::Extend:
/* XXX */
break;
}
}
break;
case StreamItem:
/* for context click, select track */
if (event->button.button == 3) {
selection->clear_tracks ();
set_selected_track_as_side_effect (op);
/* We won't get a release.*/
begin_reversible_selection_op (X_("Button 3 Menu Select"));
commit_reversible_selection_op ();
}
break;
case AutomationTrackItem:
if (eff_mouse_mode != MouseDraw && op == Selection::Set) {
set_selected_track_as_side_effect (op);
}
break;
case NoteItem:
if (press && event->button.button == 3) {
NoteBase* cnote = reinterpret_cast<NoteBase*> (item->get_data ("notebase"));
assert (cnote);
if (cnote->region_view().selection_size() == 0 || !cnote->selected()) {
selection->clear_points();
cnote->region_view().unique_select (cnote);
/* we won't get the release, so store the selection change now */
begin_reversible_selection_op (X_("Button 3 Note Selection"));
commit_reversible_selection_op ();
}
}
break;
default:
break;
}
if ((!press) && _mouse_changed_selection) {
begin_reversible_selection_op (X_("Button Selection"));
commit_reversible_selection_op ();
_mouse_changed_selection = false;
}
}
bool
Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
{
/* single mouse clicks on any of these item types operate
* independent of mouse mode, mostly because they are
* not on the main track canvas or because we want
* them to be modeless.
*/
NoteBase* note = NULL;
switch (item_type) {
case PlayheadCursorItem:
_drags->set (new CursorDrag (this, *_playhead_cursor, true), event);
return true;
case MarkerItem:
if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
hide_marker (item, event);
} else {
ArdourMarker* marker = static_cast<ArdourMarker*> (item->get_data ("marker"));
if (marker->type() == ArdourMarker::RegionCue) {
_drags->set (new RegionMarkerDrag (this, marker->region_view(), item), event);
} else {
_drags->set (new MarkerDrag (this, item), event);
}
}
return true;
case TempoMarkerItem:
if (ArdourKeyboard::indicates_constraint (event->button.state)) {
_drags->set (new TempoEndDrag (this, item), event);
} else {
_drags->set (new TempoMarkerDrag (this, item), event);
}
return true;
case BBTMarkerItem:
_drags->set (new BBTMarkerDrag (this, item), event);
return true;
case SelectionMarkerItem:
_drags->set (new SelectionMarkerDrag (this, item), event);
return true;
case MeterMarkerItem:
_drags->set (
new MeterMarkerDrag (
this,
item,
ArdourKeyboard::indicates_copy (event->button.state)
),
event
);
return true;
case VideoBarItem:
_drags->set (new VideoTimeLineDrag (this, item), event);
return true;
break;
case TempoBarItem:
case TempoCurveItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)
&& !ArdourKeyboard::indicates_constraint (event->button.state)) {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
} else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
_drags->set (new TempoCurveDrag (this, item), event);
return true;
}
return true;
case MeterBarItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)
&& !ArdourKeyboard::indicates_constraint (event->button.state)) {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
}
return true;
case BBTRulerItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)
&& !ArdourKeyboard::indicates_constraint (event->button.state)) {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
}
return true;
case TimecodeRulerItem:
case SamplesRulerItem:
case MinsecRulerItem:
case MarkerBarItem:
case SectionMarkerBarItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)
&& !ArdourKeyboard::indicates_constraint (event->button.state)) {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
}
return true;
case RangeMarkerBarItem:
if (Keyboard::modifier_state_contains (event->button.state, Keyboard::TertiaryModifier)) {
_drags->set (new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateSkipMarker), event);
} else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
_drags->set (new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateRangeMarker), event);
} else {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
}
return true;
break;
case CdMarkerBarItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
} else {
_drags->set (new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateCDMarker), event);
}
return true;
break;
case CueMarkerBarItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
} else {
/* no range dragging on this ruler/bar */
}
return true;
break;
case TransportMarkerBarItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
_drags->set (new CursorDrag (this, *_playhead_cursor, false), event);
} else {
_drags->set (new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateTransportMarker), event);
}
return true;
break;
case VelocityItem:
_drags->set (new LollipopDrag (this, item), event);
return true;
break;
case VelocityBaseItem:
{
VelocityGhostRegion* grv = static_cast<VelocityGhostRegion*> (item->get_data ("ghostregionview"));
if (grv) {
_drags->set (new VelocityLineDrag (this, grv->base_item(), Temporal::BeatTime), event);
}
}
return true;
break;
default:
break;
}
if (_join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) {
/* special case: allow trim of range selections in joined object mode;
* in theory eff should equal MouseRange in this case, but it doesn't
* because entering the range selection canvas item results in entered_regionview
* being set to 0, so update_join_object_range_location acts as if we aren't
* over a region.
*/
if (item_type == StartSelectionTrimItem) {
_drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionStartTrim), event);
} else if (item_type == EndSelectionTrimItem) {
_drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionEndTrim), event);
}
}
Editing::MouseMode eff = effective_mouse_mode ();
/* special case: allow drag of region fade in/out in object mode with join object/range enabled */
if (get_smart_mode()) {
switch (item_type) {
case FadeInHandleItem:
case FadeInTrimHandleItem:
case FadeOutHandleItem:
case FadeOutTrimHandleItem:
eff = MouseObject;
break;
default:
break;
}
}
switch (eff) {
case MouseRange:
switch (item_type) {
case StartSelectionTrimItem:
_drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionStartTrim), event);
break;
case EndSelectionTrimItem:
_drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionEndTrim), event);
break;
case SelectionItem:
if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
start_selection_grab (item, event);
return true;
} else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) {
/* grab selection for moving */
_drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionMove), event);
} else {
/* this was debated, but decided the more common action was to make a new selection */
_drags->set (new SelectionDrag (this, item, SelectionDrag::CreateSelection), event);
}
break;
case StreamItem:
if (Keyboard::modifier_state_equals (event->button.state, Keyboard::RangeSelectModifier) && !selection->time.empty()) {
_drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionExtend), event);
} else {
_drags->set (new SelectionDrag (this, item, SelectionDrag::CreateSelection), event);
}
return true;