Skip to content

Commit 14d6bb8

Browse files
committed
Add VolumeKnob
It didn't make sense for the special behavior of volume knobs to be implemented in `FloatModelEditorBase`, so I moved it to a new `VolumeKnob` class which inherits from `Knob`. This significantly reduces the size of the `FloatModelEditorBase` class and all classes which inherit from it, while also simplifying calling code.
1 parent d8f5d92 commit 14d6bb8

24 files changed

+280
-318
lines changed

include/FloatModelEditorBase.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
4141
{
4242
Q_OBJECT
4343

44-
mapPropertyFromModel(float, volumeRatio, setVolumeRatio, m_volumeRatio);
45-
4644
void initUi(const QString & name); //!< to be called by ctors
4745

4846
public:
@@ -62,16 +60,6 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
6260
setUnit(txt_after);
6361
}
6462

65-
bool isVolumeKnob() const
66-
{
67-
return m_volumeKnob;
68-
}
69-
70-
void setVolumeKnob(const bool val)
71-
{
72-
m_volumeKnob = val;
73-
}
74-
7563
//! In this mode, floating text is obtained by calling `pullFloatingText`.
7664
void setFloatingTextPullMode()
7765
{
@@ -143,9 +131,6 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
143131

144132
static SimpleTextFloat * s_textFloat;
145133

146-
bool m_volumeKnob;
147-
FloatModel m_volumeRatio;
148-
149134
QPoint m_lastMousePos; //!< mouse position in last mouseMoveEvent
150135
float m_leftOver;
151136
bool m_buttonPressed;

include/Knob.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ class LMMS_EXPORT Knob : public FloatModelEditorBase
235235
KnobType m_knobNum;
236236
};
237237

238+
239+
class LMMS_EXPORT VolumeKnob : public Knob
240+
{
241+
Q_OBJECT
242+
243+
mapPropertyFromModel(float, volumeRatio, setVolumeRatio, m_volumeRatio);
244+
245+
public:
246+
using Knob::Knob;
247+
248+
protected:
249+
QString pullFloatingText() const override;
250+
void enterValue() override;
251+
252+
private:
253+
FloatModel m_volumeRatio{100.f, 0.f, 1000000.f};
254+
};
255+
256+
238257
} // namespace lmms::gui
239258

240259
#endif // LMMS_GUI_KNOB_H

plugins/Amplifier/AmplifierControlDialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ AmplifierControlDialog::AmplifierControlDialog(AmplifierControls* controls) :
4646

4747
auto makeKnob = [this](const QString& label, const QString& hintText, const QString& unit, FloatModel* model, bool isVolume)
4848
{
49-
Knob* newKnob = new Knob(KnobType::Bright26, label, this);
49+
Knob* newKnob = isVolume
50+
? new VolumeKnob(KnobType::Bright26, label, this)
51+
: new Knob(KnobType::Bright26, label, this);
5052
newKnob->setModel(model);
5153
newKnob->setHintText(hintText, unit);
52-
newKnob->setVolumeKnob(isVolume);
5354
return newKnob;
5455
};
5556

