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.

115 lines
2.7KB

  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 <jack/jack.h>
  20. #include <jack/transport.h>
  21. jack_client_t *client;
  22. static void
  23. showtime ()
  24. {
  25. jack_position_t current;
  26. jack_transport_state_t transport_state;
  27. jack_nframes_t frame_time;
  28. transport_state = jack_transport_query (client, &current);
  29. frame_time = jack_frame_time (client);
  30. printf ("frame = %u frame_time = %u usecs = %lld \t", current.frame, frame_time, current.usecs);
  31. switch (transport_state) {
  32. case JackTransportStopped:
  33. printf ("state: Stopped");
  34. break;
  35. case JackTransportRolling:
  36. printf ("state: Rolling");
  37. break;
  38. case JackTransportStarting:
  39. printf ("state: Starting");
  40. break;
  41. default:
  42. printf ("state: [unknown]");
  43. }
  44. if (current.valid & JackPositionBBT)
  45. printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
  46. PRIi32, current.bar, current.beat, current.tick);
  47. if (current.valid & JackPositionTimecode)
  48. printf ("\tTC: (%.6f, %.6f)",
  49. current.frame_time, current.next_time);
  50. printf ("\n");
  51. }
  52. static 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. }