Skip to content

Commit

Permalink
doubled speed of midi reader when idle
Browse files Browse the repository at this point in the history
cleaned up HTML templates for GLSL nodes
  • Loading branch information
Amorano committed Sep 9, 2024
1 parent 19e3217 commit b61a6f3
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 31 deletions.
6 changes: 3 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ def json2html(json_dict: dict) -> str:

# Fill in the main template
description = json_dict['description']
if not "<div>" in description and not "<p>" in description:
description = markdown.markdown(description)
#if not "<div>" in description and not "<p>" in description:
#description = markdown.markdown(description)
# description = html.escape(description)
description = description.replace('\n', '<br>').replace(f"('", '').replace(f"')", '')

Expand Down Expand Up @@ -1010,7 +1010,7 @@ def __init__(self, *arg, **kw) -> None:
Session.CLASS_MAPPINGS[name] = class_object

if not name.endswith(Lexicon.GLSL_CUSTOM):
desc = class_object.DESCRIPTION if hasattr(class_object, 'DESCRIPTION') else ""
desc = class_object.DESCRIPTION if hasattr(class_object, 'DESCRIPTION') else name
NODE_LIST_MAP[name] = desc.split('.')[0].strip('\n')
else:
logger.debug(f"customs {name}")
Expand Down
7 changes: 6 additions & 1 deletion core/device_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class MIDIReaderNode(JOVBaseNode):
Captures MIDI messages from an external MIDI device or controller. It monitors MIDI input and provides information about the received MIDI messages, including whether a note is being played, the MIDI channel, control number, note number, value, and a normalized value. This node is essential for integrating MIDI control into various applications, such as music production, live performances, and interactive installations.
"""

CHANGED = False

@classmethod
def INPUT_TYPES(cls) -> dict:
d = super().INPUT_TYPES()
Expand All @@ -83,7 +85,9 @@ def INPUT_TYPES(cls) -> dict:

@classmethod
def IS_CHANGED(cls, **kw) -> float:
return float("nan")
if cls.CHANGED:
cls.CHANGED = False
return float("nan")

def __init__(self, *arg, **kw) -> None:
super().__init__(*arg, **kw)
Expand All @@ -98,6 +102,7 @@ def __init__(self, *arg, **kw) -> None:
self.__SERVER.start()

def __process(self, data) -> None:
MIDIReaderNode.CHANGED = True
self.__channel = data.channel
self.__note = 0
self.__control = 0
Expand Down
2 changes: 1 addition & 1 deletion node_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"GLSL (JOV) \ud83c\udf69": "Execute custom GLSL (OpenGL Shading Language) fragment shaders to generate images or apply effects",
"GLSL BLEND LINEAR (JOV) \ud83e\uddd9\ud83c\udffd": "Simple linear blend between two images",
"GLSL COLOR CONVERSION (JOV) \ud83e\uddd9\ud83c\udffd": "Convert an image from one color space (RGB, HSV, LAB, XYZ) to another",
"GLSL COLOR PALETTE (JOV) \ud83e\uddd9\ud83c\udffd": "COLOR PALETTE",
"GLSL COLOR PALETTE (JOV) \ud83e\uddd9\ud83c\udffd": "Color palette creation using the formula: color(t) = a + b * cos[tau(c*t+d)]",
"GLSL CONICAL GRADIENT (JOV) \ud83e\uddd9\ud83c\udffd": "Generate a conical gradient from black to white",
"GLSL DIRECTIONAL WARP (JOV) \ud83e\uddd9\ud83c\udffd": "Domain warp an image with a direction and distortion map",
"GLSL GRAYSCALE (JOV) \ud83e\uddd9\ud83c\udffd": "Convert input to grayscale",
Expand Down
4 changes: 2 additions & 2 deletions res/doc/template_node.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<div class='jov-panel-doc'>
<h2><a href="${root1}" target="_blank" rel="noreferrer noopener">${name}</a></h2>
<h3>${category}</h3>
<p>${documentation}</p>
<img src="${root2}" alt="${boop}">
<div align="left"><p>${documentation}</p></div>
<div align="center"><img src="${root2}" alt="${boop}"></div>
<p>OUTPUT NODE?: ${output_node}</p>
<h2>INPUT</h2>
${input_content}
Expand Down
2 changes: 1 addition & 1 deletion res/doc/template_node_plain.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class='jov-panel-doc'>
<h2>${name}</h2>
<h3>${category}</h3>
<p>${documentation}</p>
<p align="left">${documentation}</p>
<p>OUTPUT NODE?: ${output_node}</p>
<h2>INPUT</h2>
${input_content}
Expand Down
2 changes: 1 addition & 1 deletion res/glsl/create/create-palette.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// See https://iquilezles.org/articles/palettes for more information
//
// name: COLOR PALETTE
// desc: Color palette creation using the formula: color(t) = a + b cos[2π(c⋅t+d)]
// desc: Color palette creation using the formula: color(t) = a + b * cos[tau(c*t+d)]. See https://iquilezles.org/articles/palettes for more information.
// category: CREATE

uniform vec3 bias; // 0.5,0.5,0.5;0 | scale and bias (dc offset)
Expand Down
20 changes: 14 additions & 6 deletions sup/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,20 @@ 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):
while True:
if self.__device != old_device:
logger.debug(f"device loop ended {old_device}")
break
time.sleep(0.01)
failure = 0
try:
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)
except Exception as e:
if (failure := failure + 1) > 3:
logger.exception(e)
return
logger.error(e)
time.sleep(2)

class MIDIMessage:
"""Snap shot of a message from Midi device."""
Expand Down
13 changes: 6 additions & 7 deletions sup/shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"""

