LMMS
Loading...
Searching...
No Matches
Fader.h
Go to the documentation of this file.
1/*
2 * Fader.h - fader-widget used in 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#ifndef LMMS_GUI_FADER_H
48#define LMMS_GUI_FADER_H
49
50#include <QElapsedTimer>
51#include <QPixmap>
52#include <QWidget>
53
54
56#include "embed.h"
57#include "lmms_math.h"
58
59
60namespace lmms::gui
61{
62
63class SimpleTextFloat;
64
65
66class LMMS_EXPORT Fader : public QWidget, public FloatModelView
67{
68 Q_OBJECT
69public:
70 Q_PROPERTY(QColor peakOk MEMBER m_peakOk)
71 Q_PROPERTY(QColor peakClip MEMBER m_peakClip)
72 Q_PROPERTY(QColor peakWarn MEMBER m_peakWarn)
75 Q_PROPERTY(QColor unityMarker MEMBER m_unityMarker)
76
77 Fader(FloatModel* model, const QString& name, QWidget* parent, bool modelIsLinear = true);
78 Fader(FloatModel* model, const QString& name, QWidget* parent, const QPixmap& knob, bool modelIsLinear = true);
79 ~Fader() override = default;
80
81 void setPeak_L(float fPeak);
82 float getPeak_L() { return m_fPeakValue_L; }
83
84 void setPeak_R(float fPeak);
85 float getPeak_R() { return m_fPeakValue_R; }
86
87 inline float getMinPeak() const { return m_fMinPeak; }
88 inline void setMinPeak(float minPeak) { m_fMinPeak = minPeak; }
89
90 inline float getMaxPeak() const { return m_fMaxPeak; }
91 inline void setMaxPeak(float maxPeak) { m_fMaxPeak = maxPeak; }
92
93 inline bool getRenderUnityLine() const { return m_renderUnityLine; }
94 inline void setRenderUnityLine(bool value = true) { m_renderUnityLine = value; }
95
97 {
98 Up,
99 Down
100 };
101
102 void adjust(const Qt::KeyboardModifiers & modifiers, AdjustmentDirection direction);
103 void adjustByDecibelDelta(float value);
104
105 void adjustByDialog();
106
108 {
109 m_conversionFactor = b ? 100.0 : 1.0;
110 }
111
112 inline void setHintText(const QString& txt_before,
113 const QString& txt_after)
114 {
115 setDescription(txt_before);
116 setUnit(txt_after);
117 }
118
119signals:
120 void peakChanged(float peak);
121
122private:
123 void contextMenuEvent(QContextMenuEvent* me) override;
124 void mousePressEvent(QMouseEvent* ev) override;
125 void mouseDoubleClickEvent(QMouseEvent* mouseEvent) override;
126 void mouseMoveEvent(QMouseEvent* ev) override;
127 void mouseReleaseEvent(QMouseEvent* me) override;
128 void wheelEvent(QWheelEvent* ev) override;
129 void paintEvent(QPaintEvent* ev) override;
130
131 void paintLevels(QPaintEvent* ev, QPainter& painter, bool linear = false);
132 void paintFaderTicks(QPainter& painter);
133
134 float determineAdjustmentDelta(const Qt::KeyboardModifiers & modifiers) const;
135 void adjustModelByDBDelta(float value);
136
137 int calculateKnobPosYFromModel() const;
139
151 float computeScaledRatio(float dBValue) const;
152
153 void setPeak(float fPeak, float& targetPeak, float& persistentPeak, QElapsedTimer& lastPeakTimer);
154
155 void updateTextFloat();
156 void modelValueChanged();
157 QString getModelValueAsDbString() const;
158
159 bool modelIsLinear() const { return m_modelIsLinear; }
160
161 // Private members
162private:
163 float m_fPeakValue_L {0.};
164 float m_fPeakValue_R {0.};
167 float m_fMinPeak {dbfsToAmp(-42)};
169
170 QElapsedTimer m_lastPeakTimer_L;
171 QElapsedTimer m_lastPeakTimer_R;
172
173 QPixmap m_knob {embed::getIconPixmap("fader_knob")};
175
183
185 bool m_modelIsLinear {false};
186
188
189 QColor m_peakOk {10, 212, 92};
190 QColor m_peakClip {193, 32, 56};
191 QColor m_peakWarn {214, 236, 82};
192 QColor m_unityMarker {63, 63, 63, 255};
193
194 bool m_renderUnityLine {true};
195} ;
196
197
198} // namespace lmms::gui
199
200#endif // LMMS_GUI_FADER_H
#define READ(addr)
Definition Ay_Cpu.cpp:92
#define WRITE(addr, data)
Definition Ay_Cpu.cpp:93
#define override
Definition DistrhoDefines.h:73
Definition AutomatableModel.h:463
void setUnit(const QString &unit)
Definition AutomatableModelView.h:69
void setDescription(const QString &desc)
Definition AutomatableModelView.h:64
float m_conversionFactor
Definition AutomatableModelView.h:85
T value() const
Definition AutomatableModelView.h:59
bool m_renderUnityLine
Definition Fader.h:194
void setMinPeak(float minPeak)
Definition Fader.h:88
float m_persistentPeak_L
Definition Fader.h:165
QColor peakClip
Definition Fader.h:71
AdjustmentDirection
Definition Fader.h:97
void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override
Definition Fader.cpp:242
Fader(FloatModel *model, const QString &name, QWidget *parent, bool modelIsLinear=true)
Definition Fader.cpp:73
static SimpleTextFloat * s_textFloat
Definition Fader.h:187
float m_fPeakValue_R
Definition Fader.h:164
QColor m_peakClip
Definition Fader.h:190
void mousePressEvent(QMouseEvent *ev) override
Definition Fader.cpp:188
QElapsedTimer m_lastPeakTimer_L
Definition Fader.h:170
float getMaxPeak() const
Definition Fader.h:90
QPixmap m_knob
Definition Fader.h:173
float getMinPeak() const
Definition Fader.h:87
QColor m_peakOk
Definition Fader.h:189
bool m_levelsDisplayedInDBFS
Definition Fader.h:184
void mouseReleaseEvent(QMouseEvent *me) override
Definition Fader.cpp:251
void setVolumeByLocalPixelValue(int y)
Definition Fader.cpp:388
void setRenderUnityLine(bool value=true)
Definition Fader.h:94
void setMaxPeak(float maxPeak)
Definition Fader.h:91
void contextMenuEvent(QContextMenuEvent *me) override
Definition Fader.cpp:163
void wheelEvent(QWheelEvent *ev) override
Definition Fader.cpp:269
void peakChanged(float peak)
int calculateKnobPosYFromModel() const
Definition Fader.cpp:335
void setPeak(float fPeak, float &targetPeak, float &persistentPeak, QElapsedTimer &lastPeakTimer)
Definition Fader.cpp:458
QSize m_knobSize
Definition Fader.h:174
float m_fMaxPeak
Definition Fader.h:168
float computeScaledRatio(float dBValue) const
Computes the scaled ratio between the maximum dB value supported by the model and the minimum dB valu...
Definition Fader.cpp:445
void mouseMoveEvent(QMouseEvent *ev) override
Definition Fader.cpp:174
QString getModelValueAsDbString() const
Definition Fader.cpp:516
void modelValueChanged()
Definition Fader.cpp:511
void paintLevels(QPaintEvent *ev, QPainter &painter, bool linear=false)
Definition Fader.cpp:562
QColor unityMarker
Definition Fader.h:75
void paintEvent(QPaintEvent *ev) override
Definition Fader.cpp:546
float getPeak_R()
Definition Fader.h:85
QColor m_unityMarker
Definition Fader.h:192
QColor m_peakWarn
Definition Fader.h:191
bool getRenderUnityLine() const
Definition Fader.h:93
QColor peakWarn
Definition Fader.h:72
bool m_modelIsLinear
Definition Fader.h:185
bool renderUnityLine
Definition Fader.h:74
QElapsedTimer m_lastPeakTimer_R
Definition Fader.h:171
bool modelIsLinear() const
Definition Fader.h:159
void setHintText(const QString &txt_before, const QString &txt_after)
Definition Fader.h:112
void adjustModelByDBDelta(float value)
Definition Fader.cpp:302
float m_fPeakValue_L
Definition Fader.h:163
float getPeak_L()
Definition Fader.h:82
void setDisplayConversion(bool b)
Definition Fader.h:107
QColor peakOk
Definition Fader.h:70
void updateTextFloat()
Definition Fader.cpp:497
void setPeak_L(float fPeak)
Definition Fader.cpp:482
float determineAdjustmentDelta(const Qt::KeyboardModifiers &modifiers) const
Definition Fader.cpp:280
float m_fMinPeak
Definition Fader.h:167
void paintFaderTicks(QPainter &painter)
Definition Fader.cpp:715
int m_knobCenterOffset
Stores the offset to the knob center when the user drags the fader knob.
Definition Fader.h:182
bool levelsDisplayedInDBFS
Definition Fader.h:73
float m_persistentPeak_R
Definition Fader.h:166
Definition SimpleTextFloat.h:40
FloatModel * model()
Definition AutomatableModelView.h:121
int y
Definition inflate.c:1588
static PuglViewHint int value
Definition pugl.h:1708
static const char * name
Definition pugl.h:1582
static uintptr_t parent
Definition pugl.h:1644
auto getIconPixmap(std::string_view name, int width, int height, const char *const *xpm) -> QPixmap
Definition embed.cpp:107
Definition AudioPortAudio.cpp:223
TypedModelView< FloatModel > FloatModelView
Definition AutomatableModelView.h:131
float dbfsToAmp(float dbfs)
Converts dBFS-scale to linear amplitude with 0dBFS = 1.0.
Definition lmms_math.h:302
#define true
Definition ordinals.h:82
b
Definition crypt.c:628
#define const
Definition zconf.h:137