JACK example clients
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.

118 lines
2.3KB

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