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.

87 lines
1.6KB

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5. #include <stdlib.h>
  6. #include <jack/jack.h>
  7. #include <jack/transport.h>
  8. jack_client_t *client;
  9. jack_transport_info_t now;
  10. void
  11. showtime ()
  12. {
  13. jack_transport_info_t current = now;
  14. printf ("frame: %lu state: %d loop: %lu-%lu\n", current.position, current.state, current.loop_start, current.loop_end);
  15. }
  16. int
  17. process (jack_nframes_t nframes, void *arg)
  18. {
  19. now.valid = JackTransportState|JackTransportPosition|JackTransportLoop;
  20. jack_get_transport_info (client, &now);
  21. return 0;
  22. }
  23. void
  24. jack_shutdown (void *arg)
  25. {
  26. exit (1);
  27. }
  28. void
  29. signal_handler (int sig)
  30. {
  31. fprintf (stderr, "signal received, exiting ...\n");
  32. jack_client_close (client);
  33. exit (0);
  34. }
  35. int
  36. main (int argc, char *argv[])
  37. {
  38. /* try to become a client of the JACK server */
  39. if ((client = jack_client_new ("showtime")) == 0) {
  40. fprintf (stderr, "jack server not running?\n");
  41. return 1;
  42. }
  43. signal (SIGQUIT, signal_handler);
  44. signal (SIGTERM, signal_handler);
  45. signal (SIGHUP, signal_handler);
  46. signal (SIGINT, signal_handler);
  47. /* tell the JACK server to call `process()' whenever
  48. there is work to be done.
  49. */
  50. jack_set_process_callback (client, process, 0);
  51. /* tell the JACK server to call `jack_shutdown()' if
  52. it ever shuts down, either entirely, or if it
  53. just decides to stop calling us.
  54. */
  55. jack_on_shutdown (client, jack_shutdown, 0);
  56. /* tell the JACK server that we are ready to roll */
  57. if (jack_activate (client)) {
  58. fprintf (stderr, "cannot activate client");
  59. return 1;
  60. }
  61. while (1) {
  62. usleep (100000);
  63. showtime ();
  64. }
  65. jack_client_close (client);
  66. exit (0);
  67. }