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.

222 lines
5.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. /* 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)0 };
  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 ] == 0 )
  43. DPM::blend( FL_GREEN, FL_RED );
  44. box( FL_FLAT_BOX );
  45. color( FL_BACKGROUND_COLOR );
  46. }
  47. /* which marks to draw beside meter */
  48. const int marks [] = { -70, -50, -40, -30, -20, -10, -3, 0, 4 };
  49. void
  50. DPM::draw_label ( void )
  51. {
  52. /* dirty hack */
  53. if ( parent()->child( 0 ) == this )
  54. {
  55. fl_font( FL_TIMES, 8 );
  56. fl_color( FL_WHITE );
  57. /* draw marks */
  58. char pat[5];
  59. if ( type() == FL_HORIZONTAL )
  60. {
  61. for ( int i = sizeof( marks ) / sizeof( marks[0] ); i-- ; )
  62. {
  63. sprintf( pat, "%d", marks[ i ] );
  64. int v = w() * deflection( (float)marks[ i ] );
  65. fl_draw( pat, x() + v, (y() + h() + 8), 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
  66. }
  67. }
  68. else
  69. {
  70. for ( int i = sizeof( marks ) / sizeof( marks[0] ); i-- ; )
  71. {
  72. sprintf( pat, "%d", marks[ i ] );
  73. int v = h() * deflection( (float)marks[ i ] );
  74. fl_draw( pat, x() - 20, (y() + h() - 8) - v, 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
  75. }
  76. }
  77. }
  78. }
  79. void
  80. DPM::resize ( int X, int Y, int W, int H )
  81. {
  82. if ( type() == FL_HORIZONTAL )
  83. _segments = floor( W / (double)_pixels_per_segment );
  84. else
  85. _segments = floor( H / (double)_pixels_per_segment );
  86. // _last_drawn_hi_segment = 0;
  87. Fl_Widget::resize( X, Y, W, H );
  88. }
  89. void
  90. DPM::draw ( void )
  91. {
  92. if ( !_segments )
  93. return;
  94. snprintf( peak_string, sizeof( peak_string ), "%.1f", peak() );
  95. tooltip( peak_string );
  96. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  97. return;
  98. int X = x() + 2;
  99. int Y = y() + 2;
  100. int W = w() - 4;
  101. int H = h() - 4;
  102. int v = pos( value() );
  103. int pv = pos( peak() );
  104. int bh = h() / _segments;
  105. int bw = w() / _segments;
  106. if ( damage() == FL_DAMAGE_ALL )
  107. {
  108. draw_label();
  109. draw_box( FL_UP_FRAME, x(), y(), w(), h(), FL_BLACK );
  110. }
  111. fl_push_clip( X, Y, W, H );
  112. const int active = active_r();
  113. int hi, lo;
  114. /* only draw as many segments as necessary */
  115. if ( damage() == FL_DAMAGE_USER1 )
  116. {
  117. if ( v > _last_drawn_hi_segment )
  118. {
  119. hi = v;
  120. lo = _last_drawn_hi_segment;
  121. }
  122. else
  123. {
  124. hi = _last_drawn_hi_segment;
  125. lo = v;
  126. }
  127. }
  128. else
  129. {
  130. lo = 0;
  131. hi = _segments;
  132. }
  133. _last_drawn_hi_segment = v;
  134. for ( int p = lo; p <= hi; p++ )
  135. {
  136. Fl_Color c = DPM::div_color( p );
  137. if ( p > v && p != pv )
  138. c = dim_div_color( p );
  139. if ( ! active )
  140. c = fl_inactive( c );
  141. int yy = 0;
  142. int xx = 0;
  143. if ( type() == FL_HORIZONTAL )
  144. {
  145. xx = X + p * bw;
  146. fl_rectf( X + (p * bw), Y, bw, H, c );
  147. }
  148. else
  149. {
  150. yy = Y + H - ((p + 1) * bh);
  151. fl_rectf( X, yy, W, bh, c );
  152. }
  153. if ( _pixels_per_segment > 3 )
  154. {
  155. fl_color( FL_BLACK );
  156. if ( type() == FL_HORIZONTAL )
  157. {
  158. fl_line( xx, Y, xx, Y + H - 1 );
  159. }
  160. else
  161. {
  162. fl_line( X, yy, X + W - 1, yy );
  163. }
  164. }
  165. /* } */
  166. /* else */
  167. /* { */
  168. /* if ( type() == FL_HORIZONTAL ) */
  169. /* fl_draw_box( box(), X + (p * bw), Y, bw, H, c ); */
  170. /* else */
  171. /* fl_draw_box( box(), X, Y + H - ((p + 1) * bh), W, bh, c ); */
  172. /* } */
  173. }
  174. fl_pop_clip();
  175. }