RemoteVstPlugin: fixed too short arrays for preset names
[lmms.git] / include / Effect.h
blob610d4f998a9995acbba0ebc0ac3527c459373557
1 /*
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.
26 #ifndef _EFFECT_H
27 #define _EFFECT_H
29 #include "Plugin.h"
30 #include "engine.h"
31 #include "Mixer.h"
32 #include "AutomatableModel.h"
33 #include "TempoSyncKnobModel.h"
36 class EffectChain;
37 class EffectControls;
40 class EXPORT Effect : public Plugin
42 public:
43 Effect( const Plugin::Descriptor * _desc,
44 Model * _parent,
45 const Descriptor::SubPluginFeatures::Key * _key );
46 virtual ~Effect();
48 virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
49 virtual void loadSettings( const QDomElement & _this );
51 inline virtual QString nodeName() const
53 return "effect";
57 virtual bool processAudioBuffer( sampleFrame * _buf,
58 const fpp_t _frames ) = 0;
60 inline ch_cnt_t processorCount() const
62 return m_processors;
65 inline void setProcessorCount( ch_cnt_t _processors )
67 m_processors = _processors;
70 inline bool isOkay() const
72 return m_okay;
75 inline void setOkay( bool _state )
77 m_okay = _state;
81 inline bool isRunning() const
83 return m_running;
86 inline void startRunning()
88 m_bufferCount = 0;
89 m_running = true;
92 inline void stopRunning()
94 m_running = false;
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()
135 m_bufferCount = 0;
138 inline void incrementBufferCount()
140 ++m_bufferCount;
143 inline bool dontRun() const
145 return m_noRun;
148 inline void setDontRun( bool _state )
150 m_noRun = _state;
153 inline const Descriptor::SubPluginFeatures::Key & key() const
155 return m_key;
158 virtual EffectControls * controls() = 0;
160 static Effect * instantiate( const QString & _plugin_name,
161 Model * _parent,
162 Descriptor::SubPluginFeatures::Key * _key );
165 protected:
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(),
178 _dst_buf, _dst_sr,
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() );
191 void reinitSRC();
194 private:
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;
204 bool m_okay;
205 bool m_noRun;
206 bool m_running;
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;
228 #endif