fix: 🐛 audio parameter types and color input utility
- 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
This commit is contained in:
+17
-9
@@ -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]
|
||||
|
||||
+16
-4
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user