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.

92 lines
1.7KB

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