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.

198 lines
4.7KB

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