/** returns the number of frames of latency assigned to this port */ void Port::get_latency ( direction_e dir, nframes_t *min, nframes_t *max ) const { #ifdef HAVE_JACK_PORT_GET_LATENCY_RANGE jack_latency_range_t range; jack_port_get_latency_range( _port, dir == Output ? JackPlaybackLatency : JackCaptureLatency, &range ); *min = range.min; *max = range.max; #else *min = *max = jack_port_get_latency( _port ); #endif }
/***************************************************************************** * * JACK_START() * * Start jack client and attach to playback ports. * *****************************************************************************/ int jack_start(void) { const char **ports; char *p; char *q; int j; /* activate client (callbacks start, so everything else needs to be ready) */ if (jack_activate (client)) { fprintf (stderr, "Unable to activate JACK client.\n"); jack_client_close (client); jack_running = 0; jack_thread_p = 0; client = NULL; return 1; } /* all up and running now */ jack_running = 1; jack_thread_p = jack_client_thread_id (client); /* connect ports. in/out is from server perspective */ /* By default, connect PHASEX output to first two JACK hardware playback ports found */ if (setting_jack_autoconnect) { ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); if ((ports == NULL) || (ports[0] == NULL)) { fprintf (stderr, "Warning: PHASEX output not connected!\n"); fprintf (stderr, " (No physical JACK playback ports available.)\n"); } else { if (jack_connect (client, jack_port_name (output_port1), ports[0])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } if (jack_connect (client, jack_port_name (output_port2), ports[1])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } } } /* otherwise, connect to ports that match -o command line flag */ else { ports = jack_get_ports (client, NULL, NULL, JackPortIsInput); if ((ports == NULL) || (ports[0] == NULL)) { fprintf (stderr, "Warning: PHASEX output not connected!\n"); fprintf (stderr, " (No JACK playback ports available.)\n"); } else { p = jack_outputs; if (p != NULL) { if ((q = index (p, ',')) != NULL) { *q = '\0'; q++; } else { q = p; } for (j = 0; ports[j] != NULL; j++) { if (strstr (ports[j], p) != NULL) { if (jack_connect (client, jack_port_name (output_port1), ports[j])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } else if (debug) { fprintf (stderr, "JACK connected PHASEX out_1 to %s.\n", ports[j]); } p = "_no_port_"; } if (strstr (ports[j], q) != NULL) { if (jack_connect (client, jack_port_name (output_port2), ports[j])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } else if (debug) { fprintf (stderr, "JACK connected PHASEX out_2 to %s.\n", ports[j]); } q = "_no_port_"; } } if (p != q) { q--; *q = ','; } } } } free (ports); /* By default, connect PHASEX input to first two JACK hardware capture ports found */ if (setting_jack_autoconnect) { ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsOutput); if ((ports == NULL) || (ports[0] == NULL) || (ports[1] == NULL)) { fprintf (stderr, "Warning: PHASEX input not connected!\n"); fprintf (stderr, " (No physical JACK capture ports available.)\n"); } else { if (jack_connect (client, ports[0], jack_port_name (input_port1))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } if (jack_connect (client, ports[1], jack_port_name (input_port2))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } } } /* otherwise, connect to ports that match -i command line flag */ else { ports = jack_get_ports (client, NULL, NULL, JackPortIsOutput); if ((ports == NULL) || (ports[0] == NULL) || (ports[1] == NULL)) { fprintf (stderr, "Warning: PHASEX input not connected!\n"); fprintf (stderr, " (No JACK capture ports available.)\n"); } else { p = jack_inputs; if (p != NULL) { if ((q = index (p, ',')) != NULL) { *q = '\0'; q++; } else { q = p; } for (j = 0; ports[j] != NULL; j++) { if (strstr (ports[j], p) != NULL) { if (jack_connect (client, ports[j], jack_port_name (input_port1))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } else if (debug) { fprintf (stderr, "JACK connected %s to PHASEX in_1.\n", ports[j]); } p = "_no_port_"; } if (strstr (ports[j], q) != NULL) { if (jack_connect (client, ports[j], jack_port_name (input_port2))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } else if (debug) { fprintf (stderr, "JACK connected %s to PHASEX in_2.\n", ports[j]); } q = "_no_port_"; } } } } } free (ports); /* report latency and total latency */ if (debug) { fprintf (stderr, "JACK latency: %d\n", jack_port_get_latency (output_port1)); fprintf (stderr, "JACK total latency: %d\n", jack_port_get_total_latency (client, output_port1)); } return 0; }
int main (int argc, char *argv[]) { jack_client_t *client; jack_status_t status; jack_options_t options = JackNoStartServer; const char **ports, **connections; unsigned int i, j, k; int skip_port; int show_aliases = 0; int show_con = 0; int show_port_latency = 0; int show_total_latency = 0; int show_properties = 0; int show_type = 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' }, { "aliases", 0, 0, 'A' }, { "connections", 0, 0, 'c' }, { "port-latency", 0, 0, 'l' }, { "total-latency", 0, 0, 'L' }, { "properties", 0, 0, 'p' }, { "type", 0, 0, 't' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 } }; my_name = strrchr(argv[0], '/'); if (my_name == 0) { my_name = argv[0]; } else { my_name ++; } while ((c = getopt_long (argc, argv, "s:AclLphvt", long_options, &option_index)) >= 0) { switch (c) { case 's': server_name = (char *) malloc (sizeof (char) * strlen(optarg)); strcpy (server_name, optarg); options |= JackServerName; break; case 'A': aliases[0] = (char *) malloc (jack_port_name_size()); aliases[1] = (char *) malloc (jack_port_name_size()); show_aliases = 1; break; case 'c': show_con = 1; break; case 'l': show_port_latency = 1; break; case 'L': show_total_latency = 1; break; case 'p': show_properties = 1; break; case 't': show_type = 1; break; case 'h': show_usage (); return 1; break; case 'v': show_version (); return 1; break; default: show_usage (); return 1; break; } } /* 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 client = jack_client_open ("lsp", options, &status, server_name); if (client == NULL) { if (status & JackServerFailed) { fprintf (stderr, "JACK server not running\n"); } else { fprintf (stderr, "jack_client_open() failed, " "status = 0x%2.0x\n", status); } return 1; } 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 ){ skip_port = 1; } } if (skip_port) continue; printf ("%s\n", ports[i]); port = jack_port_by_name (client, ports[i]); if (show_aliases) { int cnt; int i; cnt = jack_port_get_aliases (port, aliases); for (i = 0; i < cnt; ++i) { printf (" %s\n", aliases[i]); } } 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]); } 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", range.min, range.max); jack_port_get_latency_range (port, JackCaptureLatency, &range); printf (" port capture latency = [ %" PRIu32 " %" PRIu32 " ] frames\n", range.min, range.max); } } if (show_total_latency) { if (port) { printf (" total latency = %d frames\n", jack_port_get_total_latency (client, port)); } } if (show_properties) { if (port) { int flags = jack_port_flags (port); printf (" properties: "); if (flags & JackPortIsInput) { fputs ("input,", stdout); } if (flags & JackPortIsOutput) { fputs ("output,", stdout); } if (flags & JackPortCanMonitor) { fputs ("can-monitor,", stdout); } if (flags & JackPortIsPhysical) { fputs ("physical,", stdout); } if (flags & JackPortIsTerminal) { fputs ("terminal,", stdout); } putc ('\n', stdout); } } if (show_type) { if (port) { putc ('\t', stdout); fputs (jack_port_type (port), stdout); putc ('\n', stdout); } } } error: if (show_aliases) { free(aliases[0]); free(aliases[1]); } if (ports) jack_free (ports); jack_client_close (client); exit (0); }