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.

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