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.

135 lines
3.1KB

  1. /*
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <unistd.h>
  17. #include <string.h>
  18. #include <getopt.h>
  19. #include <jack/jack.h>
  20. //#include <config.h>
  21. char * my_name;
  22. void
  23. show_version (void)
  24. {
  25. //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
  26. }
  27. void
  28. show_usage (void)
  29. {
  30. show_version ();
  31. fprintf (stderr, "\nUsage: %s [options] portname alias\n", my_name);
  32. fprintf (stderr, "List active Jack ports, and optionally display extra information.\n\n");
  33. fprintf (stderr, "Display options:\n");
  34. fprintf (stderr, " -u, --unalias remove `alias' as an alias for `port'\n");
  35. fprintf (stderr, " -h, --help Display this help message\n");
  36. fprintf (stderr, " --version Output version information and exit\n\n");
  37. fprintf (stderr, "For more information see http://jackaudio.org/\n");
  38. }
  39. int
  40. main (int argc, char *argv[])
  41. {
  42. jack_client_t *client;
  43. jack_status_t status;
  44. char* portname;
  45. char* alias;
  46. int unset = 0;
  47. int ret;
  48. int c;
  49. int option_index;
  50. extern int optind;
  51. jack_port_t* port;
  52. struct option long_options[] = {
  53. { "unalias", 0, 0, 'u' },
  54. { "help", 0, 0, 'h' },
  55. { "version", 0, 0, 'v' },
  56. { 0, 0, 0, 0 }
  57. };
  58. if (argc < 3) {
  59. show_usage ();
  60. return 1;
  61. }
  62. my_name = strrchr(argv[0], '/');
  63. if (my_name == 0) {
  64. my_name = argv[0];
  65. } else {
  66. my_name ++;
  67. }
  68. while ((c = getopt_long (argc, argv, "uhv", long_options, &option_index)) >= 0) {
  69. switch (c) {
  70. case 'u':
  71. unset = 1;
  72. break;
  73. case 'h':
  74. show_usage ();
  75. return 1;
  76. break;
  77. case 'v':
  78. show_version ();
  79. return 1;
  80. break;
  81. default:
  82. show_usage ();
  83. return 1;
  84. break;
  85. }
  86. }
  87. portname = argv[optind++];
  88. alias = argv[optind];
  89. /* Open a client connection to the JACK server. Starting a
  90. * new server only to list its ports seems pointless, so we
  91. * specify JackNoStartServer. */
  92. //JOQ: need a new server name option
  93. client = jack_client_open ("lsp", JackNoStartServer, &status);
  94. if (client == NULL) {
  95. if (status & JackServerFailed) {
  96. fprintf (stderr, "JACK server not running\n");
  97. } else {
  98. fprintf (stderr, "jack_client_open() failed, "
  99. "status = 0x%2.0x\n", status);
  100. }
  101. return 1;
  102. }
  103. if ((port = jack_port_by_name (client, portname)) == 0) {
  104. fprintf (stderr, "No port named \"%s\"\n", portname);
  105. return 1;
  106. }
  107. if (!unset) {
  108. ret = jack_port_set_alias (port, alias);
  109. } else {
  110. ret = jack_port_unset_alias (port, alias);
  111. }
  112. jack_client_close (client);
  113. return ret;
  114. }