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.

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