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.

182 lines
5.1KB

  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. _last_drawn_hi_segment = 0;
  36. pixels_per_segment( 4 );
  37. type( FL_VERTICAL );
  38. resize( X, Y, W, H );
  39. dim( 0.70f );
  40. /* initialize gradients */
  41. if ( DPM::_gradient[ 0 ] == -1 )
  42. DPM::blend( FL_GREEN, FL_RED );
  43. box( FL_ROUNDED_BOX );
  44. }
  45. /* which marks to draw beside meter */
  46. const int marks [] = { -70, -50, -40, -30, -20, -10, -3, 0, 4 };
  47. void
  48. DPM::draw_label ( void )
  49. {
  50. /* dirty hack */
  51. if ( parent()->child( 0 ) == this )
  52. {
  53. fl_font( FL_TIMES, 8 );
  54. fl_color( FL_WHITE );
  55. /* draw marks */
  56. char pat[5];
  57. if ( type() == FL_HORIZONTAL )
  58. {
  59. for ( int i = sizeof( marks ) / sizeof( marks[0] ); i-- ; )
  60. {
  61. sprintf( pat, "%d", marks[ i ] );
  62. int v = w() * deflection( (float)marks[ i ] );
  63. fl_draw( pat, x() + v, (y() + h() + 8), 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
  64. }
  65. }
  66. else
  67. {
  68. for ( int i = sizeof( marks ) / sizeof( marks[0] ); i-- ; )
  69. {
  70. sprintf( pat, "%d", marks[ i ] );
  71. int v = h() * deflection( (float)marks[ i ] );
  72. fl_draw( pat, x() - 20, (y() + h() - 8) - v, 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
  73. }
  74. }
  75. }
  76. }
  77. void
  78. DPM::resize ( int X, int Y, int W, int H )
  79. {
  80. if ( type() == FL_HORIZONTAL )
  81. _segments = floor( W / (double)_pixels_per_segment );
  82. else
  83. _segments = floor( H / (double)_pixels_per_segment );
  84. // _last_drawn_hi_segment = 0;
  85. Fl_Widget::resize( X, Y, W, H );
  86. }
  87. void
  88. DPM::draw ( void )
  89. {
  90. int v = pos( value() );
  91. int pv = pos( peak() );
  92. int bh = h() / _segments;
  93. int bw = w() / _segments;
  94. if ( damage() == FL_DAMAGE_ALL )
  95. draw_label();
  96. const int active = active_r();
  97. int hi, lo;
  98. /* only draw as many segments as necessary */
  99. if ( damage() == FL_DAMAGE_USER1 )
  100. {
  101. if ( v > _last_drawn_hi_segment )
  102. {
  103. hi = v;
  104. lo = _last_drawn_hi_segment;
  105. }
  106. else
  107. {
  108. hi = _last_drawn_hi_segment;
  109. lo = v;
  110. }
  111. }
  112. else
  113. {
  114. lo = 0;
  115. hi = _segments;
  116. }
  117. _last_drawn_hi_segment = v;
  118. for ( int p = lo; p <= hi; p++ )
  119. {
  120. Fl_Color c = DPM::div_color( p );
  121. if ( p > v && p != pv )
  122. c = dim_div_color( p );
  123. if ( ! active )
  124. c = fl_inactive( c );
  125. if ( _pixels_per_segment < 4 )
  126. {
  127. if ( type() == FL_HORIZONTAL )
  128. fl_rectf( x() + (p * bw), y(), bw, h(), c );
  129. else
  130. fl_rectf( x(), y() + h() - ((p + 1) * bh), w(), bh, c );
  131. }
  132. else
  133. {
  134. if ( type() == FL_HORIZONTAL )
  135. fl_draw_box( box(), x() + (p * bw), y(), bw, h(), c );
  136. else
  137. fl_draw_box( box(), x(), y() + h() - ((p + 1) * bh), w(), bh, c );
  138. }
  139. /* fl_color( c ); */
  140. /* fl_rectf( x(), y() + h() - (p * bh), w(), bh ); */
  141. /* fl_color( FL_BLACK ); */
  142. /* fl_rect( x(), y() + h() - (p * bh), w(), bh ); */
  143. }
  144. }