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.

154 lines
4.4KB

  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 <FL/Fl.H>
  23. #include "Timeline.H"
  24. #include "types.h"
  25. const float CLOCK_UPDATE_FREQ = 0.06f;
  26. class Clock : public Fl_Widget
  27. {
  28. nframes_t _when;
  29. nframes_t *_v;
  30. static void
  31. update_cb ( void *v )
  32. {
  33. ((Clock*)v)->update_cb();
  34. }
  35. void
  36. update_cb ( void )
  37. {
  38. Fl::repeat_timeout( CLOCK_UPDATE_FREQ, update_cb, this );
  39. set( *_v );
  40. }
  41. public:
  42. enum { BBT, HMS };
  43. static void
  44. frame_to_HMS ( char *dst, int n, nframes_t frame )
  45. {
  46. float S = (double)frame / timeline->sample_rate();
  47. int M = S / 60; S -= M * 60;
  48. int H = M / 60; M -= H * 60;
  49. int HS = ((int)(S * 100)) - (((int)S) * 100);
  50. snprintf( dst, n, "%02d:%02d:%02.0f:%02d", H, M, S, HS );
  51. }
  52. Clock ( int X, int Y, int W, int H, const char *L=0 )
  53. : Fl_Widget( X, Y, W, H, L )
  54. {
  55. _when = 0;
  56. _v = 0;
  57. box( FL_BORDER_BOX );
  58. type( HMS );
  59. /* force size */
  60. size( 170, 40 );
  61. }
  62. ~Clock ( )
  63. {
  64. Fl::remove_timeout( update_cb );
  65. }
  66. void run ( nframes_t *v )
  67. {
  68. _v = v;
  69. Fl::add_timeout( CLOCK_UPDATE_FREQ, update_cb, this );
  70. }
  71. void set ( nframes_t frame )
  72. {
  73. if ( _when != frame )
  74. {
  75. _when = frame;
  76. redraw();
  77. }
  78. }
  79. void draw ( void )
  80. {
  81. draw_box();
  82. char buf[15];
  83. *buf = '\0';
  84. switch ( type() )
  85. {
  86. case HMS:
  87. frame_to_HMS( buf, sizeof( buf ), _when );
  88. break;
  89. case BBT:
  90. // frame_to_BBT( _buf, sizeof( buf ), frame );
  91. break;
  92. default:
  93. printf( "error: invalid clock type\n" );
  94. }
  95. fl_font( FL_COURIER, 24 );
  96. Fl_Color c = FL_GREEN;
  97. fl_color( c );
  98. const int dx = x() + Fl::box_dx( box() );
  99. const int dy = y() + Fl::box_dy( box() );
  100. const int dw = w() - Fl::box_dw( box() );
  101. const int dh = h() - Fl::box_dh( box() );
  102. fl_draw( buf, dx, dy, dw, dh - 9, FL_ALIGN_CENTER );
  103. for ( int i = strlen( buf ); i--; )
  104. if ( isdigit( buf[ i ] ) )
  105. buf[ i ] = ' ';
  106. fl_color( fl_darker( c ) );
  107. fl_draw( buf, dx, dy, dw, dh - 9, FL_ALIGN_CENTER );
  108. fl_font( FL_HELVETICA, 9 );
  109. fl_color( FL_RED );
  110. const char *s = type() == HMS ? "HMS" : "BBT";
  111. fl_draw( s, dx + 4, dy, dw, dh, (Fl_Align)( FL_ALIGN_LEFT | FL_ALIGN_BOTTOM ) );
  112. if ( label() )
  113. fl_draw( label(), dx, dy, dw, dh, (Fl_Align)( FL_ALIGN_RIGHT | FL_ALIGN_BOTTOM ) );
  114. }
  115. };