Skip to content

Commit

Permalink
Merge pull request #1485 from curlymorphic/delay-1.1
Browse files Browse the repository at this point in the history
Delay effect   Clear buffer on load, correct use of interpolation, reformat
  • Loading branch information
diizy committed Dec 23, 2014
2 parents ef7d3ff + 6aae0e6 commit af66303
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 231 deletions.
34 changes: 16 additions & 18 deletions plugins/delay/delaycontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,41 @@
#include "song.h"

DelayControls::DelayControls( DelayEffect* effect ):
EffectControls( effect ),
m_effect ( effect ),
m_delayTimeModel( 0.5, 0.01, 20.0, 0.0001, 20000.0, this, tr( "Delay Samples" )) ,
m_feedbackModel(0.0f,0.0f,1.0f,0.01f,this,tr( "Feedback" ) ),
m_lfoTimeModel(2.0, 0.01, 20.0, 0.0001, 20000.0, this, tr( "Lfo Frequency" ) ),
m_lfoAmountModel(0.0, 0.0, 2.0, 0.0001, 2000.0, this, tr ( "Lfo Amount" ) )
EffectControls( effect ),
m_effect ( effect ),
m_delayTimeModel( 0.5, 0.01, 20.0, 0.0001, 20000.0, this, tr( "Delay Samples" )) ,
m_feedbackModel(0.0f,0.0f,1.0f,0.01f,this,tr( "Feedback" ) ),
m_lfoTimeModel(2.0, 0.01, 20.0, 0.0001, 20000.0, this, tr( "Lfo Frequency" ) ),
m_lfoAmountModel(0.0, 0.0, 2.0, 0.0001, 2000.0, this, tr ( "Lfo Amount" ) )
{
connect( engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( changeSampleRate() ) );
connect( engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( changeSampleRate() ) );
}




void DelayControls::loadSettings( const QDomElement &_this )
{
m_delayTimeModel.loadSettings(_this, "DelayTimeSamples" );
m_feedbackModel.loadSettings( _this, "FeebackAmount" );
m_lfoTimeModel.loadSettings( _this , "LfoFrequency");
m_lfoAmountModel.loadSettings( _this, "LfoAmount");
m_delayTimeModel.loadSettings(_this, "DelayTimeSamples" );
m_feedbackModel.loadSettings( _this, "FeebackAmount" );
m_lfoTimeModel.loadSettings( _this , "LfoFrequency");
m_lfoAmountModel.loadSettings( _this, "LfoAmount");
}




void DelayControls::saveSettings( QDomDocument& doc, QDomElement& _this )
{
m_delayTimeModel.saveSettings( doc, _this, "DelayTimeSamples" );
m_feedbackModel.saveSettings( doc, _this ,"FeebackAmount" );
m_lfoTimeModel.saveSettings( doc, _this, "LfoFrequency" );
m_lfoAmountModel.saveSettings( doc, _this ,"LfoAmount" );
m_delayTimeModel.saveSettings( doc, _this, "DelayTimeSamples" );
m_feedbackModel.saveSettings( doc, _this ,"FeebackAmount" );
m_lfoTimeModel.saveSettings( doc, _this, "LfoFrequency" );
m_lfoAmountModel.saveSettings( doc, _this ,"LfoAmount" );
}



void DelayControls::changeSampleRate()
{
m_effect->changeSampleRate();
m_effect->changeSampleRate();
}

#include "moc_delaycontrols.cxx"
52 changes: 26 additions & 26 deletions plugins/delay/delaycontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ class DelayEffect;

class DelayControls : public EffectControls
{
Q_OBJECT
Q_OBJECT
public:
DelayControls( DelayEffect* effect );
virtual ~DelayControls()
{
}
virtual void saveSettings( QDomDocument& doc, QDomElement& parent );
virtual void loadSettings( const QDomElement& _this );
inline virtual QString nodeName() const
{
return "Delay";
}
virtual int controlCount(){
return 4;
}
virtual EffectControlDialog* createView()
{
return new DelayControlsDialog( this );
}
DelayControls( DelayEffect* effect );
virtual ~DelayControls()
{
}
virtual void saveSettings( QDomDocument& doc, QDomElement& parent );
virtual void loadSettings( const QDomElement& _this );
inline virtual QString nodeName() const
{
return "Delay";
}
virtual int controlCount(){
return 4;
}
virtual EffectControlDialog* createView()
{
return new DelayControlsDialog( this );
}

private slots:
void changeSampleRate();
void changeSampleRate();

private:
DelayEffect* m_effect;
TempoSyncKnobModel m_delayTimeModel;
FloatModel m_feedbackModel;
TempoSyncKnobModel m_lfoTimeModel;
TempoSyncKnobModel m_lfoAmountModel;
DelayEffect* m_effect;
TempoSyncKnobModel m_delayTimeModel;
FloatModel m_feedbackModel;
TempoSyncKnobModel m_lfoTimeModel;
TempoSyncKnobModel m_lfoAmountModel;

friend class DelayControlsDialog;
friend class DelayEffect;
friend class DelayControlsDialog;
friend class DelayEffect;
};

