Skip to content

Commit

Permalink
prep for PR2666
Browse files Browse the repository at this point in the history
cache glsl nodes with no iTime like normal comfyui nodes
cleaned up unused midi thread vars
  • Loading branch information
Amorano committed Aug 8, 2024
1 parent 9a2411d commit 456b0c9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 29 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions core/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions core/create_glsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}'

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 26 additions & 16 deletions sup/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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)
Expand All @@ -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)
5 changes: 4 additions & 1 deletion sup/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 456b0c9

Please sign in to comment.