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.

179 lines
4.3KB

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