Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

112 lines
3.6KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. /* Digital clock widget to show points on the timeline. May be
  19. switched between Bar Beat Tick and Wallclock displays */
  20. #include <FL/Fl_Widget.H>
  21. #include <FL/fl_draw.H>
  22. #include "Timeline.H"
  23. #include "types.h"
  24. class Clock : public Fl_Widget
  25. {
  26. enum { BBT, HMS };
  27. nframes_t _when;
  28. public:
  29. static void
  30. frame_to_HMS ( char *dst, int n, nframes_t frame )
  31. {
  32. float S = (double)frame / timeline->sample_rate();
  33. int M = S / 60; S -= M * 60;
  34. int H = M / 60; M -= H * 60;
  35. snprintf( dst, n, "%d:%d:%.1f", H, M, S );
  36. }
  37. Clock ( int X, int Y, int W, int H, const char *L=0 )
  38. : Fl_Widget( X, Y, W, H, L )
  39. {
  40. _when = 0;
  41. box( FL_BORDER_BOX );
  42. type( HMS );
  43. }
  44. void set ( nframes_t frame )
  45. {
  46. if ( _when != frame )
  47. {
  48. _when = frame;
  49. redraw();
  50. }
  51. }
  52. void draw ( void )
  53. {
  54. // fl_rectf( x(), y(), w(), h(), color() );
  55. draw_box();
  56. char buf[15];
  57. switch ( type() )
  58. {
  59. case HMS:
  60. frame_to_HMS( buf, sizeof( buf ), _when );
  61. break;
  62. case BBT:
  63. // frame_to_BBT( _buf, sizeof( buf ), frame );
  64. break;
  65. default:
  66. printf( "error: invalid clock type\n" );
  67. }
  68. fl_font( FL_COURIER, 24 );
  69. Fl_Color c = FL_GREEN;
  70. fl_color( c );
  71. const int dx = x() + Fl::box_dx( box() );
  72. const int dy = y() + Fl::box_dy( box() );
  73. const int dw = w() - Fl::box_dw( box() );
  74. const int dh = h() - Fl::box_dh( box() );
  75. fl_draw( buf, dx, dy, dw, dh, FL_ALIGN_CENTER );
  76. fl_font( FL_HELVETICA, 9 );
  77. fl_color( FL_RED );
  78. const char *s = type() == HMS ? "HMS" : "BBT";
  79. fl_draw( s, dx + 4, dy, dw, dh, (Fl_Align)( FL_ALIGN_LEFT | FL_ALIGN_BOTTOM ) );
  80. if ( label() )
  81. fl_draw( label(), dx, dy, dw, dh, (Fl_Align)( FL_ALIGN_RIGHT | FL_ALIGN_BOTTOM ) );
  82. }
  83. };