jack1 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.

209 lines
5.1KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <getopt.h>
  6. #include <config.h>
  7. #include <jack/jack.h>
  8. char * my_name;
  9. void
  10. show_version (void)
  11. {
  12. fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n",
  13. my_name);
  14. }
  15. 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. struct option long_options[] = {
  52. { "aliases", 0, 0, 'A' },
  53. { "connections", 0, 0, 'c' },
  54. { "port-latency", 0, 0, 'l' },
  55. { "total-latency", 0, 0, 'L' },
  56. { "properties", 0, 0, 'p' },
  57. { "type", 0, 0, 't' },
  58. { "help", 0, 0, 'h' },
  59. { "version", 0, 0, 'v' },
  60. { 0, 0, 0, 0 }
  61. };
  62. my_name = strrchr(argv[0], '/');
  63. if (my_name == 0) {
  64. my_name = argv[0];
  65. } else {
  66. my_name ++;
  67. }
  68. while ((c = getopt_long (argc, argv, "AclLphvt", long_options, &option_index)) >= 0) {
  69. switch (c) {
  70. case 'A':
  71. aliases[0] = (char *) malloc (jack_port_name_size());
  72. aliases[1] = (char *) malloc (jack_port_name_size());
  73. show_aliases = 1;
  74. break;
  75. case 'c':
  76. show_con = 1;
  77. break;
  78. case 'l':
  79. show_port_latency = 1;
  80. break;
  81. case 'L':
  82. show_total_latency = 1;
  83. break;
  84. case 'p':
  85. show_properties = 1;
  86. break;
  87. case 't':
  88. show_type = 1;
  89. break;
  90. case 'h':
  91. show_usage ();
  92. return 1;
  93. break;
  94. case 'v':
  95. show_version ();
  96. return 1;
  97. break;
  98. default:
  99. show_usage ();
  100. return 1;
  101. break;
  102. }
  103. }
  104. /* Open a client connection to the JACK server. Starting a
  105. * new server only to list its ports seems pointless, so we
  106. * specify JackNoStartServer. */
  107. //JOQ: need a new server name option
  108. client = jack_client_open ("lsp", JackNoStartServer, &status);
  109. if (client == NULL) {
  110. if (status & JackServerFailed) {
  111. fprintf (stderr, "JACK server not running\n");
  112. } else {
  113. fprintf (stderr, "jack_client_open() failed, "
  114. "status = 0x%2.0x\n", status);
  115. }
  116. return 1;
  117. }
  118. ports = jack_get_ports (client, NULL, NULL, 0);
  119. for (i = 0; ports[i]; ++i) {
  120. // skip over any that don't match ALL of the strings presented at command line
  121. skip_port = 0;
  122. for(k=optind; k < argc; k++){
  123. if(strstr(ports[i], argv[k]) == NULL ){
  124. skip_port = 1;
  125. }
  126. }
  127. if(skip_port) continue;
  128. printf ("%s\n", ports[i]);
  129. jack_port_t *port = jack_port_by_name (client, ports[i]);
  130. if (show_aliases) {
  131. int cnt;
  132. int i;
  133. cnt = jack_port_get_aliases (port, aliases);
  134. for (i = 0; i < cnt; ++i) {
  135. printf (" %s\n", aliases[i]);
  136. }
  137. }
  138. if (show_con) {
  139. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  140. for (j = 0; connections[j]; j++) {
  141. printf (" %s\n", connections[j]);
  142. }
  143. free (connections);
  144. }
  145. }
  146. if (show_port_latency) {
  147. if (port) {
  148. printf (" port latency = %" PRIu32 " frames\n",
  149. jack_port_get_latency (port));
  150. }
  151. }
  152. if (show_total_latency) {
  153. if (port) {
  154. printf (" total latency = %" PRIu32 " frames\n",
  155. jack_port_get_total_latency (client, port));
  156. }
  157. }
  158. if (show_properties) {
  159. if (port) {
  160. int flags = jack_port_flags (port);
  161. printf (" properties: ");
  162. if (flags & JackPortIsInput) {
  163. fputs ("input,", stdout);
  164. }
  165. if (flags & JackPortIsOutput) {
  166. fputs ("output,", stdout);
  167. }
  168. if (flags & JackPortCanMonitor) {
  169. fputs ("can-monitor,", stdout);
  170. }
  171. if (flags & JackPortIsPhysical) {
  172. fputs ("physical,", stdout);
  173. }
  174. if (flags & JackPortIsTerminal) {
  175. fputs ("terminal,", stdout);
  176. }
  177. putc ('\n', stdout);
  178. }
  179. }
  180. if (show_type) {
  181. if (port) {
  182. putc ('\t', stdout);
  183. fputs (jack_port_type (port), stdout);
  184. putc ('\n', stdout);
  185. }
  186. }
  187. }
  188. jack_client_close (client);
  189. exit (0);
  190. }