From 456b0c925e0277ed4e47ded839f344f38cf140dc Mon Sep 17 00:00:00 2001 From: "Alexander G. Morano" Date: Thu, 8 Aug 2024 11:55:16 -0700 Subject: [PATCH] prep for PR2666 cache glsl nodes with no iTime like normal comfyui nodes cleaned up unused midi thread vars --- __init__.py | 2 +- core/compose.py | 13 ++++++++++--- core/create_glsl.py | 17 ++++++++++------- core/utility.py | 2 +- sup/midi.py | 42 ++++++++++++++++++++++++++---------------- sup/util.py | 5 ++++- 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/__init__.py b/__init__.py index 3308352..829b897 100644 --- a/__init__.py +++ b/__init__.py @@ -394,7 +394,7 @@ class JOVBaseNode: @classmethod def VALIDATE_INPUTS(cls, *arg, **kw) -> bool: - logger.debug(f'validate -- {arg} {kw}') + # logger.debug(f'validate -- {arg} {kw}') return True @classmethod diff --git a/core/compose.py b/core/compose.py index 3ada156..8c3af31 100644 --- a/core/compose.py +++ b/core/compose.py @@ -410,10 +410,10 @@ def run(self, **kw) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: if invert == True: pA = image_invert(pA, 1) - print(mask) + logger.debug(mask) if mask is not None: pA = image_mask_add(pA, mask) - print(pA.shape) + logger.debug(pA.shape) images.append(cv2tensor_full(pA, matte)) pbar.update_absolute(idx) @@ -769,6 +769,12 @@ def INPUT_TYPES(cls) -> dict: d.update({ "optional": { Lexicon.PIXEL: (JOV_TYPE_IMAGE, {}) + }, + "outputs": { + 0: ("MASK", {"tooltips":"Single channel output of Red Channel."}), + 1: ("MASK", {"tooltips":"Single channel output of Green Channel"}), + 2: ("MASK", {"tooltips":"Single channel output of Blue Channel"}), + 3: ("MASK", {"tooltips":"Single channel output of Alpha Channel"}), } }) return Lexicon._parse(d, cls) @@ -993,7 +999,8 @@ def INPUT_TYPES(cls) -> dict: def run(self, **kw) -> Tuple[torch.Tensor, torch.Tensor]: pA = parse_param(kw, Lexicon.PIXEL, EnumConvertType.IMAGE, None) - offset = parse_param(kw, Lexicon.XY, EnumConvertType.VEC2, [(0, 0)], -1, 1) + offset = parse_param(kw, Lexicon.XY, EnumConvertType.VEC2, [(0, 0)], -2.5, 2.5) + logger.debug(offset) angle = parse_param(kw, Lexicon.ANGLE, EnumConvertType.FLOAT, 0) size = parse_param(kw, Lexicon.SIZE, EnumConvertType.VEC2, [(1, 1)], 0.001) edge = parse_param(kw, Lexicon.EDGE, EnumConvertType.STRING, EnumEdge.CLIP.name) diff --git a/core/create_glsl.py b/core/create_glsl.py index f6a0228..b65eafd 100644 --- a/core/create_glsl.py +++ b/core/create_glsl.py @@ -99,10 +99,6 @@ def INPUT_TYPES(cls) -> dict: }) return Lexicon._parse(d, cls) - @classmethod - def IS_CHANGED(cls, **kw) -> float: - return float("nan") - def __init__(self, *arg, **kw) -> None: super().__init__(*arg, **kw) self.__glsl = GLSLShader() @@ -192,13 +188,15 @@ def INPUT_TYPES(cls) -> dict: d['optional'] = opts return Lexicon._parse(d, cls) + @classmethod + def IS_CHANGED(cls, **kw) -> float: + return float("nan") + def __init__(self, *arg, **kw) -> None: self.VERTEX = parse_param(kw, Lexicon.PROG_VERT, EnumConvertType.STRING, GLSLShader.PROG_VERTEX)[0] self.FRAGMENT = parse_param(kw, Lexicon.PROG_FRAG, EnumConvertType.STRING, GLSLShader.PROG_FRAGMENT)[0] super().__init__(*arg, **kw) - - class GLSLNodeDynamic(GLSLNodeBase): PARAM = None @@ -266,7 +264,7 @@ def import_dynamic() -> Tuple[str,...]: if meta.get('hide', False): continue - name = meta.get('name', name.split('.')[0]) + name = meta.get('name', name.split('.')[0]).upper() class_name = name.title().replace(' ', '_') class_name = f'GLSLNode_{class_name}' @@ -276,9 +274,14 @@ def import_dynamic() -> Tuple[str,...]: emoji = '🧙🏽' sort_order -= 10000 + category = GLSLNodeDynamic.CATEGORY + if (sub := meta.get('category', None)) is not None: + category += f'/{sub}' + class_def = type(class_name, (GLSLNodeDynamic,), { "NAME": f'GLSL {name} (JOV) {emoji}'.upper(), "DESCRIPTION": meta.get('desc', name), + "CATEGORY": category.upper(), "FRAGMENT": shader, "PARAM": meta.get('_', []), "SORT": sort_order, diff --git a/core/utility.py b/core/utility.py index 03831ac..d57019f 100644 --- a/core/utility.py +++ b/core/utility.py @@ -261,7 +261,7 @@ def run(self, **kw) -> Tuple[int, list]: size = len(results) if output_is_image: _, w, h = image_by_size(results) - print(w, h) + logger.debug(f"{w}, {h}") results = [image_convert(i, 4) for i in results] results = [image_matte(i, (0,0,0,0), w, h) for i in results] results = torch.stack(results, dim=0) diff --git a/sup/midi.py b/sup/midi.py index 2be13f3..d1161b4 100644 --- a/sup/midi.py +++ b/sup/midi.py @@ -82,11 +82,12 @@ def run(self) -> None: # device is not null.... logger.debug(f"starting device loop {self.__device}") - with mido.open_input(self.__device, callback=self.__callback) as inport: + with mido.open_input(self.__device, callback=self.__callback): while True: if self.__device != old_device: logger.debug(f"device loop ended {old_device}") break + time.sleep(0.01) class MIDIMessage: """Snap shot of a message from Midi device.""" @@ -109,30 +110,38 @@ def __str__(self) -> str: # === TESTING === # ============================================================================= +class Packet: + def __init__(self) -> None: + self.note = 0 + self.control = 0 + self.note_on = False + self.channel = None + self.value = 0 + + def __str__(self) -> str: + return f"{self.note_on}, {self.channel}, {self.control}, {self.note}, {self.value}" + if __name__ == "__main__": + packet = Packet() + def process(data) -> None: - channel = data.channel - note = 0 - control = 0 - note_on = False + packet.channel = data.channel match data.type: case "control_change": # control=8 value=14 time=0 - control = data.control - value = data.value + packet.control = data.control + packet.value = data.value case "note_on": - note = data.note - note_on = True - value = data.velocity + packet.note = data.note + packet.note_on = True + packet.value = data.velocity # note=59 velocity=0 time=0 case "note_off": - note = data.note - value = data.velocity + packet.note = data.note + packet.value = data.velocity # note=59 velocity=0 time=0 - - value /= 127. - # logger.debug("{} {} {} {} {}", note_on, channel, control, note, value) + packet.value /= 127. q_in = Queue() server = MIDIServerThread(q_in, None, process, daemon=True) @@ -141,4 +150,5 @@ def process(data) -> None: logger.debug(device) q_in.put(device) while True: - time.sleep(0.01) + time.sleep(0.05) + logger.debug(packet) diff --git a/sup/util.py b/sup/util.py index adcead4..c5596bf 100644 --- a/sup/util.py +++ b/sup/util.py @@ -301,8 +301,11 @@ def parse_param(data:dict, key:str, typ:EnumConvertType, default: Any, except json.JSONDecodeError: pass # see if we are a Jovimetrix hacked vector blob... {0:x, 1:y, 2:z, 3:w} elif isinstance(val, dict): + # vector patch.... + if 'xyzw' in val: + val = tuple(x for x in val["xyzw"]) # latents.... - if 'samples' in val: + elif 'samples' in val: val = tuple(x for x in val["samples"]) elif ('0' in val) or (0 in val): val = tuple(val.get(i, val.get(str(i), 0)) for i in range(min(len(val), 4)))