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.

104 lines
3.5KB

  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. #include <FL/Fl.H>
  24. #include <FL/fl_draw.H>
  25. #include <FL/Fl_Group.H>
  26. #include <math.h>
  27. #include <stdio.h>
  28. DPM::DPM ( int X, int Y, int W, int H, const char *L ) :
  29. Meter( X, Y, W, H, L )
  30. {
  31. divisions( 64 );
  32. type( FL_VERTICAL );
  33. dim( 0.80f );
  34. min_color( fl_darker( FL_GREEN ) );
  35. max_color( FL_RED );
  36. box( FL_ROUNDED_BOX );
  37. }
  38. /* which marks to draw beside meter */
  39. const int marks [] = { -70, -50, -40, -30, -20, -10, -3, 0, 4 };
  40. void
  41. DPM::draw_label ( void )
  42. {
  43. /* dirty hack */
  44. if ( parent()->child( 0 ) == this )
  45. {
  46. fl_font( FL_TIMES, 8 );
  47. fl_color( FL_WHITE );
  48. /* draw marks */
  49. for ( int i = sizeof( marks ) / sizeof( marks[0] ); i-- ; )
  50. {
  51. char pat[5];
  52. sprintf( pat, "%d", marks[ i ] );
  53. int v = h() * deflection( (float)marks[ i ] );
  54. fl_draw( pat, x() - 20, (y() + h() - 8) - v, 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
  55. }
  56. }
  57. }
  58. void
  59. DPM::draw ( void )
  60. {
  61. // draw_box( FL_FLAT_BOX, x(), y(), w(), h(), color() );
  62. int v = pos( value() );
  63. int pv = pos( peak() );
  64. int bh = h() / _divisions;
  65. int bw = w() / _divisions;
  66. if ( damage() & FL_DAMAGE_ALL )
  67. draw_label();
  68. for ( int p = _divisions; p > 0; p-- )
  69. {
  70. // Fl_Color c = fl_color_average( _min_color, _max_color, ((30.0f * log10f( (float)(_divisions - p ) ) )) / _divisions );
  71. Fl_Color c = fl_color_average( _max_color, _min_color, (float) p / _divisions );
  72. if ( p > v && p != pv )
  73. // c = fl_color_average( color(), c, _dim );
  74. c = fl_color_average( FL_BLACK, c, _dim );
  75. if ( ! active_r() )
  76. c = fl_inactive( c );
  77. if ( type() == FL_HORIZONTAL )
  78. draw_box( box(), x() + (p * bw), y(), bw, h(), c );
  79. else
  80. draw_box( box(), x(), y() + h() - (p * bh), w(), bh, c );
  81. }
  82. }