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.

136 lines
3.9KB

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