Skip to content

Add keyframe animation looping controls - #1952

Open
bmatherly wants to merge 1 commit into
masterfrom
animation_loop
Open

bmatherly wants to merge 1 commit into
masterfrom
animation_loop

Conversation

@bmatherly

Copy link
Copy Markdown
Member

Depends on mltframework/mlt#1362

This change uses the MLT animation loop feature to allow a user to set up an endless loop keyframe animation.
It adds a new "Loop" button in the keyframe panel. When enabled, the keyframes are looped after the last keyframe.
Looped keyframes are rendered in a shaded color to show them as ghost keyframes. They can't be edited.

Here is an example of the loop being applies to a rotation parameter. The parameter animates from 0-360. However, the way the looping works, the last keyframe is replaced with the first keyframe so it goes to 0 instead of 360.
image

Here is an example of the loop being applied to a double value. In this case, the last keyframe value is set to the same as the first keyframe so that the value loops seamlessly:
image

The last keyframe is a special "control" keyframe since it is actually replaced with the value of the first keyframe during interpolation. The right context menu has a convenience action to set it to match the first keyframe for cases where the user wants to do that.

image

Add a loop toggle and repeated keyframe curves to the Keyframes panel.
Show authored endpoint values in controls and provide an action to
match the first keyframe value.

Hide looping controls and guard loop APIs with older MLT versions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Loop edits can race playback and discard existing keyframes, while loop-display and interaction defects also remain.

6 open issues
What changed in this PR

Adds per-parameter animation looping to Shotcut’s keyframe editor using MLT’s loop support, with controls for managing loop endpoints and visualizing repeated animation.

Changes:

  • Add Loop toggles and shaded ghost keyframes and curves.
  • Add a “Match First Keyframe Value” context-menu action.
  • Extend the parameter model, undo tracking, and filter value reads to support looping.
File Description
src/​qmltypes/​qmlfilter.h Declare the endpoint-value read helper.
src/​qmltypes/​qmlfilter.cpp Support authored endpoint values in typed reads and comparisons.
src/​qml/​views/​keyframes/​ParameterHead.qml Add the per-parameter Loop button.
src/​qml/​views/​keyframes/​keyframes.qml Bind loop state to headers and parameter tracks.
src/​qml/​views/​keyframes/​KeyframeParameter.qml Draw repeated curves and ghost markers.
src/​models/​keyframesmodel.h Expose loop support, state, and editing methods.
src/​models/​keyframesmodel.cpp Implement loop toggling, endpoint matching, and undo integration.
src/​docks/​keyframesdock.cpp Register and display the endpoint-matching action.

Review effort: Balanced

Comment thread src/models/keyframesmodel.cpp Resolved
Comment on lines +1258 to +1276
Mlt::Animation animation = m_filter->getAnimation(key);
if (!animation.is_valid() || animation.key_count() < 2)
continue;
const int lastIndex = animation.key_count() - 1;
const int lastFrame = animation.key_get_frame(lastIndex);
const auto lastType = animation.key_get_type(lastIndex);
const QString value = m_filter->get(key, animation.key_get_frame(0));
if (m_filter->service().anim_set(qUtf8Printable(key),
qUtf8Printable(value),
lastFrame,
m_filter->duration())) {
LOG_ERROR() << "Failed to match keyframe value" << key;
} else if (animation.key_set_type(lastIndex, lastType)) {
LOG_ERROR() << "Failed to restore keyframe type" << key;
} else {
animation.interpolate();
m_filter->service().get(qUtf8Printable(key));
m_filter->updateUndoCommand(key);
}
Comment on lines +369 to +372
case LoopRole: {
#if LIBMLT_VERSION_INT >= ((7 << 16) + (43 << 8))
Mlt::Animation animation = m_filter->getAnimation(m_propertyNames[index.row()]);
return animation.is_valid() && animation.get_loop();
"y": pts[0].y
});
ctx.setLineDash([4, 3]);
for (let c = 1; pts[0].x + c * period < width && c * n < 10000; c++) {
Comment thread src/qmltypes/qmlfilter.cpp Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants