/[svn]/linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2224 - (show annotations) (download) (as text)
Mon Aug 1 19:08:09 2011 UTC (12 years, 8 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 11472 byte(s)
* implemented opcode pitchlfo_depthccN

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2011 Grigor Iliev *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #ifndef __LS_SFZSIGNALUNITRACK_H__
24 #define __LS_SFZSIGNALUNITRACK_H__
25
26 #include "../common/SignalUnitRack.h"
27 #include "EG.h"
28 #include "EGADSR.h"
29 #include "../common/AbstractVoice.h"
30 #include "../common/PulseLFO.h"
31 #include "../common/SawLFO.h"
32 #include "../common/SineLFO.h"
33
34 namespace LinuxSampler { namespace sfz {
35 const int MaxUnitCount = 1000;
36 const int maxEgCount = 100; // Maximum number of v2 envelope generators
37 const int maxLfoCount = 100; // Maximum number of v2 LFOs
38
39 class Voice;
40 class SfzSignalUnitRack;
41
42 class SfzSignalUnit: public SignalUnit {
43 public:
44 Voice* pVoice;
45
46 SfzSignalUnit(SfzSignalUnitRack* rack);
47 SfzSignalUnit(const SfzSignalUnit& Unit): SignalUnit(Unit.pRack) { Copy(Unit); }
48
49 void Copy(const SfzSignalUnit& Unit) {
50 pVoice = Unit.pVoice;
51
52 SignalUnit::Copy(Unit);
53 }
54
55 double GetSampleRate();
56 };
57
58
59 class CCUnit: public CCSignalUnit {
60 public:
61 Voice* pVoice;
62
63 CCUnit(SfzSignalUnitRack* rack);
64
65 virtual void Trigger();
66
67 void SetCCs(::sfz::Array<int>& pCC);
68 };
69
70
71 template <class T>
72 class EGUnit: public SfzSignalUnit {
73 public:
74 ::sfz::EG* pEGInfo;
75 T EG;
76
77 EGUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pEGInfo(NULL) { }
78 EGUnit(const EGUnit& Unit): SfzSignalUnit(Unit) { Copy(Unit); }
79 void operator=(const EGUnit& Unit) { Copy(Unit); }
80
81 void Copy(const EGUnit& Unit) {
82 pEGInfo = Unit.pEGInfo;
83
84 SfzSignalUnit::Copy(Unit);
85 }
86
87 virtual bool Active() { return EG.active(); }
88 virtual float GetLevel() { return DelayStage() ? 0 : EG.getLevel(); }
89
90 virtual void EnterReleaseStage() { EG.update(EG::event_release, GetSampleRate()); }
91 virtual void CancelRelease() { EG.update(EG::event_cancel_release, GetSampleRate()); }
92
93 virtual void Increment() {
94 if (DelayStage()) return;
95
96 SfzSignalUnit::Increment();
97 if (!EG.active()) return;
98
99 switch (EG.getSegmentType()) {
100 case EG::segment_lin:
101 EG.processLin();
102 break;
103 case EG::segment_exp:
104 EG.processExp();
105 break;
106 case EG::segment_end:
107 EG.getLevel();
108 break; // noop
109 case EG::segment_pow:
110 EG.processPow();
111 break;
112 }
113
114 if (EG.active()) {
115 EG.increment(1);
116 if (!EG.toStageEndLeft()) EG.update(EG::event_stage_end, GetSampleRate());
117 }
118 }
119 };
120
121 class EGv1Unit: public EGUnit<EGADSR> {
122 public:
123 int depth;
124 EGv1Unit(SfzSignalUnitRack* rack): EGUnit<EGADSR>(rack), depth(0) { }
125 virtual void Trigger();
126 };
127
128 class EGv2Unit: public EGUnit< ::LinuxSampler::sfz::EG> {
129 public:
130 EGv2Unit(SfzSignalUnitRack* rack): EGUnit< ::LinuxSampler::sfz::EG>(rack) { }
131 virtual void Trigger();
132 };
133
134 class PitchEGUnit: public EGv1Unit {
135 public:
136 PitchEGUnit(SfzSignalUnitRack* rack): EGv1Unit(rack) { }
137 virtual void Trigger();
138 };
139
140 class FilEGUnit: public EGv1Unit {
141 public:
142 FilEGUnit(SfzSignalUnitRack* rack): EGv1Unit(rack) { }
143 virtual void Trigger();
144 };
145
146 class AbstractLfo {
147 public:
148 virtual float Render() = 0;
149 virtual void Update(const uint16_t& ExtControlValue) = 0;
150 virtual void Trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) = 0;
151 };
152
153 template <class T>
154 class LfoBase: public AbstractLfo, public T {
155 public:
156 LfoBase(float Max): T(Max) { }
157 virtual float Render() { return T::render(); }
158
159 virtual void Update(const uint16_t& ExtControlValue) { T::update(ExtControlValue); }
160
161 virtual void Trigger (
162 float Frequency, start_level_t StartLevel, uint16_t InternalDepth,
163 uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate
164 ) {
165 T::trigger(Frequency, StartLevel, InternalDepth, ExtControlDepth, FlipPhase, SampleRate);
166 }
167 };
168
169 class LFOUnit: public SfzSignalUnit {
170 public:
171 ::sfz::LFO* pLfoInfo;
172 AbstractLfo* pLFO;
173
174 LFOUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pLfoInfo(NULL), pLFO(NULL) { }
175 LFOUnit(const LFOUnit& Unit): SfzSignalUnit(Unit) { Copy(Unit); }
176 void operator=(const LFOUnit& Unit) { Copy(Unit); }
177
178 void Copy(const LFOUnit& Unit) {
179 pLfoInfo = Unit.pLfoInfo;
180
181 SfzSignalUnit::Copy(Unit);
182 }
183
184 virtual bool Active() { return true; }
185 virtual void Trigger();
186 virtual void Increment();
187 virtual float GetLevel() { return Level; }
188 };
189
190 class LFOv1Unit: public LFOUnit {
191 public:
192 ::sfz::LFO lfoInfo;
193 LfoBase<LFOSigned> lfo;
194
195 LFOv1Unit(SfzSignalUnitRack* rack): LFOUnit(rack), lfo(1200.0f) {
196 pLfoInfo = &lfoInfo; pLFO = &lfo;
197 }
198
199 virtual void Trigger();
200 };
201
202 class LFOv2Unit: public LFOUnit {
203 protected:
204 FixedArray<AbstractLfo*> lfos;
205 LfoBase<LFOSigned> lfo0; // triangle
206 LfoBase<SineLFO<range_signed> > lfo1; // sine
207 LfoBase<PulseLFO<range_unsigned, 750> > lfo2; // pulse 75%
208 LfoBase<SquareLFO<range_signed> > lfo3; // square
209 LfoBase<PulseLFO<range_unsigned, 250> > lfo4; // pulse 25%
210 LfoBase<PulseLFO<range_unsigned, 125> > lfo5; // pulse 12,5%
211 LfoBase<SawLFO<range_unsigned, true> > lfo6; // saw up
212 LfoBase<SawLFO<range_unsigned, false> > lfo7; // saw down
213
214
215 public:
216 LFOv2Unit(SfzSignalUnitRack* rack);
217
218 virtual void Trigger();
219 };
220
221 class AmpLFOUnit: public LFOv1Unit {
222 public:
223 AmpLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { }
224
225 virtual void Trigger();
226 };
227
228 class PitchLFOUnit: public LFOv1Unit {
229 public:
230 CCUnit suDepthCC;
231
232 PitchLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack), suDepthCC(rack) { }
233
234 virtual void Trigger();
235 };
236
237 class FilLFOUnit: public LFOv1Unit {
238 public:
239 FilLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { }
240
241 virtual void Trigger();
242 };
243
244
245
246 class EndpointUnit: public EndpointSignalUnit {
247 public:
248 Voice* pVoice;
249
250 EndpointUnit(SfzSignalUnitRack* rack);
251
252 virtual void Trigger();
253
254 /** The endpoint should be active until the volume EG is active. */
255 virtual bool Active();
256
257 virtual float GetVolume();
258 virtual float GetFilterCutoff();
259 virtual float GetPitch();
260 virtual float GetResonance();
261 virtual float GetPan();
262
263 SfzSignalUnitRack* const GetRack();
264
265 virtual float CalculateResonance(float res) {
266 return GetResonance() + res;
267 }
268 };
269
270
271 class SfzSignalUnitRack : public SignalUnitRack {
272 private:
273 EndpointUnit suEndpoint;
274 EGv1Unit suVolEG;
275 FilEGUnit suFilEG;
276 PitchEGUnit suPitchEG;
277
278 AmpLFOUnit suAmpLFO;
279 PitchLFOUnit suPitchLFO;
280 FilLFOUnit suFilLFO;
281
282 FixedArray<EGv2Unit*> EGs;
283
284 // used for optimization - contains only the ones that are modulating volume
285 FixedArray<EGv2Unit*> volEGs;
286
287 // used for optimization - contains only the ones that are modulating pitch
288 FixedArray<EGv2Unit*> pitchEGs;
289
290
291 FixedArray<LFOv2Unit*> LFOs;
292
293 // used for optimization - contains only the ones that are modulating filter cutoff
294 FixedArray<LFOv2Unit*> filLFOs;
295
296 // used for optimization - contains only the ones that are modulating resonance
297 FixedArray<LFOv2Unit*> resLFOs;
298
299 // used for optimization - contains only the ones that are modulating pan
300 FixedArray<LFOv2Unit*> panLFOs;
301
302
303 public:
304 Voice* const pVoice;
305
306 /**
307 * @param Voice The voice to which this rack belongs.
308 */
309 SfzSignalUnitRack(Voice* voice);
310 ~SfzSignalUnitRack();
311
312 virtual EndpointSignalUnit* GetEndpointUnit();
313
314 virtual void Trigger();
315 virtual void EnterFadeOutStage();
316
317 friend class EndpointUnit;
318 };
319 }} // namespace LinuxSampler::sfz
320
321 #endif /* __LS_SFZSIGNALUNITRACK_H__ */
322

  ViewVC Help
Powered by ViewVC