Rewrite Amplifier plugin code (#6989)
* rewrite amplifier plugin style * pomelo * oroblanco * grapefruit * calamlamondin
This commit is contained in:
@@ -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 <contact/dot/diizy/at/nbl/dot/fi>",
|
||||
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<const Plugin::Descriptor::SubPluginFeatures::Key *>( data ) );
|
||||
return new AmplifierEffect(parent, static_cast<const Plugin::Descriptor::SubPluginFeatures::Key*>(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace lmms
|
||||
} // namespace lmms
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
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;
|
||||
};
|
||||
|
||||
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:" ) , "%" );
|
||||
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
|
||||
} // namespace lmms::gui
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <QDomElement>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
friend class gui::AmplifierControlDialog;
|
||||
friend class AmplifierEffect;
|
||||
|
||||
} ;
|
||||
|
||||
};
|
||||
|
||||
} // namespace lmms
|
||||
|
||||
#endif
|
||||
#endif // LMMS_AMPLIFIER_CONTROLS_H
|
||||
|
||||
Reference in New Issue
Block a user