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