Skip to content

Commit 2f37281

Browse files
authored
Fix for Mixer volume percentage labels are off by a factor of 100 (#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.
1 parent a6d0b46 commit 2f37281

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

include/AutomatableModelView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ class LMMS_EXPORT AutomatableModelView : public ModelView
6969

7070
void addDefaultActions( QMenu* menu );
7171

72+
void setConversionFactor( float factor );
73+
float getConversionFactor();
74+
7275

7376
protected:
7477
virtual void mousePressEvent( QMouseEvent* event );
7578

7679
QString m_description;
7780
QString m_unit;
81+
float m_conversionFactor; // Factor to be applied when the m_model->value is displayed
7882
} ;
7983

8084

include/Fader.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
9999

100100
void setDisplayConversion( bool b )
101101
{
102-
m_displayConversion = b;
102+
m_conversionFactor = b ? 100.0 : 1.0;
103103
}
104104

105105
inline void setHintText( const QString & _txt_before,
@@ -155,8 +155,7 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
155155
QPixmap * m_back;
156156
QPixmap * m_leds;
157157
QPixmap * m_knob;
158-
159-
bool m_displayConversion;
158+
160159
bool m_levelsDisplayedInDBFS;
161160

162161
int m_moveStartPoint;

src/gui/AutomatableModelView.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
static float floatFromClipboard(bool* ok=nullptr);
4343

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

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

6364
menu->addSeparator();
6465
menu->addAction( embed::getIconPixmap( "edit_copy" ),
6566
AutomatableModel::tr( "&Copy value (%1%2)" ).
66-
arg( model->displayValue( model->value<float>() ) ).
67+
arg( model->value<float>() * m_conversionFactor ).
6768
arg( m_unit ),
6869
amvSlots, SLOT( copyToClipboard() ) );
6970

7071
bool canPaste = true;
7172
const float valueToPaste = floatFromClipboard(&canPaste);
7273
const QString pasteDesc = canPaste ?
7374
AutomatableModel::tr( "&Paste value (%1%2)").
74-
arg( model->displayValue( valueToPaste ) ).
75+
arg( valueToPaste ).
7576
arg( m_unit )
7677
: AutomatableModel::tr( "&Paste value");
7778
QAction* pasteAction = menu->addAction( embed::getIconPixmap( "edit_paste" ),
@@ -155,8 +156,20 @@ void AutomatableModelView::mousePressEvent( QMouseEvent* event )
155156
}
156157

157158

159+
void AutomatableModelView::setConversionFactor( float factor )
160+
{
161+
if( factor != 0.0 )
162+
{
163+
m_conversionFactor = factor;
164+
}
165+
}
158166

159167

168+
float AutomatableModelView::getConversionFactor()
169+
{
170+
return m_conversionFactor;
171+
}
172+
160173

161174
AutomatableModelViewSlots::AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent ) :
162175
QObject(),
@@ -243,15 +256,15 @@ void AutomatableModelViewSlots::unlinkAllModels()
243256
void AutomatableModelViewSlots::copyToClipboard()
244257
{
245258
QClipboard* clipboard = QApplication::clipboard();
246-
clipboard->setText(QString::number(m_amv->value<float>()));
259+
clipboard->setText(QString::number(m_amv->value<float>() * m_amv->getConversionFactor()));
247260
}
248261

249262
void AutomatableModelViewSlots::pasteFromClipboard()
250263
{
251264
bool isNumber = false;
252265
const float number = floatFromClipboard(&isNumber);
253266
if (isNumber) {
254-
m_amv->modelUntyped()->setValue(number);
267+
m_amv->modelUntyped()->setValue(number / m_amv->getConversionFactor());
255268
}
256269
}
257270

