showtime.pp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. program showtime;
  2. {$MODE objfpc}{$H+}
  3. uses
  4. Jack, CTypes, SysUtils, BaseUnix;
  5. var
  6. client: Pjack_client_t;
  7. procedure showtime;
  8. var
  9. current: jack_position_t;
  10. transport_state: jack_transport_state_t;
  11. frame_time: jack_nframes_t;
  12. begin
  13. transport_state := jack_transport_query (client, @current);
  14. frame_time := jack_frame_time (client);
  15. Write('frame: ', current.frame:7, ' @ ', frame_time, #9);
  16. case transport_state of
  17. JackTransportStopped:
  18. Write ('state: Stopped');
  19. JackTransportRolling:
  20. Write ('state: Rolling');
  21. JackTransportStarting:
  22. Write ('state: Starting');
  23. else
  24. Write ('state: [unknown]');
  25. end;
  26. if (Ord(current.valid) and Ord(JackPositionBBT)) <> 0 then
  27. Write (#9'BBT: ', current.bar:3, '|', current.beat, '|', current.tick:4);
  28. if (Ord(current.valid) and Ord(JackPositionTimecode)) <> 0 then
  29. Write (#9'TC: (', current.frame_time:0:6, ', ', current.next_time:0:6, ')');
  30. if (Ord(current.valid) and Ord(JackBBTFrameOffset)) <> 0 then
  31. Write (#9'BBT offset: (', current.bbt_offset, ')');
  32. if (Ord(current.valid) and Ord(JackAudioVideoRatio)) <> 0 then
  33. Write (#9'audio/video: (', current.audio_frames_per_video_frame:0:12, ')');
  34. if (Ord(current.valid) and Ord(JackVideoFrameOffset)) <> 0 then
  35. begin
  36. if current.video_offset <> 0 then
  37. Write (#9' video@: (', current.video_offset, ')')
  38. else
  39. Write(#9' no video');
  40. end;
  41. Writeln;
  42. end;
  43. procedure jack_shutdown (arg: Pointer); cdecl;
  44. begin
  45. Halt (1);
  46. end;
  47. procedure signal_handler (sig: cint); cdecl;
  48. begin
  49. jack_client_close (client);
  50. Writeln (StdErr, 'signal received, exiting ...');
  51. Halt (0);
  52. end;
  53. begin
  54. { try to become a client of the JACK server }
  55. client := jack_client_open ('showtime', JackNullOption, nil);
  56. if client = nil then
  57. begin
  58. Writeln (StdErr, 'jack server not running?');
  59. Halt(1);
  60. end;
  61. fpsignal (SIGQUIT, @signal_handler);
  62. fpsignal (SIGTERM, @signal_handler);
  63. fpsignal (SIGHUP, @signal_handler);
  64. fpsignal (SIGINT, @signal_handler);
  65. { tell the JACK server to call `jack_shutdown()' if
  66. it ever shuts down, either entirely, or if it
  67. just decides to stop calling us.
  68. }
  69. jack_on_shutdown (client, @jack_shutdown, nil);
  70. { tell the JACK server that we are ready to roll }
  71. if jack_activate (client) <> 0 then
  72. begin
  73. Writeln (StdErr, 'cannot activate client');
  74. Halt(1);
  75. end;
  76. repeat
  77. sleep (1);
  78. showtime;
  79. until False;
  80. jack_client_close (client);
  81. Halt (0);
  82. end.