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.

86 lines
1.6KB

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