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 /*
26  * Hydrogen
27  * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
28  *
29  * http://www.hydrogen-music.org
30  *
31  * This program is free software; you can redistribute it and/or modify
32  * it under the terms of the GNU General Public License as published by
33  * the Free Software Foundation; either version 2 of the License, or
34  * (at your option) any later version.
35  *
36  * This program is distributed in the hope that it will be useful,
37  * but WITHOUT ANY WARRANTY, without even the implied warranty of
38  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39  * GNU General Public License for more details.
40  *
41  * You should have received a copy of the GNU General Public License
42  * along with this program; if not, write to the Free Software
43  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
44  *
45  */
46 
47 
48 #ifndef FADER_H
49 #define FADER_H
50 
51 #include <QtCore/QTime>
52 #include <QWidget>
53 #include <QPixmap>
54 
55 #include "AutomatableModelView.h"
56 
57 class TextFloat;
58 
59 
60 class EXPORT Fader : public QWidget, public FloatModelView
61 {
62 	Q_OBJECT
63 public:
64 	Q_PROPERTY( QColor peakGreen READ peakGreen WRITE setPeakGreen )
65 	Q_PROPERTY( QColor peakRed READ peakRed WRITE setPeakRed )
66 	Q_PROPERTY( QColor peakYellow READ peakYellow WRITE setPeakYellow )
67 	Q_PROPERTY( bool levelsDisplayedInDBFS READ getLevelsDisplayedInDBFS WRITE setLevelsDisplayedInDBFS )
68 
69 	Fader( FloatModel * _model, const QString & _name, QWidget * _parent );
70 	Fader( FloatModel * _model, const QString & _name, QWidget * _parent, QPixmap * back, QPixmap * leds, QPixmap * knob );
71 	virtual ~Fader();
72 
73 	void init(FloatModel * model, QString const & name);
74 
75 	void setPeak_L( float fPeak );
getPeak_L()76 	float getPeak_L() {	return m_fPeakValue_L;	}
77 
78 	void setPeak_R( float fPeak );
getPeak_R()79 	float getPeak_R() {	return m_fPeakValue_R;	}
80 
getMinPeak()81 	inline float getMinPeak() const { return m_fMinPeak; }
setMinPeak(float minPeak)82 	inline void setMinPeak(float minPeak) { m_fMinPeak = minPeak; }
83 
getMaxPeak()84 	inline float getMaxPeak() const { return m_fMaxPeak; }
setMaxPeak(float maxPeak)85 	inline void setMaxPeak(float maxPeak) { m_fMaxPeak = maxPeak; }
86 
87 	QColor const & peakGreen() const;
88 	void setPeakGreen( const QColor & c );
89 
90 	QColor const & peakRed() const;
91 	void setPeakRed( const QColor & c );
92 
93 	QColor const & peakYellow() const;
94 	void setPeakYellow( const QColor & c );
95 
getLevelsDisplayedInDBFS()96 	inline bool getLevelsDisplayedInDBFS() const { return m_levelsDisplayedInDBFS; }
97 	inline void setLevelsDisplayedInDBFS(bool value = true) { m_levelsDisplayedInDBFS = value; }
98 
setDisplayConversion(bool b)99 	void setDisplayConversion( bool b )
100 	{
101 		m_displayConversion = b;
102 	}
103 
setHintText(const QString & _txt_before,const QString & _txt_after)104 	inline void setHintText( const QString & _txt_before,
105 						const QString & _txt_after )
106 	{
107 		setDescription( _txt_before );
108 		setUnit( _txt_after );
109 	}
110 
111 private:
112 	virtual void contextMenuEvent( QContextMenuEvent * _me );
113 	virtual void mousePressEvent( QMouseEvent *ev );
114 	virtual void mouseDoubleClickEvent( QMouseEvent* mouseEvent );
115 	virtual void mouseMoveEvent( QMouseEvent *ev );
116 	virtual void mouseReleaseEvent( QMouseEvent * _me );
117 	virtual void wheelEvent( QWheelEvent *ev );
118 	virtual void paintEvent( QPaintEvent *ev );
119 
clips(float const & value)120 	inline bool clips(float const & value) const { return value >= 1.0f; }
121 
122 	void paintDBFSLevels(QPaintEvent *ev, QPainter & painter);
123 	void paintLinearLevels(QPaintEvent *ev, QPainter & painter);
124 
knobPosY()125 	int knobPosY() const
126 	{
127 		float fRange = model()->maxValue() - model()->minValue();
128 		float realVal = model()->value() - model()->minValue();
129 
130 		return height() - ( ( height() - m_knob->height() ) * ( realVal / fRange ) );
131 	}
132 
133 	void setPeak( float fPeak, float &targetPeak, float &persistentPeak, QTime &lastPeakTime );
134 	int calculateDisplayPeak( float fPeak );
135 
136 	void updateTextFloat();
137 
138 	// Private members
139 private:
140 	float m_fPeakValue_L;
141 	float m_fPeakValue_R;
142 	float m_persistentPeak_L;
143 	float m_persistentPeak_R;
144 	float m_fMinPeak;
145 	float m_fMaxPeak;
146 
147 	QTime m_lastPeakTime_L;
148 	QTime m_lastPeakTime_R;
149 
150 	static QPixmap * s_back;
151 	static QPixmap * s_leds;
152 	static QPixmap * s_knob;
153 
154 	QPixmap * m_back;
155 	QPixmap * m_leds;
156 	QPixmap * m_knob;
157 
158 	bool m_displayConversion;
159 	bool m_levelsDisplayedInDBFS;
160 
161 	int m_moveStartPoint;
162 	float m_startValue;
163 
164 	static TextFloat * s_textFloat;
165 
166 	QColor m_peakGreen;
167 	QColor m_peakRed;
168 	QColor m_peakYellow;
169 } ;
170 
171 
172 #endif
173