Change types

This commit is contained in:
mcDandy
2026-02-21 16:30:52 +01:00
parent 3e7560a565
commit 4bc2b67a85
4 changed files with 46 additions and 19 deletions
+21 -14
View File
@@ -1,3 +1,4 @@
from tokenize import String
from .helper_functions import (
generate_dim_variables,
parse_expr,
@@ -17,6 +18,7 @@ import re
import torch
from .Stack import MrmthStack
import copy
from .ParseTree import MrmthParseTree
class AudioMathNode(io.ComfyNode):
"""
@@ -37,7 +39,11 @@ class AudioMathNode(io.ComfyNode):
inputs=[
io.Autogrow.Input(id="V",template=io.Autogrow.TemplatePrefix(io.Audio.Input("values", optional=True), prefix="V", min=1, max=50)),
io.Autogrow.Input(id="F", template=io.Autogrow.TemplatePrefix(io.Float.Input("float", default=0.0, optional=True, lazy=True, force_input=True), prefix="F", min=1, max=50)),
io.String.Input(id="Expression", default="I0*(1-F0)+I1*F0", tooltip="Expression to apply on input audio"),
io.MultiType.Input(
io.String.Input("Expression", default="", multiline=False),
types=[io.String,MrmthParseTree],
tooltip="3D model file or path string",
),
io.Combo.Input(
id="length_mismatch",
options=["do nothing","error","tile", "pad"],
@@ -56,17 +62,14 @@ class AudioMathNode(io.ComfyNode):
@classmethod
def check_lazy_status(cls, Expression, V, F, length_mismatch="tile",batching=0,stack={}):
input_stream = InputStream(Expression)
lexer = MathExprLexer(input_stream)
stream = CommonTokenStream(lexer)
parser = MathExprParser(stream)
try:
tree = parser.start()
except:
# Fallback to simple token scanning if parse fails
return cls._fallback_lazy_check(Expression, V, F)
tree = None
parser = None
if isinstance(Expression,str):
tree = parse_expr(Expression)
parser = tree.parser
else:
tree = Expression
parser = tree.parser
# Support aliases
aliases = {"a": "V0", "b": "V1", "c": "V2", "d": "V3",
@@ -106,7 +109,7 @@ class AudioMathNode(io.ComfyNode):
for var in needed_vars:
norm = aliases.get(var, var)
if var == "V":
needed.update(V.keys())
needed.update(V.keys())
if var == "F":
needed.update(F.keys())
if re.match(r"[VF][0-9]+", norm):
@@ -231,7 +234,11 @@ class AudioMathNode(io.ComfyNode):
for k, val in F.items():
variables[k] = val if val is not None else 0.0
tree = parse_expr(Expression);
tree = None
if isinstance(Expression,str):
tree = parse_expr(Expression)
else:
tree = Expression
visitor = UnifiedMathVisitor(variables, a_w.shape,a_w.device,state_storage=stack)
result = visitor.visit(tree)
result = as_tensor(result, a_w.shape)
+14
View File
@@ -0,0 +1,14 @@
import antlr4
from comfy_api.latest import io
@io.comfytype(io_type="PARSER")
class MrmthParseTree(io.ComfyTypeIO):
Type = antlr4.Parser # Python type hint
class Input(io.Input):
def __init__(self, id: str, **kwargs):
super().__init__(id, **kwargs)
class Output(io.Output):
def __init__(self, **kwargs):
super().__init__(**kwargs)
+5 -2
View File
@@ -1,5 +1,7 @@
from comfy_api.latest import io
import torch
from .helper_functions import parse_expr
from .ParseTree import MrmthParseTree
class ScriptTextInput(io.ComfyNode):
@@ -13,10 +15,11 @@ class ScriptTextInput(io.ComfyNode):
io.String.Input(id="script", multiline=True),
],
outputs=[
io.String.Output()
MrmthParseTree.Output()
],
)
@classmethod
def execute(cls, script):
return (script,)
expr = parse_expr(script)
return (expr,)
+6 -3
View File
@@ -27,6 +27,11 @@ const FUNCTIONS = new Set([
"worley", "cellular_noise", "voronoi_noise", "plasma", "turbulence", "plasma_noise"
]);
const BRACKET_PAIRS = {
'(': ')',
'[': ']',
'{': '}'
};
const OPENING_BRACKETS = new Set(['(', '[', '{']);
const CLOSING_BRACKETS = new Set([')', ']', '}']);
@@ -318,10 +323,8 @@ function attachLineNumbers(widget) {
const rawLines = inputEl.value.split("\n");
const paddingTop = parseFloat(inputStyle.paddingTop) || 0;
const paddingBottom = parseFloat(inputStyle.paddingBottom) || 0;
const paddedScrollHeight = Math.max(0, inputEl.scrollHeight - paddingTop - paddingBottom);
const textLineCount = Math.max(1, rawLines.length);
const visibleLineCount = Math.max(1, Math.ceil(paddedScrollHeight / lineHeightPx));
const lineCount = Math.max(textLineCount, visibleLineCount);
const lineCount = textLineCount;
gutterContent.textContent = Array.from({ length: lineCount }, (_, i) => String(i + 1)).join("\n");
gutterContent.style.height = `${lineCount * lineHeightPx + paddingTop + paddingBottom}px`;
gutter.style.height = `${editorContainer.clientHeight}px`;