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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* Contributor(s): Blender Foundation, 2003-2009, Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/space_sequencer/sequencer_select.c
* \ingroup spseq
*/
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "DNA_scene_types.h"
#include "BKE_context.h"
#include "BKE_report.h"
#include "BKE_sequencer.h"
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_define.h"
/* for menu/popup icons etc etc*/
#include "ED_screen.h"
#include "ED_sequencer.h"
#include "UI_view2d.h"
/* own include */
#include "sequencer_intern.h"
static void *find_nearest_marker(int UNUSED(d1), int UNUSED(d2))
{
return NULL;
}
static void select_surrounding_handles(Scene *scene, Sequence *test) /* XXX BRING BACK */
{
Sequence *neighbor;
neighbor = find_neighboring_sequence(scene, test, SEQ_SIDE_LEFT, -1);
if (neighbor) {
/* Only select neighbor handle if matching handle from test seq is also selected, or if neighbor
* was not selected at all up till now.
* Otherwise, we get odd mismatch when shift-alt-rmb selecting neighbor strips... */
if (!(neighbor->flag & SELECT) || (test->flag & SEQ_LEFTSEL)) {
neighbor->flag |= SEQ_RIGHTSEL;
}
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
}
neighbor = find_neighboring_sequence(scene, test, SEQ_SIDE_RIGHT, -1);
if (neighbor) {
if (!(neighbor->flag & SELECT) || (test->flag & SEQ_RIGHTSEL)) { /* See comment above. */
neighbor->flag |= SEQ_LEFTSEL;
}
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
}
}
/* used for mouse selection and for SEQUENCER_OT_select_active_side() */
static void select_active_side(ListBase *seqbase, int sel_side, int channel, int frame)
{
Sequence *seq;
for (seq = seqbase->first; seq; seq = seq->next) {
if (channel == seq->machine) {
switch (sel_side) {
case SEQ_SIDE_LEFT:
if (frame > (seq->startdisp)) {
seq->flag &= ~(SEQ_RIGHTSEL | SEQ_LEFTSEL);
seq->flag |= SELECT;
}
break;
case SEQ_SIDE_RIGHT:
if (frame < (seq->startdisp)) {
seq->flag &= ~(SEQ_RIGHTSEL | SEQ_LEFTSEL);
seq->flag |= SELECT;
}
break;
case SEQ_SIDE_BOTH:
seq->flag &= ~(SEQ_RIGHTSEL | SEQ_LEFTSEL);
break;
}
}
}
}
/* used for mouse selection and for SEQUENCER_OT_select_active_side() */
static void select_linked_time(ListBase *seqbase, Sequence *seq_link)
{
Sequence *seq;
for (seq = seqbase->first; seq; seq = seq->next) {
if (seq_link->machine != seq->machine) {
int left_match = (seq->startdisp == seq_link->startdisp) ? 1 : 0;
int right_match = (seq->enddisp == seq_link->enddisp) ? 1 : 0;
if (left_match && right_match) {
/* a direct match, copy the selection settinhs */
seq->flag &= ~(SELECT | SEQ_LEFTSEL | SEQ_RIGHTSEL);
seq->flag |= seq_link->flag & (SELECT | SEQ_LEFTSEL | SEQ_RIGHTSEL);
recurs_sel_seq(seq);
}
else if (seq_link->flag & SELECT && (left_match || right_match)) {
/* clear for reselection */
seq->flag &= ~(SEQ_LEFTSEL | SEQ_RIGHTSEL);
if (left_match && seq_link->flag & SEQ_LEFTSEL)
seq->flag |= SELECT | SEQ_LEFTSEL;
if (right_match && seq_link->flag & SEQ_RIGHTSEL)
seq->flag |= SELECT | SEQ_RIGHTSEL;
recurs_sel_seq(seq);
}
}
}
}
#if 0 // BRING BACK
void select_surround_from_last(Scene *scene)
{
Sequence *seq = get_last_seq(scene);
if (seq == NULL)
return;
select_surrounding_handles(scene, seq);
}
#endif
void ED_sequencer_select_sequence_single(Scene *scene, Sequence *seq, bool deselect_all)
{
Editing *ed = BKE_sequencer_editing_get(scene, false);
if (deselect_all)
ED_sequencer_deselect_all(scene);
BKE_sequencer_active_set(scene, seq);
if ((seq->type == SEQ_TYPE_IMAGE) || (seq->type == SEQ_TYPE_MOVIE)) {
if (seq->strip)
BLI_strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR);
}
else if (seq->type == SEQ_TYPE_SOUND_RAM) {
if (seq->strip)
BLI_strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR);
}
seq->flag |= SELECT;
recurs_sel_seq(seq);
}
#if 0
static void select_neighbor_from_last(Scene *scene, int lr)
{
Sequence *seq = BKE_sequencer_active_get(scene);
Sequence *neighbor;
bool changed = false;
if (seq) {
neighbor = find_neighboring_sequence(scene, seq, lr, -1);
if (neighbor) {
switch (lr) {
case SEQ_SIDE_LEFT:
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
neighbor->flag |= SEQ_RIGHTSEL;
seq->flag |= SEQ_LEFTSEL;
break;
case SEQ_SIDE_RIGHT:
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
neighbor->flag |= SEQ_LEFTSEL;
seq->flag |= SEQ_RIGHTSEL;
break;
}
seq->flag |= SELECT;
changed = true;
}
}
if (changed) {
}
}
#endif
/* (de)select operator */
static int sequencer_de_select_all_exec(bContext *C, wmOperator *op)
{
int action = RNA_enum_get(op->ptr, "action");
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
Sequence *seq;
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
if (seq->flag & SEQ_ALLSEL) {
action = SEL_DESELECT;
break;
}
}
}
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
switch (action) {
case SEL_SELECT:
seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL);
seq->flag |= SELECT;
break;
case SEL_DESELECT:
seq->flag &= ~SEQ_ALLSEL;
break;
case SEL_INVERT:
if (seq->flag & SEQ_ALLSEL) {
seq->flag &= ~SEQ_ALLSEL;
}
else {
seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL);
seq->flag |= SELECT;
}
break;
}
}
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_all(struct wmOperatorType *ot)
{
/* identifiers */
ot->name = "(De)select All";
ot->idname = "SEQUENCER_OT_select_all";
ot->description = "Select or deselect all strips";
/* api callbacks */
ot->exec = sequencer_de_select_all_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
WM_operator_properties_select_all(ot);
}
/* (de)select operator */
static int sequencer_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
Sequence *seq;
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
if (seq->flag & SELECT) {
seq->flag &= ~SEQ_ALLSEL;
}
else {
seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL);
seq->flag |= SELECT;
}
}
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_inverse(struct wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Inverse";
ot->idname = "SEQUENCER_OT_select_inverse";
ot->description = "Select unselected strips";
/* api callbacks */
ot->exec = sequencer_select_inverse_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
View2D *v2d = UI_view2d_fromcontext(C);
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
const bool extend = RNA_boolean_get(op->ptr, "extend");
const bool linked_handle = RNA_boolean_get(op->ptr, "linked_handle");
const bool linked_time = RNA_boolean_get(op->ptr, "linked_time");
int left_right = RNA_enum_get(op->ptr, "left_right");
Sequence *seq, *neighbor, *act_orig;
int hand, sel_side;
TimeMarker *marker;
if (ed == NULL)
return OPERATOR_CANCELLED;
marker = find_nearest_marker(SCE_MARKERS, 1); //XXX - dummy function for now
seq = find_nearest_seq(scene, v2d, &hand, event->mval);
// XXX - not nice, Ctrl+RMB needs to do left_right only when not over a strip
if (seq && linked_time && (left_right == SEQ_SELECT_LR_MOUSE))
left_right = SEQ_SELECT_LR_NONE;
if (marker) {
int oldflag;
/* select timeline marker */
if (extend) {
oldflag = marker->flag;
if (oldflag & SELECT)
marker->flag &= ~SELECT;
else
marker->flag |= SELECT;
}
else {
/* deselect_markers(0, 0); */ /* XXX, in 2.4x, seq selection used to deselect all, need to re-thnik this for 2.5 */
marker->flag |= SELECT;
}
}
else if (left_right != SEQ_SELECT_LR_NONE) {
/* use different logic for this */
float x;
ED_sequencer_deselect_all(scene);
switch (left_right) {
case SEQ_SELECT_LR_MOUSE:
x = UI_view2d_region_to_view_x(v2d, event->mval[0]);
break;
case SEQ_SELECT_LR_LEFT:
x = CFRA - 1.0f;
break;
case SEQ_SELECT_LR_RIGHT:
default:
x = CFRA;
break;
}
SEQP_BEGIN (ed, seq)
{
if (((x < CFRA) && (seq->enddisp <= CFRA)) ||
((x >= CFRA) && (seq->startdisp >= CFRA)))
{
seq->flag |= SELECT;
recurs_sel_seq(seq);
}
}
SEQ_END
{
SpaceSeq *sseq = CTX_wm_space_seq(C);
if (sseq && sseq->flag & SEQ_MARKER_TRANS) {
TimeMarker *tmarker;
for (tmarker = scene->markers.first; tmarker; tmarker = tmarker->next) {
if (((x < CFRA) && (tmarker->frame <= CFRA)) ||
((x >= CFRA) && (tmarker->frame >= CFRA)))
{
tmarker->flag |= SELECT;
}
else {
tmarker->flag &= ~SELECT;
}
}
}
}
}
else {
// seq = find_nearest_seq(scene, v2d, &hand, mval);
act_orig = ed->act_seq;
if (extend == 0 && linked_handle == 0)
ED_sequencer_deselect_all(scene);
if (seq) {
BKE_sequencer_active_set(scene, seq);
if ((seq->type == SEQ_TYPE_IMAGE) || (seq->type == SEQ_TYPE_MOVIE)) {
if (seq->strip) {
BLI_strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR);
}
}
else if (seq->type == SEQ_TYPE_SOUND_RAM) {
if (seq->strip) {
BLI_strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR);
}
}
/* On Alt selection, select the strip and bordering handles */
if (linked_handle) {
if (!ELEM(hand, SEQ_SIDE_LEFT, SEQ_SIDE_RIGHT)) {
/* First click selects the strip and its adjacent handles (if valid).
* Second click selects the strip, both of its handles and its adjacent handles (if valid).
*/
const bool is_striponly_selected = ((seq->flag & SEQ_ALLSEL) == SELECT);
if (!extend) {
ED_sequencer_deselect_all(scene);
}
seq->flag &= ~SEQ_ALLSEL;
seq->flag |= is_striponly_selected ? SEQ_ALLSEL : SELECT;
select_surrounding_handles(scene, seq);
}
else {
/* always select the strip under the cursor */
seq->flag |= SELECT;
/* First click selects adjacent handles on that side.
* Second click selects all strips in that direction.
* If there are no adjacent strips, it just selects all in that direction.
*/
sel_side = hand;
neighbor = find_neighboring_sequence(scene, seq, sel_side, -1);
if (neighbor) {
switch (sel_side) {
case SEQ_SIDE_LEFT:
if ((seq->flag & SEQ_LEFTSEL) && (neighbor->flag & SEQ_RIGHTSEL)) {
if (extend == 0) ED_sequencer_deselect_all(scene);
seq->flag |= SELECT;
select_active_side(ed->seqbasep, SEQ_SIDE_LEFT, seq->machine, seq->startdisp);
}
else {
if (extend == 0) ED_sequencer_deselect_all(scene);
seq->flag |= SELECT;
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
neighbor->flag |= SEQ_RIGHTSEL;
seq->flag |= SEQ_LEFTSEL;
}
break;
case SEQ_SIDE_RIGHT:
if ((seq->flag & SEQ_RIGHTSEL) && (neighbor->flag & SEQ_LEFTSEL)) {
if (extend == 0) ED_sequencer_deselect_all(scene);
seq->flag |= SELECT;
select_active_side(ed->seqbasep, SEQ_SIDE_RIGHT, seq->machine, seq->startdisp);
}
else {
if (extend == 0) ED_sequencer_deselect_all(scene);
seq->flag |= SELECT;
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
neighbor->flag |= SEQ_LEFTSEL;
seq->flag |= SEQ_RIGHTSEL;
}
break;
}
}
else {
if (extend == 0) ED_sequencer_deselect_all(scene);
select_active_side(ed->seqbasep, sel_side, seq->machine, seq->startdisp);
}
}
}
else {
if (extend && (seq->flag & SELECT) && ed->act_seq == act_orig) {
switch (hand) {
case SEQ_SIDE_NONE:
if (linked_handle == 0)
seq->flag &= ~SEQ_ALLSEL;
break;
case SEQ_SIDE_LEFT:
seq->flag ^= SEQ_LEFTSEL;
break;
case SEQ_SIDE_RIGHT:
seq->flag ^= SEQ_RIGHTSEL;
break;
}
}
else {
seq->flag |= SELECT;
if (hand == SEQ_SIDE_LEFT) seq->flag |= SEQ_LEFTSEL;
if (hand == SEQ_SIDE_RIGHT) seq->flag |= SEQ_RIGHTSEL;
}
}
recurs_sel_seq(seq);
if (linked_time) {
select_linked_time(ed->seqbasep, seq);
}
}
}
/* marker transform */
#if 0 // XXX probably need to redo this differently for 2.5
if (marker) {
int mval[2], xo, yo;
// getmouseco_areawin(mval);
xo = mval[0];
yo = mval[1];
while (get_mbut()) {
// getmouseco_areawin(mval);
if (abs(mval[0] - xo) + abs(mval[1] - yo) > 4) {
transform_markers('g', 0);
return;
}
}
}
#endif
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
/* allowing tweaks */
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
}
void SEQUENCER_OT_select(wmOperatorType *ot)
{
static EnumPropertyItem sequencer_select_left_right_types[] = {
{SEQ_SELECT_LR_NONE, "NONE", 0, "None", "Don't do left-right selection"},
{SEQ_SELECT_LR_MOUSE, "MOUSE", 0, "Mouse", "Use mouse position for selection"},
{SEQ_SELECT_LR_LEFT, "LEFT", 0, "Left", "Select left"},
{SEQ_SELECT_LR_RIGHT, "RIGHT", 0, "Right", "Select right"},
{0, NULL, 0, NULL, NULL}
};
/* identifiers */
ot->name = "Activate/Select";
ot->idname = "SEQUENCER_OT_select";
ot->description = "Select a strip (last selected becomes the \"active strip\")";
/* api callbacks */
ot->invoke = sequencer_select_invoke;
ot->poll = ED_operator_sequencer_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
RNA_def_boolean(ot->srna, "linked_handle", 0, "Linked Handle", "Select handles next to the active strip");
/* for animation this is an enum but atm having an enum isn't useful for us */
RNA_def_enum(ot->srna, "left_right", sequencer_select_left_right_types, 0, "Left/Right", "Select based on the current frame side the cursor is on");
RNA_def_boolean(ot->srna, "linked_time", 0, "Linked Time", "Select other strips at the same time");
}
/* run recursively to select linked */
static bool select_more_less_seq__internal(Scene *scene, bool sel, const bool linked)
{
Editing *ed = BKE_sequencer_editing_get(scene, false);
Sequence *seq, *neighbor;
bool changed = false;
int isel;
if (ed == NULL)
return changed;
if (sel) {
sel = SELECT;
isel = 0;
}
else {
sel = 0;
isel = SELECT;
}
if (!linked) {
/* if not linked we only want to touch each seq once, newseq */
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
seq->tmp = NULL;
}
}
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
if ((seq->flag & SELECT) == sel) {
if (linked || (seq->tmp == NULL)) {
/* only get unselected neighbors */
neighbor = find_neighboring_sequence(scene, seq, SEQ_SIDE_LEFT, isel);
if (neighbor) {
if (sel) {
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
}
else {
neighbor->flag &= ~SELECT;
}
if (!linked) {
neighbor->tmp = (Sequence *)1;
}
changed = true;
}
neighbor = find_neighboring_sequence(scene, seq, SEQ_SIDE_RIGHT, isel);
if (neighbor) {
if (sel) {
neighbor->flag |= SELECT;
recurs_sel_seq(neighbor);
}
else {
neighbor->flag &= ~SELECT;
}
if (!linked) {
neighbor->tmp = (Sequence *)1;
}
changed = true;
}
}
}
}
return changed;
}
/* select more operator */
static int sequencer_select_more_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
if (!select_more_less_seq__internal(scene, true, false))
return OPERATOR_CANCELLED;
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_more(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select More";
ot->idname = "SEQUENCER_OT_select_more";
ot->description = "Select more strips adjacent to the current selection";
/* api callbacks */
ot->exec = sequencer_select_more_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
}
/* select less operator */
static int sequencer_select_less_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
if (!select_more_less_seq__internal(scene, false, false))
return OPERATOR_CANCELLED;
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_less(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Less";
ot->idname = "SEQUENCER_OT_select_less";
ot->description = "Shrink the current selection of adjacent selected strips";
/* api callbacks */
ot->exec = sequencer_select_less_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
}
/* select pick linked operator (uses the mouse) */
static int sequencer_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
Scene *scene = CTX_data_scene(C);
View2D *v2d = UI_view2d_fromcontext(C);
bool extend = RNA_boolean_get(op->ptr, "extend");
Sequence *mouse_seq;
int selected, hand;
/* this works like UV, not mesh */
mouse_seq = find_nearest_seq(scene, v2d, &hand, event->mval);
if (!mouse_seq)
return OPERATOR_FINISHED; /* user error as with mesh?? */
if (extend == 0)
ED_sequencer_deselect_all(scene);
mouse_seq->flag |= SELECT;
recurs_sel_seq(mouse_seq);
selected = 1;
while (selected) {
selected = select_more_less_seq__internal(scene, 1, 1);
}
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_linked_pick(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Pick Linked";
ot->idname = "SEQUENCER_OT_select_linked_pick";
ot->description = "Select a chain of linked strips nearest to the mouse pointer";
/* api callbacks */
ot->invoke = sequencer_select_linked_pick_invoke;
ot->poll = ED_operator_sequencer_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
}
/* select linked operator */
static int sequencer_select_linked_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
bool selected;
selected = true;
while (selected) {
selected = select_more_less_seq__internal(scene, true, true);
}
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_linked(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Linked";
ot->idname = "SEQUENCER_OT_select_linked";
ot->description = "Select all strips adjacent to the current selection";
/* api callbacks */
ot->exec = sequencer_select_linked_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
}
/* select handles operator */
static int sequencer_select_handles_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
Sequence *seq;
int sel_side = RNA_enum_get(op->ptr, "side");
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
if (seq->flag & SELECT) {
switch (sel_side) {
case SEQ_SIDE_LEFT:
seq->flag &= ~SEQ_RIGHTSEL;
seq->flag |= SEQ_LEFTSEL;
break;
case SEQ_SIDE_RIGHT:
seq->flag &= ~SEQ_LEFTSEL;
seq->flag |= SEQ_RIGHTSEL;
break;
case SEQ_SIDE_BOTH:
seq->flag |= SEQ_LEFTSEL + SEQ_RIGHTSEL;
break;
}
}
}
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_handles(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Handles";
ot->idname = "SEQUENCER_OT_select_handles";
ot->description = "Select manipulator handles on the sides of the selected strip";
/* api callbacks */
ot->exec = sequencer_select_handles_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side of the handle that is selected");
}
/* select side operator */
static int sequencer_select_active_side_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
Sequence *seq_act = BKE_sequencer_active_get(scene);
if (ed == NULL || seq_act == NULL)
return OPERATOR_CANCELLED;
seq_act->flag |= SELECT;
select_active_side(ed->seqbasep, RNA_enum_get(op->ptr, "side"), seq_act->machine, seq_act->startdisp);
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
void SEQUENCER_OT_select_active_side(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Active Side";
ot->idname = "SEQUENCER_OT_select_active_side";
ot->description = "Select strips on the nominated side of the active strip";
/* api callbacks */
ot->exec = sequencer_select_active_side_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side of the handle that is selected");
}
/* borderselect operator */
static int sequencer_borderselect_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
View2D *v2d = UI_view2d_fromcontext(C);
Sequence *seq;
rctf rectf, rq;
const bool select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT);
const bool extend = RNA_boolean_get(op->ptr, "extend");
if (ed == NULL)
return OPERATOR_CANCELLED;
WM_operator_properties_border_to_rctf(op, &rectf);
UI_view2d_region_to_view_rctf(v2d, &rectf, &rectf);
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
seq_rectf(seq, &rq);
if (BLI_rctf_isect(&rq, &rectf, NULL)) {
if (select) seq->flag |= SELECT;
else seq->flag &= ~SEQ_ALLSEL;
recurs_sel_seq(seq);
}
else if (!extend) {
seq->flag &= ~SEQ_ALLSEL;
recurs_sel_seq(seq);
}
}
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
/* ****** Border Select ****** */
void SEQUENCER_OT_select_border(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Border Select";
ot->idname = "SEQUENCER_OT_select_border";
ot->description = "Select strips using border selection";
/* api callbacks */
ot->invoke = WM_border_select_invoke;
ot->exec = sequencer_borderselect_exec;
ot->modal = WM_border_select_modal;
ot->cancel = WM_border_select_cancel;
ot->poll = ED_operator_sequencer_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* rna */
WM_operator_properties_gesture_border(ot, true);
}
/* ****** Selected Grouped ****** */
static EnumPropertyItem sequencer_prop_select_grouped_types[] = {
{1, "TYPE", 0, "Type", "Shared strip type"},
{2, "TYPE_BASIC", 0, "Global Type", "All strips of same basic type (Graphical or Sound)"},
{3, "TYPE_EFFECT", 0, "Effect Type",
"Shared strip effect type (if active strip is not an effect one, select all non-effect strips)"},
{4, "DATA", 0, "Data", "Shared data (scene, image, sound, etc.)"},
{5, "EFFECT", 0, "Effect", "Shared effects"},
{6, "EFFECT_LINK", 0, "Effect/Linked",
"Other strips affected by the active one (sharing some time, and below or effect-assigned)"},
{7, "OVERLAP", 0, "Overlap", "Overlapping time"},
{0, NULL, 0, NULL, NULL}
};
#define SEQ_IS_SOUND(_seq) ((_seq->type & SEQ_TYPE_SOUND_RAM) && !(_seq->type & SEQ_TYPE_EFFECT))
#define SEQ_IS_EFFECT(_seq) ((_seq->type & SEQ_TYPE_EFFECT) != 0)
#define SEQ_USE_DATA(_seq) (ELEM(_seq->type, SEQ_TYPE_SCENE, SEQ_TYPE_MOVIECLIP, SEQ_TYPE_MASK) || SEQ_HAS_PATH(_seq))
static bool select_grouped_type(Editing *ed, Sequence *actseq)
{
Sequence *seq;
bool changed = false;
SEQP_BEGIN (ed, seq)
{
if (seq->type == actseq->type) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
return changed;
}
static bool select_grouped_type_basic(Editing *ed, Sequence *actseq)
{
Sequence *seq;
bool changed = false;
const bool is_sound = SEQ_IS_SOUND(actseq);
SEQP_BEGIN (ed, seq)
{
if (is_sound ? SEQ_IS_SOUND(seq) : !SEQ_IS_SOUND(seq)) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
return changed;
}
static bool select_grouped_type_effect(Editing *ed, Sequence *actseq)
{
Sequence *seq;
bool changed = false;
const bool is_effect = SEQ_IS_EFFECT(actseq);
SEQP_BEGIN (ed, seq)
{
if (is_effect ? SEQ_IS_EFFECT(seq) : !SEQ_IS_EFFECT(seq)) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
return changed;
}
static bool select_grouped_data(Editing *ed, Sequence *actseq)
{
Sequence *seq;
bool changed = false;
const char *dir = actseq->strip ? actseq->strip->dir : NULL;
if (!SEQ_USE_DATA(actseq))
return changed;
if (SEQ_HAS_PATH(actseq) && dir) {
SEQP_BEGIN (ed, seq)
{
if (SEQ_HAS_PATH(seq) && seq->strip && STREQ(seq->strip->dir, dir)) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
}
else if (actseq->type == SEQ_TYPE_SCENE) {
Scene *sce = actseq->scene;
SEQP_BEGIN (ed, seq)
{
if (seq->type == SEQ_TYPE_SCENE && seq->scene == sce) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
}
else if (actseq->type == SEQ_TYPE_MOVIECLIP) {
MovieClip *clip = actseq->clip;
SEQP_BEGIN (ed, seq)
{
if (seq->type == SEQ_TYPE_MOVIECLIP && seq->clip == clip) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
}
else if (actseq->type == SEQ_TYPE_MASK) {
struct Mask *mask = actseq->mask;
SEQP_BEGIN (ed, seq)
{
if (seq->type == SEQ_TYPE_MASK && seq->mask == mask) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
}
return changed;
}
static bool select_grouped_effect(Editing *ed, Sequence *actseq)
{
Sequence *seq;
bool changed = false;
bool effects[SEQ_TYPE_MAX + 1];
int i;
for (i = 0; i <= SEQ_TYPE_MAX; i++)
effects[i] = false;
SEQP_BEGIN (ed, seq)
{
if ((seq->type & SEQ_TYPE_EFFECT) && ELEM(actseq, seq->seq1, seq->seq2, seq->seq3)) {
effects[seq->type] = true;
}
}
SEQ_END;
SEQP_BEGIN (ed, seq)
{
if (effects[seq->type]) {
if (seq->seq1) seq->seq1->flag |= SELECT;
if (seq->seq2) seq->seq2->flag |= SELECT;
if (seq->seq3) seq->seq3->flag |= SELECT;
changed = true;
}
}
SEQ_END;
return changed;
}
static bool select_grouped_time_overlap(Editing *ed, Sequence *actseq)
{
Sequence *seq;
bool changed = false;
SEQP_BEGIN (ed, seq)
{
if (!((seq->startdisp >= actseq->enddisp) || (seq->enddisp < actseq->startdisp))) {
seq->flag |= SELECT;
changed = true;
}
}
SEQ_END;
return changed;
}
static bool select_grouped_effect_link(Editing *ed, Sequence *actseq)
{
Sequence *seq = NULL;
bool changed = false;
const bool is_audio = ((actseq->type == SEQ_TYPE_META) || SEQ_IS_SOUND(actseq));
int startdisp = actseq->startdisp;
int enddisp = actseq->enddisp;
int machine = actseq->machine;
SeqIterator iter;
SEQP_BEGIN (ed, seq)
{
seq->tmp = NULL;
}
SEQ_END;
actseq->tmp = SET_INT_IN_POINTER(true);
for (BKE_sequence_iterator_begin(ed, &iter, true); iter.valid; BKE_sequence_iterator_next(&iter)) {
seq = iter.seq;
/* Ignore all seqs already selected! */
/* Ignore all seqs not sharing some time with active one. */
/* Ignore all seqs of incompatible types (audio vs video). */
if ((seq->flag & SELECT) || (seq->startdisp >= enddisp) || (seq->enddisp < startdisp) ||
(!is_audio && SEQ_IS_SOUND(seq)) ||
(is_audio && !((seq->type == SEQ_TYPE_META) || SEQ_IS_SOUND(seq))))
{
continue;
}
/* If the seq is an effect one, we need extra cheking! */
if (SEQ_IS_EFFECT(seq) && ((seq->seq1 && seq->seq1->tmp) ||
(seq->seq2 && seq->seq2->tmp) ||
(seq->seq3 && seq->seq3->tmp)))
{
if (startdisp > seq->startdisp) startdisp = seq->startdisp;
if (enddisp < seq->enddisp) enddisp = seq->enddisp;
if (machine < seq->machine) machine = seq->machine;
seq->tmp = SET_INT_IN_POINTER(true);
seq->flag |= SELECT;
changed = true;
/* Unfortunately, we must restart checks from the beginning. */
BKE_sequence_iterator_end(&iter);
BKE_sequence_iterator_begin(ed, &iter, true);
}
/* Video strips bellow active one, or any strip for audio (order do no matters here!). */
else if (seq->machine < machine || is_audio) {
seq->flag |= SELECT;
changed = true;
}
}
BKE_sequence_iterator_end(&iter);
return changed;
}
#undef SEQ_IS_SOUND
#undef SEQ_IS_EFFECT
#undef SEQ_USE_DATA
static int sequencer_select_grouped_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
Sequence *seq, *actseq = BKE_sequencer_active_get(scene);
int type = RNA_enum_get(op->ptr, "type");
bool changed = false, extend;
extend = RNA_boolean_get(op->ptr, "extend");
if (actseq == NULL) {
BKE_report(op->reports, RPT_ERROR, "No active sequence!");
return OPERATOR_CANCELLED;
}
if (extend == 0) {
SEQP_BEGIN (ed, seq)
{
seq->flag &= ~SELECT;
changed = true;
}
SEQ_END;
}
if (type == 1) changed |= select_grouped_type(ed, actseq);
else if (type == 2) changed |= select_grouped_type_basic(ed, actseq);
else if (type == 3) changed |= select_grouped_type_effect(ed, actseq);
else if (type == 4) changed |= select_grouped_data(ed, actseq);
else if (type == 5) changed |= select_grouped_effect(ed, actseq);
else if (type == 6) changed |= select_grouped_effect_link(ed, actseq);
else if (type == 7) changed |= select_grouped_time_overlap(ed, actseq);
if (changed) {
WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
}
void SEQUENCER_OT_select_grouped(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Grouped";
ot->description = "Select all strips grouped by various properties";
ot->idname = "SEQUENCER_OT_select_grouped";
/* api callbacks */
ot->invoke = WM_menu_invoke;
ot->exec = sequencer_select_grouped_exec;
ot->poll = sequencer_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first");
ot->prop = RNA_def_enum(ot->srna, "type", sequencer_prop_select_grouped_types, 0, "Type", "");
}
|