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.

120 lines
2.8KB

  1. /*
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. */
  14. #include <stdio.h>
  15. #include <errno.h>
  16. #include <unistd.h>
  17. #include <signal.h>
  18. #include <stdlib.h>
  19. #include <inttypes.h>
  20. #include <jack/jack.h>
  21. #include <jack/transport.h>
  22. jack_client_t *client;
  23. static void
  24. showtime ()
  25. {
  26. jack_position_t current;
  27. jack_transport_state_t transport_state;
  28. jack_nframes_t frame_time;
  29. transport_state = jack_transport_query (client, &current);
  30. frame_time = jack_frame_time (client);
  31. printf ("frame = %u frame_time = %u usecs = %lld \t", current.frame, frame_time, current.usecs);
  32. switch (transport_state) {
  33. case JackTransportStopped:
  34. printf ("state: Stopped");
  35. break;
  36. case JackTransportRolling:
  37. printf ("state: Rolling");
  38. break;
  39. case JackTransportStarting:
  40. printf ("state: Starting");
  41. break;
  42. default:
  43. printf ("state: [unknown]");
  44. }
  45. if (current.valid & JackPositionBBT)
  46. printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
  47. PRIi32, current.bar, current.beat, current.tick);
  48. if (current.valid & JackPositionTimecode)
  49. printf ("\tTC: (%.6f, %.6f)",
  50. current.frame_time, current.next_time);
  51. printf ("\n");
  52. }
  53. static void
  54. jack_shutdown (void *arg)
  55. {
  56. fprintf(stderr, "JACK shut down, exiting ...\n");
  57. exit (1);
  58. }
  59. void
  60. signal_handler (int sig)
  61. {
  62. jack_client_close (client);
  63. fprintf (stderr, "signal received, exiting ...\n");
  64. exit (0);
  65. }
  66. int
  67. main (int argc, char *argv[])
  68. {
  69. /* try to become a client of the JACK server */
  70. if ((client = jack_client_open ("showtime", JackNullOption, NULL)) == 0) {
  71. fprintf (stderr, "JACK server not running?\n");
  72. return 1;
  73. }
  74. #ifndef WIN32
  75. signal (SIGQUIT, signal_handler);
  76. signal (SIGHUP, signal_handler);
  77. #endif
  78. signal (SIGTERM, signal_handler);
  79. signal (SIGINT, signal_handler);
  80. /* tell the JACK server to call `jack_shutdown()' if
  81. it ever shuts down, either entirely, or if it
  82. just decides to stop calling us.
  83. */
  84. jack_on_shutdown (client, jack_shutdown, 0);
  85. /* tell the JACK server that we are ready to roll */
  86. if (jack_activate (client)) {
  87. fprintf (stderr, "cannot activate client");
  88. return 1;
  89. }
  90. while (1) {
  91. usleep (20);
  92. showtime ();
  93. }
  94. jack_client_close (client);
  95. exit (0);
  96. }