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.

224 lines
5.7KB

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