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.

99 lines
1.8KB

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