-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjack_audio_routing.py
68 lines (53 loc) · 2.08 KB
/
jack_audio_routing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from calfbox import cbox
import time
def cmd_dumper(cmd, fb, args):
print ("%s(%s)" % (cmd, ",".join(list(map(repr,args)))))
cbox.init_engine("") #empty string so cbox doesn't look for the .cboxrc file
cbox.Config.set("io", "use_usb", 0)
cbox.start_audio(cmd_dumper)
global Document
Document = cbox.Document
status = cbox.JackIO.status()
client_name = status.client_name
print ("Client name: %s" % client_name)
print ("Audio inputs: %d, outputs: %d" % (status.audio_inputs, status.audio_outputs))
print ("Sample rate: %d frames/sec" % (status.sample_rate))
print ("JACK period: %d frames" % (status.buffer_size))
inputs = cbox.JackIO.get_ports(".*", cbox.JackIO.AUDIO_TYPE, cbox.JackIO.PORT_IS_SOURCE | cbox.JackIO.PORT_IS_PHYSICAL)
outputs = cbox.JackIO.get_ports(".*", cbox.JackIO.AUDIO_TYPE, cbox.JackIO.PORT_IS_SINK | cbox.JackIO.PORT_IS_PHYSICAL)
scene = Document.get_scene()
scene.clear()
instrument = scene.add_new_instrument_layer("test_sampler", "sampler").get_instrument()
pgm_no = instrument.engine.get_unused_program()
pgm = instrument.engine.load_patch_from_file(pgm_no, 'synthbass.sfz', 'SynthBass')
instrument.engine.set_patch(1, pgm_no)
instrument.engine.set_patch(10, pgm_no)
print ("Connecting")
uuid = cbox.JackIO.create_audio_output('noises')
router = cbox.JackIO.create_audio_output_router(uuid, uuid)
assert type(router) is cbox.DocRecorder
router2 = cbox.JackIO.create_audio_output_router(uuid, uuid)
assert type(router2) is cbox.DocRecorder
instrument.get_output_slot(0).rec_wet.attach(router)
instrument.get_output_slot(0).rec_wet.attach(router2)
exc = None
try:
instrument.get_output_slot(0).rec_wet.attach(router2)
except Exception as e:
exc = e
assert "Router already attached" in str(exc)
instrument.get_output_slot(0).rec_wet.detach(router2)
try:
instrument.get_output_slot(0).rec_wet.detach(router2)
except Exception as e:
exc = e
assert "Recorder is not attached" in str(exc)
router.delete()
print("Ready!")
while True:
events = cbox.get_new_events()
if events:
print (events)
time.sleep(0.05)