#endif // DELAYCONTROLS_H
63 changes: 33 additions & 30 deletions plugins/delay/delaycontrolsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,44 @@


DelayControlsDialog::DelayControlsDialog( DelayControls *controls ) :
EffectControlDialog( controls )
EffectControlDialog( controls )
{
setAutoFillBackground( true );
QPalette pal;
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
setPalette( pal );
setFixedSize( 200, 75 );
setAutoFillBackground( true );
QPalette pal;
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
setPalette( pal );
setFixedSize( 200, 75 );

TempoSyncKnob* sampleDelayKnob = new TempoSyncKnob( knobBright_26, this );
sampleDelayKnob->move( 20,10 );
sampleDelayKnob->setVolumeKnob( false );
sampleDelayKnob->setModel( &controls->m_delayTimeModel );
sampleDelayKnob->setLabel( tr( "Delay" ) );
sampleDelayKnob->setHintText( tr( "Delay Time" ) + " ", " s" );
TempoSyncKnob* sampleDelayKnob = new TempoSyncKnob( knobBright_26, this );
sampleDelayKnob->move( 20,10 );
sampleDelayKnob->setVolumeKnob( false );
sampleDelayKnob->setModel( &controls->m_delayTimeModel );
sampleDelayKnob->setLabel( tr( "Delay" ) );
sampleDelayKnob->setHintText( tr( "Delay Time" ) + " ", " s" );

knob * feedbackKnob = new knob( knobBright_26, this );
feedbackKnob->move( 63,10 );
feedbackKnob->setVolumeKnob( true) ;
feedbackKnob->setModel( &controls->m_feedbackModel);
feedbackKnob->setLabel( tr( "Regen" ) );
feedbackKnob->setHintText( tr ( "Feedback Amount" ) + " " , "" );
knob * feedbackKnob = new knob( knobBright_26, this );
feedbackKnob->move( 63,10 );
feedbackKnob->setVolumeKnob( true) ;
feedbackKnob->setModel( &controls->m_feedbackModel);
feedbackKnob->setLabel( tr( "Regen" ) );
feedbackKnob->setHintText( tr ( "Feedback Amount" ) + " " , "" );

TempoSyncKnob * lfoFreqKnob = new TempoSyncKnob( knobBright_26, this );
lfoFreqKnob->move( 106,10 );
lfoFreqKnob->setVolumeKnob( false );
lfoFreqKnob->setModel( &controls->m_lfoTimeModel );
lfoFreqKnob->setLabel( tr( "Rate" ) );
lfoFreqKnob->setHintText( tr ( "Lfo") + " ", " s" );
TempoSyncKnob * lfoFreqKnob = new TempoSyncKnob( knobBright_26, this );
lfoFreqKnob->move( 106,10 );
lfoFreqKnob->setVolumeKnob( false );
lfoFreqKnob->setModel( &controls->m_lfoTimeModel );
lfoFreqKnob->setLabel( tr( "Rate" ) );
lfoFreqKnob->setHintText( tr ( "Lfo") + " ", " s" );

TempoSyncKnob * lfoAmtKnob = new TempoSyncKnob( knobBright_26, this );
lfoAmtKnob->move( 150,10 );
lfoAmtKnob->setVolumeKnob( false );
lfoAmtKnob->setModel( &controls->m_lfoAmountModel );
lfoAmtKnob->setLabel( tr( "Lfo" ) );
lfoAmtKnob->setHintText( tr ( "Lfo Amt" ) + " " , " s" );
TempoSyncKnob * lfoAmtKnob = new TempoSyncKnob( knobBright_26, this );
lfoAmtKnob->move( 150,10 );
lfoAmtKnob->setVolumeKnob( false );
lfoAmtKnob->setModel( &controls->m_lfoAmountModel );
lfoAmtKnob->setLabel( tr( "Lfo" ) );
lfoAmtKnob->setHintText( tr ( "Lfo Amt" ) + " " , " s" );


}


#include "moc_delaycontrols.cxx"
8 changes: 4 additions & 4 deletions plugins/delay/delaycontrolsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class DelayControls;
class DelayControlsDialog : public EffectControlDialog
{
public:
DelayControlsDialog( DelayControls* controls );
virtual ~DelayControlsDialog()
{
}
DelayControlsDialog( DelayControls* controls );
virtual ~DelayControlsDialog()
{
}
};

#endif // DELAYCONTROLSDIALOG_H
100 changes: 50 additions & 50 deletions plugins/delay/delayeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,80 +32,80 @@ extern "C"

Plugin::Descriptor PLUGIN_EXPORT delay_plugin_descriptor =
{
STRINGIFY( PLUGIN_NAME ),
"Delay",
QT_TRANSLATE_NOOP( "pluginBrowser", "A native delay plugin" ),
"Dave French <contact/dot/dave/dot/french3/at/googlemail/dot/com>",
0x0100,
Plugin::Effect,
new PluginPixmapLoader( "logo" ),
NULL,
NULL
STRINGIFY( PLUGIN_NAME ),
"Delay",
QT_TRANSLATE_NOOP( "pluginBrowser", "A native delay plugin" ),
"Dave French <contact/dot/dave/dot/french3/at/googlemail/dot/com>",
0x0100,
Plugin::Effect,
new PluginPixmapLoader( "logo" ),
NULL,
NULL
} ;




