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.

137 lines
3.2KB

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