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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Show current dB value of fader in tool tip
Show the current value of the fader in its tool tip. Please note that
this value is always shown in dB because the goal should be to get rid
of the linear values for the faders.

Some of the code is extracted into the new method
`Fader::getModelValueAsDbString` which is shared by
`Fader::modelValueChanged` (also new) and `Fader::updateTextFloat`.

Please note that `getModelValueAsDbString` will use "dB" instead of
"dBFS" as the unit and that it will format "-inf dB" instead of "-∞ dB".
These changes will also be visible in the text float that is used to
show the new values as the fader is being dragged.
  • Loading branch information
michaelgregorius committed Dec 24, 2024
commit be0084b76a40d0f1c5fefcdc0d41f6432d471216
2 changes: 2 additions & 0 deletions include/Fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
void setPeak(float fPeak, float& targetPeak, float& persistentPeak, QElapsedTimer& lastPeakTimer);

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

bool modelIsLinear() const { return m_modelIsLinear; }

Expand Down
46 changes: 37 additions & 9 deletions src/gui/widgets/Fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ Fader::Fader(FloatModel* model, const QString& name, QWidget* parent, bool model
setHintText("Volume:", "%");

m_conversionFactor = 100.0;

if (model)
{
// We currently assume that the model is not changed later on and only connect here once

// This is for example used to update the tool tip which shows the current value of the fader
connect(model, &FloatModel::dataChanged, this, &Fader::modelValueChanged);

// Trigger manually so that the tool tip is initialized correctly
modelValueChanged();
}
}


Expand Down Expand Up @@ -346,27 +357,44 @@ void Fader::updateTextFloat()
{
if (ConfigManager::inst()->value("app", "displaydbfs").toInt() && m_conversionFactor == 100.0)
{
QString label(tr("Volume: %1 dBFS"));
s_textFloat->setText(getModelValueAsDbString());
}
else
{
s_textFloat->setText(m_description + " " + QString("%1 ").arg(model()->value() * m_conversionFactor) + " " + m_unit);
}

s_textFloat->moveGlobal(this, QPoint(width() + 2, calculateKnobPosYFromModel() - s_textFloat->height() / 2));
}

auto const modelValue = model()->value();
if (modelValue <= 0.)
void Fader::modelValueChanged()
{
setToolTip(getModelValueAsDbString());
}

QString Fader::getModelValueAsDbString() const
{
const auto value = model()->value();

QString label(tr("Volume: %1 dB"));

if (modelIsLinear())
{
if (value <= 0.)
{
s_textFloat->setText(label.arg("-∞"));
return label.arg(tr("-inf"));
}
else
{
s_textFloat->setText(label.arg(ampToDbfs(modelValue), 3, 'f', 2));
return label.arg(ampToDbfs(value), 3, 'f', 2);
}
}
else
{
s_textFloat->setText(m_description + " " + QString("%1 ").arg(model()->value() * m_conversionFactor) + " " + m_unit);
return label.arg(value, 3, 'f', 2);
}

s_textFloat->moveGlobal(this, QPoint(width() + 2, calculateKnobPosYFromModel() - s_textFloat->height() / 2));
}


void Fader::paintEvent(QPaintEvent* ev)
{
QPainter painter(this);
Expand Down