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.

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