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.

124 lines
3.3KB

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