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.

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