Skip to content

Commit

Permalink
Listen to property change callbacks for position setting
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Aug 5, 2020
1 parent d163673 commit fde86f1
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 19 deletions.
91 changes: 74 additions & 17 deletions src/catia.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@
iConnInGroup = 3
iConnInPort = 4

URI_CANVAS_ICON = "http://kxstudio.sf.net/ns/canvas/icon"
URI_MAIN_CLIENT_NAME = "https://kx.studio/ns/carla/main-client-name"
URI_POSITION = "https://kx.studio/ns/carla/position"
URI_PLUGIN_ICON = "https://kx.studio/ns/carla/plugin-icon"
URI_PLUGIN_ID = "https://kx.studio/ns/carla/plugin-id"

URI_TYPE_INTEGER = "http://www.w3.org/2001/XMLSchema#integer"
URI_TYPE_STRING = "text/plain"

# ------------------------------------------------------------------------------------------------------------
# Catia Main Window
Expand Down Expand Up @@ -283,6 +289,7 @@ def __init__(self, parent=None):
self.PortRegistrationCallback.connect(self.slot_PortRegistrationCallback)
self.PortConnectCallback.connect(self.slot_PortConnectCallback)
self.PortRenameCallback.connect(self.slot_PortRenameCallback)
self.PropertyChangeCallback.connect(self.slot_PropertyChangeCallback)
self.ShutdownCallback.connect(self.slot_ShutdownCallback)

# -------------------------------------------------------------
Expand Down Expand Up @@ -550,6 +557,7 @@ def initJackCallbacks(self):
jacklib.set_xrun_callback(gJack.client, self.JackXRunCallback, None)
jacklib.set_port_registration_callback(gJack.client, self.JackPortRegistrationCallback, None)
jacklib.set_port_connect_callback(gJack.client, self.JackPortConnectCallback, None)
jacklib.set_property_change_callback(gJack.client, self.JackPropertyChangeCallback, None)
jacklib.on_shutdown(gJack.client, self.JackShutdownCallback, None)

jacklib.set_client_rename_callback(gJack.client, self.JackClientRenameCallback, None)
Expand Down Expand Up @@ -748,30 +756,46 @@ def canvas_addAlsaGroup(self, alsaGroupId, groupName, hwSplit):
return groupId

def canvas_addJackGroup(self, groupName):
ret, data, dataSize = jacklib.custom_get_data(gJack.client, groupName, URI_CANVAS_ICON)
props = jacklib.get_client_properties(gJack.client, groupName)

groupId = self.fLastGroupId
groupSplit = patchcanvas.SPLIT_UNDEF
groupIcon = patchcanvas.ICON_APPLICATION

if ret == 0:
iconName = voidptr2str(data)
jacklib.free(data)

if iconName == "hardware":
groupSplit = patchcanvas.SPLIT_YES
groupIcon = patchcanvas.ICON_HARDWARE
#elif iconName =="carla":
#groupIcon = patchcanvas.ICON_CARLA
elif iconName =="distrho":
groupIcon = patchcanvas.ICON_DISTRHO
elif iconName =="file":
groupIcon = patchcanvas.ICON_FILE
elif iconName =="plugin":
groupPos = ""

for prop in props:
if prop.key == URI_POSITION:
groupPos = prop.value
elif prop.key == URI_PLUGIN_ICON:
print("plugin icon is", prop.value)
elif prop.key == URI_PLUGIN_ID:
groupIcon = patchcanvas.ICON_PLUGIN

#if iconName == "hardware":
#groupSplit = patchcanvas.SPLIT_YES
#groupIcon = patchcanvas.ICON_HARDWARE
##elif iconName =="carla":
##groupIcon = patchcanvas.ICON_CARLA
#elif iconName =="distrho":
#groupIcon = patchcanvas.ICON_DISTRHO
#elif iconName =="file":
#groupIcon = patchcanvas.ICON_FILE
#elif iconName =="plugin":
#groupIcon = patchcanvas.ICON_PLUGIN

if groupPos:
x1, y1, x2, y2 = tuple(int(v) for v in groupPos.split(":",4))
groupSplit = (x1 != 0 and x2 != 0) or (y1 != 0 and y2 != 0)

patchcanvas.addGroup(groupId, groupName, groupSplit, groupIcon)

if groupPos:
if groupSplit:
patchcanvas.splitGroup(groupId)
else:
patchcanvas.joinGroup(groupId)
patchcanvas.setGroupPosFull(groupId, x1, y1, x2, y2)

