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.

122 lines
3.2KB

  1. #include <stdio.h>
  2. /*
  3. Copyright (C) 2002 Jeremy Hall
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. $Id$
  16. */
  17. #include <errno.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <jack/jack.h>
  21. jack_port_t *input_port;
  22. jack_port_t *output_port;
  23. int connecting, disconnecting;
  24. #define TRUE 1
  25. #define FALSE 0
  26. int
  27. main (int argc, char *argv[])
  28. {
  29. jack_client_t *client;
  30. char *my_name = strrchr(argv[0], '/');
  31. connecting = disconnecting = FALSE;
  32. if (my_name == 0) {
  33. my_name = argv[0];
  34. } else {
  35. my_name ++;
  36. }
  37. if (strstr(my_name, "disconnect")) {
  38. disconnecting = TRUE;
  39. } else
  40. if (strstr(my_name, "connect")) {
  41. connecting = TRUE;
  42. } else {
  43. fprintf(stderr, "ERROR! client should be called jack_connect or jack_disconnect. client is called %s\n", my_name);
  44. return 1;
  45. }
  46. if (argc != 3) {
  47. fprintf (stderr, "usage: %s <src_port> <dst_port>\n", my_name);
  48. fprintf(stderr, "The source port must be an output port of the source client.\n");
  49. fprintf (stderr, "The destination port must be an input port of the destination client.\n");
  50. return 1;
  51. }
  52. /* try to become a client of the JACK server */
  53. if ((client = jack_client_new (my_name)) == 0) {
  54. fprintf (stderr, "jack server not running?\n");
  55. return 1;
  56. }
  57. /* display the current sample rate. once the client is activated
  58. (see below), you should rely on your own sample rate
  59. callback (see above) for this value.
  60. */
  61. printf ("engine sample rate: %lu\n", jack_get_sample_rate (client));
  62. /* find the two ports */
  63. if ((input_port = jack_port_by_name(client, argv[1])) == 0) {
  64. fprintf (stderr, "ERROR %s not a valid port\n", argv[1]);
  65. return 1;
  66. }
  67. if ((output_port = jack_port_by_name(client, argv[2])) == 0) {
  68. fprintf (stderr, "ERROR %s not a valid port\n", argv[2]);
  69. return 1;
  70. }
  71. /* tell the JACK server that we are ready to roll */
  72. if (jack_activate (client)) {
  73. fprintf (stderr, "cannot activate client");
  74. return 1;
  75. }
  76. /* connect the ports. Note: you can't do this before
  77. the client is activated (this may change in the future).
  78. */
  79. /* jack_port_connect not implemented
  80. if (jack_port_connect(client, input_port, output_port)) {
  81. fprintf (stderr, "cannot connect ports\n");
  82. }
  83. */
  84. if (connecting) {
  85. if (jack_connect(client, jack_port_name(input_port), jack_port_name(output_port))) {
  86. fprintf (stderr, "cannot connect ports\n");
  87. return 1;
  88. }
  89. }
  90. if (disconnecting) {
  91. if (jack_disconnect(client, jack_port_name(input_port), jack_port_name(output_port))) {
  92. fprintf (stderr, "cannot disconnect ports\n");
  93. return 1;
  94. }
  95. }
  96. jack_client_close (client);
  97. exit (0);
  98. }