diff --git a/plugins/Amplifier/Amplifier.cpp b/plugins/Amplifier/Amplifier.cpp index 7de8fb18088..ac5fdf23b7d 100644 --- a/plugins/Amplifier/Amplifier.cpp +++ b/plugins/Amplifier/Amplifier.cpp @@ -36,9 +36,9 @@ extern "C" Plugin::Descriptor PLUGIN_EXPORT amplifier_plugin_descriptor = { - LMMS_STRINGIFY( PLUGIN_NAME ), + LMMS_STRINGIFY(PLUGIN_NAME), "Amplifier", - QT_TRANSLATE_NOOP( "PluginBrowser", "A native amplifier plugin" ), + QT_TRANSLATE_NOOP("PluginBrowser", "A native amplifier plugin"), "Vesa Kivimäki ", 0x0100, Plugin::Type::Effect, @@ -50,99 +50,61 @@ Plugin::Descriptor PLUGIN_EXPORT amplifier_plugin_descriptor = } - -AmplifierEffect::AmplifierEffect( Model* parent, const Descriptor::SubPluginFeatures::Key* key ) : - Effect( &lifier_plugin_descriptor, parent, key ), - m_ampControls( this ) +AmplifierEffect::AmplifierEffect(Model* parent, const Descriptor::SubPluginFeatures::Key* key) : + Effect(&lifier_plugin_descriptor, parent, key), + m_ampControls(this) { } - - - - - - -bool AmplifierEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames ) +bool AmplifierEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frames) { - if( !isEnabled() || !isRunning () ) - { - return( false ); - } + if (!isEnabled() || !isRunning()) { return false ; } double outSum = 0.0; const float d = dryLevel(); const float w = wetLevel(); - const ValueBuffer * volBuf = m_ampControls.m_volumeModel.valueBuffer(); - const ValueBuffer * panBuf = m_ampControls.m_panModel.valueBuffer(); - const ValueBuffer * leftBuf = m_ampControls.m_leftModel.valueBuffer(); - const ValueBuffer * rightBuf = m_ampControls.m_rightModel.valueBuffer(); + const ValueBuffer* volumeBuf = m_ampControls.m_volumeModel.valueBuffer(); + const ValueBuffer* panBuf = m_ampControls.m_panModel.valueBuffer(); + const ValueBuffer* leftBuf = m_ampControls.m_leftModel.valueBuffer(); + const ValueBuffer* rightBuf = m_ampControls.m_rightModel.valueBuffer(); - for( fpp_t f = 0; f < frames; ++f ) + for (fpp_t f = 0; f < frames; ++f) { -// qDebug( "offset %d, value %f", f, m_ampControls.m_volumeModel.value( f ) ); + const float volume = (volumeBuf ? volumeBuf->value(f) : m_ampControls.m_volumeModel.value()) * 0.01f; + const float pan = (panBuf ? panBuf->value(f) : m_ampControls.m_panModel.value()) * 0.01f; + const float left = (leftBuf ? leftBuf->value(f) : m_ampControls.m_leftModel.value()) * 0.01f; + const float right = (rightBuf ? rightBuf->value(f) : m_ampControls.m_rightModel.value()) * 0.01f; + + const float panLeft = std::min(1.0f, 1.0f - pan); + const float panRight = std::min(1.0f, 1.0f + pan); auto s = std::array{buf[f][0], buf[f][1]}; - // vol knob - if( volBuf ) - { - s[0] *= volBuf->value( f ) * 0.01f; - s[1] *= volBuf->value( f ) * 0.01f; - } - else - { - s[0] *= m_ampControls.m_volumeModel.value() * 0.01f; - s[1] *= m_ampControls.m_volumeModel.value() * 0.01f; - } - - // convert pan values to left/right values - const float pan = panBuf - ? panBuf->value( f ) - : m_ampControls.m_panModel.value(); - const float left1 = pan <= 0 - ? 1.0 - : 1.0 - pan * 0.01f; - const float right1 = pan >= 0 - ? 1.0 - : 1.0 + pan * 0.01f; - - // second stage amplification - const float left2 = leftBuf - ? leftBuf->value( f ) - : m_ampControls.m_leftModel.value(); - const float right2 = rightBuf - ? rightBuf->value( f ) - : m_ampControls.m_rightModel.value(); - - s[0] *= left1 * left2 * 0.01; - s[1] *= right1 * right2 * 0.01; + s[0] *= volume * left * panLeft; + s[1] *= volume * right * panRight; buf[f][0] = d * buf[f][0] + w * s[0]; buf[f][1] = d * buf[f][1] + w * s[1]; outSum += buf[f][0] * buf[f][0] + buf[f][1] * buf[f][1]; } - checkGate( outSum / frames ); + checkGate(outSum / frames); return isRunning(); } - - - extern "C" { // necessary for getting instance out of shared lib -PLUGIN_EXPORT Plugin * lmms_plugin_main( Model* parent, void* data ) +PLUGIN_EXPORT Plugin* lmms_plugin_main(Model* parent, void* data) { - return new AmplifierEffect( parent, static_cast( data ) ); + return new AmplifierEffect(parent, static_cast(data)); } } -} // namespace lmms \ No newline at end of file +} // namespace lmms diff --git a/plugins/Amplifier/Amplifier.h b/plugins/Amplifier/Amplifier.h index 38fd07c6fb4..8a39ffeb616 100644 --- a/plugins/Amplifier/Amplifier.h +++ b/plugins/Amplifier/Amplifier.h @@ -23,9 +23,8 @@ * */ - -#ifndef AMPLIFIER_H -#define AMPLIFIER_H +#ifndef LMMS_AMPLIFIER_H +#define LMMS_AMPLIFIER_H #include "Effect.h" #include "AmplifierControls.h" @@ -36,24 +35,21 @@ namespace lmms class AmplifierEffect : public Effect { public: - AmplifierEffect( Model* parent, const Descriptor::SubPluginFeatures::Key* key ); + AmplifierEffect(Model* parent, const Descriptor::SubPluginFeatures::Key* key); ~AmplifierEffect() override = default; - bool processAudioBuffer( sampleFrame* buf, const fpp_t frames ) override; + bool processAudioBuffer(sampleFrame* buf, const fpp_t frames) override; EffectControls* controls() override { return &m_ampControls; } - private: AmplifierControls m_ampControls; friend class AmplifierControls; - -} ; - +}; } // namespace lmms -#endif +#endif // LMMS_AMPLIFIER_H diff --git a/plugins/Amplifier/AmplifierControlDialog.cpp b/plugins/Amplifier/AmplifierControlDialog.cpp index ed9e98f29b4..1fbc3729a08 100644 --- a/plugins/Amplifier/AmplifierControlDialog.cpp +++ b/plugins/Amplifier/AmplifierControlDialog.cpp @@ -23,53 +23,38 @@ * */ - #include "AmplifierControlDialog.h" #include "AmplifierControls.h" #include "embed.h" #include "Knob.h" - namespace lmms::gui { - -AmplifierControlDialog::AmplifierControlDialog( AmplifierControls* controls ) : - EffectControlDialog( controls ) +AmplifierControlDialog::AmplifierControlDialog(AmplifierControls* controls) : + EffectControlDialog(controls) { - setAutoFillBackground( true ); + setAutoFillBackground(true); QPalette pal; - pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) ); - setPalette( pal ); - setFixedSize( 100, 110 ); - - auto volumeKnob = new Knob(KnobType::Bright26, this); - volumeKnob -> move( 16, 10 ); - volumeKnob -> setVolumeKnob( true ); - volumeKnob->setModel( &controls->m_volumeModel ); - volumeKnob->setLabel( tr( "VOL" ) ); - volumeKnob->setHintText( tr( "Volume:" ) , "%" ); - - auto panKnob = new Knob(KnobType::Bright26, this); - panKnob -> move( 57, 10 ); - panKnob->setModel( &controls->m_panModel ); - panKnob->setLabel( tr( "PAN" ) ); - panKnob->setHintText( tr( "Panning:" ) , "" ); - - auto leftKnob = new Knob(KnobType::Bright26, this); - leftKnob -> move( 16, 65 ); - leftKnob -> setVolumeKnob( true ); - leftKnob->setModel( &controls->m_leftModel ); - leftKnob->setLabel( tr( "LEFT" ) ); - leftKnob->setHintText( tr( "Left gain:" ) , "%" ); - - auto rightKnob = new Knob(KnobType::Bright26, this); - rightKnob -> move( 57, 65 ); - rightKnob -> setVolumeKnob( true ); - rightKnob->setModel( &controls->m_rightModel ); - rightKnob->setLabel( tr( "RIGHT" ) ); - rightKnob->setHintText( tr( "Right gain:" ) , "%" ); + pal.setBrush(backgroundRole(), PLUGIN_NAME::getIconPixmap("artwork")); + setPalette(pal); + setFixedSize(100, 110); + + auto makeKnob = [this](int x, int y, const QString& label, const QString& hintText, const QString& unit, FloatModel* model, bool isVolume) + { + Knob* newKnob = new Knob(KnobType::Bright26, this); + newKnob->move(x, y); + newKnob->setModel(model); + 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); } - -} // namespace lmms::gui \ No newline at end of file +} // namespace lmms::gui diff --git a/plugins/Amplifier/AmplifierControlDialog.h b/plugins/Amplifier/AmplifierControlDialog.h index ad0ed50ca2c..672830117ee 100644 --- a/plugins/Amplifier/AmplifierControlDialog.h +++ b/plugins/Amplifier/AmplifierControlDialog.h @@ -23,8 +23,8 @@ * */ -#ifndef AMPLIFIER_CONTROL_DIALOG_H -#define AMPLIFIER_CONTROL_DIALOG_H +#ifndef LMMS_GUI_AMPLIFIER_CONTROL_DIALOG_H +#define LMMS_GUI_AMPLIFIER_CONTROL_DIALOG_H #include "EffectControlDialog.h" @@ -32,23 +32,23 @@ namespace lmms { class AmplifierControls; - +class FloatModel; namespace gui { +class Knob; + class AmplifierControlDialog : public EffectControlDialog { Q_OBJECT public: - AmplifierControlDialog( AmplifierControls* controls ); + AmplifierControlDialog(AmplifierControls* controls); ~AmplifierControlDialog() override = default; - -} ; - +}; } // namespace gui } // namespace lmms -#endif +#endif // LMMS_GUI_AMPLIFIER_CONTROL_DIALOG_H diff --git a/plugins/Amplifier/AmplifierControls.cpp b/plugins/Amplifier/AmplifierControls.cpp index 30773046044..72960dd3b81 100644 --- a/plugins/Amplifier/AmplifierControls.cpp +++ b/plugins/Amplifier/AmplifierControls.cpp @@ -23,7 +23,6 @@ * */ - #include #include "AmplifierControls.h" @@ -32,51 +31,33 @@ namespace lmms { -AmplifierControls::AmplifierControls( AmplifierEffect* effect ) : - EffectControls( effect ), - m_effect( effect ), - m_volumeModel( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Volume" ) ), - m_panModel( 0.0f, -100.0f, 100.0f, 0.1f, this, tr( "Panning" ) ), - m_leftModel( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Left gain" ) ), - m_rightModel( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Right gain" ) ) +AmplifierControls::AmplifierControls(AmplifierEffect* effect) : + EffectControls(effect), + m_effect(effect), + m_volumeModel(100.0f, 0.0f, 200.0f, 0.1f, this, tr("Volume")), + m_panModel(0.0f, -100.0f, 100.0f, 0.1f, this, tr("Panning")), + m_leftModel(100.0f, 0.0f, 200.0f, 0.1f, this, tr("Left gain")), + m_rightModel(100.0f, 0.0f, 200.0f, 0.1f, this, tr("Right gain")) { -/* connect( &m_volumeModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) ); - connect( &m_panModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) ); - connect( &m_leftModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) ); - connect( &m_rightModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );*/ } - - -void AmplifierControls::changeControl() +void AmplifierControls::loadSettings(const QDomElement& parent) { -// engine::getSong()->setModified(); + m_volumeModel.loadSettings(parent, "volume"); + m_panModel.loadSettings(parent, "pan"); + m_leftModel.loadSettings(parent, "left"); + m_rightModel.loadSettings(parent, "right"); } - - -void AmplifierControls::loadSettings( const QDomElement& _this ) +void AmplifierControls::saveSettings(QDomDocument& doc, QDomElement& parent) { - m_volumeModel.loadSettings( _this, "volume" ); - m_panModel.loadSettings( _this, "pan" ); - m_leftModel.loadSettings( _this, "left" ); - m_rightModel.loadSettings( _this, "right" ); -} - - - - -void AmplifierControls::saveSettings( QDomDocument& doc, QDomElement& _this ) -{ - m_volumeModel.saveSettings( doc, _this, "volume" ); - m_panModel.saveSettings( doc, _this, "pan" ); - m_leftModel.saveSettings( doc, _this, "left" ); - m_rightModel.saveSettings( doc, _this, "right" ); + m_volumeModel.saveSettings(doc, parent, "volume"); + m_panModel.saveSettings(doc, parent, "pan"); + m_leftModel.saveSettings(doc, parent, "left"); + m_rightModel.saveSettings(doc, parent, "right"); } } // namespace lmms - - diff --git a/plugins/Amplifier/AmplifierControls.h b/plugins/Amplifier/AmplifierControls.h index 573f6f8964c..6b5063dddfe 100644 --- a/plugins/Amplifier/AmplifierControls.h +++ b/plugins/Amplifier/AmplifierControls.h @@ -23,8 +23,8 @@ * */ -#ifndef AMPLIFIER_CONTROLS_H -#define AMPLIFIER_CONTROLS_H +#ifndef LMMS_AMPLIFIER_CONTROLS_H +#define LMMS_AMPLIFIER_CONTROLS_H #include "EffectControls.h" #include "AmplifierControlDialog.h" @@ -39,34 +39,24 @@ namespace gui class AmplifierControlDialog; } - class AmplifierControls : public EffectControls { Q_OBJECT public: - AmplifierControls( AmplifierEffect* effect ); + AmplifierControls(AmplifierEffect* effect); ~AmplifierControls() override = default; - void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override; - void loadSettings( const QDomElement & _this ) override; + void saveSettings(QDomDocument& doc, QDomElement& parent) override; + void loadSettings(const QDomElement& parent) override; inline QString nodeName() const override { return "AmplifierControls"; } - - int controlCount() override - { - return 4; - } - gui::EffectControlDialog* createView() override { - return new gui::AmplifierControlDialog( this ); + return new gui::AmplifierControlDialog(this); } - - -private slots: - void changeControl(); + int controlCount() override { return 4; } private: AmplifierEffect* m_effect; @@ -77,10 +67,8 @@ private slots: friend class gui::AmplifierControlDialog; friend class AmplifierEffect; - -} ; - +}; } // namespace lmms -#endif +#endif // LMMS_AMPLIFIER_CONTROLS_H