From 427506f77117248e30e81ec5370175b369dd5294 Mon Sep 17 00:00:00 2001 From: Mel Massadian <7041726+melMass@users.noreply.github.com> Date: Sat, 8 Nov 2025 13:08:14 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20audio=20parameter=20types?= =?UTF-8?q?=20and=20color=20input=20utility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - changed MTB_AudioCut length and offset from FLOAT to INT type, expecting milliseconds - added sys.maxsize for parameter limits and millisecond tooltips - fixed calculation to explicitly cast to float before math operations - uncommented hex_to_rgb import in legacy.py - expanded MTB_ColorInput to return hex and RGB formats alongside color - added return names and output tooltips for better usability --- nodes/audio.py | 26 +++++++++++++++++--------- nodes/legacy.py | 20 ++++++++++++++++---- 2 files changed, 33 insertions(+), 13 deletions(-) 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]