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.

121 lines
3.8KB

  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. nframes_t _when;
  27. public:
  28. enum { BBT, HMS };
  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, "%02d:%02d:%02.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. /* force size */
  44. size( 170, 40 );
  45. }
  46. void set ( nframes_t frame )
  47. {
  48. if ( _when != frame )
  49. {
  50. _when = frame;
  51. redraw();
  52. }
  53. }
  54. void draw ( void )
  55. {
  56. draw_box();
  57. char buf[15];
  58. *buf = '\0';
  59. switch ( type() )
  60. {
  61. case HMS:
  62. frame_to_HMS( buf, sizeof( buf ), _when );
  63. break;
  64. case BBT:
  65. // frame_to_BBT( _buf, sizeof( buf ), frame );
  66. break;
  67. default:
  68. printf( "error: invalid clock type\n" );
  69. }
  70. fl_font( FL_COURIER, 24 );
  71. Fl_Color c = FL_GREEN;
  72. fl_color( c );
  73. const int dx = x() + Fl::box_dx( box() );
  74. const int dy = y() + Fl::box_dy( box() );
  75. const int dw = w() - Fl::box_dw( box() );
  76. const int dh = h() - Fl::box_dh( box() );
  77. fl_draw( buf, dx, dy, dw, dh - 9, FL_ALIGN_CENTER );
  78. for ( int i = strlen( buf ); i--; )
  79. if ( isdigit( buf[ i ] ) )
  80. buf[ i ] = ' ';
  81. fl_color( fl_darker( c ) );
  82. fl_draw( buf, dx, dy, dw, dh - 9, FL_ALIGN_CENTER );
  83. fl_font( FL_HELVETICA, 9 );
  84. fl_color( FL_RED );
  85. const char *s = type() == HMS ? "HMS" : "BBT";
  86. fl_draw( s, dx + 4, dy, dw, dh, (Fl_Align)( FL_ALIGN_LEFT | FL_ALIGN_BOTTOM ) );
  87. if ( label() )
  88. fl_draw( label(), dx, dy, dw, dh, (Fl_Align)( FL_ALIGN_RIGHT | FL_ALIGN_BOTTOM ) );
  89. }
  90. };