Skip to content

Instantly share code, notes, and snippets.

@volition74
Created September 4, 2025 13:24
Show Gist options
  • Select an option

  • Save volition74/064f251f8df9de828b1184bd61a11cb1 to your computer and use it in GitHub Desktop.

Select an option

Save volition74/064f251f8df9de828b1184bd61a11cb1 to your computer and use it in GitHub Desktop.
Start Stop (gate) Values with Markers expression in After Effects
// === CONFIG ===
var offValue = 0; // Value to use outside of active segments
var blendDur = 0.5; // Duration (in seconds) for blending in/out
// ==============
var t = time;
var val = value;
var markers = thisLayer.marker; // change to thisComp.marker for compostion based maerkers
var segments = [];
// Collect all "start" and "stop" markers with time
for (var i = 1; i <= markers.numKeys; i++) {
var m = markers.key(i);
if (m.comment.toLowerCase() === "start") {
segments.push({ t: m.time, type: "start" });
} else if (m.comment.toLowerCase() === "stop") {
segments.push({ t: m.time, type: "stop" });
}
}
// Sort by time
segments.sort(function(a, b) {
return a.t - b.t;
});
// Build active time ranges
var ranges = [];
var inSeg = false;
var segStart = thisLayer.inPoint;
for (var i = 0; i < segments.length; i++) {
var s = segments[i];
if (s.type === "start") {
if (!inSeg) {
segStart = s.t;
inSeg = true;
}
} else if (s.type === "stop") {
if (inSeg) {
ranges.push([segStart, s.t]);
inSeg = false;
} else {
// orphan stop
ranges.push([thisLayer.inPoint, s.t]);
}
}
}
// Handle trailing open "start"
if (inSeg) {
ranges.push([segStart, thisLayer.outPoint]);
}
// Check if time is in any range
var active = false;
var blend = 0;
for (var i = 0; i < ranges.length; i++) {
var a = ranges[i][0];
var b = ranges[i][1];
if (t >= a - blendDur && t <= b + blendDur) {
if (t < a) {
// Blending in
blend = ease(t, a - blendDur, a, 0, 1);
} else if (t > b) {
// Blending out
blend = ease(t, b, b + blendDur, 1, 0);
} else {
blend = 1;
}
active = true;
break;
}
}
linear(blend, 0, 1, offValue, val);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment