Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faders with a dB scale (instead of linear/percentage) #7636

Merged
merged 25 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
872409a
Use dbFS scale for the faders
michaelgregorius Apr 5, 2024
f8e0bf5
Apply curve to faders
michaelgregorius Dec 23, 2024
def44ae
Support for dB models
michaelgregorius Dec 24, 2024
be0084b
Show current dB value of fader in tool tip
michaelgregorius Dec 24, 2024
a6dbdc0
Let users enter values in dB
michaelgregorius Dec 24, 2024
14c3c97
Remove option "Display volume as dBFS"
michaelgregorius Dec 24, 2024
3510dea
Extend Fader::wheelEvent
michaelgregorius Dec 24, 2024
1f9f96d
Adjust the wheel behavior for faders with dB models
michaelgregorius Dec 24, 2024
a86ca84
Less "jumpy" knobs
michaelgregorius Dec 27, 2024
71c0ed7
Make MSVC happy
michaelgregorius Dec 27, 2024
795c681
Introduce constexpr for scaling exponent
michaelgregorius Dec 29, 2024
344fae2
Draw fader ticks
michaelgregorius Dec 29, 2024
aa74df2
Fader adjustments via keyboard
michaelgregorius Dec 29, 2024
4a720cb
Move the fader of the selected channel
michaelgregorius Jan 12, 2025
d451531
Enter fader value when space key pressed
michaelgregorius Jan 12, 2025
fa9148e
Merge remote-tracking branch 'upstream/master' into FadersWithDbScale
michaelgregorius Jan 12, 2025
8f0d877
More prominent fader ticks around 0 dB
michaelgregorius Feb 1, 2025
ff435d5
Work around a Qt bug
michaelgregorius Feb 1, 2025
5a66348
Fix wheel events without any modifier
michaelgregorius Feb 1, 2025
8d5c523
Code review changes
michaelgregorius Feb 8, 2025
ccae1b5
Make minimum dB value a constexpr
michaelgregorius Feb 8, 2025
f02c464
More flexible painting of fader ticks
michaelgregorius Feb 8, 2025
41598a9
Make the zero indicator bolder
michaelgregorius Feb 8, 2025
57ad0e6
Make rendering of fader ticks a preference
michaelgregorius Feb 8, 2025
74d33a6
Move constexprs to anonymous namespace
michaelgregorius Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions include/Fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
Q_PROPERTY(bool renderUnityLine READ getRenderUnityLine WRITE setRenderUnityLine)
Q_PROPERTY(QColor unityMarker MEMBER m_unityMarker)

Fader(FloatModel* model, const QString& name, QWidget* parent);
Fader(FloatModel* model, const QString& name, QWidget* parent, const QPixmap& knob);
Fader(FloatModel* model, const QString& name, QWidget* parent, bool modelIsLinear = true);
Fader(FloatModel* model, const QString& name, QWidget* parent, const QPixmap& knob, bool modelIsLinear = true);
~Fader() override = default;

void setPeak_L(float fPeak);
Expand All @@ -93,6 +93,17 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
inline bool getRenderUnityLine() const { return m_renderUnityLine; }
inline void setRenderUnityLine(bool value = true) { m_renderUnityLine = value; }

enum class AdjustmentDirection
{
Up,
Down
};

void adjust(const Qt::KeyboardModifiers & modifiers, AdjustmentDirection direction);
void adjustByDecibelDelta(float value);

void adjustByDialog();

