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.

124 lines
3.2KB

  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. $Id$
  15. */
  16. #include <stdio.h>
  17. #include <errno.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <jack/jack.h>
  22. jack_port_t *input_port;
  23. jack_port_t *output_port;
  24. int connecting, disconnecting;
  25. #define TRUE 1
  26. #define FALSE 0
  27. int
  28. main (int argc, char *argv[])
  29. {
  30. jack_client_t *client;
  31. char *my_name = strrchr(argv[0], '/');
  32. connecting = disconnecting = FALSE;
  33. if (my_name == 0) {
  34. my_name = argv[0];
  35. } else {
  36. my_name ++;
  37. }
  38. if (strstr(my_name, "disconnect")) {
  39. disconnecting = TRUE;
  40. } else
  41. if (strstr(my_name, "connect")) {
  42. connecting = TRUE;
  43. } else {
  44. fprintf(stderr, "ERROR! client should be called jack_connect or jack_disconnect. client is called %s\n", my_name);
  45. return 1;
  46. }
  47. if (argc != 3) {
  48. fprintf (stderr, "usage: %s <src_port> <dst_port>\n", my_name);
  49. fprintf(stderr, "The source port must be an output port of the source client.\n");
  50. fprintf (stderr, "The destination port must be an input port of the destination client.\n");
  51. return 1;
  52. }
  53. /* try to become a client of the JACK server */
  54. if ((client = jack_client_new (my_name)) == 0) {
  55. fprintf (stderr, "jack server not running?\n");
  56. return 1;
  57. }
  58. /* display the current sample rate. once the client is activated
  59. (see below), you should rely on your own sample rate
  60. callback (see above) for this value.
  61. */
  62. printf ("engine sample rate: %" PRIu32 "\n",
  63. jack_get_sample_rate (client));
  64. /* find the two ports */
  65. if ((input_port = jack_port_by_name(client, argv[1])) == 0) {
  66. fprintf (stderr, "ERROR %s not a valid port\n", argv[1]);
  67. return 1;
  68. }
  69. if ((output_port = jack_port_by_name(client, argv[2])) == 0) {
  70. fprintf (stderr, "ERROR %s not a valid port\n", argv[2]);
  71. return 1;
  72. }
  73. /* tell the JACK server that we are ready to roll */
  74. if (jack_activate (client)) {
  75. fprintf (stderr, "cannot activate client");
  76. return 1;
  77. }
  78. /* connect the ports. Note: you can't do this before
  79. the client is activated (this may change in the future).
  80. */
  81. /* jack_port_connect not implemented
  82. if (jack_port_connect(client, input_port, output_port)) {
  83. fprintf (stderr, "cannot connect ports\n");
  84. }
  85. */
  86. if (connecting) {
  87. if (jack_connect(client, jack_port_name(input_port), jack_port_name(output_port))) {
  88. fprintf (stderr, "cannot connect ports\n");
  89. return 1;
  90. }
  91. }
  92. if (disconnecting) {
  93. if (jack_disconnect(client, jack_port_name(input_port), jack_port_name(output_port))) {
  94. fprintf (stderr, "cannot disconnect ports\n");
  95. return 1;
  96. }
  97. }
  98. jack_client_close (client);
  99. exit (0);
  100. }