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.

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