|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +"""Create a JACK client that prints a lot of information. |
| 4 | +
|
| 5 | +This client registers all possible callbacks (except the process |
| 6 | +callback, which would be just too much noise) and prints some |
| 7 | +information whenever they are called. |
| 8 | +
|
| 9 | +""" |
| 10 | +import jack |
| 11 | + |
| 12 | + |
| 13 | +def error(msg): |
| 14 | + print("Error:", msg) |
| 15 | + |
| 16 | + |
| 17 | +def info(msg): |
| 18 | + print("Info:", msg) |
| 19 | + |
| 20 | + |
| 21 | +print("setting error/info functions") |
| 22 | +jack.set_error_function(error) |
| 23 | +jack.set_info_function(info) |
| 24 | + |
| 25 | + |
| 26 | +print("starting chatty client") |
| 27 | + |
| 28 | +client = jack.Client("Chatty-Client") |
| 29 | + |
| 30 | +if client.status.server_started: |
| 31 | + print("JACK server was started") |
| 32 | +else: |
| 33 | + print("JACK server was already running") |
| 34 | +if client.status.name_not_unique: |
| 35 | + print("unique client name generated:", client.name) |
| 36 | + |
| 37 | + |
| 38 | +print("registering callbacks") |
| 39 | + |
| 40 | + |
| 41 | +def shutdown(status, reason, userdata): |
| 42 | + print("JACK shutdown!") |
| 43 | + print("status:", status) |
| 44 | + print("reason:", reason) |
| 45 | + |
| 46 | +client.set_shutdown_callback(shutdown) |
| 47 | + |
| 48 | + |
| 49 | +def freewheel(starting, userdata): |
| 50 | + print(["stopping", "starting"][starting], "freewheel mode") |
| 51 | + |
| 52 | +client.set_freewheel_callback(freewheel) |
| 53 | + |
| 54 | + |
| 55 | +def blocksize(blocksize, userdata): |
| 56 | + print("setting blocksize to", blocksize) |
| 57 | + return jack.SUCCESS |
| 58 | + |
| 59 | +client.set_blocksize_callback(blocksize) |
| 60 | + |
| 61 | + |
| 62 | +def samplerate(samplerate, userdata): |
| 63 | + print("setting samplerate to", samplerate) |
| 64 | + return jack.SUCCESS |
| 65 | + |
| 66 | +client.set_samplerate_callback(samplerate) |
| 67 | + |
| 68 | + |
| 69 | +def client_registration(name, register, userdata): |
| 70 | + print("client", repr(name), ["unregistered", "registered"][register]) |
| 71 | + |
| 72 | +client.set_client_registration_callback(client_registration) |
| 73 | + |
| 74 | + |
| 75 | +def port_registration(port, register, userdata): |
| 76 | + print(repr(port), ["unregistered", "registered"][register]) |
| 77 | + |
| 78 | +client.set_port_registration_callback(port_registration) |
| 79 | + |
| 80 | + |
| 81 | +def port_connect(a, b, connect, userdata): |
| 82 | + print(["disconnected", "connected"][connect], a, "and", b) |
| 83 | + |
| 84 | +client.set_port_connect_callback(port_connect) |
| 85 | + |
| 86 | + |
| 87 | +def port_rename(port, old, new, userdata): |
| 88 | + print("renamed", port, "from", repr(old), "to", repr(new)) |
| 89 | + return jack.SUCCESS |
| 90 | + |
| 91 | +client.set_port_rename_callback(port_rename) |
| 92 | + |
| 93 | + |
| 94 | +def graph_order(userdata): |
| 95 | + print("graph order changed") |
| 96 | + return jack.SUCCESS |
| 97 | + |
| 98 | +client.set_graph_order_callback(graph_order) |
| 99 | + |
| 100 | + |
| 101 | +def xrun(userdata): |
| 102 | + print("xrun; delay", client.xrun_delayed_usecs, "microseconds") |
| 103 | + return jack.SUCCESS |
| 104 | + |
| 105 | +client.set_xrun_callback(xrun) |
| 106 | + |
| 107 | + |
| 108 | +print("activating JACK") |
| 109 | +client.activate() |
| 110 | + |
| 111 | +print("#" * 80) |
| 112 | +print("press Return to quit") |
| 113 | +print("#" * 80) |
| 114 | +input() |
| 115 | + |
| 116 | +print("closing JACK") |
| 117 | +client.close() |
0 commit comments