Cleanup: rename MAXSEQ -> SEQ_MAX_CHANNELS and make it C++ constexpr

When I was learning VSE code, MAXSEQ constant (a preprocessor define!) was
confusing. It makes it sound like it is "max sequences", but it is actually
"max channels". So rename it to SEQ_MAX_CHANNELS and make it C++ constexpr int
instead of preprocessor macro.

Pull Request: https://projects.blender.org/blender/blender/pulls/128024
This commit is contained in:
Aras Pranckevicius
2024-09-23 15:43:45 +02:00
committed by Aras Pranckevicius
parent a8767d943d
commit ecce5f45ac
19 changed files with 117 additions and 57 deletions

View File

@@ -1193,7 +1193,7 @@ static void link_recurs_seq(BlendDataReader *reader, ListBase *lb)
LISTBASE_FOREACH_MUTABLE (Sequence *, seq, lb) {
/* Sanity check. */
if (!SEQ_valid_strip_channel(seq)) {
if (!SEQ_is_valid_strip_channel(seq)) {
BLI_freelinkN(lb, seq);
BLO_read_data_reports(reader)->count.sequence_strips_skipped++;
}

View File

@@ -3053,7 +3053,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
&sl->regionbase;
LISTBASE_FOREACH (ARegion *, region, regionbase) {
if (region->regiontype == RGN_TYPE_WINDOW) {
region->v2d.max[1] = MAXSEQ;
region->v2d.max[1] = SEQ_MAX_CHANNELS;
}
}
break;

View File

@@ -115,8 +115,15 @@ static void sequencer_generic_props__internal(wmOperatorType *ot, int flag)
MAXFRAME);
}
RNA_def_int(
ot->srna, "channel", 1, 1, MAXSEQ, "Channel", "Channel to place this strip into", 1, MAXSEQ);
RNA_def_int(ot->srna,
"channel",
1,
1,
SEQ_MAX_CHANNELS,
"Channel",
"Channel to place this strip into",
1,
SEQ_MAX_CHANNELS);
RNA_def_boolean(
ot->srna, "replace_sel", true, "Replace Selection", "Deselect previously selected strips");
@@ -1453,7 +1460,7 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op)
if (!RNA_struct_property_is_set(op->ptr, "channel")) {
if (seq1 != nullptr) {
int chan = max_ii(seq1 ? seq1->machine : 0, seq2 ? seq2->machine : 0);
if (chan < MAXSEQ) {
if (chan < SEQ_MAX_CHANNELS) {
load_data.channel = chan;
}
}

View File

@@ -83,7 +83,7 @@ static void displayed_channel_range_get(const SeqChannelDrawContext *context,
BLI_rctf_init(&strip_boundbox, 0.0f, 0.0f, 1.0f, r_channel_range[1]);
SEQ_timeline_expand_boundbox(context->scene, context->seqbase, &strip_boundbox);
CLAMP(r_channel_range[0], strip_boundbox.ymin, strip_boundbox.ymax);
CLAMP(r_channel_range[1], strip_boundbox.ymin, MAXSEQ);
CLAMP(r_channel_range[1], strip_boundbox.ymin, SEQ_MAX_CHANNELS);
}
static std::string draw_channel_widget_tooltip(bContext * /*C*/, void *argN, const char * /*tip*/)

View File

@@ -162,11 +162,11 @@ static void select_active_side(
static void select_active_side_range(const Scene *scene,
ListBase *seqbase,
const int sel_side,
const int frame_ranges[MAXSEQ],
const int frame_ranges[SEQ_MAX_CHANNELS],
const int frame_ignore)
{
LISTBASE_FOREACH (Sequence *, seq, seqbase) {
if (seq->machine < MAXSEQ) {
if (seq->machine < SEQ_MAX_CHANNELS) {
const int frame = frame_ranges[seq->machine];
if (frame == frame_ignore) {
continue;
@@ -1952,13 +1952,13 @@ static int sequencer_select_side_exec(bContext *C, wmOperator *op)
const int sel_side = RNA_enum_get(op->ptr, "side");
const int frame_init = sel_side == SEQ_SIDE_LEFT ? INT_MIN : INT_MAX;
int frame_ranges[MAXSEQ];
int frame_ranges[SEQ_MAX_CHANNELS];
bool selected = false;
copy_vn_i(frame_ranges, ARRAY_SIZE(frame_ranges), frame_init);
LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) {
if (UNLIKELY(seq->machine >= MAXSEQ)) {
if (UNLIKELY(seq->machine >= SEQ_MAX_CHANNELS)) {
continue;
}
int *frame_limit_p = &frame_ranges[seq->machine];

View File

@@ -629,7 +629,7 @@ static void drawmeta_contents(TimelineDrawContext *timeline_ctx,
uchar col[4];
int chan_min = MAXSEQ;
int chan_min = SEQ_MAX_CHANNELS;
int chan_max = 0;
int chan_range = 0;
/* Some vertical margin to account for rounded corners, so that contents do

View File

@@ -319,7 +319,7 @@ static void seq_view_collection_rect_timeline(const bContext *C,
const Scene *scene = CTX_data_scene(C);
int xmin = MAXFRAME * 2;
int xmax = -MAXFRAME * 2;
int ymin = MAXSEQ + 1;
int ymin = SEQ_MAX_CHANNELS + 1;
int ymax = 0;
int xmargin = FPS;

View File

@@ -181,7 +181,7 @@ static SpaceLink *sequencer_create(const ScrArea * /*area*/, const Scene *scene)
region->v2d.min[1] = 1.0f;
region->v2d.max[0] = MAXFRAMEF;
region->v2d.max[1] = MAXSEQ;
region->v2d.max[1] = SEQ_MAX_CHANNELS;
region->v2d.minzoom = 0.01f;
region->v2d.maxzoom = 100.0f;

View File

@@ -501,13 +501,13 @@ static void createTransSeqData(bContext * /*C*/, TransInfo *t)
SEQ_EDGE_PAN_MAX_SPEED,
SEQ_EDGE_PAN_DELAY,
SEQ_EDGE_PAN_ZOOM_INFLUENCE);
UI_view2d_edge_pan_set_limits(&ts->edge_pan, -FLT_MAX, FLT_MAX, 1, MAXSEQ + 1);
UI_view2d_edge_pan_set_limits(&ts->edge_pan, -FLT_MAX, FLT_MAX, 1, SEQ_MAX_CHANNELS + 1);
ts->initial_v2d_cur = t->region->v2d.cur;
/* Loop 2: build transdata array. */
SeqToTransData_build(t, ed->seqbasep, td, td2d, tdsq);
ts->selection_channel_range_min = MAXSEQ + 1;
ts->selection_channel_range_min = SEQ_MAX_CHANNELS + 1;
LISTBASE_FOREACH (Sequence *, seq, SEQ_active_seqbase_get(ed)) {
if ((seq->flag & SELECT) != 0) {
ts->selection_channel_range_min = min_ii(ts->selection_channel_range_min, seq->machine);
@@ -598,7 +598,7 @@ static void flushTransSeq(TransInfo *t)
}
}
seq->machine = round_fl_to_int(td->loc[1] + edge_pan_offset[1]);
CLAMP(seq->machine, 1, MAXSEQ);
CLAMP(seq->machine, 1, SEQ_MAX_CHANNELS);
break;
}
case SEQ_LEFTSEL: { /* No vertical transform. */
@@ -721,8 +721,8 @@ void transform_convert_sequencer_channel_clamp(TransInfo *t, float r_val[2])
const int min_channel_after_transform = ts->selection_channel_range_min + channel_offset;
const int max_channel_after_transform = ts->selection_channel_range_max + channel_offset;
if (max_channel_after_transform > MAXSEQ) {
r_val[1] -= max_channel_after_transform - MAXSEQ;
if (max_channel_after_transform > SEQ_MAX_CHANNELS) {
r_val[1] -= max_channel_after_transform - SEQ_MAX_CHANNELS;
}
if (min_channel_after_transform < 1) {
r_val[1] -= min_channel_after_transform - 1;

View File

@@ -578,8 +578,6 @@ typedef struct SoundEqualizerModifierData {
/** \name Flags & Types
* \{ */
#define MAXSEQ 128
/** #Editor::overlay_frame_flag */
enum {
SEQ_EDIT_OVERLAY_FRAME_SHOW = 1,

View File

@@ -2240,7 +2240,7 @@ static void rna_def_sequence(BlenderRNA *brna)
prop = RNA_def_property(srna, "channel", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, nullptr, "machine");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 1, MAXSEQ);
RNA_def_property_range(prop, 1, SEQ_MAX_CHANNELS);
RNA_def_property_ui_text(prop, "Channel", "Y position of the sequence strip");
RNA_def_property_int_funcs(
prop, nullptr, "rna_Sequence_channel_set", nullptr); /* overlap test */
@@ -3065,7 +3065,7 @@ static void rna_def_multicam(StructRNA *srna)
prop = RNA_def_property(srna, "multicam_source", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, nullptr, "multicam_source");
RNA_def_property_range(prop, 0, MAXSEQ - 1);
RNA_def_property_range(prop, 0, SEQ_MAX_CHANNELS - 1);
RNA_def_property_ui_text(prop, "Multicam Source Channel", "");
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_invalidate_raw_update");

View File

@@ -19,6 +19,7 @@
#include "RNA_define.hh"
#include "SEQ_edit.hh"
#include "SEQ_sequencer.hh"
#include "rna_internal.hh"
@@ -47,7 +48,6 @@
# include "SEQ_relations.hh"
# include "SEQ_render.hh"
# include "SEQ_retiming.hh"
# include "SEQ_sequencer.hh"
# include "SEQ_time.hh"
# include "WM_api.hh"
@@ -868,8 +868,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(func, "clip", "MovieClip", "", "Movie clip to add");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,
"frame_start",
@@ -892,8 +899,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(func, "mask", "Mask", "", "Mask to add");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,
"frame_start",
@@ -916,8 +930,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene to add");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,
"frame_start",
@@ -940,8 +961,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_string(func, "filepath", "File", 0, "", "Filepath to image");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,
"frame_start",
@@ -967,8 +995,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_string(func, "filepath", "File", 0, "", "Filepath to movie");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,
"frame_start",
@@ -994,8 +1029,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_string(func, "filepath", "File", 0, "", "Filepath to movie");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,
"frame_start",
@@ -1016,8 +1058,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_function_ui_description(func, "Add a new meta sequence");
parm = RNA_def_string(func, "name", "Name", 0, "", "Name for the new sequence");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,
"frame_start",
@@ -1040,8 +1089,15 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, const bool metastri
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_enum(func, "type", seq_effect_items, 0, "Type", "type for the new sequence");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(
func, "channel", 0, 1, MAXSEQ, "Channel", "The channel for the new sequence", 1, MAXSEQ);
parm = RNA_def_int(func,
"channel",
0,
1,
SEQ_MAX_CHANNELS,
"Channel",
"The channel for the new sequence",
1,
SEQ_MAX_CHANNELS);
/* don't use MAXFRAME since it makes importer scripts fail */
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_int(func,

View File

@@ -6157,7 +6157,7 @@ static void rna_def_space_sequencer(BlenderRNA *brna)
prop,
"Display Channel",
"The channel number shown in the image preview. 0 is the result of all strips combined");
RNA_def_property_range(prop, -5, MAXSEQ);
RNA_def_property_range(prop, -5, SEQ_MAX_CHANNELS);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SEQUENCER, "rna_SequenceEditor_update_cache");
prop = RNA_def_property(srna, "preview_channels", PROP_ENUM, PROP_NONE);

View File

@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2004 Blender Authors
/* SPDX-FileCopyrightText: 2004-2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -21,6 +21,8 @@ struct SeqTimelineChannel;
struct Sequence;
struct SequencerToolSettings;
constexpr int SEQ_MAX_CHANNELS = 128;
/* RNA enums, just to be more readable */
enum {
SEQ_SIDE_MOUSE = -1,
@@ -96,7 +98,7 @@ void SEQ_sequence_base_dupli_recursive(const Scene *scene_src,
const ListBase *seqbase,
int dupe_flag,
int flag);
bool SEQ_valid_strip_channel(Sequence *seq);
bool SEQ_is_valid_strip_channel(const Sequence *seq);
/**
* Read and Write functions for `.blend` file data.

View File

@@ -18,6 +18,7 @@
#include "BLT_translation.hh"
#include "SEQ_channels.hh"
#include "SEQ_sequencer.hh"
ListBase *SEQ_channels_displayed_get(Editing *ed)
{
@@ -32,7 +33,7 @@ void SEQ_channels_displayed_set(Editing *ed, ListBase *channels)
void SEQ_channels_ensure(ListBase *channels)
{
/* Allocate channels. Channel 0 is never used, but allocated to prevent off by 1 issues. */
for (int i = 0; i < MAXSEQ + 1; i++) {
for (int i = 0; i < SEQ_MAX_CHANNELS + 1; i++) {
SeqTimelineChannel *channel = static_cast<SeqTimelineChannel *>(
MEM_callocN(sizeof(SeqTimelineChannel), "seq timeline channel"));
SNPRINTF(channel->name, DATA_("Channel %d"), i);

View File

@@ -276,7 +276,7 @@ Vector<Sequence *> seq_get_shown_sequences(const Scene *scene,
scene, channels, seqbase, timeline_frame, chanshown);
const int strip_count = strips.size();
if (UNLIKELY(strip_count > MAXSEQ)) {
if (UNLIKELY(strip_count > SEQ_MAX_CHANNELS)) {
BLI_assert_msg(0, "Too many strips, this shouldn't happen");
return result;
}

View File

@@ -692,15 +692,9 @@ void SEQ_sequence_base_dupli_recursive(const Scene *scene_src,
}
}
bool SEQ_valid_strip_channel(Sequence *seq)
bool SEQ_is_valid_strip_channel(const Sequence *seq)
{
if (seq->machine < 1) {
return false;
}
if (seq->machine > MAXSEQ) {
return false;
}
return true;
return seq->machine >= 1 && seq->machine <= SEQ_MAX_CHANNELS;
}
SequencerToolSettings *SEQ_tool_settings_copy(SequencerToolSettings *tool_settings)

View File

@@ -142,14 +142,14 @@ bool SEQ_transform_seqbase_shuffle_ex(ListBase *seqbasep,
test->machine += channel_delta;
while (SEQ_transform_test_overlap(evil_scene, seqbasep, test)) {
if ((channel_delta > 0) ? (test->machine >= MAXSEQ) : (test->machine < 1)) {
if ((channel_delta > 0) ? (test->machine >= SEQ_MAX_CHANNELS) : (test->machine < 1)) {
break;
}
test->machine += channel_delta;
}
if (!SEQ_valid_strip_channel(test)) {
if (!SEQ_is_valid_strip_channel(test)) {
/* Blender 2.4x would remove the strip.
* nicer to move it to the end */
@@ -335,7 +335,7 @@ static void seq_transform_handle_expand_to_fit(Scene *scene,
/* Temporarily move right side strips beyond timeline boundary. */
for (Sequence *seq : right_side_strips) {
seq->machine += MAXSEQ * 2;
seq->machine += SEQ_MAX_CHANNELS * 2;
}
/* Shuffle transformed standalone strips. This is because transformed strips can overlap with
@@ -346,7 +346,7 @@ static void seq_transform_handle_expand_to_fit(Scene *scene,
/* Move temporarily moved strips back to their original place and tag for shuffling. */
for (Sequence *seq : right_side_strips) {
seq->machine -= MAXSEQ * 2;
seq->machine -= SEQ_MAX_CHANNELS * 2;
}
/* Shuffle again to displace strips on right side. Final effect shuffling is done in
* SEQ_transform_handle_overlap. */

View File

@@ -115,6 +115,8 @@
#include "GPU_context.hh"
#include "SEQ_sequencer.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "UI_view2d.hh"
@@ -1032,7 +1034,7 @@ static void file_read_reports_finalize(BlendFileReadReport *bf_reports)
RPT_ERROR,
"%d sequence strips were not read because they were in a channel larger than %d",
bf_reports->count.sequence_strips_skipped,
MAXSEQ);
SEQ_MAX_CHANNELS);
}
BLI_linklist_free(bf_reports->resynced_lib_overrides_libraries, nullptr);