groupObj = [None, None, None]
groupObj[iGroupId] = groupId
groupObj[iGroupName] = groupName
Expand Down Expand Up @@ -1112,6 +1136,11 @@ def JackPortRenameCallback(self, portId, oldName, newName, arg):
self.PortRenameCallback.emit(portId, str(oldName, encoding="utf-8"), str(newName, encoding="utf-8"))
return 0

def JackPropertyChangeCallback(self, uuid, key, change, arg):
if DEBUG: print("PropertyChangeCallback(%i, %s, %i)" % (uuid, key, change))
self.PropertyChangeCallback.emit(jacklib.jack_uuid_t(uuid), str(key, encoding="utf-8"), change)
return 0

def JackShutdownCallback(self, arg):
if DEBUG: print("JackShutdownCallback()")
self.ShutdownCallback.emit()
Expand Down Expand Up @@ -1223,6 +1252,34 @@ def slot_PortRenameCallback(self, portIdJack, oldName, newName):
else:
self.canvas_renamePort(portIdCanvas, portShortName)

@pyqtSlot(jacklib.jack_uuid_t, str, int)
def slot_PropertyChangeCallback(self, uuid, key, change):
if key != URI_POSITION:
return

prop = jacklib.get_property(uuid, key)

if prop is None:
return

x1, y1, x2, y2 = tuple(int(v) for v in prop.value.split(":",4))

clientName = jacklib.get_client_name_by_uuid(gJack.client, jacklib.uuid_unparse(uuid))

if not clientName:
return

groupId = self.canvas_getGroupId(jacklib._d(clientName))

if groupId == -1:
return

if (x1 != 0 and x2 != 0) or (y1 != 0 and y2 != 0):
patchcanvas.splitGroup(groupId)
else:
patchcanvas.joinGroup(groupId)
patchcanvas.setGroupPosFull(groupId, x1, y1, x2, y2)

@pyqtSlot()
def slot_ShutdownCallback(self):
self.jackStopped()
Expand Down
23 changes: 21 additions & 2 deletions src/jacklib/jacklib.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class _jack_client(Structure):
JACK_DEFAULT_AUDIO_TYPE = "32 bit float mono audio"
JACK_DEFAULT_MIDI_TYPE = "8 bit raw midi"

JACK_UUID_SIZE = 36
JACK_UUID_STRING_SIZE = JACK_UUID_SIZE + 1
JACK_UUID_EMPTY_INITIALIZER = 0

# Meta data
_JACK_METADATA_PREFIX = "http://jackaudio.org/metadata/"
JACK_METADATA_CONNECTED = _JACK_METADATA_PREFIX + "connected"
Expand Down Expand Up @@ -981,7 +985,7 @@ def port_connected_to(port, port_name):


def port_get_connections(port):
ports = jlib.jack_port_get_connections(port)
ports = jlib.jack_port_get_connections(port)
if not ports:
return
for port_name in ports:
Expand Down Expand Up @@ -1496,6 +1500,12 @@ def midi_get_lost_event_count(port_buffer):
except AttributeError:
jlib.jack_uuid_parse = None

try:
jlib.jack_uuid_unparse.argtypes = [jack_uuid_t, c_char_p]
jlib.jack_uuid_unparse.restype = None
except AttributeError:
jlib.jack_uuid_unparse = None


def set_session_callback(client, session_callback, arg):
if jlib.jack_set_session_callback:
Expand Down Expand Up @@ -1566,14 +1576,23 @@ def client_has_session_callback(client, client_name):


def uuid_parse(uuid_cstr):
if jlib.jack_uuid_parse:
if jlib.jack_uuid_parse and uuid_cstr is not None:
uuid = jack_uuid_t()
res = jlib.jack_uuid_parse(uuid_cstr, byref(uuid))
return uuid if res != -1 else None

return -1


def uuid_unparse(uuid, encoding=ENCODING):
if jlib.jack_uuid_unparse:
uuid_str = c_char_p(b" " * JACK_UUID_STRING_SIZE)
jlib.jack_uuid_unparse(uuid, uuid_str)
return _d(uuid_str.value, encoding)

return ""


# -------------------------------------------------------------------------------------------------
# Custom

Expand Down
1 change: 1 addition & 0 deletions src/shared_canvasjack.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class AbstractCanvasJackClass(QMainWindow):
PortRegistrationCallback = pyqtSignal(int, bool)
PortConnectCallback = pyqtSignal(int, int, bool)
PortRenameCallback = pyqtSignal(int, str, str)
PropertyChangeCallback = pyqtSignal(jacklib.jack_uuid_t, str, int)
ShutdownCallback = pyqtSignal()

SIGTERM = pyqtSignal()
Expand Down

0 comments on commit fde86f1

Please sign in to comment.