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.

179 lines
4.3KB

  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. void
  11. show_version (void)
  12. {
  13. //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n",
  14. //my_name);
  15. }
  16. void
  17. show_usage (void)
  18. {
  19. show_version ();
  20. fprintf (stderr, "\nUsage: %s [options]\n", my_name);
  21. fprintf (stderr, "List active Jack ports, and optionally display extra information.\n\n");
  22. fprintf (stderr, "Display options:\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://jackit.sourceforge.net/\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_con = 0;
  41. int show_port_latency = 0;
  42. int show_total_latency = 0;
  43. int show_properties = 0;
  44. int show_type = 0;
  45. int c;
  46. int option_index;
  47. jack_port_t *port;
  48. struct option long_options[] = {
  49. { "connections", 0, 0, 'c' },
  50. { "port-latency", 0, 0, 'l' },
  51. { "total-latency", 0, 0, 'L' },
  52. { "properties", 0, 0, 'p' },
  53. { "type", 0, 0, 't' },
  54. { "help", 0, 0, 'h' },
  55. { "version", 0, 0, 'v' },
  56. { 0, 0, 0, 0 }
  57. };
  58. my_name = strrchr(argv[0], '/');
  59. if (my_name == 0) {
  60. my_name = argv[0];
  61. } else {
  62. my_name ++;
  63. }
  64. while ((c = getopt_long (argc, argv, "clLphvt", long_options, &option_index)) >= 0) {
  65. switch (c) {
  66. case 'c':
  67. show_con = 1;
  68. break;
  69. case 'l':
  70. show_port_latency = 1;
  71. break;
  72. case 'L':
  73. show_total_latency = 1;
  74. break;
  75. case 'p':
  76. show_properties = 1;
  77. break;
  78. case 't':
  79. show_type = 1;
  80. break;
  81. case 'h':
  82. show_usage ();
  83. return 1;
  84. break;
  85. case 'v':
  86. show_version ();
  87. return 1;
  88. break;
  89. default:
  90. show_usage ();
  91. return 1;
  92. break;
  93. }
  94. }
  95. /* Open a client connection to the JACK server. Starting a
  96. * new server only to list its ports seems pointless, so we
  97. * specify JackNoStartServer. */
  98. //JOQ: need a new server name option
  99. client = jack_client_open ("lsp", JackNoStartServer, &status);
  100. if (client == NULL) {
  101. if (status & JackServerFailed) {
  102. fprintf (stderr, "JACK server not running\n");
  103. } else {
  104. fprintf (stderr, "jack_client_open() failed, "
  105. "status = 0x%2.0x\n", status);
  106. }
  107. return 1;
  108. }
  109. ports = jack_get_ports (client, NULL, NULL, 0);
  110. for (i = 0; ports[i]; ++i) {
  111. printf ("%s\n", ports[i]);
  112. port = jack_port_by_name (client, ports[i]);
  113. if (show_con) {
  114. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  115. for (j = 0; connections[j]; j++) {
  116. printf (" %s\n", connections[j]);
  117. }
  118. free (connections);
  119. }
  120. }
  121. if (show_port_latency) {
  122. if (port) {
  123. printf (" port latency = %ld frames\n",
  124. jack_port_get_latency (port));
  125. }
  126. }
  127. if (show_total_latency) {
  128. if (port) {
  129. printf (" total latency = %ld frames\n",
  130. jack_port_get_total_latency (client, port));
  131. }
  132. }
  133. if (show_properties) {
  134. if (port) {
  135. int flags = jack_port_flags (port);
  136. printf (" properties: ");
  137. if (flags & JackPortIsInput) {
  138. fputs ("input,", stdout);
  139. }
  140. if (flags & JackPortIsOutput) {
  141. fputs ("output,", stdout);
  142. }
  143. if (flags & JackPortCanMonitor) {
  144. fputs ("can-monitor,", stdout);
  145. }
  146. if (flags & JackPortIsPhysical) {
  147. fputs ("physical,", stdout);
  148. }
  149. if (flags & JackPortIsTerminal) {
  150. fputs ("terminal,", stdout);
  151. }
  152. putc ('\n', stdout);
  153. }
  154. }
  155. if (show_type) {
  156. if (port) {
  157. putc ('\t', stdout);
  158. fputs (jack_port_type (port), stdout);
  159. putc ('\n', stdout);
  160. }
  161. }
  162. }
  163. jack_client_close (client);
  164. exit (0);
  165. }