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.

143 lines
3.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 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. const char **ports, **connections;
  35. unsigned int i, j;
  36. int show_con = 0;
  37. int show_latency = 0;
  38. int show_properties = 0;
  39. int c;
  40. int option_index;
  41. struct option long_options[] = {
  42. { "connections", 0, 0, 'c' },
  43. { "latency", 0, 0, 'l' },
  44. { "properties", 0, 0, 'p' },
  45. { "help", 0, 0, 'h' },
  46. { "version", 0, 0, 'v' },
  47. { 0, 0, 0, 0 }
  48. };
  49. my_name = strrchr(argv[0], '/');
  50. if (my_name == 0) {
  51. my_name = argv[0];
  52. } else {
  53. my_name ++;
  54. }
  55. while ((c = getopt_long (argc, argv, "clphv", long_options, &option_index)) >= 0) {
  56. switch (c) {
  57. case 'c':
  58. show_con = 1;
  59. break;
  60. case 'l':
  61. show_latency = 1;
  62. break;
  63. case 'p':
  64. show_properties = 1;
  65. break;
  66. case 'h':
  67. show_usage ();
  68. return 1;
  69. break;
  70. case 'v':
  71. show_version ();
  72. return 1;
  73. break;
  74. default:
  75. show_usage ();
  76. return 1;
  77. break;
  78. }
  79. }
  80. /* try to become a client of the JACK server */
  81. if ((client = jack_client_new ("lsp")) == 0) {
  82. fprintf (stderr, "jack server not running?\n");
  83. return 1;
  84. }
  85. ports = jack_get_ports (client, NULL, NULL, 0);
  86. for (i = 0; ports[i]; ++i) {
  87. printf ("%s\n", ports[i]);
  88. if (show_con) {
  89. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  90. for (j = 0; connections[j]; j++) {
  91. printf (" %s\n", connections[j]);
  92. }
  93. free (connections);
  94. }
  95. }
  96. if (show_latency) {
  97. jack_port_t *port = jack_port_by_name (client, ports[i]);
  98. if (port) {
  99. printf (" latency = %lu frames\n", jack_port_get_total_latency (client, port));
  100. free (port);
  101. }
  102. }
  103. if (show_properties) {
  104. jack_port_t *port = jack_port_by_name (client, ports[i]);
  105. if (port) {
  106. int flags = jack_port_flags (port);
  107. printf (" properties: ");
  108. if (flags & JackPortIsInput) {
  109. fputs ("input,", stdout);
  110. }
  111. if (flags & JackPortIsOutput) {
  112. fputs ("output,", stdout);
  113. }
  114. if (flags & JackPortCanMonitor) {
  115. fputs ("can-monitor,", stdout);
  116. }
  117. if (flags & JackPortIsPhysical) {
  118. fputs ("physical,", stdout);
  119. }
  120. if (flags & JackPortIsTerminal) {
  121. fputs ("terminal,", stdout);
  122. }
  123. putc ('\n', stdout);
  124. }
  125. }
  126. }
  127. jack_client_close (client);
  128. exit (0);
  129. }