diff options
author | Richard Antalik <richardantalik@gmail.com> | 2021-12-01 14:30:57 +0300 |
---|---|---|
committer | Richard Antalik <richardantalik@gmail.com> | 2021-12-01 14:49:17 +0300 |
commit | 1ef8ef4941dd84c8968109b5c858ed8d082d9187 (patch) | |
tree | 38bbdc6eabd661b2022ed1b0bb833ad601e87d3d /source/blender/editors/space_sequencer/sequencer_select.c | |
parent | d5d91b4ae41b9861d8294d055f4e7db0499b0026 (diff) |
Cleanup: Remove seq->tmp_flag DNA member
Commit f0d20198b290 used this field to flag rendered strips which were
queried by `SEQ_query_rendered_strips()`. Then operators iterate all
strips and checks state of `seq->tmp_flag`.
Use collection returned by `SEQ_query_rendered_strips` directly.
There should be no functional changes.
This commit adds functions `all_strips_from_context` and
`selected_strips_from_context` that provide collection of strips based
on context. Most operators can use this collection directly.
There is already `seq->tmp` DNA field, but is should not be used unless
absolutely necessary. Better option is to use human readable flag.
Best is to not use DNA fields for temporary storage in runtime.
Diffstat (limited to 'source/blender/editors/space_sequencer/sequencer_select.c')
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_select.c | 189 |
1 files changed, 90 insertions, 99 deletions
diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index cf18429862e..90dfcc7b14d 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -64,6 +64,34 @@ /** \name Selection Utilities * \{ */ +SeqCollection *all_strips_from_context(bContext *C) +{ + Scene *scene = CTX_data_scene(C); + ListBase *seqbase = SEQ_active_seqbase_get(SEQ_editing_get(scene)); + + const bool is_preview = sequencer_view_has_preview_poll(C); + if (is_preview) { + return SEQ_query_rendered_strips(seqbase, scene->r.cfra, 0); + } + + return SEQ_query_all_strips(seqbase); +} + +SeqCollection *selected_strips_from_context(bContext *C) +{ + Scene *scene = CTX_data_scene(C); + ListBase *seqbase = SEQ_active_seqbase_get(SEQ_editing_get(scene)); + + const bool is_preview = sequencer_view_has_preview_poll(C); + if (is_preview) { + SeqCollection *strips = SEQ_query_rendered_strips(seqbase, scene->r.cfra, 0); + SEQ_filter_selected_strips(strips); + return strips; + } + + return SEQ_query_selected_strips(seqbase); +} + static void select_surrounding_handles(Scene *scene, Sequence *test) /* XXX BRING BACK */ { Sequence *neighbor; @@ -411,25 +439,18 @@ static void sequencer_select_do_updates(bContext *C, Scene *scene) 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 = SEQ_editing_get(scene); - Sequence *seq; - const bool is_preview = sequencer_view_has_preview_poll(C); - if (is_preview) { - if (!sequencer_view_preview_only_poll(C)) { - return OPERATOR_CANCELLED; - } - SEQ_query_rendered_strips_to_tag(ed->seqbasep, scene->r.cfra, 0); + if (sequencer_view_has_preview_poll(C) && !sequencer_view_preview_only_poll(C)) { + return OPERATOR_CANCELLED; } + SeqCollection *strips = all_strips_from_context(C); + Sequence *seq; + if (action == SEL_TOGGLE) { action = SEL_SELECT; - for (seq = ed->seqbasep->first; seq; seq = seq->next) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + SEQ_ITERATOR_FOREACH (seq, strips) { if (seq->flag & SEQ_ALLSEL) { action = SEL_DESELECT; break; @@ -437,10 +458,7 @@ static int sequencer_de_select_all_exec(bContext *C, wmOperator *op) } } - for (seq = ed->seqbasep->first; seq; seq = seq->next) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + SEQ_ITERATOR_FOREACH (seq, strips) { switch (action) { case SEL_SELECT: seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL); @@ -461,8 +479,9 @@ static int sequencer_de_select_all_exec(bContext *C, wmOperator *op) } } - ED_outliner_select_sync_from_sequence_tag(C); + SEQ_collection_free(strips); + ED_outliner_select_sync_from_sequence_tag(C); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene); return OPERATOR_FINISHED; @@ -494,21 +513,15 @@ void SEQUENCER_OT_select_all(struct wmOperatorType *ot) static int sequencer_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); - Editing *ed = SEQ_editing_get(scene); - Sequence *seq; - const bool is_preview = sequencer_view_has_preview_poll(C); - if (is_preview) { - if (!sequencer_view_preview_only_poll(C)) { - return OPERATOR_CANCELLED; - } - SEQ_query_rendered_strips_to_tag(ed->seqbasep, scene->r.cfra, 0); + if (sequencer_view_has_preview_poll(C) && !sequencer_view_preview_only_poll(C)) { + return OPERATOR_CANCELLED; } - for (seq = ed->seqbasep->first; seq; seq = seq->next) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + SeqCollection *strips = all_strips_from_context(C); + Sequence *seq; + + SEQ_ITERATOR_FOREACH (seq, strips) { if (seq->flag & SELECT) { seq->flag &= ~SEQ_ALLSEL; } @@ -518,8 +531,9 @@ static int sequencer_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) } } - ED_outliner_select_sync_from_sequence_tag(C); + SEQ_collection_free(strips); + ED_outliner_select_sync_from_sequence_tag(C); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene); return OPERATOR_FINISHED; @@ -1784,17 +1798,15 @@ static const EnumPropertyItem sequencer_prop_select_grouped_types[] = { #define SEQ_CHANNEL_CHECK(_seq, _chan) (ELEM((_chan), 0, (_seq)->machine)) -static bool select_grouped_type(ListBase *seqbasep, - const bool is_preview, +static bool select_grouped_type(SeqCollection *strips, + ListBase *seqbase, Sequence *actseq, const int channel) { bool changed = false; - LISTBASE_FOREACH (Sequence *, seq, seqbasep) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + Sequence *seq; + SEQ_ITERATOR_FOREACH (seq, strips) { if (SEQ_CHANNEL_CHECK(seq, channel) && seq->type == actseq->type) { seq->flag |= SELECT; changed = true; @@ -1804,18 +1816,16 @@ static bool select_grouped_type(ListBase *seqbasep, return changed; } -static bool select_grouped_type_basic(ListBase *seqbase, - const bool is_preview, +static bool select_grouped_type_basic(SeqCollection *strips, + ListBase *seqbase, Sequence *actseq, const int channel) { bool changed = false; const bool is_sound = SEQ_IS_SOUND(actseq); - LISTBASE_FOREACH (Sequence *, seq, seqbase) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + Sequence *seq; + SEQ_ITERATOR_FOREACH (seq, strips) { if (SEQ_CHANNEL_CHECK(seq, channel) && (is_sound ? SEQ_IS_SOUND(seq) : !SEQ_IS_SOUND(seq))) { seq->flag |= SELECT; changed = true; @@ -1825,18 +1835,16 @@ static bool select_grouped_type_basic(ListBase *seqbase, return changed; } -static bool select_grouped_type_effect(ListBase *seqbase, - const bool is_preview, +static bool select_grouped_type_effect(SeqCollection *strips, + ListBase *seqbase, Sequence *actseq, const int channel) { bool changed = false; const bool is_effect = SEQ_IS_EFFECT(actseq); - LISTBASE_FOREACH (Sequence *, seq, seqbase) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + Sequence *seq; + SEQ_ITERATOR_FOREACH (seq, strips) { if (SEQ_CHANNEL_CHECK(seq, channel) && (is_effect ? SEQ_IS_EFFECT(seq) : !SEQ_IS_EFFECT(seq))) { seq->flag |= SELECT; @@ -1847,8 +1855,8 @@ static bool select_grouped_type_effect(ListBase *seqbase, return changed; } -static bool select_grouped_data(ListBase *seqbase, - const bool is_preview, +static bool select_grouped_data(SeqCollection *strips, + ListBase *seqbase, Sequence *actseq, const int channel) { @@ -1859,11 +1867,10 @@ static bool select_grouped_data(ListBase *seqbase, return changed; } + Sequence *seq; + if (SEQ_HAS_PATH(actseq) && dir) { - LISTBASE_FOREACH (Sequence *, seq, seqbase) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + SEQ_ITERATOR_FOREACH (seq, strips) { if (SEQ_CHANNEL_CHECK(seq, channel) && SEQ_HAS_PATH(seq) && seq->strip && STREQ(seq->strip->dir, dir)) { seq->flag |= SELECT; @@ -1873,7 +1880,7 @@ static bool select_grouped_data(ListBase *seqbase, } else if (actseq->type == SEQ_TYPE_SCENE) { Scene *sce = actseq->scene; - LISTBASE_FOREACH (Sequence *, seq, seqbase) { + SEQ_ITERATOR_FOREACH (seq, strips) { if (SEQ_CHANNEL_CHECK(seq, channel) && seq->type == SEQ_TYPE_SCENE && seq->scene == sce) { seq->flag |= SELECT; changed = true; @@ -1882,7 +1889,7 @@ static bool select_grouped_data(ListBase *seqbase, } else if (actseq->type == SEQ_TYPE_MOVIECLIP) { MovieClip *clip = actseq->clip; - LISTBASE_FOREACH (Sequence *, seq, seqbase) { + SEQ_ITERATOR_FOREACH (seq, strips) { if (SEQ_CHANNEL_CHECK(seq, channel) && seq->type == SEQ_TYPE_MOVIECLIP && seq->clip == clip) { seq->flag |= SELECT; @@ -1892,7 +1899,7 @@ static bool select_grouped_data(ListBase *seqbase, } else if (actseq->type == SEQ_TYPE_MASK) { struct Mask *mask = actseq->mask; - LISTBASE_FOREACH (Sequence *, seq, seqbase) { + SEQ_ITERATOR_FOREACH (seq, strips) { if (SEQ_CHANNEL_CHECK(seq, channel) && seq->type == SEQ_TYPE_MASK && seq->mask == mask) { seq->flag |= SELECT; changed = true; @@ -1903,8 +1910,8 @@ static bool select_grouped_data(ListBase *seqbase, return changed; } -static bool select_grouped_effect(ListBase *seqbase, - const bool is_preview, +static bool select_grouped_effect(SeqCollection *strips, + ListBase *seqbase, Sequence *actseq, const int channel) { @@ -1916,9 +1923,6 @@ static bool select_grouped_effect(ListBase *seqbase, } LISTBASE_FOREACH (Sequence *, seq, seqbase) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } if (SEQ_CHANNEL_CHECK(seq, channel) && (seq->type & SEQ_TYPE_EFFECT) && ELEM(actseq, seq->seq1, seq->seq2, seq->seq3)) { effects[seq->type] = true; @@ -1926,9 +1930,6 @@ static bool select_grouped_effect(ListBase *seqbase, } LISTBASE_FOREACH (Sequence *, seq, seqbase) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } if (SEQ_CHANNEL_CHECK(seq, channel) && effects[seq->type]) { if (seq->seq1) { seq->seq1->flag |= SELECT; @@ -1946,14 +1947,11 @@ static bool select_grouped_effect(ListBase *seqbase, return changed; } -static bool select_grouped_time_overlap(ListBase *seqbase, const bool is_preview, Sequence *actseq) +static bool select_grouped_time_overlap(SeqCollection *strips, ListBase *seqbase, Sequence *actseq) { bool changed = false; LISTBASE_FOREACH (Sequence *, seq, seqbase) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } if (seq->startdisp < actseq->enddisp && seq->enddisp > actseq->startdisp) { seq->flag |= SELECT; changed = true; @@ -1982,31 +1980,26 @@ static void query_lower_channel_strips(Sequence *seq_reference, /* Select all strips within time range and with lower channel of initial selection. Then select * effect chains of these strips. */ -static bool select_grouped_effect_link(ListBase *seqbase, - const bool is_preview, +static bool select_grouped_effect_link(SeqCollection *strips, + ListBase *seqbase, Sequence *UNUSED(actseq), const int UNUSED(channel)) { /* Get collection of strips. */ - SeqCollection *collection = SEQ_query_selected_strips(seqbase); - const int selected_strip_count = BLI_gset_len(collection->set); - SEQ_collection_expand(seqbase, collection, query_lower_channel_strips); - SEQ_collection_expand(seqbase, collection, SEQ_query_strip_effect_chain); + SEQ_filter_selected_strips(strips); + const int selected_strip_count = SEQ_collection_len(strips); + SEQ_collection_expand(seqbase, strips, query_lower_channel_strips); + SEQ_collection_expand(seqbase, strips, SEQ_query_strip_effect_chain); /* Check if other strips will be affected. */ - const bool changed = BLI_gset_len(collection->set) > selected_strip_count; + const bool changed = SEQ_collection_len(strips) > selected_strip_count; /* Actual logic. */ Sequence *seq; - SEQ_ITERATOR_FOREACH (seq, collection) { - if (is_preview && (seq->tmp_tag == false)) { - continue; - } + SEQ_ITERATOR_FOREACH (seq, strips) { seq->flag |= SELECT; } - SEQ_collection_free(collection); - return changed; } @@ -2021,17 +2014,13 @@ static int sequencer_select_grouped_exec(bContext *C, wmOperator *op) Sequence *actseq = SEQ_select_active_get(scene); const bool is_preview = sequencer_view_has_preview_poll(C); - if (is_preview) { - if (!sequencer_view_preview_only_poll(C)) { - return OPERATOR_CANCELLED; - } - SEQ_query_rendered_strips_to_tag(seqbase, scene->r.cfra, 0); - if (actseq && actseq->tmp_tag == false) { - actseq = NULL; - } + if (is_preview && !sequencer_view_preview_only_poll(C)) { + return OPERATOR_CANCELLED; } - if (actseq == NULL) { + SeqCollection *strips = all_strips_from_context(C); + + if (actseq == NULL || (is_preview && !SEQ_collection_has_strip(actseq, strips))) { BKE_report(op->reports, RPT_ERROR, "No active sequence!"); return OPERATOR_CANCELLED; } @@ -2051,31 +2040,33 @@ static int sequencer_select_grouped_exec(bContext *C, wmOperator *op) switch (type) { case SEQ_SELECT_GROUP_TYPE: - changed |= select_grouped_type(seqbase, is_preview, actseq, channel); + changed |= select_grouped_type(strips, seqbase, actseq, channel); break; case SEQ_SELECT_GROUP_TYPE_BASIC: - changed |= select_grouped_type_basic(seqbase, is_preview, actseq, channel); + changed |= select_grouped_type_basic(strips, seqbase, actseq, channel); break; case SEQ_SELECT_GROUP_TYPE_EFFECT: - changed |= select_grouped_type_effect(seqbase, is_preview, actseq, channel); + changed |= select_grouped_type_effect(strips, seqbase, actseq, channel); break; case SEQ_SELECT_GROUP_DATA: - changed |= select_grouped_data(seqbase, is_preview, actseq, channel); + changed |= select_grouped_data(strips, seqbase, actseq, channel); break; case SEQ_SELECT_GROUP_EFFECT: - changed |= select_grouped_effect(seqbase, is_preview, actseq, channel); + changed |= select_grouped_effect(strips, seqbase, actseq, channel); break; case SEQ_SELECT_GROUP_EFFECT_LINK: - changed |= select_grouped_effect_link(seqbase, is_preview, actseq, channel); + changed |= select_grouped_effect_link(strips, seqbase, actseq, channel); break; case SEQ_SELECT_GROUP_OVERLAP: - changed |= select_grouped_time_overlap(seqbase, is_preview, actseq); + changed |= select_grouped_time_overlap(strips, seqbase, actseq); break; default: BLI_assert(0); break; } + SEQ_collection_free(strips); + if (changed) { ED_outliner_select_sync_from_sequence_tag(C); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene); |