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.

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