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

Individual knob labels rendered using the widget font #7525

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
2 changes: 2 additions & 0 deletions include/CustomTextKnob.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class LMMS_EXPORT CustomTextKnob : public Knob

CustomTextKnob( const Knob& other ) = delete;

static CustomTextKnob* buildKnobWithSmallPixelFont(KnobType knob_num, QWidget* parent, const QString& description, const QString& label);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to mention "Knob" in the function name. createWithSmallFont might be better.

Or just make this a constructor.


inline void setValueText(const QString & _value_text)
{
m_value_text = _value_text;
Expand Down
12 changes: 11 additions & 1 deletion include/Knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ class LMMS_EXPORT Knob : public FloatModelEditorBase
Knob( QWidget * _parent = nullptr, const QString & _name = QString() ); //!< default ctor
Knob( const Knob& other ) = delete;

void setLabel( const QString & txt );
static Knob* buildLegacyKnob(KnobType knob_num, const QString& label, QWidget* parent, const QString & _name = QString());
static Knob* buildKnobWithSmallPixelFont(KnobType knob_num, const QString& label, QWidget* parent, const QString & _name = QString());

void setLabel(const QString & txt);
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved
void setHtmlLabel( const QString &htmltxt );

bool legacyMode() const { return m_legacyMode; }
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved
void setLegacyMode(bool legacyMode);

void setTotalAngle( float angle );

// Begin styled knob accessors
Expand Down Expand Up @@ -122,14 +128,18 @@ class LMMS_EXPORT Knob : public FloatModelEditorBase
float _innerRadius = 1) const;

void drawKnob( QPainter * _p );
void drawLabel(QPainter& p);
bool updateAngle();

int angleFromValue( float value, float minValue, float maxValue, float totalAngle ) const
{
return static_cast<int>( ( value - 0.5 * ( minValue + maxValue ) ) / ( maxValue - minValue ) * m_totalAngle ) % 360;
}

void updateFixedSize();

QString m_label;
bool m_legacyMode = false;
bool m_isHtmlLabel;
QTextDocument* m_tdRenderer;

Expand Down
3 changes: 3 additions & 0 deletions include/TempoSyncKnob.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class LMMS_EXPORT TempoSyncKnob : public Knob
TempoSyncKnob( KnobType knobNum, QWidget* parent = nullptr, const QString& name = QString() );
~TempoSyncKnob() override;

