2 * Effect.h - base class for effects
4 * Copyright (c) 2006-2007 Danny McRae <khjklujn/at/users.sourceforge.net>
5 * Copyright (c) 2006-2009 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.
32 #include "AutomatableModel.h"
33 #include "TempoSyncKnobModel.h"
40 class EXPORT Effect
: public Plugin
43 Effect( const Plugin::Descriptor
* _desc
,
45 const Descriptor::SubPluginFeatures::Key
* _key
);
48 virtual void saveSettings( QDomDocument
& _doc
, QDomElement
& _parent
);
49 virtual void loadSettings( const QDomElement
& _this
);
51 inline virtual QString
nodeName() const
57 virtual bool processAudioBuffer( sampleFrame
* _buf
,
58 const fpp_t _frames
) = 0;
60 inline ch_cnt_t
processorCount() const
65 inline void setProcessorCount( ch_cnt_t _processors
)
67 m_processors
= _processors
;
70 inline bool isOkay() const
75 inline void setOkay( bool _state
)
81 inline bool isRunning() const
86 inline void startRunning()
92 inline void stopRunning()
97 inline bool isEnabled() const
99 return m_enabledModel
.value();
102 inline f_cnt_t
timeout() const
104 const float samples
=
105 engine::getMixer()->processingSampleRate() *
106 m_autoQuitModel
.value() / 1000.0f
;
107 return 1 + ( static_cast<Uint32
>( samples
) /
108 engine::getMixer()->framesPerPeriod() );
111 inline float wetLevel() const
113 return m_wetDryModel
.value();
116 inline float dryLevel() const
118 return 1.0f
- m_wetDryModel
.value();
121 inline float gate() const
123 const float level
= m_gateModel
.value();
124 return level
*level
* m_processors
*
125 engine::getMixer()->framesPerPeriod();
128 inline f_cnt_t
bufferCount() const
130 return m_bufferCount
;
133 inline void resetBufferCount()
138 inline void incrementBufferCount()
143 inline bool dontRun() const
148 inline void setDontRun( bool _state
)
153 inline const Descriptor::SubPluginFeatures::Key
& key() const
158 virtual EffectControls
* controls() = 0;
160 static Effect
* instantiate( const QString
& _plugin_name
,
162 Descriptor::SubPluginFeatures::Key
* _key
);
166 void checkGate( double _out_sum
);
168 virtual PluginView
* instantiateView( QWidget
* );
170 // some effects might not be capable of higher sample-rates so they can
171 // sample it down before processing and back after processing
172 inline void sampleDown( const sampleFrame
* _src_buf
,
173 sampleFrame
* _dst_buf
,
174 sample_rate_t _dst_sr
)
176 resample( 0, _src_buf
,
177 engine::getMixer()->processingSampleRate(),
179 engine::getMixer()->framesPerPeriod() );
182 inline void sampleBack( const sampleFrame
* _src_buf
,
183 sampleFrame
* _dst_buf
,
184 sample_rate_t _src_sr
)
186 resample( 1, _src_buf
, _src_sr
, _dst_buf
,
187 engine::getMixer()->processingSampleRate(),
188 engine::getMixer()->framesPerPeriod() * _src_sr
/
189 engine::getMixer()->processingSampleRate() );
195 void resample( int _i
, const sampleFrame
* _src_buf
,
196 sample_rate_t _src_sr
,
197 sampleFrame
* _dst_buf
, sample_rate_t _dst_sr
,
198 const f_cnt_t _frames
);
200 Descriptor::SubPluginFeatures::Key m_key
;
202 ch_cnt_t m_processors
;
207 f_cnt_t m_bufferCount
;
209 BoolModel m_enabledModel
;
210 FloatModel m_wetDryModel
;
211 FloatModel m_gateModel
;
212 TempoSyncKnobModel m_autoQuitModel
;
214 SRC_DATA m_srcData
[2];
215 SRC_STATE
* m_srcState
[2];
218 friend class EffectView
;
219 friend class EffectChain
;
224 typedef Effect::Descriptor::SubPluginFeatures::Key EffectKey
;
225 typedef Effect::Descriptor::SubPluginFeatures::KeyList EffectKeyList
;