From b91513dfe544041c13eb00efeb501d022dfe485e Mon Sep 17 00:00:00 2001 From: Daniel Martinek Date: Mon, 23 Mar 2026 21:45:09 +0100 Subject: [PATCH] add optional stack remember on batch to AUdioMathNode --- more_math/AudioMathNode.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/more_math/AudioMathNode.py b/more_math/AudioMathNode.py index 3c9530d..74d3f46 100644 --- a/more_math/AudioMathNode.py +++ b/more_math/AudioMathNode.py @@ -48,6 +48,14 @@ class AudioMathNode(io.ComfyNode): tooltip="How to handle mismatched image batch sizes. tile: repeat shorter inputs; error: raise error on mismatch; pad: treat missing frames as zero." ), io.Int.Input(id="batching", default=0), + io.Bool.Input( + id="remember_stack", + default=False, + display_name="Remember stack across batch", + tooltip=( + "If enabled, stack is copied at output leading to changes being remembered during batch operations (node runs multiple times in sucession). If disabled each batch gets it's own copy of the stack." + ), + ), MrmthStack.Input(id="stack", tooltip="Access stack between nodes",optional=True) ], outputs=[ @@ -57,17 +65,17 @@ class AudioMathNode(io.ComfyNode): ) @classmethod - def check_lazy_status(cls, Expression, V, F, length_mismatch="tile",batching=0,stack={}): + def check_lazy_status(cls, Expression, V, F, length_mismatch="tile",batching=0,, remember_stack=False,stack={}): return checkLazyNew(Expression,V,F) @classmethod - def execute(cls, V, F, Expression, length_mismatch="tile",batching=0,stack={}): + def execute(cls, V, F, Expression, length_mismatch="tile",batching=0,, remember_stack=False, stack={}): # Identify all present audio inputs and their keys tensor_keys = [k for k, v in V.items() if v is not None and isinstance(v, dict) and "waveform" in v] if not tensor_keys: raise ValueError("At least one audio input is required.") - stack = copy.deepcopy(stack) if stack is not None else {} + stack = stack if remember_stack else (copy.deepcopy(stack) if stack is not None else {}) waveforms = {k: V[k]["waveform"] for k in tensor_keys} sample_rates = {k + "sr": V[k].get("sample_rate", 44100) for k in tensor_keys} @@ -142,4 +150,6 @@ class AudioMathNode(io.ComfyNode): res_list.append({"waveform": result_chunk, "sample_rate": sample_rate}) return (res_list, stack) else: + stack = stack if remember_stack else copy.deepcopy(stack) + return ([{"waveform": result, "sample_rate": sample_rate}], stack)