Skip to content

Commit

Permalink
Fix for Mixer volume percentage labels are off by a factor of 100 (#…
Browse files Browse the repository at this point in the history
…5661)

Add m_conversionFactor to the AutomatableModelView. This factor will be applied to the model->value when displaying
it in the contextmenu of the control for the reset and copy actions. The factor will be applied when copying the value to
the clipboard. When pasting from the clipboard, the value will be divided by the factor.

Remove the model->displayValue() calls when updating the reset/copy/paste action text labels as this gives e.g. in the
Equalizer the wrong action text for the Frequency knobs.

In the Fader class, remove the m_displayConversion variable but rather use the new m_conversionFactor variable.
Rewire the setDisplayConversion() function to set the m_conversionFactor to 1.0 or 100.0.

Faders in FxMixer show now the correct context menu. Copying and pasting values between faders or even volume knobs
in tracks shows consistent behavior. Other faders (like in Eq) show the old behavior.
  • Loading branch information
DigArtRoks authored Sep 21, 2020
1 parent a6d0b46 commit 2f37281
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
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 @@ -99,7 +99,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 @@ -155,8 +155,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

0 comments on commit 2f37281

Please sign in to comment.