DelayEffect::DelayEffect( Model* parent, const Plugin::Descriptor::SubPluginFeatures::Key* key ) :
Effect( &delay_plugin_descriptor, parent, key ),
m_delayControls( this )
Effect( &delay_plugin_descriptor, parent, key ),
m_delayControls( this )
{
m_delay = 0;
m_delay = new StereoDelay( 20, engine::mixer()->processingSampleRate() );
m_lfo = new Lfo( engine::mixer()->processingSampleRate() );
m_delay = 0;
m_delay = new StereoDelay( 20, engine::mixer()->processingSampleRate() );
m_lfo = new Lfo( engine::mixer()->processingSampleRate() );
}




DelayEffect::~DelayEffect()
{
if( m_delay )
{
delete m_delay;
}
if( m_lfo )
{
delete m_lfo;
}
if( m_delay )
{
delete m_delay;
}
if( m_lfo )
{
delete m_lfo;
}
}




bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
if( !isEnabled() || !isRunning () )
{
return( false );
}
double outSum = 0.0;
const float d = dryLevel();
const float w = wetLevel();
const float length = m_delayControls.m_delayTimeModel.value() * engine::mixer()->processingSampleRate();
const float amplitude = m_delayControls.m_lfoAmountModel.value() * engine::mixer()->processingSampleRate();
m_lfo->setFrequency( 1.0 / m_delayControls.m_lfoTimeModel.value() );
m_delay->setFeedback( m_delayControls.m_feedbackModel.value() );
sample_t dryS[2];
for( fpp_t f = 0; f < frames; ++f )
{
dryS[0] = buf[f][0];
dryS[1] = buf[f][1];
m_delay->setLength( ( float )length + ( amplitude * ( float )m_lfo->tick() ) );
m_delay->tick( buf[f] );

buf[f][0] = ( d * dryS[0] ) + ( w * buf[f][0] );
buf[f][1] = ( d * dryS[1] ) + ( w * buf[f][1] );
outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];
}
checkGate( outSum / frames );
return isRunning();
if( !isEnabled() || !isRunning () )
{
return( false );
}
double outSum = 0.0;
const float d = dryLevel();
const float w = wetLevel();
const float length = m_delayControls.m_delayTimeModel.value() * engine::mixer()->processingSampleRate();
const float amplitude = m_delayControls.m_lfoAmountModel.value() * engine::mixer()->processingSampleRate();
m_lfo->setFrequency( 1.0 / m_delayControls.m_lfoTimeModel.value() );
m_delay->setFeedback( m_delayControls.m_feedbackModel.value() );
sample_t dryS[2];
for( fpp_t f = 0; f < frames; ++f )
{
dryS[0] = buf[f][0];
dryS[1] = buf[f][1];
m_delay->setLength( ( float )length + ( amplitude * ( float )m_lfo->tick() ) );
m_delay->tick( buf[f] );

buf[f][0] = ( d * dryS[0] ) + ( w * buf[f][0] );
buf[f][1] = ( d * dryS[1] ) + ( w * buf[f][1] );
outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];
}
checkGate( outSum / frames );
return isRunning();
}

void DelayEffect::changeSampleRate()
{
m_lfo->setSampleRate( engine::mixer()->processingSampleRate() );
m_delay->setSampleRate( engine::mixer()->processingSampleRate() );
m_lfo->setSampleRate( engine::mixer()->processingSampleRate() );
m_delay->setSampleRate( engine::mixer()->processingSampleRate() );
}


Expand All @@ -117,7 +117,7 @@ extern "C"
//needed for getting plugin out of shared lib
Plugin * PLUGIN_EXPORT lmms_plugin_main( Model* parent, void* data )
{
return new DelayEffect( parent , static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>( data ) );
return new DelayEffect( parent , static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>( data ) );
}

}}
Expand Down
22 changes: 11 additions & 11 deletions plugins/delay/delayeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
class DelayEffect : public Effect
{
public:
DelayEffect(Model* parent , const Descriptor::SubPluginFeatures::Key* key );
virtual ~DelayEffect();
virtual bool processAudioBuffer( sampleFrame* buf, const fpp_t frames );
virtual EffectControls* controls()
{
return &m_delayControls;
}
void changeSampleRate();
DelayEffect(Model* parent , const Descriptor::SubPluginFeatures::Key* key );
virtual ~DelayEffect();
virtual bool processAudioBuffer( sampleFrame* buf, const fpp_t frames );
virtual EffectControls* controls()
{
return &m_delayControls;
}
void changeSampleRate();

private:
DelayControls m_delayControls;
StereoDelay* m_delay;
Lfo* m_lfo;
DelayControls m_delayControls;
StereoDelay* m_delay;
Lfo* m_lfo;
};

#endif // DELAYEFFECT_H
Loading

0 comments on commit af66303

Please sign in to comment.