static TempoSyncKnob* buildLegacyKnob(KnobType knob_num, const QString& label, QWidget* parent);
static TempoSyncKnob* buildKnobWithSmallPixelFont(KnobType knob_num, const QString& label, QWidget* parent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like these could also be given more concise names or be made constructors.

And it would be good to cut down on duplicate code by not having these build functions in all 3 knob classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turning it into a constructor would lead to lots of verbose code in several areas. With this PR the Knob is intended to render the label using the font that's currently set for it. Without any intervention this normally would be the font that's used by its parent (as is also the case for Qt widgets).

Let's see what Knob::buildKnobWithSmallPixelFont does:

auto result = new Knob(knobNum, parent, name);
result->setFont(adjustedToPixelSize(result->font(), SMALL_FONT_SIZE));
result->setLabel(label);

return result;

One of the things that it does is to set the font to the small font size by using adjustedToPixelSize. This would have to be repeated in all places where clients currently use buildKnobWithSmallPixelFont. The label would also need to be set explicitly because the Knob constructor does not support taking the label. Therefore I propose to keep the builder/factory methods for now.

What do you think about moving the build methods that are currently provided by Knob, CustomTextKnob and TempoSyncKnob into a factory class?


const QString & syncDescription();
void setSyncDescription( const QString & _new_description );

Expand Down
21 changes: 12 additions & 9 deletions plugins/Amplifier/AmplifierControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "embed.h"
#include "Knob.h"

#include <QGridLayout>


namespace lmms::gui
{

Expand All @@ -38,23 +41,23 @@ AmplifierControlDialog::AmplifierControlDialog(AmplifierControls* controls) :
QPalette pal;
pal.setBrush(backgroundRole(), PLUGIN_NAME::getIconPixmap("artwork"));
setPalette(pal);
setFixedSize(100, 110);

QGridLayout* gridLayout = new QGridLayout(this);

auto makeKnob = [this](int x, int y, const QString& label, const QString& hintText, const QString& unit, FloatModel* model, bool isVolume)
auto makeKnob = [this](const QString& label, const QString& hintText, const QString& unit, FloatModel* model, bool isVolume)
{
Knob* newKnob = new Knob(KnobType::Bright26, this);
newKnob->move(x, y);
Knob* newKnob = new Knob(KnobType::Bright26, this);
newKnob->setModel(model);
newKnob->setLabel(label);
newKnob->setLabel(label);
newKnob->setHintText(hintText, unit);
newKnob->setVolumeKnob(isVolume);
return newKnob;
};

makeKnob(16, 10, tr("VOL"), tr("Volume:"), "%", &controls->m_volumeModel, true);
makeKnob(57, 10, tr("PAN"), tr("Panning:"), "%", &controls->m_panModel, false);
makeKnob(16, 65, tr("LEFT"), tr("Left gain:"), "%", &controls->m_leftModel, true);
makeKnob(57, 65, tr("RIGHT"), tr("Right gain:"), "%", &controls->m_rightModel, true);
gridLayout->addWidget(makeKnob(tr("VOL"), tr("Volume:"), "%", &controls->m_volumeModel, true), 0, 0, Qt::AlignHCenter);
gridLayout->addWidget(makeKnob(tr("PAN"), tr("Panning:"), "%", &controls->m_panModel, false), 0, 1, Qt::AlignHCenter);
gridLayout->addWidget(makeKnob(tr("LEFT"), tr("Left gain:"), "%", &controls->m_leftModel, true), 1, 0, Qt::AlignHCenter);
gridLayout->addWidget(makeKnob(tr("RIGHT"), tr("Right gain:"), "%", &controls->m_rightModel, true), 1, 1, Qt::AlignHCenter);
}

} // namespace lmms::gui
7 changes: 3 additions & 4 deletions plugins/BassBooster/BassBoosterControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ BassBoosterControlDialog::BassBoosterControlDialog( BassBoosterControls* control
QPalette pal;
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
setPalette( pal );
setFixedSize( 120, 60 );

auto tl = new QVBoxLayout(this);
tl->addSpacing( 4 );
Expand All @@ -52,17 +51,17 @@ BassBoosterControlDialog::BassBoosterControlDialog( BassBoosterControls* control

auto freqKnob = new Knob(KnobType::Bright26, this);
freqKnob->setModel( &controls->m_freqModel );
freqKnob->setLabel( tr( "FREQ" ) );
freqKnob->setLabel(tr("FREQ"));
freqKnob->setHintText( tr( "Frequency:" ) , "Hz" );

auto gainKnob = new Knob(KnobType::Bright26, this);
gainKnob->setModel( &controls->m_gainModel );
gainKnob->setLabel( tr( "GAIN" ) );
gainKnob->setLabel(tr("GAIN"));
gainKnob->setHintText( tr( "Gain:" ) , "" );

auto ratioKnob = new Knob(KnobType::Bright26, this);
ratioKnob->setModel( &controls->m_ratioModel );
ratioKnob->setLabel( tr( "RATIO" ) );
ratioKnob->setLabel(tr("RATIO"));
ratioKnob->setHintText( tr( "Ratio:" ) , "" );

l->addWidget( freqKnob );
Expand Down
26 changes: 12 additions & 14 deletions plugins/Bitcrush/BitcrushControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "embed.h"
#include "BitcrushControlDialog.h"
#include "BitcrushControls.h"
#include "FontHelper.h"
#include "LedCheckBox.h"
#include "Knob.h"

Expand All @@ -46,37 +47,37 @@ BitcrushControlDialog::BitcrushControlDialog( BitcrushControls * controls ) :
setFixedSize( 181, 128 );

// labels
const auto labelFont = adjustedToPixelSize(font(), DEFAULT_FONT_SIZE);

auto inLabel = new QLabel(tr("IN"), this);
inLabel->setFont(labelFont);
inLabel->move( 24, 15 );

auto outLabel = new QLabel(tr("OUT"), this);
outLabel->setFont(labelFont);
outLabel->move( 139, 15 );

// input knobs
auto inGain = new Knob(KnobType::Bright26, this);
auto inGain = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("GAIN"), this);
inGain->move( 16, 32 );
inGain->setModel( & controls->m_inGain );
inGain->setLabel( tr( "GAIN" ) );
inGain->setHintText( tr( "Input gain:" ) , " dBFS" );

auto inNoise = new Knob(KnobType::Bright26, this);
auto inNoise = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("NOISE"), this);
inNoise->move( 14, 76 );
inNoise->setModel( & controls->m_inNoise );
inNoise->setLabel( tr( "NOISE" ) );
inNoise->setHintText( tr( "Input noise:" ) , "%" );


