/[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 2222 - (show annotations) (download) (as text)
Thu Jul 28 18:24:12 2011 UTC (12 years, 8 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 9348 byte(s)
* sfz engine: implemented opcodes fileg_delay, fileg_start, fileg_attack,
  fileg_hold, fileg_decay, fileg_sustain, fileg_release, fileg_vel2delay,
  fileg_vel2attack, fileg_vel2hold, fileg_vel2decay, fileg_vel2sustain,
  fileg_vel2release
* bumped version to 1.0.0.cvs13

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
31 namespace LinuxSampler { namespace sfz {
32 const int MaxUnitCount = 1000;
33 const int maxEgCount = 100; // Maximum number of v2 envelope generators
34 const int maxLfoCount = 100; // Maximum number of v2 LFOs
35
36 class Voice;
37 class SfzSignalUnitRack;
38
39 class SfzSignalUnit: public SignalUnit {
40 public:
41 Voice* pVoice;
42
43 SfzSignalUnit(SfzSignalUnitRack* rack);
44 SfzSignalUnit(const SfzSignalUnit& Unit): SignalUnit(Unit.pRack) { Copy(Unit); }
45
46 void Copy(const SfzSignalUnit& Unit) {
47 pVoice = Unit.pVoice;
48
49 SignalUnit::Copy(Unit);
50 }
51
52 double GetSampleRate();
53 };
54
55 template <class T>
56 class EGUnit: public SfzSignalUnit {
57 public:
58 ::sfz::EG* pEGInfo;
59 T EG;
60
61 EGUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pEGInfo(NULL) { }
62 EGUnit(const EGUnit& Unit): SfzSignalUnit(Unit) { Copy(Unit); }
63 void operator=(const EGUnit& Unit) { Copy(Unit); }
64
65 void Copy(const EGUnit& Unit) {
66 pEGInfo = Unit.pEGInfo;
67
68 SfzSignalUnit::Copy(Unit);
69 }
70
71 virtual bool Active() { return EG.active(); }
72 virtual float GetLevel() { return DelayStage() ? 0 : EG.getLevel(); }
73
74 virtual void EnterReleaseStage() { EG.update(EG::event_release, GetSampleRate()); }
75 virtual void CancelRelease() { EG.update(EG::event_cancel_release, GetSampleRate()); }
76
77 virtual void Increment() {
78 if (DelayStage()) return;
79
80 SfzSignalUnit::Increment();
81 if (!EG.active()) return;
82
83 switch (EG.getSegmentType()) {
84 case EG::segment_lin:
85 EG.processLin();
86 break;
87 case EG::segment_exp:
88 EG.processExp();
89 break;
90 case EG::segment_end:
91 EG.getLevel();
92 break; // noop
93 case EG::segment_pow:
94 EG.processPow();
95 break;
96 }
97
98 if (EG.active()) {
99 EG.increment(1);
100 if (!EG.toStageEndLeft()) EG.update(EG::event_stage_end, GetSampleRate());
101 }
102 }
103 };
104
105 class EGv1Unit: public EGUnit<EGADSR> {
106 public:
107 int depth;
108 EGv1Unit(SfzSignalUnitRack* rack): EGUnit<EGADSR>(rack), depth(0) { }
109 virtual void Trigger();
110 };
111
112 class EGv2Unit: public EGUnit< ::LinuxSampler::sfz::EG> {
113 public:
114 EGv2Unit(SfzSignalUnitRack* rack): EGUnit< ::LinuxSampler::sfz::EG>(rack) { }
115 virtual void Trigger();
116 };
117
118 class PitchEGUnit: public EGv1Unit {
119 public:
120 PitchEGUnit(SfzSignalUnitRack* rack): EGv1Unit(rack) { }
121 virtual void Trigger();
122 };
123
124 class FilEGUnit: public EGv1Unit {
125 public:
126 FilEGUnit(SfzSignalUnitRack* rack): EGv1Unit(rack) { }
127 virtual void Trigger();
128 };
129
130 class LFOUnit: public SfzSignalUnit {
131 public:
132 ::sfz::LFO* pLfoInfo;
133 LFOSigned lfo;
134
135 LFOUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pLfoInfo(NULL), lfo(1200.0f) { }
136 LFOUnit(const LFOUnit& Unit): SfzSignalUnit(Unit), lfo(1200.0f) { Copy(Unit); }
137 void operator=(const LFOUnit& Unit) { Copy(Unit); }
138
139 void Copy(const LFOUnit& Unit) {
140 pLfoInfo = Unit.pLfoInfo;
141
142 SfzSignalUnit::Copy(Unit);
143 }
144
145 virtual bool Active() { return true; }
146 virtual void Trigger();
147 virtual void Increment();
148 virtual float GetLevel() { return Level; }
149 };
150
151 class LFOv1Unit: public LFOUnit {
152 public:
153 ::sfz::LFO lfoInfo;
154
155 LFOv1Unit(SfzSignalUnitRack* rack): LFOUnit(rack) { pLfoInfo = &lfoInfo; }
156
157 virtual void Trigger();
158 };
159
160 class LFOv2Unit: public LFOUnit {
161 public:
162 LFOv2Unit(SfzSignalUnitRack* rack): LFOUnit(rack) { }
163
164 virtual void Trigger();
165 };
166
167 class AmpLFOUnit: public LFOv1Unit {
168 public:
169 AmpLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { }
170
171 virtual void Trigger();
172 };
173
174 class PitchLFOUnit: public LFOv1Unit {
175 public:
176 PitchLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { }
177
178 virtual void Trigger();
179 };
180
181 class FilLFOUnit: public LFOv1Unit {
182 public:
183 FilLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { }
184
185 virtual void Trigger();
186 };
187
188
189
190 class EndpointUnit : public EndpointSignalUnit {
191 public:
192 Voice* pVoice;
193
194 EndpointUnit(SfzSignalUnitRack* rack);
195
196 virtual void Trigger();
197
198 /** The endpoint should be active until the volume EG is active. */
199 virtual bool Active();
200
201 virtual float GetVolume();
202 virtual float GetFilterCutoff();
203 virtual float GetPitch();
204 virtual float GetResonance();
205 virtual float GetPan();
206
207 SfzSignalUnitRack* const GetRack();
208
209 virtual float CalculateResonance(float res) {
210 return GetResonance() + res;
211 }
212 };
213
214
215 class SfzSignalUnitRack : public SignalUnitRack {
216 private:
217 EndpointUnit suEndpoint;
218 EGv1Unit suVolEG;
219 FilEGUnit suFilEG;
220 PitchEGUnit suPitchEG;
221
222 AmpLFOUnit suAmpLFO;
223 PitchLFOUnit suPitchLFO;
224 FilLFOUnit suFilLFO;
225
226 FixedArray<EGv2Unit*> EGs;
227
228 // used for optimization - contains only the ones that are modulating volume
229 FixedArray<EGv2Unit*> volEGs;
230
231 // used for optimization - contains only the ones that are modulating pitch
232 FixedArray<EGv2Unit*> pitchEGs;
233
234
235 FixedArray<LFOv2Unit*> LFOs;
236
237 // used for optimization - contains only the ones that are modulating filter cutoff
238 FixedArray<LFOv2Unit*> filLFOs;
239
240 // used for optimization - contains only the ones that are modulating resonance
241 FixedArray<LFOv2Unit*> resLFOs;
242
243 // used for optimization - contains only the ones that are modulating pan
244 FixedArray<LFOv2Unit*> panLFOs;
245
246
247 public:
248 Voice* const pVoice;
249
250 /**
251 * @param Voice The voice to which this rack belongs.
252 */
253 SfzSignalUnitRack(Voice* voice);
254 ~SfzSignalUnitRack();
255
256 virtual EndpointSignalUnit* GetEndpointUnit();
257
258 virtual void Trigger();
259 virtual void EnterFadeOutStage();
260
261 friend class EndpointUnit;
262 };
263 }} // namespace LinuxSampler::sfz
264
265 #endif /* __LS_SFZSIGNALUNITRACK_H__ */
266

  ViewVC Help
Powered by ViewVC