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.

131 lines
3.7KB

  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. /* Base class for all meters */
  19. #include <FL/Fl.H>
  20. #include <FL/Fl_Widget.H>
  21. #include <FL/Fl_Valuator.H>
  22. class Meter : public Fl_Valuator
  23. {
  24. float _peak;
  25. float _value;
  26. protected:
  27. virtual void draw ( void ) = 0;
  28. virtual int handle ( int m )
  29. {
  30. if ( m == FL_PUSH )
  31. {
  32. // if ( Fl::event_button3() )
  33. // hide();
  34. // else
  35. reset();
  36. return 1;
  37. }
  38. return Fl_Widget::handle( m );
  39. }
  40. float
  41. deflection ( float db )
  42. {
  43. float def = 0.0f;
  44. if ( db < -70.0f )
  45. def = 0.0f;
  46. else if ( db < -60.0f )
  47. def = ( db + 70.0f ) * 0.25f;
  48. else if ( db < -50.0f )
  49. def = ( db + 60.0f ) * 0.5f + 2.5f;
  50. else if ( db < -40.0f )
  51. def = ( db + 50.0f ) * 0.75f + 7.5f;
  52. else if ( db < -30.0f )
  53. def = ( db + 40.0f ) * 1.5f + 15.0f;
  54. else if ( db < -20.0f )
  55. def = ( db + 30.0f ) * 2.0f + 30.0f;
  56. else if ( db < 6.0f )
  57. def = ( db + 20.0f ) * 2.5f + 50.0f;
  58. else
  59. def = 115.0f;
  60. return def / 115.0f;
  61. }
  62. public:
  63. Meter ( int X, int Y, int W, int H, const char *L = 0 ) :
  64. Fl_Valuator( X, Y, W, H, L )
  65. {
  66. _peak = _value = -80.0f;
  67. }
  68. virtual ~Meter ( ) { }
  69. void value ( float v )
  70. {
  71. damage( FL_DAMAGE_USER1 );
  72. _value = v;
  73. if ( _value > _peak )
  74. _peak = _value;
  75. }
  76. float value ( void ) const { return _value; }
  77. float peak ( void ) const { return _peak; }
  78. void reset ( void ) { _peak = -80.0f; redraw(); }
  79. };
  80. #include <FL/Fl_Group.H>
  81. #include <stdio.h>
  82. /* ... Extension methods for any group containing only meters. Access
  83. * via a cast to (Meter_Pack *) */
  84. class Meter_Pack : public Fl_Group
  85. {
  86. public:
  87. /** return a pointer to the meter for channel /c/ in group of meters /g/ */
  88. Meter *
  89. channel ( int c )
  90. {
  91. if ( c > children() )
  92. {
  93. fprintf( stderr, "no such channel\n" );
  94. return NULL;
  95. }
  96. return (Meter *)child( c );
  97. }
  98. int
  99. channels ( void ) const { return children(); }
  100. };