-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathadd_delay_node.py
More file actions
61 lines (47 loc) · 1.67 KB
/
add_delay_node.py
File metadata and controls
61 lines (47 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import time
import comfy.utils
class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
any_type = AnyType("*")
class add_delay_node:
"""Node that adds a configurable delay between operations"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input": (any_type, {"defaultInput": True}),
"delay_seconds": ("FLOAT", {
"default": 1.0,
"min": 0.0,
"step": 0.1
}),
},
}
RETURN_TYPES = (any_type,)
RETURN_NAMES = ("output",)
FUNCTION = "add_delay"
CATEGORY = "utils"
def add_delay(self, input, delay_seconds):
delay_text = f"{delay_seconds:.1f} second{'s' if delay_seconds != 1 else ''}"
print(f"[Delay Node] Starting delay of {delay_text}")
progress_bar = comfy.utils.ProgressBar(delay_seconds)
update_interval_seconds = 1.0
start_time = time.monotonic()
while True:
current_elapsed = time.monotonic() - start_time
progress_bar.update_absolute(min(current_elapsed, delay_seconds))
if current_elapsed >= delay_seconds:
# time is up
break
# Sleep one entire update interval, or the remaining fraction if we are at the end
time_to_sleep = min(update_interval_seconds, delay_seconds - current_elapsed)
time.sleep(time_to_sleep)
print(f"[Delay Node] Delay of {delay_text} completed")
return (input,)
NODE_CLASS_MAPPINGS = {
"Add Delay": add_delay_node
}
NODE_DISPLAY_NAME_MAPPINGS = {
"Add Delay": "Add Delay"
}