jack2 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.

101 lines
2.0KB

  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. void
  10. showtime ()
  11. {
  12. jack_position_t current;
  13. jack_transport_state_t transport_state;
  14. jack_nframes_t frame_time;
  15. transport_state = jack_transport_query (client, &current);
  16. frame_time = jack_frame_time (client);
  17. //printf ("frame: %7" PRIu32 " @ %" PRIu32 "\t", current.frame, frame_time);
  18. printf ("frame = %ld frame_time = %ld usecs = %lld \t", current.frame, frame_time, current.usecs);
  19. switch (transport_state) {
  20. case JackTransportStopped:
  21. printf ("state: Stopped");
  22. break;
  23. case JackTransportRolling:
  24. printf ("state: Rolling");
  25. break;
  26. case JackTransportStarting:
  27. printf ("state: Starting");
  28. break;
  29. default:
  30. printf ("state: [unknown]");
  31. }
  32. if (current.valid & JackPositionBBT)
  33. printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
  34. PRIi32, current.bar, current.beat, current.tick);
  35. if (current.valid & JackPositionTimecode)
  36. printf ("\tTC: (%.6f, %.6f)",
  37. current.frame_time, current.next_time);
  38. printf ("\n");
  39. }
  40. void
  41. jack_shutdown (void *arg)
  42. {
  43. exit (1);
  44. }
  45. void
  46. signal_handler (int sig)
  47. {
  48. jack_client_close (client);
  49. fprintf (stderr, "signal received, exiting ...\n");
  50. exit (0);
  51. }
  52. int
  53. main (int argc, char *argv[])
  54. {
  55. /* try to become a client of the JACK server */
  56. if ((client = jack_client_new ("showtime")) == 0) {
  57. fprintf (stderr, "jack server not running?\n");
  58. return 1;
  59. }
  60. signal (SIGQUIT, signal_handler);
  61. signal (SIGTERM, signal_handler);
  62. signal (SIGHUP, signal_handler);
  63. signal (SIGINT, signal_handler);
  64. /* tell the JACK server to call `jack_shutdown()' if
  65. it ever shuts down, either entirely, or if it
  66. just decides to stop calling us.
  67. */
  68. jack_on_shutdown (client, jack_shutdown, 0);
  69. /* tell the JACK server that we are ready to roll */
  70. if (jack_activate (client)) {
  71. fprintf (stderr, "cannot activate client");
  72. return 1;
  73. }
  74. while (1) {
  75. usleep (20);
  76. showtime ();
  77. }
  78. jack_client_close (client);
  79. exit (0);
  80. }