2
* effect.cpp - base-class for effects
4
* Copyright (c) 2006-2007 Danny McRae <khjklujn/at/users.sourceforge.net>
5
* Copyright (c) 2006-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
7
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public
11
* License as published by the Free Software Foundation; either
12
* version 2 of the License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* General Public License for more details.
19
* You should have received a copy of the GNU General Public
20
* License along with this program (see COPYING); if not, write to the
21
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
* Boston, MA 02110-1301 USA.
27
#include <QtXml/QDomElement>
33
#include "dummy_effect.h"
34
#include "effect_chain.h"
35
#include "effect_view.h"
38
effect::effect( const plugin::descriptor * _desc,
40
const descriptor::subPluginFeatures::key * _key ) :
41
plugin( _desc, _parent ),
42
m_key( _key ? *_key : descriptor::subPluginFeatures::key() ),
48
m_enabledModel( TRUE, this, tr( "Effect enabled" ) ),
49
m_wetDryModel( 1.0f, -1.0f, 1.0f, 0.01f, this, tr( "Wet/Dry mix" ) ),
50
m_gateModel( 0.0f, 0.0f, 1.0f, 0.01f, this, tr( "Gate" ) ),
51
m_autoQuitModel( 1.0f, 1.0f, 8000.0f, 100.0f, 1.0f, this, tr( "Decay" ) )
53
m_srcState[0] = m_srcState[1] = NULL;
62
for( int i = 0; i < 2; ++i )
64
if( m_srcState[i] != NULL )
66
src_delete( m_srcState[i] );
74
void effect::saveSettings( QDomDocument & _doc, QDomElement & _this )
76
m_enabledModel.saveSettings( _doc, _this, "on" );
77
m_wetDryModel.saveSettings( _doc, _this, "wet" );
78
m_autoQuitModel.saveSettings( _doc, _this, "autoquit" );
79
m_gateModel.saveSettings( _doc, _this, "gate" );
80
getControls()->saveState( _doc, _this );
86
void effect::loadSettings( const QDomElement & _this )
88
m_enabledModel.loadSettings( _this, "on" );
89
m_wetDryModel.loadSettings( _this, "wet" );
90
m_autoQuitModel.loadSettings( _this, "autoquit" );
91
m_gateModel.loadSettings( _this, "gate" );
93
QDomNode node = _this.firstChild();
94
while( !node.isNull() )
96
if( node.isElement() )
98
if( getControls()->nodeName() == node.nodeName() )
100
getControls()->restoreState( node.toElement() );
103
node = node.nextSibling();
111
effect * effect::instantiate( const QString & _plugin_name,
113
descriptor::subPluginFeatures::key * _key )
115
plugin * p = plugin::instantiate( _plugin_name, _parent, _key );
116
// check whether instantiated plugin is an effect
117
if( dynamic_cast<effect *>( p ) != NULL )
119
// everything ok, so return pointer
120
return( dynamic_cast<effect *>( p ) );
123
// not quite... so delete plugin and return dummy effect
125
return( new dummyEffect( _parent ) );
131
void effect::checkGate( double _out_sum )
133
// Check whether we need to continue processing input. Restart the
134
// counter if the threshold has been exceeded.
135
if( _out_sum <= getGate()+0.000001 )
137
incrementBufferCount();
138
if( getBufferCount() > getTimeout() )
153
pluginView * effect::instantiateView( QWidget * _parent )
155
return( new effectView( this, _parent ) );
161
void effect::reinitSRC( void )
163
for( int i = 0; i < 2; ++i )
165
if( m_srcState[i] != NULL )
167
src_delete( m_srcState[i] );
170
if( ( m_srcState[i] = src_new(
171
engine::getMixer()->currentQualitySettings().
172
libsrcInterpolation(),
173
DEFAULT_CHANNELS, &error ) ) == NULL )
175
fprintf( stderr, "Error: src_new() failed in effect.cpp!\n" );
183
void effect::resample( int _i, const sampleFrame * _src_buf,
184
sample_rate_t _src_sr,
185
sampleFrame * _dst_buf, sample_rate_t _dst_sr,
188
if( m_srcState[_i] == NULL )
192
m_srcData[_i].input_frames = _frames;
193
m_srcData[_i].output_frames = engine::getMixer()->framesPerPeriod();
194
m_srcData[_i].data_in = (float *) _src_buf[0];
195
m_srcData[_i].data_out = _dst_buf[0];
196
m_srcData[_i].src_ratio = (double) _dst_sr / _src_sr;
197
m_srcData[_i].end_of_input = 0;
199
if( ( error = src_process( m_srcState[_i], &m_srcData[_i] ) ) )
201
fprintf( stderr, "effect::resample(): error while resampling: %s\n",
202
src_strerror( error ) );