plugins/AudioFileProcessor/AudioFileProcessorView.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ AudioFileProcessorView::AudioFileProcessorView(Instrument* instrument,
114114
m_stutterButton->setToolTip(
115115
tr("Continue sample playback across notes"));
116116

117-
m_ampKnob = new Knob(KnobType::Bright26, this);
118-
m_ampKnob->setVolumeKnob(true);
117+
m_ampKnob = new VolumeKnob(KnobType::Bright26, this);
119118
m_ampKnob->move(5, 108);
120119
m_ampKnob->setHintText(tr("Amplify:"), "%");
121120

plugins/Delay/DelayControlsDialog.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,21 @@ DelayControlsDialog::DelayControlsDialog( DelayControls *controls ) :
4747

4848
auto sampleDelayKnob = new TempoSyncKnob(KnobType::Bright26, tr("DELAY"), this, Knob::LabelRendering::LegacyFixedFontSize);
4949
sampleDelayKnob->move( 10,14 );
50-
sampleDelayKnob->setVolumeKnob( false );
5150
sampleDelayKnob->setModel( &controls->m_delayTimeModel );
5251
sampleDelayKnob->setHintText( tr( "Delay time" ) + " ", " s" );
5352

54-
auto feedbackKnob = new Knob(KnobType::Bright26, tr("FDBK"), this, Knob::LabelRendering::LegacyFixedFontSize);
53+
auto feedbackKnob = new VolumeKnob(KnobType::Bright26, tr("FDBK"), this, Knob::LabelRendering::LegacyFixedFontSize);
5554
feedbackKnob->move( 11, 58 );
56-
feedbackKnob->setVolumeKnob( true) ;
5755
feedbackKnob->setModel( &controls->m_feedbackModel);
5856
feedbackKnob->setHintText( tr ( "Feedback amount" ) + " " , "" );
5957

6058
auto lfoFreqKnob = new TempoSyncKnob(KnobType::Bright26, tr("RATE"), this, Knob::LabelRendering::LegacyFixedFontSize);
6159
lfoFreqKnob->move( 11, 119 );
62-
lfoFreqKnob->setVolumeKnob( false );
6360
lfoFreqKnob->setModel( &controls->m_lfoTimeModel );
6461
lfoFreqKnob->setHintText( tr ( "LFO frequency") + " ", " s" );
6562

6663
auto lfoAmtKnob = new TempoSyncKnob(KnobType::Bright26, tr("AMNT"), this, Knob::LabelRendering::LegacyFixedFontSize);
6764
lfoAmtKnob->move( 11, 159 );
68-
lfoAmtKnob->setVolumeKnob( false );
6965
lfoAmtKnob->setModel( &controls->m_lfoAmountModel );
7066
lfoAmtKnob->setHintText( tr ( "LFO amount" ) + " " , " s" );
7167

plugins/DualFilter/DualFilterControlDialog.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@
3434
namespace lmms::gui
3535
{
3636

37-
38-
#define makeknob( name, x, y, model, label, hint, unit ) \
39-
Knob * name = new Knob(KnobType::Bright26, label, SMALL_FONT_SIZE, this); \
40-
(name) -> move( x, y ); \
41-
(name) ->setModel( &controls-> model ); \
42-
(name) ->setHintText( hint, unit );
43-
44-
45-
4637
DualFilterControlDialog::DualFilterControlDialog( DualFilterControls* controls ) :
4738
EffectControlDialog( controls )
4839
{
@@ -52,16 +43,24 @@ DualFilterControlDialog::DualFilterControlDialog( DualFilterControls* controls )
5243
setPalette( pal );
5344
setFixedSize( 373, 109 );
5445

55-
makeknob( cut1Knob, 24, 26, m_cut1Model, tr( "FREQ" ), tr( "Cutoff frequency" ), "Hz" )
56-
makeknob( res1Knob, 74, 26, m_res1Model, tr( "RESO" ), tr( "Resonance" ), "" )
57-
makeknob( gain1Knob, 124, 26, m_gain1Model, tr( "GAIN" ), tr( "Gain" ), "%" )
58-
makeknob( mixKnob, 173, 37, m_mixModel, tr( "MIX" ), tr( "Mix" ), "" )
59-
makeknob( cut2Knob, 222, 26, m_cut2Model, tr( "FREQ" ), tr( "Cutoff frequency" ), "Hz" )
60-
makeknob( res2Knob, 272, 26, m_res2Model, tr( "RESO" ), tr( "Resonance" ), "" )
61-
makeknob( gain2Knob, 322, 26, m_gain2Model, tr( "GAIN" ), tr( "Gain" ), "%" )
62-
63-
gain1Knob-> setVolumeKnob( true );
64-
gain2Knob-> setVolumeKnob( true );
46+
auto makeKnob = [this](int x, int y, Model* model,
47+
const QString& label, const QString& hint, const QString& unit, bool isVolumeKnob = false)
48+
{
49+
Knob* knob = isVolumeKnob
50+
? new VolumeKnob(KnobType::Bright26, label, SMALL_FONT_SIZE, this)
51+
: new Knob(KnobType::Bright26, label, SMALL_FONT_SIZE, this);
52+
knob->move(x, y);
53+
knob->setModel(model);
54+
knob->setHintText(hint, unit);
55+
};
56+
57+
makeKnob(24, 26, &controls->m_cut1Model, tr("FREQ"), tr("Cutoff frequency"), "Hz");
58+
makeKnob(74, 26, &controls->m_res1Model, tr("RESO"), tr("Resonance"), "");
59+
makeKnob(124, 26, &controls->m_gain1Model, tr("GAIN"), tr("Gain"), "%", true);
60+
makeKnob(173, 37, &controls->m_mixModel, tr("MIX"), tr("Mix"), "");
61+
makeKnob(222, 26, &controls->m_cut2Model, tr("FREQ"), tr("Cutoff frequency"), "Hz");
62+
makeKnob(272, 26, &controls->m_res2Model, tr("RESO"), tr("Resonance"), "");
63+
makeKnob(322, 26, &controls->m_gain2Model, tr("GAIN"), tr("Gain"), "%", true);
6564

6665
auto enabled1Toggle = new LedCheckBox("", this, tr("Filter 1 enabled"), LedCheckBox::LedColor::Green);
6766
auto enabled2Toggle = new LedCheckBox("", this, tr("Filter 2 enabled"), LedCheckBox::LedColor::Green);

plugins/DynamicsProcessor/DynamicsProcessorControlDialog.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,14 @@ DynProcControlDialog::DynProcControlDialog(
5959
waveGraph->setGraphColor( QColor( 85, 204, 145 ) );
6060
waveGraph -> setMaximumSize( 204, 205 );
6161

62-
auto inputKnob = new Knob(KnobType::Bright26, tr("INPUT"), SMALL_FONT_SIZE, this);
63-
inputKnob -> setVolumeKnob( true );
64-
inputKnob -> setVolumeRatio( 1.0 );
62+
auto inputKnob = new VolumeKnob(KnobType::Bright26, tr("INPUT"), SMALL_FONT_SIZE, this);
63+
inputKnob->setVolumeRatio(1.0);
6564
inputKnob -> move( 26, 223 );
6665
inputKnob->setModel( &_controls->m_inputModel );
6766
inputKnob->setHintText( tr( "Input gain:" ) , "" );
6867

69-
auto outputKnob = new Knob(KnobType::Bright26, tr("OUTPUT"), SMALL_FONT_SIZE, this);
70-
outputKnob -> setVolumeKnob( true );
71-
outputKnob -> setVolumeRatio( 1.0 );
68+
auto outputKnob = new VolumeKnob(KnobType::Bright26, tr("OUTPUT"), SMALL_FONT_SIZE, this);
69+
outputKnob->setVolumeRatio(1.0);
7270
outputKnob -> move( 76, 223 );
7371
outputKnob->setModel( &_controls->m_outputModel );
7472
outputKnob->setHintText( tr( "Output gain:" ) , "" );

plugins/Eq/EqControlsDialog.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,12 @@ EqControlsDialog::EqControlsDialog( EqControls *controls ) :
107107
{
108108
auto resKnob = new Knob(KnobType::Bright26, this);
109109
resKnob->move( distance, 440 );
110-
resKnob->setVolumeKnob(false);
111110
resKnob->setModel( m_parameterWidget->getBandModels( i )->res );
112111
if(i > 1 && i < 6) { resKnob->setHintText( tr( "Bandwidth: " ) , tr( " Octave" ) ); }
113112
else { resKnob->setHintText(tr("Resonance: "), ""); }
114113

115114
auto freqKnob = new Knob(KnobType::Bright26, this);
116115
freqKnob->move( distance, 396 );
117-
freqKnob->setVolumeKnob( false );
118116
freqKnob->setModel( m_parameterWidget->getBandModels( i )->freq );
119117
freqKnob->setHintText( tr( "Frequency:" ), "Hz" );
120118

plugins/Flanger/FlangerControlsDialog.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,26 @@ FlangerControlsDialog::FlangerControlsDialog( FlangerControls *controls ) :
4848
mainLayout->addLayout(knobLayout);
4949

5050
auto delayKnob = new Knob(KnobType::Bright26, tr("DELAY"), this);
51-
delayKnob->setVolumeKnob( false );
5251
delayKnob->setModel( &controls->m_delayTimeModel );
5352
delayKnob->setHintText( tr( "Delay time:" ) + " ", "s" );
5453

5554
auto lfoFreqKnob = new TempoSyncKnob(KnobType::Bright26, tr("RATE"), this);
56-
lfoFreqKnob->setVolumeKnob( false );
5755
lfoFreqKnob->setModel( &controls->m_lfoFrequencyModel );
5856
lfoFreqKnob->setHintText( tr( "Period:" ) , " Sec" );
5957

6058
auto lfoAmtKnob = new Knob(KnobType::Bright26, tr("AMNT"), this);
61-
lfoAmtKnob->setVolumeKnob( false );
6259
lfoAmtKnob->setModel( &controls->m_lfoAmountModel );
6360
lfoAmtKnob->setHintText( tr( "Amount:" ) , "" );
6461

6562
auto lfoPhaseKnob = new Knob(KnobType::Bright26, tr("PHASE"), this);
66-
lfoPhaseKnob->setVolumeKnob( false );
6763
lfoPhaseKnob->setModel( &controls->m_lfoPhaseModel );
6864
lfoPhaseKnob->setHintText( tr( "Phase:" ) , " degrees" );
6965

70-
auto feedbackKnob = new Knob(KnobType::Bright26, tr("FDBK"), this);
71-
feedbackKnob->setVolumeKnob( true) ;
66+
auto feedbackKnob = new VolumeKnob(KnobType::Bright26, tr("FDBK"), this);
7267
feedbackKnob->setModel( &controls->m_feedbackModel );
7368
feedbackKnob->setHintText( tr( "Feedback amount:" ) , "" );
7469

75-
auto whiteNoiseKnob = new Knob(KnobType::Bright26, tr("NOISE"), this);
76-
whiteNoiseKnob->setVolumeKnob( true) ;
70+
auto whiteNoiseKnob = new VolumeKnob(KnobType::Bright26, tr("NOISE"), this);
7771
whiteNoiseKnob->setModel( &controls->m_whiteNoiseAmountModel );
7872
whiteNoiseKnob->setHintText( tr( "White noise amount:" ) , "" );
7973

0 commit comments

Comments
 (0)