Fader.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Fader.h - fader-widget used in FX-mixer - partly taken from Hydrogen
  3. *
  4. * Copyright (c) 2008-2012 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. /*
  25. * Hydrogen
  26. * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
  27. *
  28. * http://www.hydrogen-music.org
  29. *
  30. * This program is free software; you can redistribute it and/or modify
  31. * it under the terms of the GNU General Public License as published by
  32. * the Free Software Foundation; either version 2 of the License, or
  33. * (at your option) any later version.
  34. *
  35. * This program is distributed in the hope that it will be useful,
  36. * but WITHOUT ANY WARRANTY, without even the implied warranty of
  37. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. * GNU General Public License for more details.
  39. *
  40. * You should have received a copy of the GNU General Public License
  41. * along with this program; if not, write to the Free Software
  42. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  43. *
  44. */
  45. #ifndef FADER_H
  46. #define FADER_H
  47. #include <QtCore/QTime>
  48. #include <QWidget>
  49. #include <QPixmap>
  50. #include "AutomatableModelView.h"
  51. class TextFloat;
  52. class EXPORT Fader : public QWidget, public FloatModelView
  53. {
  54. Q_OBJECT
  55. public:
  56. Q_PROPERTY( QColor peakGreen READ peakGreen WRITE setPeakGreen )
  57. Q_PROPERTY( QColor peakRed READ peakRed WRITE setPeakRed )
  58. Q_PROPERTY( QColor peakYellow READ peakYellow WRITE setPeakYellow )
  59. Q_PROPERTY( bool levelsDisplayedInDBFS READ getLevelsDisplayedInDBFS WRITE setLevelsDisplayedInDBFS )
  60. Fader( FloatModel * _model, const QString & _name, QWidget * _parent );
  61. Fader( FloatModel * _model, const QString & _name, QWidget * _parent, QPixmap * back, QPixmap * leds, QPixmap * knob );
  62. virtual ~Fader();
  63. void init(FloatModel * model, QString const & name);
  64. void setPeak_L( float fPeak );
  65. float getPeak_L() { return m_fPeakValue_L; }
  66. void setPeak_R( float fPeak );
  67. float getPeak_R() { return m_fPeakValue_R; }
  68. inline float getMinPeak() const { return m_fMinPeak; }
  69. inline void setMinPeak(float minPeak) { m_fMinPeak = minPeak; }
  70. inline float getMaxPeak() const { return m_fMaxPeak; }
  71. inline void setMaxPeak(float maxPeak) { m_fMaxPeak = maxPeak; }
  72. QColor const & peakGreen() const;
  73. void setPeakGreen( const QColor & c );
  74. QColor const & peakRed() const;
  75. void setPeakRed( const QColor & c );
  76. QColor const & peakYellow() const;
  77. void setPeakYellow( const QColor & c );
  78. inline bool getLevelsDisplayedInDBFS() const { return m_levelsDisplayedInDBFS; }
  79. inline void setLevelsDisplayedInDBFS(bool value = true) { m_levelsDisplayedInDBFS = value; }
  80. void setDisplayConversion( bool b )
  81. {
  82. m_displayConversion = b;
  83. }
  84. inline void setHintText( const QString & _txt_before,
  85. const QString & _txt_after )
  86. {
  87. setDescription( _txt_before );
  88. setUnit( _txt_after );
  89. }
  90. private:
  91. virtual void contextMenuEvent( QContextMenuEvent * _me );
  92. virtual void mousePressEvent( QMouseEvent *ev );
  93. virtual void mouseDoubleClickEvent( QMouseEvent* mouseEvent );
  94. virtual void mouseMoveEvent( QMouseEvent *ev );
  95. virtual void mouseReleaseEvent( QMouseEvent * _me );
  96. virtual void wheelEvent( QWheelEvent *ev );
  97. virtual void paintEvent( QPaintEvent *ev );
  98. inline bool clips(float const & value) const { return value >= 1.0f; }
  99. void paintDBFSLevels(QPaintEvent *ev, QPainter & painter);
  100. void paintLinearLevels(QPaintEvent *ev, QPainter & painter);
  101. int knobPosY() const
  102. {
  103. float fRange = model()->maxValue() - model()->minValue();
  104. float realVal = model()->value() - model()->minValue();
  105. return height() - ( ( height() - m_knob->height() ) * ( realVal / fRange ) );
  106. }
  107. void setPeak( float fPeak, float &targetPeak, float &persistentPeak, QTime &lastPeakTime );
  108. int calculateDisplayPeak( float fPeak );
  109. void updateTextFloat();
  110. // Private members
  111. private:
  112. float m_fPeakValue_L;
  113. float m_fPeakValue_R;
  114. float m_persistentPeak_L;
  115. float m_persistentPeak_R;
  116. float m_fMinPeak;
  117. float m_fMaxPeak;
  118. QTime m_lastPeakTime_L;
  119. QTime m_lastPeakTime_R;
  120. static QPixmap * s_back;
  121. static QPixmap * s_leds;
  122. static QPixmap * s_knob;
  123. QPixmap * m_back;
  124. QPixmap * m_leds;
  125. QPixmap * m_knob;
  126. bool m_displayConversion;
  127. bool m_levelsDisplayedInDBFS;
  128. int m_moveStartPoint;
  129. float m_startValue;
  130. static TextFloat * s_textFloat;
  131. QColor m_peakGreen;
  132. QColor m_peakRed;
  133. QColor m_peakYellow;
  134. } ;
  135. #endif