Skip to content

Commit 8f8916a

Browse files
committed
Use set_*_callback() as decorators in all examples
See spatialaudio#4.
1 parent b5ea811 commit 8f8916a

4 files changed

Lines changed: 20 additions & 33 deletions

File tree

‎examples/chatty_client.py‎

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
from __future__ import print_function # only needed for Python 2.x
1111
import jack
1212

13+
print("setting error/info functions")
14+
1315

16+
@jack.set_error_function
1417
def error(msg):
1518
print("Error:", msg)
1619

1720

21+
@jack.set_info_function
1822
def info(msg):
1923
print("Info:", msg)
2024

2125

22-
print("setting error/info functions")
23-
jack.set_error_function(error)
24-
jack.set_info_function(info)
25-
26-
2726
print("starting chatty client")
2827

2928
client = jack.Client("Chatty-Client")
@@ -39,71 +38,62 @@ def info(msg):
3938
print("registering callbacks")
4039

4140

41+
@client.set_shutdown_callback
4242
def shutdown(status, reason):
4343
print("JACK shutdown!")
4444
print("status:", status)
4545
print("reason:", reason)
4646

47-
client.set_shutdown_callback(shutdown)
48-
4947

48+
@client.set_freewheel_callback
5049
def freewheel(starting):
5150
print(["stopping", "starting"][starting], "freewheel mode")
5251

53-
client.set_freewheel_callback(freewheel)
54-
5552

53+
@client.set_blocksize_callback
5654
def blocksize(blocksize):
5755
print("setting blocksize to", blocksize)
5856
return jack.SUCCESS
5957

60-
client.set_blocksize_callback(blocksize)
61-
6258

59+
@client.set_samplerate_callback
6360
def samplerate(samplerate):
6461
print("setting samplerate to", samplerate)
6562
return jack.SUCCESS
6663

67-
client.set_samplerate_callback(samplerate)
68-
6964

65+
@client.set_client_registration_callback
7066
def client_registration(name, register):
7167
print("client", repr(name), ["unregistered", "registered"][register])
7268

73-
client.set_client_registration_callback(client_registration)
74-
7569

70+
@client.set_port_registration_callback
7671
def port_registration(port, register):
7772
print(repr(port), ["unregistered", "registered"][register])
7873

79-
client.set_port_registration_callback(port_registration)
80-
8174

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

85-
client.set_port_connect_callback(port_connect)
86-
8779

80+
@client.set_port_rename_callback
8881
def port_rename(port, old, new):
8982
print("renamed", port, "from", repr(old), "to", repr(new))
9083
return jack.SUCCESS
9184

92-
client.set_port_rename_callback(port_rename)
93-
9485

86+
@client.set_graph_order_callback
9587
def graph_order():
9688
print("graph order changed")
9789
return jack.SUCCESS
9890

99-
client.set_graph_order_callback(graph_order)
100-
10191

92+
@client.set_xrun_callback
10293
def xrun():
10394
print("xrun; delay", client.xrun_delayed_usecs, "microseconds")
10495
return jack.SUCCESS
10596

106-
client.set_xrun_callback(xrun)
10797

10898
print("activating JACK")
10999
with client:

‎examples/midi_chords.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
outport = client.midi_outports.register("output")
2121

2222

23-
def callback(frames):
23+
@client.set_process_callback
24+
def process(frames):
2425
outport.clear_buffer()
2526
for offset, indata in inport.incoming_midi_events():
2627
# Note: This may raise an exception:
@@ -33,8 +34,6 @@ def callback(frames):
3334
outport.write_midi_event(offset, (status, pitch + i, vel))
3435
return jack.CALL_AGAIN
3536

36-
client.set_process_callback(callback)
37-
3837
with client:
3938
print("#" * 80)
4039
print("press Return to quit")

‎examples/midi_monitor.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
port = client.midi_inports.register("input")
1010

1111

12-
def callback(frames):
12+
@client.set_process_callback
13+
def process(frames):
1314
for offset, data in port.incoming_midi_events():
1415
# TODO: use ringbuffer
1516
print("{0}: 0x{1}".format(client.last_frame_time + offset,
1617
binascii.hexlify(data).decode()))
1718
return jack.CALL_AGAIN
1819

19-
client.set_process_callback(callback)
20-
2120
with client:
2221
print("#" * 80)
2322
print("press Return to quit")

‎examples/thru_client.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,22 @@
4141
event = threading.Event()
4242

4343

44+
@client.set_process_callback
4445
def process(frames):
4546
assert len(client.inports) == len(client.outports)
4647
assert frames == client.blocksize
4748
for i, o in zip(client.inports, client.outports):
4849
o.get_buffer()[:] = i.get_buffer()
4950
return jack.CALL_AGAIN
5051

51-
client.set_process_callback(process)
52-
5352

53+
@client.set_shutdown_callback
5454
def shutdown(status, reason):
5555
print("JACK shutdown!")
5656
print("status:", status)
5757
print("reason:", reason)
5858
event.set()
5959

60-
client.set_shutdown_callback(shutdown)
6160

6261
# create two port pairs
6362
for number in 1, 2:

0 commit comments

Comments
 (0)