this fixes a problem with initialization
This commit is contained in:
@@ -32,14 +32,15 @@ class SequenceControlBase(ControlNodeBase):
|
||||
return inputs
|
||||
|
||||
def update_sequence_base(self, values: list, steps_per_item: int, sequence_mode: str, batch_size: int = 1, always_execute: bool = True):
|
||||
# Initialize or get state
|
||||
state = self.get_state(
|
||||
{
|
||||
"current_index": 0,
|
||||
"step_counter": 0,
|
||||
"direction": 1, # 1 for forward, -1 for reverse (used in pingpong)
|
||||
}
|
||||
)
|
||||
# Define default state
|
||||
default_state = {
|
||||
"current_index": 0,
|
||||
"step_counter": 0,
|
||||
"direction": 1, # 1 for forward, -1 for reverse (used in pingpong)
|
||||
}
|
||||
|
||||
# Initialize or get state - make sure to use the default state
|
||||
state = self.get_state(default_state)
|
||||
|
||||
if not values:
|
||||
if batch_size > 1:
|
||||
@@ -48,13 +49,21 @@ class SequenceControlBase(ControlNodeBase):
|
||||
|
||||
# Fast path for batch_size=1 (real-time case)
|
||||
if batch_size == 1:
|
||||
# Update step counter
|
||||
# Update step counter (ensure it exists first)
|
||||
if "step_counter" not in state:
|
||||
state["step_counter"] = 0
|
||||
state["step_counter"] += 1
|
||||
|
||||
# Check if we should move to next item
|
||||
if state["step_counter"] >= steps_per_item:
|
||||
state["step_counter"] = 0
|
||||
|
||||
# Ensure other state values exist
|
||||
if "current_index" not in state:
|
||||
state["current_index"] = 0
|
||||
if "direction" not in state:
|
||||
state["direction"] = 1
|
||||
|
||||
# Update index based on sequence mode
|
||||
if sequence_mode == "forward":
|
||||
state["current_index"] = (state["current_index"] + 1) % len(values)
|
||||
@@ -77,9 +86,17 @@ class SequenceControlBase(ControlNodeBase):
|
||||
return (values[state["current_index"]],)
|
||||
|
||||
# Batch processing path
|
||||
# Update step counter
|
||||
# Update step counter (ensure it exists first)
|
||||
if "step_counter" not in state:
|
||||
state["step_counter"] = 0
|
||||
state["step_counter"] += 1
|
||||
|
||||
# Ensure other state values exist
|
||||
if "current_index" not in state:
|
||||
state["current_index"] = 0
|
||||
if "direction" not in state:
|
||||
state["direction"] = 1
|
||||
|
||||
# Check if we should move to next item
|
||||
if state["step_counter"] >= steps_per_item:
|
||||
state["step_counter"] = 0
|
||||
|
||||
@@ -43,7 +43,18 @@ class ValueControlBase(ControlNodeBase):
|
||||
return self.update_value_base(*args, **kwargs)
|
||||
|
||||
def update_value_base(self, maximum_value, minimum_value, starting_value, steps_per_cycle, movement_type, batch_size=1, always_execute=True):
|
||||
state = self.get_state({"current_value": None, "phase": 0.0})
|
||||
# Define default state
|
||||
default_state = {"current_value": None, "phase": 0.0}
|
||||
|
||||
# Initialize or get state
|
||||
state = self.get_state(default_state)
|
||||
|
||||
# Ensure state keys exist
|
||||
if "current_value" not in state:
|
||||
state["current_value"] = None
|
||||
if "phase" not in state:
|
||||
state["phase"] = 0.0
|
||||
|
||||
pattern = MOVEMENT_PATTERNS[movement_type]
|
||||
|
||||
# Fast path for batch_size=1 (real-time case)
|
||||
@@ -256,7 +267,14 @@ class StringControl(ControlNodeBase):
|
||||
return ([""] * batch_size,)
|
||||
return ("",)
|
||||
|
||||
state = self.get_state({"phase": 0.0})
|
||||
# Define default state
|
||||
default_state = {"phase": 0.0}
|
||||
|
||||
# Get state and ensure keys exist
|
||||
state = self.get_state(default_state)
|
||||
if "phase" not in state:
|
||||
state["phase"] = 0.0
|
||||
|
||||
pattern = MOVEMENT_PATTERNS[movement_type]
|
||||
|
||||
# Update phase
|
||||
|
||||
Reference in New Issue
Block a user