Browse Source

Sync example-clients/lsp.c with jack1

Signed-off-by: falkTX <falktx@falktx.com>
tags/v1.9.13
falkTX 7 years ago
parent
commit
8e2c84ea48
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 57 additions and 25 deletions
  1. +57
    -25
      example-clients/lsp.c

+ 57
- 25
example-clients/lsp.c View File

@@ -22,19 +22,34 @@
#include <string.h>
#include <getopt.h>
#include <inttypes.h>

#include <jack/jack.h>
#include <jack/session.h>
#include <jack/uuid.h>

char * my_name;

void error_callback (const char *err)
static void
show_version (void)
{
//fprintf (stderr, "%s\n", err);
//fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
}

static void
show_version (void)
printf_name2uuid (jack_client_t* client, const char* pname)
{
//fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
char *port_component = strchr( pname, ':' );
size_t csize = port_component - pname + 1;
char client_component[csize];
snprintf(client_component, csize, "%s", pname);

char *uuid = jack_get_uuid_for_client_name(client, client_component);
if (uuid) {
printf("%s%s\n", uuid, port_component );
} else {
printf("%s\n",pname);
}
jack_free(uuid);
}

static void
@@ -48,11 +63,13 @@ show_usage (void)
fprintf (stderr, " -s, --server <name> Connect to the jack server named <name>\n");
fprintf (stderr, " -A, --aliases List aliases for each port\n");
fprintf (stderr, " -c, --connections List connections to/from each port\n");
fprintf (stderr, " -l, --latency Display per-port latency in frames at each port\n");
fprintf (stderr, " -L, --latency Display total latency in frames at each port\n");
fprintf (stderr, " -l, --port-latency Display per-port latency in frames at each port\n");
fprintf (stderr, " -L, --total-latency Display total latency in frames at each port\n");
fprintf (stderr, " -p, --properties Display port properties. Output may include:\n"
" input|output, can-monitor, physical, terminal\n\n");
fprintf (stderr, " -t, --type Display port type\n");
fprintf (stderr, " -u, --uuid Display uuid instead of client name (if available)\n");
fprintf (stderr, " -U, --port-uuid Display port uuid\n");
fprintf (stderr, " -h, --help Display this help message\n");
fprintf (stderr, " --version Output version information and exit\n\n");
fprintf (stderr, "For more information see http://jackaudio.org/\n");
@@ -73,11 +90,12 @@ main (int argc, char *argv[])
int show_total_latency = 0;
int show_properties = 0;
int show_type = 0;
int show_uuid = 0;
int show_port_uuid = 0;
int c;
int option_index;
char* aliases[2];
char *server_name = NULL;
jack_port_t *port;

struct option long_options[] = {
{ "server", 1, 0, 's' },
@@ -87,6 +105,8 @@ main (int argc, char *argv[])
{ "total-latency", 0, 0, 'L' },
{ "properties", 0, 0, 'p' },
{ "type", 0, 0, 't' },
{ "uuid", 0, 0, 'u' },
{ "port-uuid", 0, 0, 'U' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
{ 0, 0, 0, 0 }
@@ -99,7 +119,7 @@ main (int argc, char *argv[])
my_name ++;
}

while ((c = getopt_long (argc, argv, "s:AclLphvt", long_options, &option_index)) >= 0) {
while ((c = getopt_long (argc, argv, "s:AclLphvtuU", long_options, &option_index)) >= 0) {
switch (c) {
case 's':
server_name = (char *) malloc (sizeof (char) * strlen(optarg));
@@ -126,6 +146,12 @@ main (int argc, char *argv[])
case 't':
show_type = 1;
break;
case 'u':
show_uuid = 1;
break;
case 'U':
show_port_uuid = 1;
break;
case 'h':
show_usage ();
return 1;
@@ -141,13 +167,9 @@ main (int argc, char *argv[])
}
}

jack_set_error_function(error_callback);

/* Open a client connection to the JACK server. Starting a
* new server only to list its ports seems pointless, so we
* specify JackNoStartServer. */
//JOQ: need a new server name option

if ((client = jack_client_open ("lsp", options, &status, server_name)) == 0) {
fprintf (stderr, "Error: cannot connect to JACK, ");
if (status & JackServerFailed) {
@@ -159,21 +181,31 @@ main (int argc, char *argv[])
}

ports = jack_get_ports (client, NULL, NULL, 0);
if (!ports)
goto error;

for (i = 0; ports && ports[i]; ++i) {
// skip over any that don't match ALL of the strings presented at command line
skip_port = 0;
for(k = optind; k < argc; k++){
if(strstr(ports[i], argv[k]) == NULL ){
for (k = optind; k < argc; k++){
if (strstr(ports[i], argv[k]) == NULL ){
skip_port = 1;
}
}
if (skip_port) continue;

printf ("%s\n", ports[i]);
port = jack_port_by_name (client, ports[i]);
if (show_uuid) {
printf_name2uuid(client, ports[i]);
} else {
printf ("%s\n", ports[i]);
}

jack_port_t *port = jack_port_by_name (client, ports[i]);

if (show_port_uuid) {
char buf[JACK_UUID_STRING_SIZE];
jack_uuid_t uuid = jack_port_uuid (port);
jack_uuid_unparse (uuid, buf);
printf (" uuid: %s\n", buf);
}

if (show_aliases) {
int cnt;
@@ -188,16 +220,19 @@ main (int argc, char *argv[])
if (show_con) {
if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
for (j = 0; connections[j]; j++) {
printf (" %s\n", connections[j]);
printf(" ");
if (show_uuid) {
printf_name2uuid(client, connections[j]);
} else {
printf("%s\n", connections[j]);
}
}
free (connections);
jack_free (connections);
}
}
if (show_port_latency) {
if (port) {
jack_latency_range_t range;
printf (" port latency = %" PRIu32 " frames\n",
jack_port_get_latency (port));

jack_port_get_latency_range (port, JackPlaybackLatency, &range);
printf (" port playback latency = [ %" PRIu32 " %" PRIu32 " ] frames\n",
@@ -233,7 +268,6 @@ main (int argc, char *argv[])
if (flags & JackPortIsTerminal) {
fputs ("terminal,", stdout);
}

putc ('\n', stdout);
}
}
@@ -246,7 +280,6 @@ main (int argc, char *argv[])
}
}

error:
if (show_aliases) {
free(aliases[0]);
free(aliases[1]);
@@ -256,4 +289,3 @@ error:
jack_client_close (client);
exit (0);
}


Loading…
Cancel
Save