Allow additional sequence prompt shots
This commit is contained in:
@@ -113,20 +113,41 @@ function configure(node) {
|
|||||||
};
|
};
|
||||||
const addSlot = (clip, afterIndex = clip.slots.length - 1) => {
|
const addSlot = (clip, afterIndex = clip.slots.length - 1) => {
|
||||||
const duration = Number(clip.duration) || 0.1;
|
const duration = Number(clip.duration) || 0.1;
|
||||||
if (afterIndex === clip.slots.length - 1 && afterIndex >= 0) {
|
if (!clip.slots.length) {
|
||||||
const previous = clip.slots[afterIndex];
|
clip.slots.push({ start: 0, end: duration, text: "" });
|
||||||
const split = Number(previous.start) + Math.max(0.1, (duration - Number(previous.start)) / 2);
|
|
||||||
previous.end = Math.min(duration - 0.1, split);
|
|
||||||
clip.slots.splice(afterIndex + 1, 0, { start: previous.end, end: duration, text: "" });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const previousEnd = afterIndex >= 0 ? Number(clip.slots[afterIndex]?.end) || 0 : 0;
|
const newCount = clip.slots.length + 1;
|
||||||
const remaining = Math.max(0.1, duration - previousEnd);
|
// Keep a minimum only when the selected duration allows it. The old
|
||||||
clip.slots.splice(afterIndex + 1, 0, {
|
// fixed 0.1s floor made later shots collapse at short frame choices.
|
||||||
start: previousEnd,
|
const minSlice = Math.min(0.1, duration / newCount);
|
||||||
end: Math.min(duration, previousEnd + Math.max(0.1, remaining / 2)),
|
let splitIndex = Math.max(0, Math.min(afterIndex, clip.slots.length - 1));
|
||||||
text: "",
|
const lengthOf = (slot) => Math.max(0, Number(slot.end) - Number(slot.start));
|
||||||
});
|
if (lengthOf(clip.slots[splitIndex]) < minSlice * 2) {
|
||||||
|
splitIndex = clip.slots.reduce(
|
||||||
|
(best, slot, index) => lengthOf(slot) > lengthOf(clip.slots[best]) ? index : best,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const target = clip.slots[splitIndex];
|
||||||
|
const start = Number(target?.start) || 0;
|
||||||
|
const end = Math.min(duration, Number(target?.end) || duration);
|
||||||
|
let split = start + (end - start) / 2;
|
||||||
|
split = Math.max(start + minSlice, Math.min(end - minSlice, split));
|
||||||
|
if (!(split > start && split < end)) {
|
||||||
|
// This is only reachable for malformed or extremely short state;
|
||||||
|
// redistribute boundaries evenly so the new shot is still real.
|
||||||
|
const texts = clip.slots.map((slot) => slot.text || "");
|
||||||
|
texts.splice(splitIndex + 1, 0, "");
|
||||||
|
clip.slots = texts.map((text, index) => ({
|
||||||
|
start: duration * index / newCount,
|
||||||
|
end: duration * (index + 1) / newCount,
|
||||||
|
text,
|
||||||
|
}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
target.end = split;
|
||||||
|
clip.slots.splice(splitIndex + 1, 0, { start: split, end, text: "" });
|
||||||
};
|
};
|
||||||
const formatTime = (seconds) => `00:${Number(seconds).toFixed(3).padStart(6, "0")}`;
|
const formatTime = (seconds) => `00:${Number(seconds).toFixed(3).padStart(6, "0")}`;
|
||||||
// Keep the user's script as the source of truth, like CSGlide does. The
|
// Keep the user's script as the source of truth, like CSGlide does. The
|
||||||
|
|||||||
Reference in New Issue
Block a user