blendAt method
The blocks' answer at t. Inside one block, that block. Inside two,
the earlier leads and the later comes in, blend running 0 to 1 from
the later's start to the earlier's end. Between blocks the last one
to end holds its end; before the first, the first holds its start.
Implementation
ClipBlend blendAt(Duration t) {
var active = [
for (var c in clips)
if (t >= c.at && t <= c.end) c,
];
if (active.isEmpty) {
MotionClip? before;
for (var c in clips) {
if (c.end < t && (before == null || c.end > before.end)) before = c;
}
var hold = before ?? clips.first;
return (
clip: hold.clip,
time: hold.timeAt(before == null ? hold.at : hold.end),
clip2: '',
time2: 0,
blend: 0,
);
}
var a = active.first;
if (active.length == 1) {
return (clip: a.clip, time: a.timeAt(t), clip2: '', time2: 0, blend: 0);
}
var b = active[1];
var overlap = (a.end - b.at).inMicroseconds;
var blend = overlap <= 0
? 1.0
: ((t - b.at).inMicroseconds / overlap).clamp(0.0, 1.0);
return (
clip: a.clip,
time: a.timeAt(t),
clip2: b.clip,
time2: b.timeAt(t),
blend: blend,
);
}