jack1 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.

175 lines
4.6KB

  1. /*
  2. Copyright (C) 2002 Jeremy Hall
  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 <errno.h>
  17. #include <unistd.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #include <getopt.h>
  21. #include <config.h>
  22. #include <jack/jack.h>
  23. jack_port_t *input_port;
  24. jack_port_t *output_port;
  25. int connecting, disconnecting;
  26. #define TRUE 1
  27. #define FALSE 0
  28. void
  29. show_version (char *my_name)
  30. {
  31. fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
  32. }
  33. void
  34. show_usage (char *my_name)
  35. {
  36. show_version (my_name);
  37. fprintf (stderr, "\nusage: %s [options] <src_port> <dst_port>\n", my_name);
  38. fprintf (stderr, "Connects two JACK ports together.\n\n");
  39. fprintf (stderr, " The source port must be an output port of the source client.\n");
  40. fprintf (stderr, " The destination port must be an input port of the destination client.\n");
  41. fprintf (stderr, " -s, --server <name> Connect to the jack server named <name>\n");
  42. fprintf (stderr, " -v, --version Output version information and exit\n");
  43. fprintf (stderr, " -h, --help Display this help message\n\n");
  44. fprintf (stderr, "For more information see http://jackaudio.org/\n");
  45. }
  46. int
  47. main (int argc, char *argv[])
  48. {
  49. jack_client_t *client;
  50. jack_status_t status;
  51. char *server_name = NULL;
  52. int c;
  53. int option_index;
  54. jack_options_t options = JackNoStartServer;
  55. char *my_name = strrchr(argv[0], '/');
  56. struct option long_options[] = {
  57. { "server", 1, 0, 's' },
  58. { "help", 0, 0, 'h' },
  59. { "version", 0, 0, 'v' },
  60. { 0, 0, 0, 0 }
  61. };
  62. while ((c = getopt_long (argc, argv, "s:AclLphvt", long_options, &option_index)) >= 0) {
  63. switch (c) {
  64. case 's':
  65. server_name = (char *) malloc (sizeof (char) * strlen(optarg));
  66. strcpy (server_name, optarg);
  67. options |= JackServerName;
  68. break;
  69. case 'h':
  70. show_usage (my_name);
  71. return 1;
  72. break;
  73. case 'v':
  74. show_version (my_name);
  75. return 1;
  76. break;
  77. default:
  78. show_usage (my_name);
  79. return 1;
  80. break;
  81. }
  82. }
  83. connecting = disconnecting = FALSE;
  84. if (my_name == 0) {
  85. my_name = argv[0];
  86. } else {
  87. my_name ++;
  88. }
  89. if (strstr(my_name, "disconnect")) {
  90. disconnecting = TRUE;
  91. } else
  92. if (strstr(my_name, "connect")) {
  93. connecting = TRUE;
  94. } else {
  95. fprintf(stderr, "ERROR! client should be called jack_connect or jack_disconnect. client is called %s\n", my_name);
  96. return 1;
  97. }
  98. if (argc < 3) show_usage(my_name);
  99. /* try to become a client of the JACK server */
  100. if ((client = jack_client_open (my_name, options, &status, server_name)) == 0) {
  101. fprintf (stderr, "jack server not running?\n");
  102. return 1;
  103. }
  104. /* display the current sample rate. once the client is activated
  105. (see below), you should rely on your own sample rate
  106. callback (see above) for this value.
  107. */
  108. printf ("engine sample rate: %" PRIu32 "\n",
  109. jack_get_sample_rate (client));
  110. /* find the two ports */
  111. if ((input_port = jack_port_by_name(client, argv[argc-1])) == 0) {
  112. fprintf (stderr, "ERROR %s not a valid port\n", argv[argc-1]);
  113. return 1;
  114. }
  115. if ((output_port = jack_port_by_name(client, argv[argc-2])) == 0) {
  116. fprintf (stderr, "ERROR %s not a valid port\n", argv[argc-2]);
  117. return 1;
  118. }
  119. /* tell the JACK server that we are ready to roll */
  120. if (jack_activate (client)) {
  121. fprintf (stderr, "cannot activate client");
  122. return 1;
  123. }
  124. /* connect the ports. Note: you can't do this before
  125. the client is activated (this may change in the future).
  126. */
  127. /* jack_port_connect not implemented
  128. if (jack_port_connect(client, input_port, output_port)) {
  129. fprintf (stderr, "cannot connect ports\n");
  130. }
  131. */
  132. if (connecting) {
  133. if (jack_connect(client, jack_port_name(input_port), jack_port_name(output_port))) {
  134. fprintf (stderr, "cannot connect ports\n");
  135. return 1;
  136. }
  137. }
  138. if (disconnecting) {
  139. if (jack_disconnect(client, jack_port_name(input_port), jack_port_name(output_port))) {
  140. fprintf (stderr, "cannot disconnect ports\n");
  141. return 1;
  142. }
  143. }
  144. jack_client_close (client);
  145. exit (0);
  146. }