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.

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