diff --git a/nodes/audio.py b/nodes/audio.py index cb5c637..b2af31e 100644 --- a/nodes/audio.py +++ b/nodes/audio.py @@ -1,3 +1,4 @@ +import sys from typing import TYPE_CHECKING, Any, TypedDict import torch @@ -485,17 +486,24 @@ class MTB_AudioCut(MtbAudio): "required": { "audio": ("AUDIO",), "length": ( - ("FLOAT"), + ("INT"), { - "default": 1000.0, - "min": 0.0, - "max": 999999.0, + "default": 1000, + "min": 100, + "max": sys.maxsize, "step": 1, + "tooltip": "Length in milliseconds", }, ), "offset": ( - ("FLOAT"), - {"default": 0.0, "min": 0.0, "max": 999999.0, "step": 1}, + ("INT"), + { + "default": 0, + "min": 0, + "max": sys.maxsize, + "step": 1, + "tooltip": "Offset in milliseconds", + }, ), }, } @@ -505,11 +513,11 @@ class MTB_AudioCut(MtbAudio): CATEGORY = "mtb/audio" FUNCTION = "cut" - def cut(self, audio: AudioTensor, length: float, offset: float): + def cut(self, audio: AudioTensor, length: int, offset: int): sample_rate = audio["sample_rate"] - start_idx = int(offset * sample_rate / 1000) + start_idx: int = int(float(offset) * float(sample_rate) / 1000) end_idx = min( - start_idx + int(length * sample_rate / 1000), + start_idx + int(float(length) * float(sample_rate) / 1000), audio["waveform"].shape[-1], ) cut_waveform = audio["waveform"][:, :, start_idx:end_idx] diff --git a/nodes/legacy.py b/nodes/legacy.py index 642e33f..f2a5e05 100644 --- a/nodes/legacy.py +++ b/nodes/legacy.py @@ -1,6 +1,14 @@ -# from ..utils import hex_to_rgb +from ..utils import hex_to_rgb + + class MTB_ColorInput: - RETURN_TYPES = ("COLOR",) + RETURN_TYPES = ("COLOR","STRING","STRING") + RETURN_NAMES = ("color","hex","r,g,b") + OUTPUT_TOOLTIPS = ( + "Color in mtb format (internaly just a hex string)", + "Hex color string", + "RGB values as comma-separated string", + ) FUNCTION = "color" CATEGORY = "mtb/color" @@ -10,8 +18,12 @@ class MTB_ColorInput: "required": {"color": ("MTB_COLOR", {"default": "#ffffff"})}, } - def color(self, color): - return (color,) + def color(self, color:str): + # convert hex to rgb + r, g, b = hex_to_rgb(color) + + # TODO: official COLOR will be without the # + return (color,color,f"{r},{g},{b}") __nodes__ = [MTB_ColorInput]