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

Fix for Mixer volume percentage labels are off by a factor of 100 #5661

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions include/AutomatableModelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ class LMMS_EXPORT AutomatableModelView : public ModelView

void addDefaultActions( QMenu* menu );

void setConversionFactor( float factor );
float getConversionFactor();


protected:
virtual void mousePressEvent( QMouseEvent* event );

QString m_description;
QString m_unit;
float m_conversionFactor; // Factor to be applied when the m_model->value is displayed
} ;


Expand Down
5 changes: 2 additions & 3 deletions include/Fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView

void setDisplayConversion( bool b )
{
m_displayConversion = b;
m_conversionFactor = b ? 100.0 : 1.0;
}

inline void setHintText( const QString & _txt_before,
Expand Down Expand Up @@ -154,8 +154,7 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
QPixmap * m_back;
QPixmap * m_leds;
QPixmap * m_knob;

bool m_displayConversion;

bool m_levelsDisplayedInDBFS;

int m_moveStartPoint;
Expand Down
25 changes: 19 additions & 6 deletions src/gui/AutomatableModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
static float floatFromClipboard(bool* ok=nullptr);

AutomatableModelView::AutomatableModelView( ::Model* model, QWidget* _this ) :
ModelView( model, _this )
ModelView( model, _this ),
m_conversionFactor( 1.0 )
{
widget()->setAcceptDrops( true );
widget()->setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) );
Expand All @@ -56,22 +57,22 @@ void AutomatableModelView::addDefaultActions( QMenu* menu )

menu->addAction( embed::getIconPixmap( "reload" ),
AutomatableModel::tr( "&Reset (%1%2)" ).
arg( model->displayValue( model->initValue<float>() ) ).
arg( model->initValue<float>() * m_conversionFactor ).
arg( m_unit ),
model, SLOT( reset() ) );

menu->addSeparator();
menu->addAction( embed::getIconPixmap( "edit_copy" ),
AutomatableModel::tr( "&Copy value (%1%2)" ).
arg( model->displayValue( model->value<float>() ) ).
arg( model->value<float>() * m_conversionFactor ).
arg( m_unit ),
amvSlots, SLOT( copyToClipboard() ) );

bool canPaste = true;
const float valueToPaste = floatFromClipboard(&canPaste);
const QString pasteDesc = canPaste ?
AutomatableModel::tr( "&Paste value (%1%2)").
arg( model->displayValue( valueToPaste ) ).
arg( valueToPaste ).
arg( m_unit )
: AutomatableModel::tr( "&Paste value");
QAction* pasteAction = menu->addAction( embed::getIconPixmap( "edit_paste" ),
Expand Down Expand Up @@ -155,8 +156,20 @@ void AutomatableModelView::mousePressEvent( QMouseEvent* event )
}


void AutomatableModelView::setConversionFactor( float factor )
{
if( factor != 0.0 )
{
m_conversionFactor = factor;
}
}


float AutomatableModelView::getConversionFactor()
{
return m_conversionFactor;
}


AutomatableModelViewSlots::AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent ) :
QObject(),
Expand Down Expand Up @@ -243,15 +256,15 @@ void AutomatableModelViewSlots::unlinkAllModels()
void AutomatableModelViewSlots::copyToClipboard()
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(QString::number(m_amv->value<float>()));
clipboard->setText(QString::number(m_amv->value<float>() * m_amv->getConversionFactor()));
}

void AutomatableModelViewSlots::pasteFromClipboard()
{
bool isNumber = false;
const float number = floatFromClipboard(&isNumber);
if (isNumber) {
m_amv->modelUntyped()->setValue(number);
m_amv->modelUntyped()->setValue(number / m_amv->getConversionFactor());
}
}

Expand Down
35 changes: 11 additions & 24 deletions src/gui/widgets/Fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Fader::Fader( FloatModel * _model, const QString & _name, QWidget * _parent ) :
m_persistentPeak_R( 0.0 ),
m_fMinPeak( 0.01f ),
m_fMaxPeak( 1.1 ),
m_displayConversion( true ),
m_levelsDisplayedInDBFS(false),
m_moveStartPoint( -1 ),
m_startValue( 0 ),
Expand Down Expand Up @@ -102,6 +101,8 @@ Fader::Fader( FloatModel * _model, const QString & _name, QWidget * _parent ) :
m_knob = s_knob;

init(_model, _name);

m_conversionFactor = 100.0;
}


Expand All @@ -114,7 +115,6 @@ Fader::Fader( FloatModel * model, const QString & name, QWidget * parent, QPixma
m_persistentPeak_R( 0.0 ),
m_fMinPeak( 0.01f ),
m_fMaxPeak( 1.1 ),
m_displayConversion( false ),
m_levelsDisplayedInDBFS(false),
m_moveStartPoint( -1 ),
m_startValue( 0 ),
Expand Down Expand Up @@ -217,26 +217,13 @@ void Fader::mouseDoubleClickEvent( QMouseEvent* mouseEvent )
bool ok;
float newValue;
// TODO: dbV handling
if( m_displayConversion )
{
newValue = QInputDialog::getDouble( this, tr( "Set value" ),
tr( "Please enter a new value between %1 and %2:" ).
arg( model()->minValue() * 100 ).
arg( model()->maxValue() * 100 ),
model()->getRoundedValue() * 100,
model()->minValue() * 100,
model()->maxValue() * 100, model()->getDigitCount(), &ok ) * 0.01f;
}
else
{
newValue = QInputDialog::getDouble( this, tr( "Set value" ),
tr( "Please enter a new value between %1 and %2:" ).
arg( model()->minValue() ).
arg( model()->maxValue() ),
model()->getRoundedValue(),
model()->minValue(),
model()->maxValue(), model()->getDigitCount(), &ok );
}
newValue = QInputDialog::getDouble( this, tr( "Set value" ),
tr( "Please enter a new value between %1 and %2:" ).
arg( model()->minValue() * m_conversionFactor ).
arg( model()->maxValue() * m_conversionFactor ),
model()->getRoundedValue() * m_conversionFactor,
model()->minValue() * m_conversionFactor,
model()->maxValue() * m_conversionFactor, model()->getDigitCount(), &ok ) / m_conversionFactor;

if( ok )
{
Expand Down Expand Up @@ -330,14 +317,14 @@ void Fader::setPeak_R( float fPeak )
// update tooltip showing value and adjust position while changing fader value
void Fader::updateTextFloat()
{
if( ConfigManager::inst()->value( "app", "displaydbfs" ).toInt() && m_displayConversion )
if( ConfigManager::inst()->value( "app", "displaydbfs" ).toInt() && m_conversionFactor == 100.0 )
{
s_textFloat->setText( QString("Volume: %1 dBFS").
arg( ampToDbfs( model()->value() ), 3, 'f', 2 ) );
}
else
{
s_textFloat->setText( m_description + " " + QString("%1 ").arg( m_displayConversion ? model()->value() * 100 : model()->value() ) + " " + m_unit );
s_textFloat->setText( m_description + " " + QString("%1 ").arg( model()->value() * m_conversionFactor ) + " " + m_unit );
}
s_textFloat->moveGlobal( this, QPoint( width() - ( *m_knob ).width() - 5, knobPosY() - 46 ) );
}
Expand Down