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.

190 lines
5.3KB

  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. /* a Digital Peak Meter, either horizontal or vertical. Color is a
  19. gradient from min_color() to max_color(). box() is used to draw the
  20. individual 'lights'. division() controls how many 'lights' there
  21. are. value() is volume in dBFS */
  22. #include "DPM.H"
  23. /* we cache the gradient for (probably excessive) speed */
  24. float DPM::_dim;
  25. Fl_Color DPM::_gradient[128] = { (Fl_Color)-1 };
  26. Fl_Color DPM::_dim_gradient[128];
  27. #include <FL/Fl.H>
  28. #include <FL/fl_draw.H>
  29. #include <FL/Fl_Group.H>
  30. #include <math.h>
  31. #include <stdio.h>
  32. DPM::DPM ( int X, int Y, int W, int H, const char *L ) :
  33. Meter( X, Y, W, H, L )
  34. {
  35. tooltip( peak_string );
  36. _last_drawn_hi_segment = 0;
  37. pixels_per_segment( 4 );
  38. type( FL_VERTICAL );
  39. resize( X, Y, W, H );
  40. dim( 0.70f );
  41. /* initialize gradients */
  42. if ( DPM::_gradient[ 0 ] == -1 )
  43. DPM::blend( FL_GREEN, FL_RED );
  44. box( FL_ROUNDED_BOX );
  45. }
  46. /* which marks to draw beside meter */
  47. const int marks [] = { -70, -50, -40, -30, -20, -10, -3, 0, 4 };
  48. void
  49. DPM::draw_label ( void )
  50. {
  51. /* dirty hack */
  52. if ( parent()->child( 0 ) == this )
  53. {
  54. fl_font( FL_TIMES, 8 );
  55. fl_color( FL_WHITE );
  56. /* draw marks */
  57. char pat[5];
  58. if ( type() == FL_HORIZONTAL )
  59. {
  60. for ( int i = sizeof( marks ) / sizeof( marks[0] ); i-- ; )
  61. {
  62. sprintf( pat, "%d", marks[ i ] );
  63. int v = w() * deflection( (float)marks[ i ] );
  64. fl_draw( pat, x() + v, (y() + h() + 8), 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
  65. }
  66. }
  67. else
  68. {
  69. for ( int i = sizeof( marks ) / sizeof( marks[0] ); i-- ; )
  70. {
  71. sprintf( pat, "%d", marks[ i ] );
  72. int v = h() * deflection( (float)marks[ i ] );
  73. fl_draw( pat, x() - 20, (y() + h() - 8) - v, 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
  74. }
  75. }
  76. }
  77. }
  78. void
  79. DPM::resize ( int X, int Y, int W, int H )
  80. {
  81. if ( type() == FL_HORIZONTAL )
  82. _segments = floor( W / (double)_pixels_per_segment );
  83. else
  84. _segments = floor( H / (double)_pixels_per_segment );
  85. // _last_drawn_hi_segment = 0;
  86. Fl_Widget::resize( X, Y, W, H );
  87. }
  88. void
  89. DPM::draw ( void )
  90. {
  91. snprintf( peak_string, sizeof( peak_string ), "%.1f", peak() );
  92. tooltip( peak_string );
  93. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  94. return;
  95. int v = pos( value() );
  96. int pv = pos( peak() );
  97. int bh = h() / _segments;
  98. int bw = w() / _segments;
  99. if ( damage() == FL_DAMAGE_ALL )
  100. draw_label();
  101. const int active = active_r();
  102. int hi, lo;
  103. /* only draw as many segments as necessary */
  104. if ( damage() == FL_DAMAGE_USER1 )
  105. {
  106. if ( v > _last_drawn_hi_segment )
  107. {
  108. hi = v;
  109. lo = _last_drawn_hi_segment;
  110. }
  111. else
  112. {
  113. hi = _last_drawn_hi_segment;
  114. lo = v;
  115. }
  116. }
  117. else
  118. {
  119. lo = 0;
  120. hi = _segments;
  121. }
  122. _last_drawn_hi_segment = v;
  123. for ( int p = lo; p <= hi; p++ )
  124. {
  125. Fl_Color c = DPM::div_color( p );
  126. if ( p > v && p != pv )
  127. c = dim_div_color( p );
  128. if ( ! active )
  129. c = fl_inactive( c );
  130. if ( _pixels_per_segment < 4 )
  131. {
  132. if ( type() == FL_HORIZONTAL )
  133. fl_rectf( x() + (p * bw), y(), bw, h(), c );
  134. else
  135. fl_rectf( x(), y() + h() - ((p + 1) * bh), w(), bh, c );
  136. }
  137. else
  138. {
  139. if ( type() == FL_HORIZONTAL )
  140. fl_draw_box( box(), x() + (p * bw), y(), bw, h(), c );
  141. else
  142. fl_draw_box( box(), x(), y() + h() - ((p + 1) * bh), w(), bh, c );
  143. }
  144. /* fl_color( c ); */
  145. /* fl_rectf( x(), y() + h() - (p * bh), w(), bh ); */
  146. /* fl_color( FL_BLACK ); */
  147. /* fl_rect( x(), y() + h() - (p * bh), w(), bh ); */
  148. }
  149. }