JACK tools
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.

122 lines
2.4KB

  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] portname alias\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, " -u, --unalias remove `alias' as an alias for `port'\n");
  23. fprintf (stderr, " -h, --help Display this help message\n");
  24. fprintf (stderr, " --version Output version information and exit\n\n");
  25. fprintf (stderr, "For more information see http://jackaudio.org/\n");
  26. }
  27. int
  28. main (int argc, char *argv[])
  29. {
  30. jack_client_t *client;
  31. jack_status_t status;
  32. char* portname;
  33. char* alias;
  34. int unset = 0;
  35. int ret;
  36. int c;
  37. int option_index;
  38. extern int optind;
  39. jack_port_t* port;
  40. struct option long_options[] = {
  41. { "unalias", 0, 0, 'u' },
  42. { "help", 0, 0, 'h' },
  43. { "version", 0, 0, 'v' },
  44. { 0, 0, 0, 0 }
  45. };
  46. if (argc < 3) {
  47. show_usage ();
  48. return 1;
  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, "uhv", long_options, &option_index)) >= 0) {
  57. switch (c) {
  58. case 'u':
  59. unset = 1;
  60. break;
  61. case 'h':
  62. show_usage ();
  63. return 1;
  64. break;
  65. case 'v':
  66. show_version ();
  67. return 1;
  68. break;
  69. default:
  70. show_usage ();
  71. return 1;
  72. break;
  73. }
  74. }
  75. portname = argv[optind++];
  76. alias = argv[optind];
  77. /* Open a client connection to the JACK server. Starting a
  78. * new server only to list its ports seems pointless, so we
  79. * specify JackNoStartServer. */
  80. //JOQ: need a new server name option
  81. client = jack_client_open ("lsp", JackNoStartServer, &status);
  82. if (client == NULL) {
  83. if (status & JackServerFailed) {
  84. fprintf (stderr, "JACK server not running\n");
  85. } else {
  86. fprintf (stderr, "jack_client_open() failed, "
  87. "status = 0x%2.0x\n", status);
  88. }
  89. return 1;
  90. }
  91. if ((port = jack_port_by_name (client, portname)) == 0) {
  92. fprintf (stderr, "No port named \"%s\"\n", portname);
  93. return 1;
  94. }
  95. if (!unset) {
  96. ret = jack_port_set_alias (port, alias);
  97. } else {
  98. ret = jack_port_unset_alias (port, alias);
  99. }
  100. jack_client_close (client);
  101. return ret;
  102. }