Seed controls added to Ksamplers

This commit is contained in:
Julien Lubimiv 2023-03-27 18:12:13 -04:00
parent d3a375c8fb
commit 7429161b57
2 changed files with 49 additions and 26 deletions

View File

@ -1,4 +1,4 @@
import { ComfyWidgets, addRandomizeWidget } from "/scripts/widgets.js"; import { ComfyWidgets, addSeedControlWidget } from "/scripts/widgets.js";
import { app } from "/scripts/app.js"; import { app } from "/scripts/app.js";
const CONVERTED_TYPE = "converted-widget"; const CONVERTED_TYPE = "converted-widget";
@ -23,7 +23,7 @@ function hideWidget(node, widget, suffix = "") {
return widget.value; return widget.value;
}; };
// Hide any linked widgets, e.g. seed+randomize // Hide any linked widgets, e.g. seed+seedControl
if (widget.linkedWidgets) { if (widget.linkedWidgets) {
for (const w of widget.linkedWidgets) { for (const w of widget.linkedWidgets) {
hideWidget(node, w, ":" + widget.name); hideWidget(node, w, ":" + widget.name);
@ -40,7 +40,7 @@ function showWidget(widget) {
delete widget.origComputeSize; delete widget.origComputeSize;
delete widget.origSerializeValue; delete widget.origSerializeValue;
// Hide any linked widgets, e.g. seed+randomize // Hide any linked widgets, e.g. seed+seedControl
if (widget.linkedWidgets) { if (widget.linkedWidgets) {
for (const w of widget.linkedWidgets) { for (const w of widget.linkedWidgets) {
showWidget(w); showWidget(w);
@ -285,7 +285,7 @@ app.registerExtension({
} }
if (widget.type === "number") { if (widget.type === "number") {
addRandomizeWidget(this, widget, "Random after every gen"); addSeedControlWidget(this, widget, "fixed_seed");
} }
// When our value changes, update other widgets to reflect our changes // When our value changes, update other widgets to reflect our changes

View File

@ -10,37 +10,60 @@ function getNumberDefaults(inputData, defaultStep) {
return { val: defaultVal, config: { min, max, step: 10.0 * step } }; return { val: defaultVal, config: { min, max, step: 10.0 * step } };
} }
export function addRandomizeWidget(node, targetWidget, name, defaultValue = false) { export function addSeedControlWidget(node, targetWidget, defauly, options) {
const randomize = node.addWidget("toggle", name, defaultValue, function (v) {}, { const seedControl = node.addWidget("combo", "seed control after generating", "Fixed Seed", function (v) { }, {
on: "enabled", values: ["Fixed Seed", "increment", "decrement", "randomize"] },)
off: "disabled", seedControl.afterQueued = () => {
serialize: false, // Don't include this in prompt.
});
randomize.afterQueued = () => { const min = targetWidget.options?.min;
if (randomize.value) { let max = targetWidget.options?.max;
var v = seedControl.value;
switch (v) {
case ("Fixed Seed"):
console.log("Fixed Seed");
break;
case ("increment"):
targetWidget.value += 1;
console.log("increment");
break;
case ("decrement"):
targetWidget.value -= 1;
console.log("decrement");
break;
case ("randomize"):
const min = targetWidget.options?.min; const min = targetWidget.options?.min;
let max = targetWidget.options?.max; let max = targetWidget.options?.max;
if (min != null || max != null) { if (min != null || max != null) {
if (max) { if (max) {
// limit max to something that javascript can handle // limit max to something that javascript can handle
max = Math.min(1125899906842624, max); max = Math.min(1125899906842624, max);
console.log("Random");
} }
targetWidget.value = Math.floor(Math.random() * ((max ?? 9999999999) - (min ?? 0) + 1) + (min ?? 0)); targetWidget.value = Math.floor(Math.random() * ((max ?? 9999999999) - (min ?? 0) + 1) + (min ?? 0));
console.log("Random");
} else { } else {
targetWidget.value = Math.floor(Math.random() * 1125899906842624); targetWidget.value = Math.floor(Math.random() * 1125899906842624);
console.log("Random");
} }
break;
default:
console.log("default (fail)");
} }
}; };
return randomize;
return seedControl;
} }
function seedWidget(node, inputName, inputData) { function seedWidget(node, inputName, inputData) {
const seed = ComfyWidgets.INT(node, inputName, inputData); const seed = ComfyWidgets.INT(node, inputName, inputData);
const randomize = addRandomizeWidget(node, seed.widget, "Random seed after every gen", true); const seedControl = addSeedControlWidget(node, seed.widget, "Fixed Seed");
seed.widget.linkedWidgets = [randomize]; seed.widget.linkedWidgets = [seedControl];
return { widget: seed, randomize }; return { widget: seed, seedControl};
} }
const MultilineSymbol = Symbol(); const MultilineSymbol = Symbol();