Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
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.

138 lines
4.0KB

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