|
1 <stránka |
|
2 xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
|
3 xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"> |
|
4 |
|
5 <nadpis>Working with JACK ports</nadpis> |
|
6 <perex>list ports and connections, connect and disconnect ports, both MIDI and audio</perex> |
|
7 <m:pořadí-příkladu>04400</m:pořadí-příkladu> |
|
8 |
|
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
|
10 |
|
11 <p> |
|
12 A powerful audio system called <a href="https://jackaudio.org/">JACK</a> allows us to |
|
13 build pipelines consisting of audio interfaces, players, recorders, filters and effects… |
|
14 and route sound streams (both PCM and MIDI) through them. |
|
15 MIDI messages can come from keyboards or other hardware MIDI controllers or from MIDI players and other software. |
|
16 </p> |
|
17 |
|
18 <p> |
|
19 In JACK, we have <em>clients</em> (applications) and they have <em>ports</em> (input and output channels). |
|
20 The JACK graph consists of connections between input and output ports. |
|
21 There might be multiple connections from or to a single port – singals are then replicated or combined. |
|
22 Obviously, we can connect MIDI ports only to other MIDI ports and PCM/audio ports only to other ports of the same kind. |
|
23 However there can be applications with both kinds of ports that e.g. translate MIDI signal to audio signal (synthesizers). |
|
24 </p> |
|
25 |
|
26 <m:img src="img/jack-connections-2.png"/> |
|
27 |
|
28 <p> |
|
29 The JACK <em>daemon</em> is responsible for maintaining the graph and transmitting the messages. |
|
30 Clients connect to the <em>daemon</em>. |
|
31 </p> |
|
32 |
|
33 <p> |
|
34 Since <m:a href="release-v0.17">v0.17</m:a>, we can list the ports using the <code>relpipe-in-jack</code> command: |
|
35 </p> |
|
36 |
|
37 <m:pre jazyk="bash"><![CDATA[relpipe-in-jack --list-ports true --list-midi-messages false | relpipe-out-tabular]]></m:pre> |
|
38 |
|
39 <p>and see it as a relation:</p> |
|
40 |
|
41 <pre><![CDATA[port: |
|
42 ╭───────────────────────────────────┬───────────────┬─────────────────┬──────────────────┬────────────────────┬────────────────────┬────────────────┬────────────────┬─────────────────────────╮ |
|
43 │ name (string) │ uuid (string) │ input (boolean) │ output (boolean) │ physical (boolean) │ terminal (boolean) │ mine (boolean) │ midi (boolean) │ type (string) │ |
|
44 ├───────────────────────────────────┼───────────────┼─────────────────┼──────────────────┼────────────────────┼────────────────────┼────────────────┼────────────────┼─────────────────────────┤ |
|
45 │ system:capture_1 │ │ false │ true │ true │ true │ false │ false │ 32 bit float mono audio │ |
|
46 │ system:capture_2 │ │ false │ true │ true │ true │ false │ false │ 32 bit float mono audio │ |
|
47 │ system:playback_1 │ │ true │ false │ true │ true │ false │ false │ 32 bit float mono audio │ |
|
48 │ system:playback_2 │ │ true │ false │ true │ true │ false │ false │ 32 bit float mono audio │ |
|
49 │ j2a_bridge:playback │ │ true │ false │ false │ false │ false │ true │ 8 bit raw midi │ |
|
50 │ relpipe-in-jack_processed:midi-in │ │ true │ false │ false │ false │ false │ true │ 8 bit raw midi │ |
|
51 │ relpipe-out-jack:midi-out │ │ false │ true │ false │ false │ false │ true │ 8 bit raw midi │ |
|
52 │ a2j_bridge:capture │ │ false │ true │ false │ false │ false │ true │ 8 bit raw midi │ |
|
53 │ yoshimi:left │ │ false │ true │ false │ false │ false │ false │ 32 bit float mono audio │ |
|
54 │ yoshimi:right │ │ false │ true │ false │ false │ false │ false │ 32 bit float mono audio │ |
|
55 │ yoshimi:midi in │ │ true │ false │ false │ false │ false │ true │ 8 bit raw midi │ |
|
56 │ Qtractor:Master/in_1 │ │ true │ false │ false │ false │ false │ false │ 32 bit float mono audio │ |
|
57 │ Qtractor:Master/in_2 │ │ true │ false │ false │ false │ false │ false │ 32 bit float mono audio │ |
|
58 │ Qtractor:Master/out_1 │ │ false │ true │ false │ false │ false │ false │ 32 bit float mono audio │ |
|
59 │ Qtractor:Master/out_2 │ │ false │ true │ false │ false │ false │ false │ 32 bit float mono audio │ |
|
60 │ qmidiarp:in │ │ true │ false │ false │ false │ false │ true │ 8 bit raw midi │ |
|
61 │ qmidiarp:out 1 │ │ false │ true │ false │ false │ false │ true │ 8 bit raw midi │ |
|
62 │ qmidiarp:out 2 │ │ false │ true │ false │ false │ false │ true │ 8 bit raw midi │ |
|
63 │ jack-keyboard:midi_out │ │ false │ true │ false │ false │ false │ true │ 8 bit raw midi │ |
|
64 │ jack-keyboard:midi_in │ │ true │ false │ false │ false │ false │ true │ 8 bit raw midi │ |
|
65 │ relpipe-in-jack_original:midi-in │ │ true │ false │ false │ false │ false │ true │ 8 bit raw midi │ |
|
66 │ relpipe-in-jack:midi-in │ │ true │ false │ false │ false │ true │ true │ 8 bit raw midi │ |
|
67 ╰───────────────────────────────────┴───────────────┴─────────────────┴──────────────────┴────────────────────┴────────────────────┴────────────────┴────────────────┴─────────────────────────╯ |
|
68 Record count: 22]]></pre> |
|
69 |
|
70 <p> |
|
71 Port names are prefixed with the names of clients. |
|
72 We see the port direction in the <code>input</code> and <code>output</code> attributes |
|
73 and can distinguish MIDI and audio ports by the value of the <code>midi</code> attribute. |
|
74 </p> |
|
75 |
|
76 <p> |
|
77 We can also list the connections using the <code>--list-connections true</code> option: |
|
78 </p> |
|
79 |
|
80 <pre><![CDATA[connection: |
|
81 ╭────────────────┬───────────────────────────┬───────────────────────────────────╮ |
|
82 │ event (string) │ source_port (string) │ destination_port (string) │ |
|
83 ├────────────────┼───────────────────────────┼───────────────────────────────────┤ |
|
84 │ connect │ system:capture_1 │ Qtractor:Master/in_1 │ |
|
85 │ connect │ system:capture_2 │ Qtractor:Master/in_2 │ |
|
86 │ connect │ relpipe-out-jack:midi-out │ qmidiarp:in │ |
|
87 │ connect │ relpipe-out-jack:midi-out │ relpipe-in-jack_original:midi-in │ |
|
88 │ connect │ yoshimi:left │ system:playback_1 │ |
|
89 │ connect │ yoshimi:right │ system:playback_2 │ |
|
90 │ connect │ Qtractor:Master/out_1 │ system:playback_1 │ |
|
91 │ connect │ Qtractor:Master/out_2 │ system:playback_2 │ |
|
92 │ connect │ qmidiarp:out 1 │ yoshimi:midi in │ |
|
93 │ connect │ qmidiarp:out 1 │ relpipe-in-jack_processed:midi-in │ |
|
94 │ connect │ jack-keyboard:midi_out │ qmidiarp:in │ |
|
95 │ connect │ jack-keyboard:midi_out │ relpipe-in-jack_original:midi-in │ |
|
96 ╰────────────────┴───────────────────────────┴───────────────────────────────────╯ |
|
97 Record count: 12]]></pre> |
|
98 |
|
99 <p> |
|
100 Instead of formatting as a table, we can direct this relation into a file and later recreate the saved connections: |
|
101 </p> |
|
102 |
|
103 <m:pre jazyk="bash"><![CDATA[relpipe-in-jack --list-connections true --list-midi-messages false > connections.rp |
|
104 cat connections.rp | relpipe-out-jack --required-connections 0]]></m:pre> |
|
105 |
|
106 <p> |
|
107 If we want to store the connections in a human readable format in order to be able to edit them, |
|
108 we should add e.g. <code>relpipe-out-csv</code> (or XML, or Recfile) stage before redirecting the stream to the file |
|
109 and add <code>relpipe-in-csv</code> etc. stage to the second pipeline. |
|
110 </p> |
|
111 |
|
112 <pre><![CDATA["event","source_port","destination_port" |
|
113 "connect","system:capture_1","Qtractor:Master/in_1" |
|
114 "connect","system:capture_2","Qtractor:Master/in_2" |
|
115 "connect","relpipe-out-jack:midi-out","qmidiarp:in" |
|
116 "connect","relpipe-out-jack:midi-out","relpipe-in-jack_original:midi-in" |
|
117 "connect","yoshimi:left","system:playback_1" |
|
118 "connect","yoshimi:right","system:playback_2" |
|
119 "connect","Qtractor:Master/out_1","system:playback_1" |
|
120 "connect","Qtractor:Master/out_2","system:playback_2" |
|
121 "connect","qmidiarp:out 1","yoshimi:midi in" |
|
122 "connect","qmidiarp:out 1","relpipe-in-jack_processed:midi-in" |
|
123 "connect","jack-keyboard:midi_out","qmidiarp:in" |
|
124 "connect","jack-keyboard:midi_out","relpipe-in-jack_original:midi-in"]]></pre> |
|
125 |
|
126 |
|
127 <p> |
|
128 Or we can write the file by hand and just send it to the JACK output module: |
|
129 </p> |
|
130 |
|
131 <m:pre jazyk="bash"><![CDATA[cat connections.csv | relpipe-in-csv | relpipe-out-jack --required-connections 0]]></m:pre> |
|
132 |
|
133 <p> |
|
134 The primary purpose of the <code>relpipe-out-jack</code> is sending MIDI messages. |
|
135 And because it does not make much sense to send them nowhere, it waits for at least one connection. |
|
136 But if we are not sending any messages and are using this tool just to connect or disconnect the ports, |
|
137 we should set <code>--required-connections 0</code>. |
|
138 </p> |
|
139 |
|
140 <p> |
|
141 We can also connect or disconnect particular ports specified on the command line: |
|
142 </p> |
|
143 |
|
144 <m:pre jazyk="bash"><![CDATA[relpipe-in-jack --connect-ports "a2j_bridge:capture" "qmidiarp:in" --list-midi-messages false]]></m:pre> |
|
145 |
|
146 <p> |
|
147 The primary purpose of the <code>relpipe-in-jack</code> command is monitoring the MIDI commands. |
|
148 If we want just to connect or disconnect some ports, we can disable monitoring by setting <code>--list-midi-messages false</code> |
|
149 and the command will return immediately. |
|
150 </p> |
|
151 |
|
152 <p> |
|
153 The port names are suggested by the Bash-completion, so we do not have to memorize them. |
|
154 Because these names contain the colon, we should use quotes (otherwise the Bash-completion may be confused). |
|
155 </p> |
|
156 |
|
157 <p> |
|
158 Disconnecting works the same way – just use the <code>--disconnect-ports</code> option |
|
159 or specify the <code>disconnect</code> command in the <code>event</code> attribute. |
|
160 </p> |
|
161 |
|
162 <p> |
|
163 Note: there are sophisticated GUI tools focused on working with the JACK graph |
|
164 like <a href="https://qjackctl.sourceforge.io/">QjackCtl</a> or <a href="https://kx.studio/Applications:Claudia">KXStudio/Claudia</a>. |
|
165 But sometimes it is useful to have a simple CLI tool for this job. |
|
166 </p> |
|
167 |
|
168 </text> |
|
169 |
|
170 </stránka> |