Skip to content

Commit 7b1cf82

Browse files
committed
Add example scripts
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
1 parent e0b31e4 commit 7b1cf82

7 files changed

Lines changed: 210 additions & 0 deletions

examples/jack-transport-query.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
from ctypes import pointer
7+
import jacklib
8+
from jacklib.helpers import get_jack_status_error_string
9+
10+
11+
status = jacklib.jack_status_t()
12+
client = jacklib.client_open("transport-query", jacklib.JackNoStartServer, status)
13+
14+
if status:
15+
err = get_jack_status_error_string(status)
16+
sys.exit("Error connecting to JACK server: %s" % err)
17+
18+
position = jacklib.jack_position_t()
19+
transport_state = jacklib.transport_query(client, pointer(position))
20+
21+
for name, type_ in sorted(position._fields_):
22+
value = getattr(position, name)
23+
if name == 'padding':
24+
value = list(value)
25+
print("{}: {}".format(name, value), file=sys.stderr)
26+
27+
if transport_state == jacklib.JackTransportStopped:
28+
print("JACK transport stopped, starting it now.")
29+
jacklib.transport_start(client)
30+
elif transport_state == jacklib.JackTransportRolling:
31+
print("JACK transport rolling, stopping it now.")
32+
jacklib.transport_stop(client)
33+
elif transport_state == jacklib.JackTransportStarting:
34+
print("JACK transport starting, nothing to do.")
35+
else:
36+
print("Unknown JACK transport state.")
37+
38+
jacklib.client_close(client)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
import jacklib
7+
from jacklib.helpers import get_jack_status_error_string
8+
9+
10+
if sys.argv[1:]:
11+
clientname = sys.argv[1]
12+
else:
13+
sys.exit("Usage: %s <client name>" % sys.argv[0])
14+
15+
status = jacklib.jack_status_t()
16+
client = jacklib.client_open("list-all-client-properties", jacklib.JackNoStartServer, status)
17+
18+
if status:
19+
err = get_jack_status_error_string(status)
20+
sys.exit("Error connecting to JACK server: %s" % err)
21+
22+
properties = jacklib.get_client_properties(client, clientname)
23+
24+
for prop in properties:
25+
print("{p.key}: {p.value} (type: {p.type})".format(p=prop))
26+
27+
jacklib.client_close(client)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
import jacklib
7+
from jacklib.helpers import get_jack_status_error_string
8+
9+
10+
if sys.argv[1:]:
11+
portname = sys.argv[1]
12+
else:
13+
sys.exit("Usage: %s <port name>" % sys.argv[0])
14+
15+
status = jacklib.jack_status_t()
16+
client = jacklib.client_open("list-all-port-properties", jacklib.JackNoStartServer, status)
17+
18+
if status:
19+
err = get_jack_status_error_string(status)
20+
sys.exit("Error connecting to JACK server: %s" % err)
21+
22+
properties = jacklib.get_port_properties(client, portname)
23+
24+
for prop in properties:
25+
print("{p.key}: {p.value} (type: {p.type})".format(p=prop))
26+
27+
jacklib.client_close(client)

examples/list_all_properties.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
import jacklib
7+
from jacklib.helpers import get_jack_status_error_string
8+
9+
10+
status = jacklib.jack_status_t()
11+
client = jacklib.client_open("list-all-properties", jacklib.JackNoStartServer, status)
12+
13+
if status:
14+
err = get_jack_status_error_string(status)
15+
sys.exit("Error connecting to JACK server: %s" % err)
16+
17+
properties = jacklib.get_all_properties()
18+
19+
for subject, props in properties.items():
20+
print("Subject %s:" % subject)
21+
22+
for prop in props:
23+
print("* {p.key}: {p.value} (type: {p.type})".format(p=prop))
24+
25+
print('')
26+
27+
jacklib.client_close(client)

examples/list_port_info.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
import jacklib
7+
from jacklib.helpers import c_char_p_p_to_list, get_jack_status_error_string
8+
9+
10+
status = jacklib.jack_status_t()
11+
client = jacklib.client_open("list-port-info", jacklib.JackNoStartServer, status)
12+
13+
if status:
14+
err = get_jack_status_error_string(status)
15+
sys.exit("Error connecting to JACK server: %s" % err)
16+
17+
for portname in c_char_p_p_to_list(jacklib.get_ports(client)):
18+
port = jacklib.port_by_name(client, portname)
19+
uuid = jacklib.port_uuid(port)
20+
21+
print("Port name: %s\nUUID: %s" % (portname, uuid))
22+
num_aliases, *aliases = jacklib.port_get_aliases(port)
23+
if num_aliases:
24+
print("Aliases: %s" % ", ".join(aliases[:num_aliases]))
25+
26+
pretty_name = jacklib.get_port_pretty_name(client, portname)
27+
if pretty_name:
28+
print("Pretty-name: {}".format(pretty_name))
29+
30+
props = jacklib.get_port_properties(client, portname)
31+
if props:
32+
print("Properties:")
33+
for prop in props:
34+
print(" * {}: {} (type: {})".format(prop.key, prop.value, prop.type))
35+
36+
print('')
37+
38+
jacklib.client_close(client)

examples/print_port_pretty_name.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
import jacklib
7+
from jacklib.helpers import get_jack_status_error_string
8+
9+
10+
if sys.argv[1:]:
11+
portname = sys.argv[1]
12+
else:
13+
sys.exit("Usage: %s <port name>" % sys.argv[0])
14+
15+
status = jacklib.jack_status_t()
16+
client = jacklib.client_open("print-port-pretty-name", jacklib.JackNoStartServer, status)
17+
18+
if status:
19+
err = get_jack_status_error_string(status)
20+
sys.exit("Error connecting to JACK server: %s" % err)
21+
22+
pretty_name = jacklib.get_port_pretty_name(client, portname)
23+
print("Pretty name for '%s': %r" % (portname, pretty_name or '<not set>'))
24+
25+
jacklib.client_close(client)

examples/set_port_pretty_name.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
import jacklib
7+
from jacklib.helpers import get_jack_status_error_string
8+
9+
10+
if len(sys.argv) == 3:
11+
portname = sys.argv[1]
12+
pretty_name = sys.argv[2]
13+
else:
14+
sys.exit("Usage: %s <port name> <pretty-name>" % sys.argv[0])
15+
16+
status = jacklib.jack_status_t()
17+
client = jacklib.client_open("set-port-pretty-name", jacklib.JackNoStartServer, status)
18+
19+
if status:
20+
err = get_jack_status_error_string(status)
21+
sys.exit("Error connecting to JACK server: %s" % err)
22+
23+
res = jacklib.set_port_pretty_name(client, portname, pretty_name)
24+
if res != -1:
25+
print("Pretty name for port '%s' is now '%s'." % (portname, pretty_name))
26+
27+
28+
jacklib.client_close(client)

0 commit comments

Comments
 (0)