import re
from enum import Enum
import sys
from enum import Enum, EnumType
from typing import Any, Dict, Tuple

import cv2
Expand Down Expand Up @@ -72,7 +72,7 @@ class EnumGLSLColorConvert(Enum):

RE_VARIABLE = re.compile(r"uniform\s+(\w+)\s+(\w+);(?:\s*\/\/\s*([A-Za-z0-9.,\s]*))?\s*(?:;\s*([0-9.-]+))?\s*(?:;\s*([0-9.-]+))?\s*(?:;\s*([0-9.-]+))?\s*(?:\|\s*(.*))?$", re.MULTILINE)

RE_SHADER_META = re.compile(r"^\/\/\s?([A-Za-z_]{3,}):\s?([A-Za-z_0-9 \-\(\)\[\]\/\.\,;]+)$", re.MULTILINE)
RE_SHADER_META = re.compile(r"^\/\/\s?([A-Za-z_]{3,}):\s?(.+)$", re.MULTILINE)

# =============================================================================

Expand Down Expand Up @@ -442,12 +442,11 @@ def render(self, time_delta:float=0.,
texture_index += 1
elif val:
funct = LAMBDA_UNIFORM[p_type]
if issubclass(p_value, (Enum,)):
if isinstance(p_value, EnumType):
val = p_value[val].value
else:
if isinstance(val, str):
val = val.split(',')
val = parse_value(val, PTYPE[p_type], 0)
elif isinstance(val, str):
val = val.split(',')
val = parse_value(val, PTYPE[p_type], 0)
if not isinstance(val, (list, tuple)):
val = [val]
funct(p_loc, *val)
Expand Down
13 changes: 4 additions & 9 deletions web/jovimetrix.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,21 @@
.jov-panel-doc {
background: var(--comfy-menu-bg);
color: var(--fg-color);
font: 12px monospace;
padding: 3px;
margin: 3px;
border-radius: 5px;
font: 0.9em monospace;
border-radius: 3px;
border: medium solid var(--border-color);
overflow: auto;
width: 100%;
height: 90vh;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
scrollbar-width: thin;
scrollbar-color: var(--fg-color) var(--bg-color);
}

.jov-panel-doc h2, .jov-panel-doc h3 {
width: 100%;
text-align: center;
margin: 4px 0;
margin: 3px 0;
}

.jov-panel-doc p {
Expand All @@ -185,7 +180,7 @@

.jov-panel-doc img {
display: block;
max-width: 640px;
max-width: 512px;
max-height: 70vh;
width: 100%;
height: auto;
Expand Down

0 comments on commit b61a6f3

Please sign in to comment.