diff --git a/web/sequence_prompt_builder.js b/web/sequence_prompt_builder.js index 98a350b..e53761d 100644 --- a/web/sequence_prompt_builder.js +++ b/web/sequence_prompt_builder.js @@ -2,6 +2,18 @@ import { app } from "../../scripts/app.js"; const CLASS = "DumasH3SequencePromptBuilder"; const MAX_CLIPS = 16; +const DURATION_OPTIONS = [ + ["1–5", 5, 2, 0.21], ["6–22", 22, 7, 0.92], ["23–39", 39, 12, 1.63], + ["40–56", 56, 17, 2.33], ["57–73", 73, 22, 3.04], ["74–90", 90, 27, 3.75], + ["91–107", 107, 32, 4.46], ["108–124", 124, 37, 5.17], ["125–141", 141, 42, 5.88], + ["142–158", 158, 47, 6.58], ["159–175", 175, 52, 7.29], ["176–192", 192, 57, 8.00], + ["193–209", 209, 62, 8.71], ["210–226", 226, 67, 9.42], ["227–243", 243, 72, 10.13], + ["244–260", 260, 77, 10.83], ["261–277", 277, 82, 11.54], ["278–294", 294, 87, 12.25], + ["295–311", 311, 92, 12.96], ["312–328", 328, 97, 13.67], ["329–345", 345, 102, 14.38], + ["346–362", 362, 107, 15.08], +].map(([requested, actual, latent, labelSeconds]) => ({ + requested, actual, latent, labelSeconds, seconds: actual / 24, +})); const get = (node, name) => node.widgets?.find((widget) => widget.name === name); const el = (tag, text = "") => { const item = document.createElement(tag); item.textContent = text; return item; }; @@ -32,6 +44,7 @@ function configure(node) { const secondsWidget = get(node, "default_chunk_seconds"); const stateWidget = get(node, "timeline_json"); if (!countWidget || !secondsWidget || !stateWidget) return; + hide(secondsWidget); hide(stateWidget); const panel = el("div"); panel.style.cssText = "box-sizing:border-box;position:relative;width:calc(100% + 14px);margin-left:-7px;min-width:420px;padding:9px;color:#d9e3dc;background:#292929;border:1px solid #454545;border-radius:4px;font:12px Arial;pointer-events:auto"; @@ -139,7 +152,12 @@ function configure(node) { }; const render = () => { const count = Math.max(1, Math.min(MAX_CLIPS, Number(countWidget.value) || 1)); - const chunkDuration = Number(secondsWidget.value) || 4; + const currentSeconds = Number(secondsWidget.value) || DURATION_OPTIONS[6].seconds; + const selectedDuration = DURATION_OPTIONS.reduce((best, option) => + Math.abs(option.seconds - currentSeconds) < Math.abs(best.seconds - currentSeconds) ? option : best, + DURATION_OPTIONS[6]); + if (Number(secondsWidget.value) !== selectedDuration.seconds) secondsWidget.value = selectedDuration.seconds; + const chunkDuration = selectedDuration.seconds; while (state.clips.length < count) state.clips.push({ duration: chunkDuration, slots: [] }); state.clips = state.clips.slice(0, count); active = Math.min(active, count - 1); panel.replaceChildren(); @@ -156,8 +174,28 @@ function configure(node) { clip.duration = duration; if (clip.slots.length) clip.slots[clip.slots.length - 1].end = duration; promptText = promptFor(clip); + const durationControl = el("div"); + durationControl.style.cssText = "display:flex;align-items:center;gap:8px;margin:0 0 8px;color:#b7d6bf"; + const durationLabel = el("span", "Chunk duration / frame choice"); + durationLabel.style.cssText = "font-weight:bold;white-space:nowrap"; + const durationSelect = document.createElement("select"); + durationSelect.style.cssText = "flex:1;min-width:0;box-sizing:border-box;padding:4px 6px;color:#e8e8e8;background:#171717;border:1px solid #596b60;border-radius:4px;font:11px monospace"; + DURATION_OPTIONS.forEach((option) => { + const item = document.createElement("option"); + item.value = String(option.seconds); + item.textContent = `${option.requested} requested → ${option.actual} actual / ${option.latent} latent / ${option.labelSeconds.toFixed(2)}s`; + item.selected = option === selectedDuration; + durationSelect.append(item); + }); + durationSelect.title = "Choose a native H3 frame length; actual frames are encoded from the latent-frame choice."; + durationSelect.onchange = () => { + secondsWidget.value = Number(durationSelect.value); + secondsWidget.callback?.(secondsWidget.value); + }; + durationControl.append(durationLabel, durationSelect); + panel.append(durationControl); const durationRow = el("div"); durationRow.style.cssText = "display:flex;align-items:center;gap:8px;margin:4px 0 6px;color:#b7d6bf"; - durationRow.append(el("strong", `Clip ${active + 1}`), el("span", `· ${duration.toFixed(1)}s shared chunk duration`)); panel.append(durationRow); + durationRow.append(el("strong", `Clip ${active + 1}`), el("span", `· ${selectedDuration.actual} actual frames · ${selectedDuration.latent} latent frames · ${selectedDuration.labelSeconds.toFixed(2)}s shared chunk duration`)); panel.append(durationRow); const timeline = el("div"); timeline.style.cssText = "position:relative;height:38px;margin:8px 0 4px;background:#171717;border-radius:4px;overflow:hidden;border:1px solid #555"; const palette = ["#4b9b67", "#4d7fb1", "#a87945", "#8c5aa8", "#a44f5d", "#3f8e8a"]; let prompt = null;