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.

156 lines
3.9KB

  1. /*
  2. * smaplerate.c -- get current samplerate
  3. *
  4. * Copyright (C) 2003 Jack O'Quin.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <unistd.h>
  23. #include <signal.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <jack/jack.h>
  27. #include <jack/transport.h>
  28. char *package; /* program name */
  29. jack_client_t *client;
  30. jack_session_event_t notify_type;
  31. char *save_path = NULL;
  32. void jack_shutdown(void *arg)
  33. {
  34. fprintf(stderr, "JACK shut down, exiting ...\n");
  35. exit(1);
  36. }
  37. void signal_handler(int sig)
  38. {
  39. jack_client_close(client);
  40. fprintf(stderr, "signal received, exiting ...\n");
  41. exit(0);
  42. }
  43. void parse_arguments(int argc, char *argv[])
  44. {
  45. /* basename $0 */
  46. package = strrchr(argv[0], '/');
  47. if (package == 0)
  48. package = argv[0];
  49. else
  50. package++;
  51. if (argc==2) {
  52. if( !strcmp( argv[1], "quit" ) ) {
  53. notify_type = JackSessionQuit;
  54. return;
  55. }
  56. }
  57. if (argc==3) {
  58. if( !strcmp( argv[1], "save" ) ) {
  59. notify_type = JackSessionSave;
  60. save_path = argv[2];
  61. return;
  62. }
  63. }
  64. fprintf(stderr, "usage: %s quit|save [path]\n", package);
  65. exit(9);
  66. }
  67. int main(int argc, char *argv[])
  68. {
  69. parse_arguments(argc, argv);
  70. struct session_command *retval;
  71. int i,j;
  72. /* become a JACK client */
  73. if ((client = jack_client_new(package)) == 0) {
  74. fprintf(stderr, "JACK server not running?\n");
  75. exit(1);
  76. }
  77. signal(SIGQUIT, signal_handler);
  78. signal(SIGTERM, signal_handler);
  79. signal(SIGHUP, signal_handler);
  80. signal(SIGINT, signal_handler);
  81. jack_on_shutdown(client, jack_shutdown, 0);
  82. retval = jack_session_notify( client, notify_type, save_path );
  83. for(i=0; retval[i].uid != 0; i++ ) {
  84. printf( "%s &\n", retval[i].command );
  85. }
  86. for(i=0; retval[i].uid != 0; i++ ) {
  87. char uidstring[16];
  88. char *info_cookie;
  89. snprintf( uidstring, sizeof(uidstring), "%d", retval[i].uid );
  90. info_cookie = jack_get_cookie_by_uuid( client, uidstring, "info" );
  91. if( info_cookie ) {
  92. printf( "info cookie: %s\n", info_cookie );
  93. jack_free( info_cookie );
  94. }
  95. info_cookie = jack_get_cookie_by_uuid( client, uidstring, "info2" );
  96. if( info_cookie ) {
  97. printf( "info2 cookie: %s\n", info_cookie );
  98. jack_free( info_cookie );
  99. }
  100. info_cookie = jack_get_cookie_by_uuid( client, uidstring, "unset" );
  101. if( info_cookie ) {
  102. printf( "info2 cookie: %s\n", info_cookie );
  103. jack_free( info_cookie );
  104. } else {
  105. printf( "notset cookie not set\n" );
  106. }
  107. char* port_regexp = alloca( jack_client_name_size()+3 );
  108. char* client_name = jack_get_client_name_by_uuid( client, uidstring );
  109. printf( "client by uuid(%d) %s\n", retval[i].uid, client_name );
  110. snprintf( port_regexp, jack_client_name_size()+3, "%s", client_name );
  111. printf( "port_regexp: %s\n", port_regexp );
  112. jack_free(client_name);
  113. const char **ports = jack_get_ports( client, port_regexp, NULL, 0 );
  114. if( !ports )
  115. continue;
  116. for (i = 0; ports[i]; ++i) {
  117. printf( "port: %s\n", ports[i] );
  118. const char **connections;
  119. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  120. for (j = 0; connections[j]; j++) {
  121. printf( "jack_connect %s %s\n", ports[i], connections[j] );
  122. }
  123. jack_free (connections);
  124. }
  125. }
  126. jack_free(ports);
  127. }
  128. free(retval);
  129. jack_client_close(client);
  130. return 0;
  131. }