jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
5.1KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #ifndef WIN32
  4. #include <unistd.h>
  5. #endif
  6. #include <string.h>
  7. #include <getopt.h>
  8. #include <jack/jack.h>
  9. char * my_name;
  10. static void
  11. show_version (void)
  12. {
  13. //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
  14. }
  15. static void
  16. show_usage (void)
  17. {
  18. show_version ();
  19. fprintf (stderr, "\nUsage: %s [options] [filter string]\n", my_name);
  20. fprintf (stderr, "List active Jack ports, and optionally display extra information.\n");
  21. fprintf (stderr, "Optionally filter ports which match ALL strings provided after any options.\n\n");
  22. fprintf (stderr, "Display options:\n");
  23. fprintf (stderr, " -A, --aliases List aliases for each port\n");
  24. fprintf (stderr, " -c, --connections List connections to/from each port\n");
  25. fprintf (stderr, " -l, --latency Display per-port latency in frames at each port\n");
  26. fprintf (stderr, " -L, --latency Display total latency in frames at each port\n");
  27. fprintf (stderr, " -p, --properties Display port properties. Output may include:\n"
  28. " input|output, can-monitor, physical, terminal\n\n");
  29. fprintf (stderr, " -t, --type Display port type\n");
  30. fprintf (stderr, " -h, --help Display this help message\n");
  31. fprintf (stderr, " --version Output version information and exit\n\n");
  32. fprintf (stderr, "For more information see http://jackaudio.org/\n");
  33. }
  34. int
  35. main (int argc, char *argv[])
  36. {
  37. jack_client_t *client;
  38. jack_status_t status;
  39. const char **ports, **connections;
  40. unsigned int i, j, k;
  41. int skip_port;
  42. int show_aliases = 0;
  43. int show_con = 0;
  44. int show_port_latency = 0;
  45. int show_total_latency = 0;
  46. int show_properties = 0;
  47. int show_type = 0;
  48. int c;
  49. int option_index;
  50. char* aliases[2];
  51. jack_port_t *port;
  52. struct option long_options[] = {
  53. { "aliases", 0, 0, 'A' },
  54. { "connections", 0, 0, 'c' },
  55. { "port-latency", 0, 0, 'l' },
  56. { "total-latency", 0, 0, 'L' },
  57. { "properties", 0, 0, 'p' },
  58. { "type", 0, 0, 't' },
  59. { "help", 0, 0, 'h' },
  60. { "version", 0, 0, 'v' },
  61. { 0, 0, 0, 0 }
  62. };
  63. my_name = strrchr(argv[0], '/');
  64. if (my_name == 0) {
  65. my_name = argv[0];
  66. } else {
  67. my_name ++;
  68. }
  69. while ((c = getopt_long (argc, argv, "AclLphvt", long_options, &option_index)) >= 0) {
  70. switch (c) {
  71. case 'A':
  72. aliases[0] = (char *) malloc (jack_port_name_size());
  73. aliases[1] = (char *) malloc (jack_port_name_size());
  74. show_aliases = 1;
  75. break;
  76. case 'c':
  77. show_con = 1;
  78. break;
  79. case 'l':
  80. show_port_latency = 1;
  81. break;
  82. case 'L':
  83. show_total_latency = 1;
  84. break;
  85. case 'p':
  86. show_properties = 1;
  87. break;
  88. case 't':
  89. show_type = 1;
  90. break;
  91. case 'h':
  92. show_usage ();
  93. return 1;
  94. break;
  95. case 'v':
  96. show_version ();
  97. return 1;
  98. break;
  99. default:
  100. show_usage ();
  101. return 1;
  102. break;
  103. }
  104. }
  105. /* Open a client connection to the JACK server. Starting a
  106. * new server only to list its ports seems pointless, so we
  107. * specify JackNoStartServer. */
  108. //JOQ: need a new server name option
  109. client = jack_client_open ("lsp", JackNoStartServer, &status);
  110. if (client == NULL) {
  111. if (status & JackServerFailed) {
  112. fprintf (stderr, "JACK server not running\n");
  113. } else {
  114. fprintf (stderr, "jack_client_open() failed, "
  115. "status = 0x%2.0x\n", status);
  116. }
  117. return 1;
  118. }
  119. ports = jack_get_ports (client, NULL, NULL, 0);
  120. for (i = 0; ports[i]; ++i) {
  121. // skip over any that don't match ALL of the strings presented at command line
  122. skip_port = 0;
  123. for(k = optind; k < argc; k++){
  124. if(strstr(ports[i], argv[k]) == NULL ){
  125. skip_port = 1;
  126. }
  127. }
  128. if(skip_port) continue;
  129. printf ("%s\n", ports[i]);
  130. port = jack_port_by_name (client, ports[i]);
  131. if (show_aliases) {
  132. int cnt;
  133. int i;
  134. cnt = jack_port_get_aliases (port, aliases);
  135. for (i = 0; i < cnt; ++i) {
  136. printf (" %s\n", aliases[i]);
  137. }
  138. }
  139. if (show_con) {
  140. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  141. for (j = 0; connections[j]; j++) {
  142. printf (" %s\n", connections[j]);
  143. }
  144. free (connections);
  145. }
  146. }
  147. if (show_port_latency) {
  148. if (port) {
  149. printf (" port latency = %ld frames\n",
  150. jack_port_get_latency (port));
  151. }
  152. }
  153. if (show_total_latency) {
  154. if (port) {
  155. printf (" total latency = %ld frames\n",
  156. jack_port_get_total_latency (client, port));
  157. }
  158. }
  159. if (show_properties) {
  160. if (port) {
  161. int flags = jack_port_flags (port);
  162. printf (" properties: ");
  163. if (flags & JackPortIsInput) {
  164. fputs ("input,", stdout);
  165. }
  166. if (flags & JackPortIsOutput) {
  167. fputs ("output,", stdout);
  168. }
  169. if (flags & JackPortCanMonitor) {
  170. fputs ("can-monitor,", stdout);
  171. }
  172. if (flags & JackPortIsPhysical) {
  173. fputs ("physical,", stdout);
  174. }
  175. if (flags & JackPortIsTerminal) {
  176. fputs ("terminal,", stdout);
  177. }
  178. putc ('\n', stdout);
  179. }
  180. }
  181. if (show_type) {
  182. if (port) {
  183. putc ('\t', stdout);
  184. fputs (jack_port_type (port), stdout);
  185. putc ('\n', stdout);
  186. }
  187. }
  188. }
  189. jack_client_close (client);
  190. exit (0);
  191. }