VSE: Implement Snapping to Markers

This patch adds the ability to snap strips to markers. Previously, there
only existed options to snap to hold offsets and the current frame.

This snap type works identically to other snapping options by checking
for the relevant bit (here `SEQ_SNAP_TO_MARKERS`) and adding the marker
frame numbers to `snap_data->target_snap_points` within
`seq_snap_target_points_build()`.

To enable `seq_get_snap_target_points_count()` to have access to marker
information, the current Scene object is now passed to the function.

Pull Request: https://projects.blender.org/blender/blender/pulls/120450
This commit is contained in:
John Swenson
2024-04-23 01:54:14 +02:00
committed by Richard Antalik
parent 5644a0c621
commit cff532e134
7 changed files with 32 additions and 4 deletions

View File

@@ -2764,6 +2764,7 @@ class SEQUENCER_PT_snapping(Panel):
col = layout.column(heading="Snap to", align=True)
col.prop(sequencer_tool_settings, "snap_to_current_frame")
col.prop(sequencer_tool_settings, "snap_to_hold_offset")
col.prop(sequencer_tool_settings, "snap_to_markers")
col = layout.column(heading="Ignore", align=True)
col.prop(sequencer_tool_settings, "snap_ignore_muted", text="Muted Strips")

View File

@@ -29,7 +29,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 19
#define BLENDER_FILE_SUBVERSION 20
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@@ -63,6 +63,7 @@
#include "BKE_tracking.h"
#include "SEQ_iterator.hh"
#include "SEQ_sequencer.hh"
#include "ANIM_armature_iter.hh"
#include "ANIM_bone_collections.hh"
@@ -3185,6 +3186,13 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 402, 20)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
SequencerToolSettings *sequencer_tool_settings = SEQ_tool_settings_ensure(scene);
sequencer_tool_settings->snap_mode |= SEQ_SNAP_TO_MARKERS;
}
}
/**
* Always bump subversion in BKE_blender_version.h when adding versioning
* code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check.

View File

@@ -152,7 +152,8 @@ static blender::VectorSet<Sequence *> query_snap_targets(Scene *scene,
return snap_targets;
}
static int seq_get_snap_target_points_count(short snap_mode,
static int seq_get_snap_target_points_count(const Scene *scene,
short snap_mode,
blender::Span<Sequence *> snap_targets)
{
int count = 2; /* Strip start and end are always used. */
@@ -167,6 +168,10 @@ static int seq_get_snap_target_points_count(short snap_mode,
count++;
}
if (snap_mode & SEQ_SNAP_TO_MARKERS) {
count += BLI_listbase_count(&scene->markers);
}
return count;
}
@@ -175,7 +180,8 @@ static bool seq_snap_target_points_build(Scene *scene,
TransSeqSnapData *snap_data,
blender::Span<Sequence *> snap_targets)
{
const size_t point_count_target = seq_get_snap_target_points_count(snap_mode, snap_targets);
const size_t point_count_target = seq_get_snap_target_points_count(
scene, snap_mode, snap_targets);
if (point_count_target == 0) {
return false;
}
@@ -188,6 +194,13 @@ static bool seq_snap_target_points_build(Scene *scene,
i++;
}
if (snap_mode & SEQ_SNAP_TO_MARKERS) {
LISTBASE_FOREACH (TimeMarker *, marker, &scene->markers) {
snap_data->target_snap_points[i] = marker->frame;
i++;
}
}
for (Sequence *seq : snap_targets) {
snap_data->target_snap_points[i] = SEQ_time_left_handle_frame_get(scene, seq);
snap_data->target_snap_points[i + 1] = SEQ_time_right_handle_frame_get(scene, seq);

View File

@@ -2417,6 +2417,7 @@ enum {
SEQ_SNAP_TO_STRIPS = 1 << 0,
SEQ_SNAP_TO_CURRENT_FRAME = 1 << 1,
SEQ_SNAP_TO_STRIP_HOLD = 1 << 2,
SEQ_SNAP_TO_MARKERS = 1 << 3,
};
/** #SequencerToolSettings::snap_flag */

View File

@@ -4190,6 +4190,11 @@ static void rna_def_sequencer_tool_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Hold Offset", "Snap to strip hold offsets");
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, nullptr); /* header redraw */
prop = RNA_def_property(srna, "snap_to_markers", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "snap_mode", SEQ_SNAP_TO_MARKERS);
RNA_def_property_ui_text(prop, "Markers", "Snap to markers");
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, nullptr); /* header redraw */
prop = RNA_def_property(srna, "snap_ignore_muted", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "snap_flag", SEQ_SNAP_IGNORE_MUTED);
RNA_def_property_ui_text(prop, "Ignore Muted Strips", "Don't snap to hidden strips");

View File

@@ -331,7 +331,7 @@ SequencerToolSettings *SEQ_tool_settings_init()
MEM_callocN(sizeof(SequencerToolSettings), "Sequencer tool settings"));
tool_settings->fit_method = SEQ_SCALE_TO_FIT;
tool_settings->snap_mode = SEQ_SNAP_TO_STRIPS | SEQ_SNAP_TO_CURRENT_FRAME |
SEQ_SNAP_TO_STRIP_HOLD;
SEQ_SNAP_TO_STRIP_HOLD | SEQ_SNAP_TO_MARKERS;
tool_settings->snap_distance = 15;
tool_settings->overlap_mode = SEQ_OVERLAP_SHUFFLE;
tool_settings->pivot_point = V3D_AROUND_LOCAL_ORIGINS;