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.

144 lines
3.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 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, " -h, --help Display this help message\n");
  28. fprintf (stderr, " --version Output version information and exit\n\n");
  29. fprintf (stderr, "For more information see http://jackit.sourceforge.net/\n");
  30. }
  31. int
  32. main (int argc, char *argv[])
  33. {
  34. jack_client_t *client;
  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. /* try to become a client of the JACK server */
  82. if ((client = jack_client_new ("lsp")) == 0) {
  83. fprintf (stderr, "jack server not running?\n");
  84. return 1;
  85. }
  86. ports = jack_get_ports (client, NULL, NULL, 0);
  87. for (i = 0; ports[i]; ++i) {
  88. printf ("%s\n", ports[i]);
  89. if (show_con) {
  90. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  91. for (j = 0; connections[j]; j++) {
  92. printf (" %s\n", connections[j]);
  93. }
  94. free (connections);
  95. }
  96. }
  97. if (show_latency) {
  98. jack_port_t *port = jack_port_by_name (client, ports[i]);
  99. if (port) {
  100. // printf (" latency = %" PRIu32 " frames\n",
  101. // jack_port_get_total_latency (client, port));
  102. free (port);
  103. }
  104. }
  105. if (show_properties) {
  106. jack_port_t *port = jack_port_by_name (client, ports[i]);
  107. if (port) {
  108. int flags = jack_port_flags (port);
  109. printf (" properties: ");
  110. if (flags & JackPortIsInput) {
  111. fputs ("input,", stdout);
  112. }
  113. if (flags & JackPortIsOutput) {
  114. fputs ("output,", stdout);
  115. }
  116. if (flags & JackPortCanMonitor) {
  117. fputs ("can-monitor,", stdout);
  118. }
  119. if (flags & JackPortIsPhysical) {
  120. fputs ("physical,", stdout);
  121. }
  122. if (flags & JackPortIsTerminal) {
  123. fputs ("terminal,", stdout);
  124. }
  125. putc ('\n', stdout);
  126. }
  127. }
  128. }
  129. jack_client_close (client);
  130. exit (0);
  131. }