all fixed, names changed to reflect expanded functionality

This commit is contained in:
FizzleDorf 2023-04-02 15:48:35 -04:00
parent d95c9946d5
commit a2d09199ba
3 changed files with 120 additions and 47 deletions

View File

@ -1,11 +1,14 @@
import { ComfyWidgets, addSeedControlWidget } from "/scripts/widgets.js"; import { ComfyWidgets, addValueControlWidget } 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";
const VALID_TYPES = ["STRING", "combo", "number"]; const VALID_TYPES = ["STRING", "combo", "number"];
function isConvertableWidget(widget, config) { function isConvertableWidget(widget, config) {
if (widget.name == "seed control after generate") if (widget.name == "control_after_generate" ||
widget.name == "batch_size" ||
widget.name == "start_at_step" ||
widget.name == "end_at_step")
widget.allowConvertToInput = false; widget.allowConvertToInput = false;
else else
return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]); return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]);
@ -290,14 +293,13 @@ app.registerExtension({
} else { } else {
widget = this.addWidget(type, widgetName /*"value"*/, null, () => { }, {}); widget = this.addWidget(type, widgetName /*"value"*/, null, () => { }, {});
} }
}
if (widget.type === "number" && combinedWidgetType != "INT:seed" && combinedWidgetType != "INT:seed") { if (widget.type === "number" && combinedWidgetType != "INT:seed" && combinedWidgetType != "INT:noise_seed") {
addSeedControlWidget(this, widget, "fixed seed"); addValueControlWidget(this, widget, "fixed");
}
} }
if (node?.widgets && widget) { if (node?.widgets && widget) {
const theirWidget = node.widgets.find((w) => w.name === widgetName); const theirWidget = node.widgets.find((w) => w.name === widgetName);

View File

@ -828,7 +828,7 @@ class ComfyApp {
widget.value = widget.value.slice(7); widget.value = widget.value.slice(7);
} }
} }
if (widget.name == "seed control after generating") { if (widget.name == "control_after_generate") {
if (widget.value == true) { if (widget.value == true) {
widget.value = "randomize"; widget.value = "randomize";
} }

View File

@ -10,31 +10,73 @@ 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 addSeedControlWidget(node, targetWidget, defaultValue = "randomize", values) { export function addValueControlWidget(node, targetWidget, defaultValue = "randomize", values) {
const seedControl = node.addWidget("combo", "seed control after generate", defaultValue, function (v) { }, { const valueControl = node.addWidget("combo", "control_after_generate", defaultValue, function (v) { }, {
values: ["fixed", "increment", "decrement", "randomize"], values: ["fixed", "increment", "decrement", "randomize"],
serialize: false, // Don't include this in prompt. serialize: false, // Don't include this in prompt.
}) })
seedControl.afterQueued = () => { valueControl.afterQueued = () => {
var v = seedControl.value; var v = valueControl.value;
var w = targetWidget.name;
const min = targetWidget.options?.min; let min = 0.0;
let max = targetWidget.options?.max; let max = targetWidget.options?.max;
let range = Math.max(min, max);
//set the max/min values depending on the parameter
switch (w) {
case ("seed"):
case ("noise_seed"):
console.log("noise_seed/seed");
max = 1125899906842624; // limit max to something that javascript can handle
range = Math.max(min, max);
break;
case ("cfg"):
console.log("cfg");
max = 50.0;
range = Math.max(min, max);
break;
case ("steps"):
max = 100;
min = 1;
range = Math.max(min, max);
break;
case ("start_at_step"):
max = 50000;
range = Math.max(min, max);
break;
case ("end_at_step"):
min = 50000;
max = 100000;
range = Math.max(min, max);
break;
case ("denoise"):
console.log("denoise");
max = 1.0;
min = 0.001;
range = Math.max(min, max);
break;
case ("height"):
case ("width"):
console.log("width/height");
min = 64;
max = 1920;
range = Math.max(0, Math.floor((max - min) / 64));
break;
default:
console.log("default (Failed)");
break;
}
//adjust values based on valueControl Behaviour
switch (v) { switch (v) {
case ("fixed"): case ("fixed"):
console.log("fixed"); console.log("fixed");
break; break;
case ("increment"): case ("increment"):
if (min != null || max != null) { if (min != null || max != null) {
if (max) {
// limit max to something that javascript can handle
if (targetWidget.name != "steps")
max = Math.min(1125899906842624.0, max);
else
max = 1000;
}
/*if (max) { //loop to lowest and continue batch /*if (max) { //loop to lowest and continue batch
targetWidget.value = 0; targetWidget.value = 0;
console.log("increment"); console.log("increment");
@ -44,19 +86,24 @@ export function addSeedControlWidget(node, targetWidget, defaultValue = "randomi
} }
} else {*/ } else {*/
if (max) { if (max) {
targetWidget.value += 1.0; if (w == "denoise") {
console.log("increment"); targetWidget.value += 0.01;
} console.log("denoise decrement");
} else if (w == "cfg") {
targetWidget.value += 0.5;
console.log("cfg increment");
} else if (w == "width" || w == "height") {
targetWidget.value += 64;
console.log("width/height decrement");
} else {
targetWidget.value += 1.0;
console.log("decrement");
}
}
} }
break; break;
case ("decrement"): case ("decrement"):
if (min != null || max != null) { if (min != null || max != null) {
if (min) {
// limit min to 0
if (targetWidget.name != "steps")
min = Math.min(0, min);
}
/*if (min) { //Loop to highest and continue batch /*if (min) { //Loop to highest and continue batch
targetWidget.value = 1125899906842624; targetWidget.value = 1125899906842624;
console.log("decrement"); console.log("decrement");
@ -64,39 +111,63 @@ export function addSeedControlWidget(node, targetWidget, defaultValue = "randomi
targetWidget.value -= 1; targetWidget.value -= 1;
console.log("decrement"); console.log("decrement");
} else {*/ } else {*/
if (min) { if (max) {
targetWidget.value -= 1.0; if (w == "denoise") {
console.log("decrement"); targetWidget.value -= 0.01;
console.log("denoise decrement");
} else if (w == "cfg") {
targetWidget.value -= 0.5;
console.log("cfg decrement");
} else if (w == "width" || w == "height") {
targetWidget.value -= 64;
console.log("width/height decrement");
} else {
targetWidget.value -= 1.0;
console.log("decrement");
}
} }
} }
break; break;
case ("randomize"): case ("randomize"):
if (min != null || max != null) { if (min != null || max != null) {
if (max) { switch (w) {
// limit max to something that javascript can handle case ("cfg"):
if (targetWidget.name != "steps") case ("denoise"):
max = Math.min(1125899906842624.0, max); console.log("random denoise");
else targetWidget.value = parseFloat((Math.floor(Math.random() * ((range * 100) + 1)) / 100).toFixed(2));
max = 1000; break;
case ("height"):
case ("width"):
targetWidget.value = Math.floor(Math.random() * range) * 64 + min;
console.log("Random resolution");
break;
default:
targetWidget.value = Math.floor(Math.random() * range);
console.log("Random");
break;
} }
targetWidget.value = Math.floor(Math.random() * ((max ?? 9999999999.0) - (min ?? 0) + 1) + (min ?? 0));
console.log("Random");
} else {
targetWidget.value = Math.floor(Math.random() * 1125899906842624.0);
console.log("Random");
} }
break; break;
default: default:
console.log("default (failed to detect input!)"); console.log("default (failed to detect input!)");
break;
} }
};
return seedControl; /*check if values are over or under their respective
} * ranges and set them to min or max.*/
if (targetWidget.value < min)
targetWidget.value = min;
if (targetWidget.value > max)
targetWidget.value = max;
}
return valueControl;
};
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 seedControl = addSeedControlWidget(node, seed.widget, "randomize"); const seedControl = addValueControlWidget(node, seed.widget, "randomize");
seed.widget.linkedWidgets = [seedControl]; seed.widget.linkedWidgets = [seedControl];
return seed; return seed;