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.

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