Release V3.5.1 conditioning bridge and reference audio
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
const CONFIGURATION = Symbol("h3ContinuumLastQueuedSeedConfiguration");
|
||||
|
||||
function normalizeControlMode(value) {
|
||||
if (value === true) return "randomize";
|
||||
if (value === false) return "fixed";
|
||||
return String(value ?? "").trim().toLowerCase();
|
||||
}
|
||||
|
||||
function sameSeed(left, right) {
|
||||
if (left == null || right == null) return false;
|
||||
return String(left) === String(right);
|
||||
}
|
||||
|
||||
function clearAutomaticUpdate(state) {
|
||||
state.auto_updated_seed = undefined;
|
||||
state.auto_update_pending = false;
|
||||
}
|
||||
|
||||
function findSeedWidgets(node) {
|
||||
const seedWidget = node.widgets?.find((widget) => widget.name === "base_seed");
|
||||
const controlWidget = seedWidget?.linkedWidgets?.find(
|
||||
(widget) => widget.name === "control_after_generate",
|
||||
) ?? node.widgets?.find((widget) => widget.name === "control_after_generate");
|
||||
return { seedWidget, controlWidget };
|
||||
}
|
||||
|
||||
export function configureLastQueuedSeedReuse(node) {
|
||||
const { seedWidget, controlWidget } = findSeedWidgets(node);
|
||||
if (!seedWidget || !controlWidget) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const existing = node[CONFIGURATION];
|
||||
if (existing?.seedWidget === seedWidget && existing?.controlWidget === controlWidget) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const state = {
|
||||
last_queued_seed: undefined,
|
||||
auto_updated_seed: undefined,
|
||||
previous_control_mode: normalizeControlMode(controlWidget.value),
|
||||
auto_update_pending: false,
|
||||
};
|
||||
let applyingAutomaticUpdate = false;
|
||||
let restoringQueuedSeed = false;
|
||||
|
||||
const previousSeedCallback = seedWidget.callback;
|
||||
seedWidget.callback = function(value, ...args) {
|
||||
const result = previousSeedCallback?.call(this, value, ...args);
|
||||
if (
|
||||
!applyingAutomaticUpdate
|
||||
&& !restoringQueuedSeed
|
||||
&& state.auto_update_pending
|
||||
&& !sameSeed(value, state.auto_updated_seed)
|
||||
) {
|
||||
clearAutomaticUpdate(state);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const previousControlCallback = controlWidget.callback;
|
||||
controlWidget.callback = function(value, ...args) {
|
||||
const priorMode = state.previous_control_mode;
|
||||
const result = previousControlCallback?.call(this, value, ...args);
|
||||
const nextMode = normalizeControlMode(value ?? controlWidget.value);
|
||||
|
||||
if (priorMode === "randomize" && nextMode === "fixed") {
|
||||
if (
|
||||
state.auto_update_pending
|
||||
&& sameSeed(seedWidget.value, state.auto_updated_seed)
|
||||
&& state.last_queued_seed != null
|
||||
) {
|
||||
restoringQueuedSeed = true;
|
||||
try {
|
||||
seedWidget.value = state.last_queued_seed;
|
||||
seedWidget.callback?.(state.last_queued_seed);
|
||||
} finally {
|
||||
restoringQueuedSeed = false;
|
||||
}
|
||||
}
|
||||
clearAutomaticUpdate(state);
|
||||
} else if (nextMode !== "randomize") {
|
||||
clearAutomaticUpdate(state);
|
||||
}
|
||||
|
||||
state.previous_control_mode = nextMode;
|
||||
return result;
|
||||
};
|
||||
|
||||
const previousAfterQueued = controlWidget.afterQueued;
|
||||
controlWidget.afterQueued = function(...args) {
|
||||
const before = seedWidget.value;
|
||||
applyingAutomaticUpdate = true;
|
||||
let result;
|
||||
try {
|
||||
result = previousAfterQueued?.apply(this, args);
|
||||
} finally {
|
||||
applyingAutomaticUpdate = false;
|
||||
}
|
||||
const after = seedWidget.value;
|
||||
const mode = normalizeControlMode(controlWidget.value);
|
||||
state.previous_control_mode = mode;
|
||||
|
||||
if (
|
||||
mode === "randomize"
|
||||
&& state.last_queued_seed != null
|
||||
&& sameSeed(before, state.last_queued_seed)
|
||||
&& !sameSeed(after, before)
|
||||
) {
|
||||
state.auto_updated_seed = after;
|
||||
state.auto_update_pending = true;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
node[CONFIGURATION] = { seedWidget, controlWidget, state };
|
||||
return true;
|
||||
}
|
||||
|
||||
export function captureLastQueuedSeed(node, queuedSeed) {
|
||||
if (!configureLastQueuedSeedReuse(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const configuration = node[CONFIGURATION];
|
||||
const { controlWidget, state } = configuration;
|
||||
if (queuedSeed == null || Array.isArray(queuedSeed)) {
|
||||
state.last_queued_seed = undefined;
|
||||
state.previous_control_mode = normalizeControlMode(controlWidget.value);
|
||||
clearAutomaticUpdate(state);
|
||||
return false;
|
||||
}
|
||||
state.last_queued_seed = queuedSeed;
|
||||
state.previous_control_mode = normalizeControlMode(controlWidget.value);
|
||||
clearAutomaticUpdate(state);
|
||||
return true;
|
||||
}
|
||||
+27
-2
@@ -1,4 +1,9 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import {
|
||||
captureLastQueuedSeed,
|
||||
configureLastQueuedSeedReuse,
|
||||
} from "./last_queued_seed.js";
|
||||
import { configureReferenceAudioInputs } from "./reference_audio_ui.js";
|
||||
|
||||
const PRODUCTION_NODE_CLASS = "H3ContinuumSamplerProduction";
|
||||
const TIMELINE_NODE_CLASS = "H3ContinuumSamplerTimelineVideo";
|
||||
@@ -238,6 +243,9 @@ function configureNode(node) {
|
||||
removeUnusedInput(node, PROMPT_OVERRIDES_INPUT);
|
||||
}
|
||||
applyRuntimeSettings(node);
|
||||
if (isV35) {
|
||||
configureLastQueuedSeedReuse(node);
|
||||
}
|
||||
hidePersistentWidget(findWidget(node, "diagnostics"));
|
||||
hidePersistentWidget(findWidget(node, "strict_compatibility"));
|
||||
hidePersistentWidget(findWidget(node, "debug"));
|
||||
@@ -251,8 +259,20 @@ function configureNode(node) {
|
||||
|
||||
function configureNodeAfterSetup(node) {
|
||||
configureNode(node);
|
||||
setTimeout(() => configureNode(node), 0);
|
||||
setTimeout(() => configureNode(node), 100);
|
||||
const configureDeferred = () => {
|
||||
configureNode(node);
|
||||
if (
|
||||
node.comfyClass === V35_NODE_CLASS
|
||||
&& (
|
||||
!node.__h3ContinuumLoadedGraphNode
|
||||
|| node.__h3ContinuumAfterConfigureGraph
|
||||
)
|
||||
) {
|
||||
configureReferenceAudioInputs(node);
|
||||
}
|
||||
};
|
||||
setTimeout(configureDeferred, 0);
|
||||
setTimeout(configureDeferred, 100);
|
||||
}
|
||||
|
||||
app.registerExtension({
|
||||
@@ -291,11 +311,13 @@ app.registerExtension({
|
||||
},
|
||||
|
||||
loadedGraphNode(node) {
|
||||
node.__h3ContinuumLoadedGraphNode = true;
|
||||
configureNodeAfterSetup(node);
|
||||
},
|
||||
|
||||
afterConfigureGraph() {
|
||||
for (const node of app.graph?._nodes || []) {
|
||||
node.__h3ContinuumAfterConfigureGraph = true;
|
||||
configureNodeAfterSetup(node);
|
||||
}
|
||||
},
|
||||
@@ -305,6 +327,9 @@ app.registerExtension({
|
||||
for (const node of app.graph?._nodes || []) {
|
||||
const projectWidget = configureNode(node);
|
||||
const apiNode = prompt.output?.[String(node.id)];
|
||||
if (node.comfyClass === V35_NODE_CLASS) {
|
||||
captureLastQueuedSeed(node, apiNode?.inputs?.base_seed);
|
||||
}
|
||||
if (apiNode?.inputs) {
|
||||
if (
|
||||
node.comfyClass === PRODUCTION_NODE_CLASS
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
const REFERENCE_AUDIO_WIDGET = "Reference Audio Inputs";
|
||||
const REFERENCE_AUDIO_HIDDEN = "Hidden";
|
||||
const REFERENCE_AUDIO_SHOW = "Show";
|
||||
|
||||
const INPUT_DEFINITIONS = [
|
||||
{
|
||||
name: "reference_audio_1",
|
||||
type: "AUDIO",
|
||||
label: "Reference Audio (Optional)",
|
||||
shape: 7,
|
||||
},
|
||||
{
|
||||
name: "reference_audio_vae",
|
||||
type: "VAE",
|
||||
label: "Reference Audio VAE (Optional)",
|
||||
shape: 7,
|
||||
},
|
||||
];
|
||||
|
||||
const NORMALIZED_INPUT_LABELS = {
|
||||
reference_video_1: "Video Guide Frames",
|
||||
driving_audio: "Driving Audio",
|
||||
audio_vae: "Driving Audio VAE",
|
||||
reference_audio_1: "Reference Audio (Optional)",
|
||||
reference_audio_vae: "Reference Audio VAE (Optional)",
|
||||
};
|
||||
|
||||
function findInput(node, name) {
|
||||
return node.inputs?.find((input) => input.name === name);
|
||||
}
|
||||
|
||||
function findWidget(node) {
|
||||
return node.widgets?.find((widget) => widget.name === REFERENCE_AUDIO_WIDGET);
|
||||
}
|
||||
|
||||
function normalizeInputLabels(node) {
|
||||
for (const input of node.inputs || []) {
|
||||
const label = NORMALIZED_INPUT_LABELS[input.name];
|
||||
if (label) {
|
||||
input.label = label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function inputHasLink(input) {
|
||||
return input?.link != null && input.link !== -1;
|
||||
}
|
||||
|
||||
function hasReferenceAudioLink(node) {
|
||||
return INPUT_DEFINITIONS.some(({ name }) => inputHasLink(findInput(node, name)));
|
||||
}
|
||||
|
||||
function rememberInputDefinitions(node) {
|
||||
node.__h3ContinuumReferenceAudioDefinitions ||= {};
|
||||
for (const definition of INPUT_DEFINITIONS) {
|
||||
const input = findInput(node, definition.name);
|
||||
if (!input || node.__h3ContinuumReferenceAudioDefinitions[definition.name]) {
|
||||
continue;
|
||||
}
|
||||
node.__h3ContinuumReferenceAudioDefinitions[definition.name] = {
|
||||
name: definition.name,
|
||||
type: input.type || definition.type,
|
||||
label: definition.label,
|
||||
shape: input.shape ?? definition.shape,
|
||||
index: node.inputs.indexOf(input),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function inputDefinition(node, name) {
|
||||
const remembered = node.__h3ContinuumReferenceAudioDefinitions?.[name];
|
||||
return remembered || INPUT_DEFINITIONS.find((definition) => definition.name === name);
|
||||
}
|
||||
|
||||
function resizeNode(node) {
|
||||
const computed = node.computeSize?.();
|
||||
if (computed && node.setSize) {
|
||||
const width = Math.max(Number(node.size?.[0]) || 0, Number(computed[0]) || 0);
|
||||
node.setSize([width, computed[1]]);
|
||||
}
|
||||
node.setDirtyCanvas?.(true, true);
|
||||
}
|
||||
|
||||
function showReferenceAudioInputs(node) {
|
||||
for (const expected of INPUT_DEFINITIONS) {
|
||||
if (findInput(node, expected.name)) {
|
||||
continue;
|
||||
}
|
||||
const definition = inputDefinition(node, expected.name);
|
||||
const input = node.addInput?.(definition.name, definition.type, {
|
||||
label: definition.label,
|
||||
shape: definition.shape,
|
||||
});
|
||||
const addedIndex = node.inputs?.indexOf(input) ?? -1;
|
||||
const rememberedIndex = Number(definition.index);
|
||||
const firstWidgetInput = node.inputs?.findIndex(
|
||||
(candidate) => candidate.name === "prompt_mode",
|
||||
) ?? -1;
|
||||
const requestedIndex = Number.isInteger(rememberedIndex)
|
||||
? rememberedIndex
|
||||
: (firstWidgetInput >= 0 ? firstWidgetInput : node.inputs.length - 1);
|
||||
const targetIndex = Math.min(
|
||||
Math.max(0, requestedIndex),
|
||||
Math.max(0, node.inputs.length - 1),
|
||||
);
|
||||
if (addedIndex >= 0 && addedIndex !== targetIndex) {
|
||||
node.inputs.splice(addedIndex, 1);
|
||||
node.inputs.splice(targetIndex, 0, input);
|
||||
}
|
||||
}
|
||||
normalizeInputLabels(node);
|
||||
return INPUT_DEFINITIONS.every(({ name }) => Boolean(findInput(node, name)));
|
||||
}
|
||||
|
||||
function hideReferenceAudioInputs(node) {
|
||||
if (hasReferenceAudioLink(node)) {
|
||||
return false;
|
||||
}
|
||||
const indices = INPUT_DEFINITIONS.map(({ name }) =>
|
||||
node.inputs?.findIndex((input) => input.name === name) ?? -1
|
||||
);
|
||||
for (const index of indices.filter((index) => index >= 0).sort((left, right) => right - left)) {
|
||||
node.removeInput?.(index);
|
||||
}
|
||||
return INPUT_DEFINITIONS.every(({ name }) => !findInput(node, name));
|
||||
}
|
||||
|
||||
function setReferenceAudioVisibility(node, widget, show) {
|
||||
rememberInputDefinitions(node);
|
||||
const applied = show
|
||||
? showReferenceAudioInputs(node)
|
||||
: hideReferenceAudioInputs(node);
|
||||
if (!applied) {
|
||||
showReferenceAudioInputs(node);
|
||||
widget.value = REFERENCE_AUDIO_SHOW;
|
||||
}
|
||||
resizeNode(node);
|
||||
return applied;
|
||||
}
|
||||
|
||||
function ensureVisibilityWidget(node) {
|
||||
let widget = findWidget(node);
|
||||
if (widget) {
|
||||
return widget;
|
||||
}
|
||||
if (!node.addWidget) {
|
||||
return null;
|
||||
}
|
||||
const initialValue = hasReferenceAudioLink(node)
|
||||
? REFERENCE_AUDIO_SHOW
|
||||
: REFERENCE_AUDIO_HIDDEN;
|
||||
widget = node.addWidget(
|
||||
"combo",
|
||||
REFERENCE_AUDIO_WIDGET,
|
||||
initialValue,
|
||||
(value) => {
|
||||
setReferenceAudioVisibility(
|
||||
node,
|
||||
widget,
|
||||
value === REFERENCE_AUDIO_SHOW,
|
||||
);
|
||||
},
|
||||
{ values: [REFERENCE_AUDIO_HIDDEN, REFERENCE_AUDIO_SHOW] },
|
||||
);
|
||||
widget.options ||= {};
|
||||
widget.options.serialize = false;
|
||||
widget.serializeValue = () => undefined;
|
||||
return widget;
|
||||
}
|
||||
|
||||
function attachWorkflowSerializationGuard(node, widget) {
|
||||
if (node.__h3ContinuumReferenceAudioSerializationGuard) {
|
||||
return;
|
||||
}
|
||||
const previous = node.onSerialize;
|
||||
node.onSerialize = function(info, ...args) {
|
||||
const result = previous?.call(this, info, ...args);
|
||||
const widgetIndex = node.widgets?.indexOf(widget) ?? -1;
|
||||
if (
|
||||
widgetIndex >= 0
|
||||
&& Array.isArray(info?.widgets_values)
|
||||
&& widgetIndex === node.widgets.length - 1
|
||||
&& info.widgets_values.length === node.widgets.length
|
||||
) {
|
||||
info.widgets_values.pop();
|
||||
}
|
||||
return result;
|
||||
};
|
||||
node.__h3ContinuumReferenceAudioSerializationGuard = true;
|
||||
}
|
||||
|
||||
function attachConnectionRefresh(node, widget) {
|
||||
if (node.__h3ContinuumReferenceAudioConnectionCallback) {
|
||||
return;
|
||||
}
|
||||
const previous = node.onConnectionsChange;
|
||||
node.onConnectionsChange = function(...args) {
|
||||
const result = previous?.apply(this, args);
|
||||
setTimeout(() => {
|
||||
normalizeInputLabels(node);
|
||||
if (hasReferenceAudioLink(node)) {
|
||||
widget.value = REFERENCE_AUDIO_SHOW;
|
||||
setReferenceAudioVisibility(node, widget, true);
|
||||
}
|
||||
}, 0);
|
||||
return result;
|
||||
};
|
||||
node.__h3ContinuumReferenceAudioConnectionCallback = true;
|
||||
}
|
||||
|
||||
export function configureReferenceAudioInputs(node) {
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
normalizeInputLabels(node);
|
||||
rememberInputDefinitions(node);
|
||||
const widget = ensureVisibilityWidget(node);
|
||||
if (!widget) {
|
||||
return false;
|
||||
}
|
||||
attachWorkflowSerializationGuard(node, widget);
|
||||
if (hasReferenceAudioLink(node)) {
|
||||
widget.value = REFERENCE_AUDIO_SHOW;
|
||||
}
|
||||
setReferenceAudioVisibility(
|
||||
node,
|
||||
widget,
|
||||
widget.value === REFERENCE_AUDIO_SHOW,
|
||||
);
|
||||
attachConnectionRefresh(node, widget);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user