Skip to content

Commit

Permalink
Merge pull request #94 from noiseorchestra/make-compatible-with-new-j…
Browse files Browse the repository at this point in the history
…acktrip-version

Make compatible with JackTrip v1.2 and v1.3
  • Loading branch information
sandreae authored Feb 5, 2021
2 parents d0de2fc + 27843f3 commit 7719380
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 121 deletions.
73 changes: 41 additions & 32 deletions patcher_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,59 @@
import jacktrip_pypatcher as jtp
from pathlib import Path

print("setting error/info functions")

def check_for_jacktrip_client(name):
if name.startswith("..") or name.startswith("__"):
return True
return False

@jack.set_error_function
def error(msg):
print("Error:", msg)

def main():

@jack.set_info_function
def info(msg):
print("Info:", msg)
print("setting error/info functions")

@jack.set_error_function
def error(msg):
print("Error:", msg)

print("starting chatty client")
@jack.set_info_function
def info(msg):
print("Info:", msg)

client = jack.Client("Chatty-Client")
print("starting chatty client")

if client.status.server_started:
print("JACK server was started")
else:
print("JACK server was already running")
if client.status.name_not_unique:
print("unique client name generated:", client.name)
client = jack.Client("Chatty-Client")

if client.status.server_started:
print("JACK server was started")
else:
print("JACK server was already running")
if client.status.name_not_unique:
print("unique client name generated:", client.name)

print("registering callbacks")
print("registering callbacks")

@client.set_client_registration_callback
def client_registration(name, register):
isJacktripClient = check_for_jacktrip_client(name)
print("client", repr(name), ["unregistered", "registered"][register])
print(
name, " starts with '..' or '__' ? (therefore JT client?)", isJacktripClient
)
if isJacktripClient:
print("touching")
touch_path = Path("/var/tmp/jacktrip_pypatcher")
touch_path.touch()

@client.set_client_registration_callback
def client_registration(name, register):
print("client", repr(name), ["unregistered", "registered"][register])
print(name, " starts with '..'? (therefore JT client?)", name.startswith(".."))
if name.startswith(".."):
print("touching")
touch_path = Path("/var/tmp/jacktrip_pypatcher")
touch_path.touch()
@client.set_port_connect_callback
def port_connect(a, b, connect):
print(["disconnected", "connected"][connect], a, "and", b)

print("activating JACK")
with client:
while True:
sleep(0.1)

@client.set_port_connect_callback
def port_connect(a, b, connect):
print(["disconnected", "connected"][connect], a, "and", b)


print("activating JACK")
with client:
while True:
sleep(0.1)
if __name__ == "__main__":
main()
14 changes: 14 additions & 0 deletions test_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from unittest.mock import Mock
import patcher_callback


def test_jacktrip_v1_2():
assert patcher_callback.check_for_jacktrip_client("...ffff.123.123.123.123")


def test_jacktrip_v1_3():
assert patcher_callback.check_for_jacktrip_client("__ffff.123.123.123.123")


def test_non_jacktrip_client():
assert patcher_callback.check_for_jacktrip_client("00ffff.123.123.123.123") == False
Loading

0 comments on commit 7719380

Please sign in to comment.