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.

130 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_ENTER || m == FL_LEAVE )
  31. return 1;
  32. else if ( m == FL_PUSH && Fl::event_button1())
  33. {
  34. reset();
  35. return 1;
  36. }
  37. return Fl_Valuator::handle( m );
  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. public:
  62. Meter ( int X, int Y, int W, int H, const char *L = 0 ) :
  63. Fl_Valuator( X, Y, W, H, L )
  64. {
  65. _peak = _value = -80.0f;
  66. }
  67. virtual ~Meter ( ) { }
  68. void value ( float v )
  69. {
  70. damage( FL_DAMAGE_USER1 );
  71. _value = v;
  72. if ( _value > _peak )
  73. _peak = _value;
  74. }
  75. float value ( void ) const { return _value; }
  76. float peak ( void ) const { return _peak; }
  77. void reset ( void ) { _peak = -80.0f; redraw(); }
  78. };
  79. #include <FL/Fl_Group.H>
  80. #include <stdio.h>
  81. /* ... Extension methods for any group containing only meters. Access
  82. * via a cast to (Meter_Pack *) */
  83. class Meter_Pack : public Fl_Group
  84. {
  85. public:
  86. /** return a pointer to the meter for channel /c/ in group of meters /g/ */
  87. Meter *
  88. channel ( int c )
  89. {
  90. if ( c > children() )
  91. {
  92. fprintf( stderr, "no such channel\n" );
  93. return NULL;
  94. }
  95. return (Meter *)child( c );
  96. }
  97. int
  98. channels ( void ) const { return children(); }
  99. };