2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <jack/jack.h>
27 #include <jack/session.h>
28 #include <jack/uuid.h>
35 //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
39 printf_name2uuid (jack_client_t
* client
, const char* pname
)
41 char *port_component
= strchr( pname
, ':' );
42 size_t csize
= port_component
- pname
+ 1;
43 char client_component
[csize
];
44 snprintf(client_component
, csize
, "%s", pname
);
46 char *uuid
= jack_get_uuid_for_client_name(client
, client_component
);
48 printf("%s%s\n", uuid
, port_component
);
59 fprintf (stderr
, "\nUsage: %s [options] [filter string]\n", my_name
);
60 fprintf (stderr
, "List active Jack ports, and optionally display extra information.\n");
61 fprintf (stderr
, "Optionally filter ports which match ALL strings provided after any options.\n\n");
62 fprintf (stderr
, "Display options:\n");
63 fprintf (stderr
, " -s, --server <name> Connect to the jack server named <name>\n");
64 fprintf (stderr
, " -A, --aliases List aliases for each port\n");
65 fprintf (stderr
, " -c, --connections List connections to/from each port\n");
66 fprintf (stderr
, " -l, --port-latency Display per-port latency in frames at each port\n");
67 fprintf (stderr
, " -L, --total-latency Display total latency in frames at each port\n");
68 fprintf (stderr
, " -p, --properties Display port properties. Output may include:\n"
69 " input|output, can-monitor, physical, terminal\n\n");
70 fprintf (stderr
, " -t, --type Display port type\n");
71 fprintf (stderr
, " -u, --uuid Display uuid instead of client name (if available)\n");
72 fprintf (stderr
, " -U, --port-uuid Display port uuid\n");
73 fprintf (stderr
, " -h, --help Display this help message\n");
74 fprintf (stderr
, " --version Output version information and exit\n\n");
75 fprintf (stderr
, "For more information see http://jackaudio.org/\n");
79 main (int argc
, char *argv
[])
81 jack_client_t
*client
;
83 jack_options_t options
= JackNoStartServer
;
84 const char **ports
, **connections
;
89 int show_port_latency
= 0;
90 int show_total_latency
= 0;
91 int show_properties
= 0;
94 int show_port_uuid
= 0;
98 char *server_name
= NULL
;
100 struct option long_options
[] = {
101 { "server", 1, 0, 's' },
102 { "aliases", 0, 0, 'A' },
103 { "connections", 0, 0, 'c' },
104 { "port-latency", 0, 0, 'l' },
105 { "total-latency", 0, 0, 'L' },
106 { "properties", 0, 0, 'p' },
107 { "type", 0, 0, 't' },
108 { "uuid", 0, 0, 'u' },
109 { "port-uuid", 0, 0, 'U' },
110 { "help", 0, 0, 'h' },
111 { "version", 0, 0, 'v' },
115 my_name
= strrchr(argv
[0], '/');
122 while ((c
= getopt_long (argc
, argv
, "s:AclLphvtuU", long_options
, &option_index
)) >= 0) {
125 server_name
= (char *) malloc (sizeof (char) * strlen(optarg
));
126 strcpy (server_name
, optarg
);
127 options
|= JackServerName
;
130 aliases
[0] = (char *) malloc (jack_port_name_size());
131 aliases
[1] = (char *) malloc (jack_port_name_size());
138 show_port_latency
= 1;
141 show_total_latency
= 1;
170 /* Open a client connection to the JACK server. Starting a
171 * new server only to list its ports seems pointless, so we
172 * specify JackNoStartServer. */
173 if ((client
= jack_client_open ("lsp", options
, &status
, server_name
)) == 0) {
174 fprintf (stderr
, "Error: cannot connect to JACK, ");
175 if (status
& JackServerFailed
) {
176 fprintf (stderr
, "server is not running.\n");
178 fprintf (stderr
, "jack_client_open() failed, status = 0x%2.0x\n", status
);
183 ports
= jack_get_ports (client
, NULL
, NULL
, 0);
185 for (i
= 0; ports
&& ports
[i
]; ++i
) {
186 // skip over any that don't match ALL of the strings presented at command line
188 for (k
= optind
; k
< argc
; k
++){
189 if (strstr(ports
[i
], argv
[k
]) == NULL
){
193 if (skip_port
) continue;
196 printf_name2uuid(client
, ports
[i
]);
198 printf ("%s\n", ports
[i
]);
201 jack_port_t
*port
= jack_port_by_name (client
, ports
[i
]);
203 if (show_port_uuid
) {
204 char buf
[JACK_UUID_STRING_SIZE
];
205 jack_uuid_t uuid
= jack_port_uuid (port
);
206 jack_uuid_unparse (uuid
, buf
);
207 printf (" uuid: %s\n", buf
);
214 cnt
= jack_port_get_aliases (port
, aliases
);
215 for (i
= 0; i
< cnt
; ++i
) {
216 printf (" %s\n", aliases
[i
]);
221 if ((connections
= jack_port_get_all_connections (client
, jack_port_by_name(client
, ports
[i
]))) != 0) {
222 for (j
= 0; connections
[j
]; j
++) {
225 printf_name2uuid(client
, connections
[j
]);
227 printf("%s\n", connections
[j
]);
230 jack_free (connections
);
233 if (show_port_latency
) {
235 jack_latency_range_t range
;
237 jack_port_get_latency_range (port
, JackPlaybackLatency
, &range
);
238 printf (" port playback latency = [ %" PRIu32
" %" PRIu32
" ] frames\n",
239 range
.min
, range
.max
);
241 jack_port_get_latency_range (port
, JackCaptureLatency
, &range
);
242 printf (" port capture latency = [ %" PRIu32
" %" PRIu32
" ] frames\n",
243 range
.min
, range
.max
);
246 if (show_total_latency
) {
248 printf (" total latency = %d frames\n",
249 jack_port_get_total_latency (client
, port
));
252 if (show_properties
) {
254 int flags
= jack_port_flags (port
);
255 printf (" properties: ");
256 if (flags
& JackPortIsInput
) {
257 fputs ("input,", stdout
);
259 if (flags
& JackPortIsOutput
) {
260 fputs ("output,", stdout
);
262 if (flags
& JackPortCanMonitor
) {
263 fputs ("can-monitor,", stdout
);
265 if (flags
& JackPortIsPhysical
) {
266 fputs ("physical,", stdout
);
268 if (flags
& JackPortIsTerminal
) {
269 fputs ("terminal,", stdout
);
277 fputs (jack_port_type (port
), stdout
);
289 jack_client_close (client
);