// output knobs
auto outGain = new Knob(KnobType::Bright26, this);
auto outGain = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("GAIN"), this);
outGain->move( 138, 32 );
outGain->setModel( & controls->m_outGain );
outGain->setLabel( tr( "GAIN" ) );
outGain->setHintText( tr( "Output gain:" ) , " dBFS" );

auto outClip = new Knob(KnobType::Bright26, this);
auto outClip = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("CLIP"), this);
outClip->move( 138, 76 );
outClip->setModel( & controls->m_outClip );
outClip->setLabel( tr( "CLIP" ) );
outClip->setHintText( tr( "Output clip:" ) , " dBFS");


Expand All @@ -94,24 +95,21 @@ BitcrushControlDialog::BitcrushControlDialog( BitcrushControls * controls ) :


// rate crushing knobs
auto rate = new Knob(KnobType::Bright26, this);
auto rate = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("FREQ"), this);
rate->move( 59, 32 );
rate->setModel( & controls->m_rate );
rate->setLabel( tr( "FREQ" ) );
rate->setHintText( tr( "Sample rate:" ) , " Hz" );

auto stereoDiff = new Knob(KnobType::Bright26, this);
auto stereoDiff = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("STEREO"), this);
stereoDiff->move( 72, 76 );
stereoDiff->setModel( & controls->m_stereoDiff );
stereoDiff->setLabel( tr( "STEREO" ) );
stereoDiff->setHintText( tr( "Stereo difference:" ) , "%" );


// depth crushing knob
auto levels = new Knob(KnobType::Bright26, this);
auto levels = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("QUANT"), this);
levels->move( 92, 32 );
levels->setModel( & controls->m_levels );
levels->setLabel( tr( "QUANT" ) );
levels->setHintText( tr( "Levels:" ) , "" );
}

Expand Down
5 changes: 2 additions & 3 deletions plugins/CarlaBase/Carla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,9 @@ void CarlaParamsView::refreshKnobs()
for (uint32_t i = 0; i < m_carlaInstrument->m_paramModels.size(); ++i)
{
bool enabled = m_carlaInstrument->m_paramModels[i]->enabled();
m_knobs.push_back(new Knob(KnobType::Dark28, m_inputScrollAreaWidgetContent));
QString name = (*m_carlaInstrument->m_paramModels[i]).displayName();
const QString name = (*m_carlaInstrument->m_paramModels[i]).displayName();
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved
m_knobs.push_back(Knob::buildLegacyKnob(KnobType::Dark28, name, m_inputScrollAreaWidgetContent));
m_knobs[i]->setHintText(name, "");
m_knobs[i]->setLabel(name);
m_knobs[i]->setObjectName(name); // this is being used for filtering the knobs.

// Set the newly created model to the knob.
Expand Down
9 changes: 3 additions & 6 deletions plugins/CrossoverEQ/CrossoverEQControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,19 @@ CrossoverEQControlDialog::CrossoverEQControlDialog( CrossoverEQControls * contro
setFixedSize( 167, 178 );

// knobs
auto xover12 = new Knob(KnobType::Bright26, this);
auto xover12 = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, "1/2", this);
xover12->move( 29, 11 );
xover12->setModel( & controls->m_xover12 );
xover12->setLabel( "1/2" );
xover12->setHintText( tr( "Band 1/2 crossover:" ), " Hz" );

auto xover23 = new Knob(KnobType::Bright26, this);
auto xover23 = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, "2/3", this);
xover23->move( 69, 11 );
xover23->setModel( & controls->m_xover23 );
xover23->setLabel( "2/3" );
xover23->setHintText( tr( "Band 2/3 crossover:" ), " Hz" );