src/gui/widgets/Fader.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ Fader::Fader( FloatModel * _model, const QString & _name, QWidget * _parent ) :
7272
m_persistentPeak_R( 0.0 ),
7373
m_fMinPeak( 0.01f ),
7474
m_fMaxPeak( 1.1 ),
75-
m_displayConversion( true ),
7675
m_levelsDisplayedInDBFS(false),
7776
m_moveStartPoint( -1 ),
7877
m_startValue( 0 ),
@@ -102,6 +101,8 @@ Fader::Fader( FloatModel * _model, const QString & _name, QWidget * _parent ) :
102101
m_knob = s_knob;
103102

104103
init(_model, _name);
104+
105+
m_conversionFactor = 100.0;
105106
}
106107

107108

@@ -114,7 +115,6 @@ Fader::Fader( FloatModel * model, const QString & name, QWidget * parent, QPixma
114115
m_persistentPeak_R( 0.0 ),
115116
m_fMinPeak( 0.01f ),
116117
m_fMaxPeak( 1.1 ),
117-
m_displayConversion( false ),
118118
m_levelsDisplayedInDBFS(false),
119119
m_moveStartPoint( -1 ),
120120
m_startValue( 0 ),
@@ -217,26 +217,13 @@ void Fader::mouseDoubleClickEvent( QMouseEvent* mouseEvent )
217217
bool ok;
218218
float newValue;
219219
// TODO: dbV handling
220-
if( m_displayConversion )
221-
{
222-
newValue = QInputDialog::getDouble( this, tr( "Set value" ),
223-
tr( "Please enter a new value between %1 and %2:" ).
224-
arg( model()->minValue() * 100 ).
225-
arg( model()->maxValue() * 100 ),
226-
model()->getRoundedValue() * 100,
227-
model()->minValue() * 100,
228-
model()->maxValue() * 100, model()->getDigitCount(), &ok ) * 0.01f;
229-
}
230-
else
231-
{
232-
newValue = QInputDialog::getDouble( this, tr( "Set value" ),
233-
tr( "Please enter a new value between %1 and %2:" ).
234-
arg( model()->minValue() ).
235-
arg( model()->maxValue() ),
236-
model()->getRoundedValue(),
237-
model()->minValue(),
238-
model()->maxValue(), model()->getDigitCount(), &ok );
239-
}
220+
newValue = QInputDialog::getDouble( this, tr( "Set value" ),
221+
tr( "Please enter a new value between %1 and %2:" ).
222+
arg( model()->minValue() * m_conversionFactor ).
223+
arg( model()->maxValue() * m_conversionFactor ),
224+
model()->getRoundedValue() * m_conversionFactor,
225+
model()->minValue() * m_conversionFactor,
226+
model()->maxValue() * m_conversionFactor, model()->getDigitCount(), &ok ) / m_conversionFactor;
240227

241228
if( ok )
242229
{
@@ -330,14 +317,14 @@ void Fader::setPeak_R( float fPeak )
330317
// update tooltip showing value and adjust position while changing fader value
331318
void Fader::updateTextFloat()
332319
{
333-
if( ConfigManager::inst()->value( "app", "displaydbfs" ).toInt() && m_displayConversion )
320+
if( ConfigManager::inst()->value( "app", "displaydbfs" ).toInt() && m_conversionFactor == 100.0 )
334321
{
335322
s_textFloat->setText( QString("Volume: %1 dBFS").
336323
arg( ampToDbfs( model()->value() ), 3, 'f', 2 ) );
337324
}
338325
else
339326
{
340-
s_textFloat->setText( m_description + " " + QString("%1 ").arg( m_displayConversion ? model()->value() * 100 : model()->value() ) + " " + m_unit );
327+
s_textFloat->setText( m_description + " " + QString("%1 ").arg( model()->value() * m_conversionFactor ) + " " + m_unit );
341328
}
342329
s_textFloat->moveGlobal( this, QPoint( width() - ( *m_knob ).width() - 5, knobPosY() - 46 ) );
343330
}

0 commit comments

Comments
 (0)