void setDisplayConversion(bool b)
{
m_conversionFactor = b ? 100.0 : 1.0;
Expand All @@ -118,18 +129,31 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
void paintEvent(QPaintEvent* ev) override;

void paintLevels(QPaintEvent* ev, QPainter& painter, bool linear = false);
void paintFaderTicks(QPainter& painter);

int knobPosY() const
{
float fRange = model()->maxValue() - model()->minValue();
float realVal = model()->value() - model()->minValue();
float determineAdjustmentDelta(const Qt::KeyboardModifiers & modifiers) const;
void adjustModelByDBDelta(float value);

return height() - ((height() - m_knob.height()) * (realVal / fRange));
}
int calculateKnobPosYFromModel() const;
void setVolumeByLocalPixelValue(int y);

// Computes the scaled ratio between the maximum dB value supported by the model and the minimum
// dB value that's supported by the fader from the given actual dB value.
// If the provided input value lies inside the aforementioned interval then the result will be
// a value between 0 (value == minimum value) and 1 (value == maximum model value).
// If you look at the graphical representation of the fader then 0 represents a point at the bottom
// of the fader and 1 a point at the top of the fader.
// The ratio is scaled by an internal exponent which is an implementation detail that cannot be
// changed for now.
float computeScaledRatio(float dBValue) const;

void setPeak(float fPeak, float& targetPeak, float& persistentPeak, QElapsedTimer& lastPeakTimer);

void updateTextFloat();
void modelValueChanged();
QString getModelValueAsDbString() const;

bool modelIsLinear() const { return m_modelIsLinear; }

// Private members
private:
Expand All @@ -145,10 +169,16 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView

QPixmap m_knob {embed::getIconPixmap("fader_knob")};

// Stores the offset to the knob center when the user drags the fader knob.
// This is needed to make it feel like the users drag the knob without it
// jumping immediately to the click position.
int m_knobCenterOffset {0};

bool m_levelsDisplayedInDBFS {true};
bool m_modelIsLinear {false};

int m_moveStartPoint {-1};
float m_startValue {0.};
// The dbFS amount after which we drop down to -inf dbFS
float const m_faderMinDb {-120.};

static SimpleTextFloat* s_textFloat;

Expand Down
2 changes: 2 additions & 0 deletions include/MixerChannelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class MixerChannelView : public QWidget
QColor strokeInnerInactive() const { return m_strokeInnerInactive; }
void setStrokeInnerInactive(const QColor& c) { m_strokeInnerInactive = c; }

Fader* fader() const { return m_fader; }

public slots:
void renameChannel();
void resetColor();
Expand Down
2 changes: 0 additions & 2 deletions include/SetupDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ protected slots:

private slots:
// General settings widget.
void toggleDisplaydBFS(bool enabled);
void toggleTooltips(bool enabled);
void toggleDisplayWaveform(bool enabled);
void toggleNoteLabels(bool enabled);
Expand Down Expand Up @@ -134,7 +133,6 @@ private slots:
TabBar * m_tabBar;

// General settings widgets.
bool m_displaydBFS;
bool m_tooltips;
bool m_displayWaveform;
bool m_printNoteLabels;
Expand Down
8 changes: 4 additions & 4 deletions plugins/CrossoverEQ/CrossoverEQControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,25 @@ CrossoverEQControlDialog::CrossoverEQControlDialog( CrossoverEQControls * contro
QPixmap const fader_knob(PLUGIN_NAME::getIconPixmap("fader_knob2"));

// faders
auto gain1 = new Fader(&controls->m_gain1, tr("Band 1 gain"), this, fader_knob);
auto gain1 = new Fader(&controls->m_gain1, tr("Band 1 gain"), this, fader_knob, false);
gain1->move( 7, 56 );
gain1->setDisplayConversion( false );
gain1->setHintText( tr( "Band 1 gain:" ), " dBFS" );
gain1->setRenderUnityLine(false);

auto gain2 = new Fader(&controls->m_gain2, tr("Band 2 gain"), this, fader_knob);
auto gain2 = new Fader(&controls->m_gain2, tr("Band 2 gain"), this, fader_knob, false);
gain2->move( 47, 56 );
gain2->setDisplayConversion( false );
gain2->setHintText( tr( "Band 2 gain:" ), " dBFS" );
gain2->setRenderUnityLine(false);

auto gain3 = new Fader(&controls->m_gain3, tr("Band 3 gain"), this, fader_knob);
auto gain3 = new Fader(&controls->m_gain3, tr("Band 3 gain"), this, fader_knob, false);
gain3->move( 87, 56 );
gain3->setDisplayConversion( false );
gain3->setHintText( tr( "Band 3 gain:" ), " dBFS" );
gain3->setRenderUnityLine(false);

auto gain4 = new Fader(&controls->m_gain4, tr("Band 4 gain"), this, fader_knob);
auto gain4 = new Fader(&controls->m_gain4, tr("Band 4 gain"), this, fader_knob, false);
gain4->move( 127, 56 );
gain4->setDisplayConversion( false );
gain4->setHintText( tr( "Band 4 gain:" ), " dBFS" );
Expand Down
2 changes: 1 addition & 1 deletion plugins/Eq/EqFader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EqFader : public Fader
Q_OBJECT
public:
EqFader( FloatModel * model, const QString & name, QWidget * parent, float* lPeak, float* rPeak ) :
Fader( model, name, parent )
Fader(model, name, parent, false)
{
setMinimumSize( 23, 116 );
setMaximumSize( 23, 116 );
Expand Down
1 change: 1 addition & 0 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void ConfigManager::upgrade_1_1_90()
void ConfigManager::upgrade_1_1_91()
{
// rename displaydbv to displaydbfs
// Note: the value of "displaydbfs" is not evaluated anymore!
if (!value("app", "displaydbv").isNull())
{
setValue("app", "displaydbfs", value("app", "displaydbv"));
Expand Down
15 changes: 2 additions & 13 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,13 +1099,7 @@ void MainWindow::updateViewMenu()
// Here we should put all look&feel -stuff from configmanager
// that is safe to change on the fly. There is probably some
// more elegant way to do this.
auto qa = new QAction(tr("Volume as dBFS"), this);
qa->setData("displaydbfs");
qa->setCheckable( true );
qa->setChecked( ConfigManager::inst()->value( "app", "displaydbfs" ).toInt() );
m_viewMenu->addAction(qa);

qa = new QAction(tr( "Smooth scroll" ), this);
auto qa = new QAction(tr( "Smooth scroll" ), this);
qa->setData("smoothscroll");
qa->setCheckable( true );
qa->setChecked( ConfigManager::inst()->value( "ui", "smoothscroll" ).toInt() );
Expand Down Expand Up @@ -1135,12 +1129,7 @@ void MainWindow::updateConfig( QAction * _who )
QString tag = _who->data().toString();
bool checked = _who->isChecked();

if( tag == "displaydbfs" )
{
ConfigManager::inst()->setValue( "app", "displaydbfs",
QString::number(checked) );
}
else if ( tag == "tooltips" )
if ( tag == "tooltips" )
{
ConfigManager::inst()->setValue( "tooltips", "disabled",
QString::number(!checked) );
Expand Down
28 changes: 28 additions & 0 deletions src/gui/MixerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,51 +479,79 @@



void MixerView::keyPressEvent(QKeyEvent * e)
{
auto adjustCurrentFader = [this](const Qt::KeyboardModifiers& modifiers, Fader::AdjustmentDirection direction)
{
auto* mixerChannel = currentMixerChannel();

if (mixerChannel)
{
mixerChannel->fader()->adjust(modifiers, direction);
}
};

switch(e->key())
{
case Qt::Key_Delete:
deleteChannel(m_currentMixerChannel->channelIndex());
break;
case Qt::Key_Left:
if (e->modifiers() & Qt::AltModifier)
{
moveChannelLeft(m_currentMixerChannel->channelIndex());
}
else
{
// select channel to the left
setCurrentMixerChannel(m_currentMixerChannel->channelIndex() - 1);
}
break;
case Qt::Key_Right:
if (e->modifiers() & Qt::AltModifier)
{
moveChannelRight(m_currentMixerChannel->channelIndex());
}
else
{
// select channel to the right
setCurrentMixerChannel(m_currentMixerChannel->channelIndex() + 1);
}
break;
case Qt::Key_Up:
case Qt::Key_Plus:
adjustCurrentFader(e->modifiers(), Fader::AdjustmentDirection::Up);
break;
case Qt::Key_Down:
case Qt::Key_Minus:
adjustCurrentFader(e->modifiers(), Fader::AdjustmentDirection::Down);
break;
case Qt::Key_Insert:
if (e->modifiers() & Qt::ShiftModifier)
{
addNewChannel();
}
break;
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_F2:
renameChannel(m_currentMixerChannel->channelIndex());
break;
case Qt::Key_Space:
{
auto* mixerChannel = currentMixerChannel();

if (mixerChannel)
{
mixerChannel->fader()->adjustByDialog();
}
}
break;
}
}



Check notice on line 554 in src/gui/MixerView.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/gui/MixerView.cpp#L482-L554

Complex Method
void MixerView::closeEvent(QCloseEvent * ce)
{
if (parentWidget())
Expand Down
12 changes: 0 additions & 12 deletions src/gui/modals/SetupDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ inline void labelWidget(QWidget * w, const QString & txt)


SetupDialog::SetupDialog(ConfigTab tab_to_open) :
m_displaydBFS(ConfigManager::inst()->value(
"app", "displaydbfs").toInt()),
m_tooltips(!ConfigManager::inst()->value(
"tooltips", "disabled").toInt()),
m_displayWaveform(ConfigManager::inst()->value(
Expand Down Expand Up @@ -231,8 +229,6 @@ SetupDialog::SetupDialog(ConfigTab tab_to_open) :
QGroupBox * guiGroupBox = new QGroupBox(tr("Graphical user interface (GUI)"), generalControls);
QVBoxLayout * guiGroupLayout = new QVBoxLayout(guiGroupBox);

addCheckBox(tr("Display volume as dBFS "), guiGroupBox, guiGroupLayout,
m_displaydBFS, SLOT(toggleDisplaydBFS(bool)), true);
addCheckBox(tr("Enable tooltips"), guiGroupBox, guiGroupLayout,
m_tooltips, SLOT(toggleTooltips(bool)), true);
addCheckBox(tr("Enable master oscilloscope by default"), guiGroupBox, guiGroupLayout,
Expand Down Expand Up @@ -913,8 +909,6 @@ void SetupDialog::accept()
from taking mouse input, rendering the application unusable. */
QDialog::accept();

ConfigManager::inst()->setValue("app", "displaydbfs",
QString::number(m_displaydBFS));
ConfigManager::inst()->setValue("tooltips", "disabled",
QString::number(!m_tooltips));
ConfigManager::inst()->setValue("ui", "displaywaveform",
Expand Down Expand Up @@ -1003,12 +997,6 @@ void SetupDialog::accept()

// General settings slots.

void SetupDialog::toggleDisplaydBFS(bool enabled)
{
m_displaydBFS = enabled;
}


void SetupDialog::toggleTooltips(bool enabled)
{
m_tooltips = enabled;
Expand Down
Loading
Loading