auto xover34 = new Knob(KnobType::Bright26, this);
auto xover34 = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, "3/4", this);
xover34->move( 109, 11 );
xover34->setModel( & controls->m_xover34 );
xover34->setLabel( "3/4" );
xover34->setHintText( tr( "Band 3/4 crossover:" ), " Hz" );

QPixmap const fader_knob(PLUGIN_NAME::getIconPixmap("fader_knob2"));
Expand Down
12 changes: 4 additions & 8 deletions plugins/Delay/DelayControlsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,28 @@ DelayControlsDialog::DelayControlsDialog( DelayControls *controls ) :
setPalette( pal );
setFixedSize( 300, 208 );

auto sampleDelayKnob = new TempoSyncKnob(KnobType::Bright26, this);
auto sampleDelayKnob = TempoSyncKnob::buildLegacyKnob(KnobType::Bright26, tr("DELAY"), this);
sampleDelayKnob->move( 10,14 );
sampleDelayKnob->setVolumeKnob( false );
sampleDelayKnob->setModel( &controls->m_delayTimeModel );
sampleDelayKnob->setLabel( tr( "DELAY" ) );
sampleDelayKnob->setHintText( tr( "Delay time" ) + " ", " s" );

auto feedbackKnob = new Knob(KnobType::Bright26, this);
auto feedbackKnob = Knob::buildLegacyKnob(KnobType::Bright26, tr("FDBK"), this);
feedbackKnob->move( 11, 58 );
feedbackKnob->setVolumeKnob( true) ;
feedbackKnob->setModel( &controls->m_feedbackModel);
feedbackKnob->setLabel( tr( "FDBK" ) );
feedbackKnob->setHintText( tr ( "Feedback amount" ) + " " , "" );

auto lfoFreqKnob = new TempoSyncKnob(KnobType::Bright26, this);
auto lfoFreqKnob = TempoSyncKnob::buildLegacyKnob(KnobType::Bright26, tr("RATE"), this);
lfoFreqKnob->move( 11, 119 );
lfoFreqKnob->setVolumeKnob( false );
lfoFreqKnob->setModel( &controls->m_lfoTimeModel );
lfoFreqKnob->setLabel( tr( "RATE" ) );
lfoFreqKnob->setHintText( tr ( "LFO frequency") + " ", " s" );

auto lfoAmtKnob = new TempoSyncKnob(KnobType::Bright26, this);
auto lfoAmtKnob = TempoSyncKnob::buildLegacyKnob(KnobType::Bright26, tr("AMNT"), this);
lfoAmtKnob->move( 11, 159 );
lfoAmtKnob->setVolumeKnob( false );
lfoAmtKnob->setModel( &controls->m_lfoAmountModel );
lfoAmtKnob->setLabel( tr( "AMNT" ) );
lfoAmtKnob->setHintText( tr ( "LFO amount" ) + " " , " s" );

auto outFader
Expand Down
16 changes: 10 additions & 6 deletions plugins/Dispersion/DispersionControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "LcdSpinBox.h"
#include "PixmapButton.h"

#include <QHBoxLayout>


namespace lmms::gui
{
Expand All @@ -43,39 +45,41 @@ DispersionControlDialog::DispersionControlDialog(DispersionControls* controls) :
QPalette pal;
pal.setBrush(backgroundRole(), PLUGIN_NAME::getIconPixmap("artwork"));
setPalette(pal);
setFixedSize(207, 50);

auto layout = new QHBoxLayout(this);

LcdSpinBox * m_amountBox = new LcdSpinBox(3, this, "Amount");
m_amountBox->setModel(&controls->m_amountModel);
m_amountBox->move(5, 10);
m_amountBox->setLabel(tr("AMOUNT"));
m_amountBox->setToolTip(tr("Number of all-pass filters"));

Knob * freqKnob = new Knob(KnobType::Bright26, this);
freqKnob->move(59, 8);
freqKnob->setModel(&controls->m_freqModel);
freqKnob->setLabel(tr("FREQ"));
freqKnob->setHintText(tr("Frequency:") , " Hz");

Knob * resoKnob = new Knob(KnobType::Bright26, this);
resoKnob->move(99, 8);
resoKnob->setModel(&controls->m_resoModel);
resoKnob->setLabel(tr("RESO"));
resoKnob->setHintText(tr("Resonance:") , " octaves");

Knob * feedbackKnob = new Knob(KnobType::Bright26, this);
feedbackKnob->move(139, 8);
feedbackKnob->setModel(&controls->m_feedbackModel);
feedbackKnob->setLabel(tr("FEED"));
feedbackKnob->setHintText(tr("Feedback:") , "");

PixmapButton * dcButton = new PixmapButton(this, tr("DC Offset Removal"));
dcButton->move(176, 16);
dcButton->setActiveGraphic(PLUGIN_NAME::getIconPixmap("dc_active"));
dcButton->setInactiveGraphic(PLUGIN_NAME::getIconPixmap("dc_inactive"));
dcButton->setCheckable(true);
dcButton->setModel(&controls->m_dcModel);
dcButton->setToolTip(tr("Remove DC Offset"));

layout->addWidget(m_amountBox);
layout->addWidget(freqKnob);
layout->addWidget(resoKnob);
layout->addWidget(feedbackKnob);
layout->addWidget(dcButton);
}


Expand Down
3 changes: 1 addition & 2 deletions plugins/DualFilter/DualFilterControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ namespace lmms::gui


#define makeknob( name, x, y, model, label, hint, unit ) \
Knob * name = new Knob( KnobType::Bright26, this); \
Knob * name = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, label, this); \
(name) -> move( x, y ); \
(name) ->setModel( &controls-> model ); \
(name) ->setLabel( label ); \
(name) ->setHintText( hint, unit );


Expand Down
12 changes: 4 additions & 8 deletions plugins/DynamicsProcessor/DynamicsProcessorControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,28 @@ DynProcControlDialog::DynProcControlDialog(
waveGraph->setGraphColor( QColor( 85, 204, 145 ) );
waveGraph -> setMaximumSize( 204, 205 );

auto inputKnob = new Knob(KnobType::Bright26, this);
auto inputKnob = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("INPUT"), this);
inputKnob -> setVolumeKnob( true );
inputKnob -> setVolumeRatio( 1.0 );
inputKnob -> move( 26, 223 );
inputKnob->setModel( &_controls->m_inputModel );
inputKnob->setLabel( tr( "INPUT" ) );
inputKnob->setHintText( tr( "Input gain:" ) , "" );

auto outputKnob = new Knob(KnobType::Bright26, this);
auto outputKnob = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("OUTPUT"), this);
outputKnob -> setVolumeKnob( true );
outputKnob -> setVolumeRatio( 1.0 );
outputKnob -> move( 76, 223 );
outputKnob->setModel( &_controls->m_outputModel );
outputKnob->setLabel( tr( "OUTPUT" ) );
outputKnob->setHintText( tr( "Output gain:" ) , "" );

auto attackKnob = new Knob(KnobType::Bright26, this);
auto attackKnob = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("ATTACK"), this);
attackKnob -> move( 24, 268 );
attackKnob->setModel( &_controls->m_attackModel );
attackKnob->setLabel( tr( "ATTACK" ) );
attackKnob->setHintText( tr( "Peak attack time:" ) , "ms" );

auto releaseKnob = new Knob(KnobType::Bright26, this);
auto releaseKnob = Knob::buildKnobWithSmallPixelFont(KnobType::Bright26, tr("RELEASE"), this);
releaseKnob -> move( 74, 268 );
releaseKnob->setModel( &_controls->m_releaseModel );
releaseKnob->setLabel( tr( "RELEASE" ) );
releaseKnob->setHintText( tr( "Peak release time:" ) , "ms" );

//wavegraph control buttons
Expand Down
Loading
Loading