1 |
iliev |
2218 |
/*************************************************************************** |
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 |
iliev |
2219 |
#include "../common/AbstractVoice.h" |
30 |
iliev |
2218 |
|
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 |
iliev |
2219 |
class EGUnit: public SfzSignalUnit { |
57 |
iliev |
2218 |
public: |
58 |
|
|
::sfz::EG* pEGInfo; |
59 |
|
|
T EG; |
60 |
|
|
|
61 |
|
|
EGUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pEGInfo(NULL) { } |
62 |
iliev |
2219 |
EGUnit(const EGUnit& Unit): SfzSignalUnit(Unit) { Copy(Unit); } |
63 |
iliev |
2218 |
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 |
iliev |
2220 |
virtual float GetLevel() { return DelayStage() ? 0 : EG.getLevel(); } |
73 |
iliev |
2218 |
|
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 |
iliev |
2220 |
int depth; |
108 |
|
|
EGv1Unit(SfzSignalUnitRack* rack): EGUnit<EGADSR>(rack), depth(0) { } |
109 |
iliev |
2218 |
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 |
iliev |
2220 |
class PitchEGUnit: public EGv1Unit { |
119 |
|
|
public: |
120 |
|
|
PitchEGUnit(SfzSignalUnitRack* rack): EGv1Unit(rack) { } |
121 |
|
|
virtual void Trigger(); |
122 |
|
|
}; |
123 |
|
|
|
124 |
iliev |
2219 |
class LFOUnit: public SfzSignalUnit { |
125 |
|
|
public: |
126 |
|
|
::sfz::LFO* pLfoInfo; |
127 |
|
|
LFOSigned lfo; |
128 |
|
|
|
129 |
|
|
LFOUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pLfoInfo(NULL), lfo(1200.0f) { } |
130 |
|
|
LFOUnit(const LFOUnit& Unit): SfzSignalUnit(Unit), lfo(1200.0f) { Copy(Unit); } |
131 |
|
|
void operator=(const LFOUnit& Unit) { Copy(Unit); } |
132 |
|
|
|
133 |
|
|
void Copy(const LFOUnit& Unit) { |
134 |
|
|
pLfoInfo = Unit.pLfoInfo; |
135 |
|
|
|
136 |
|
|
SfzSignalUnit::Copy(Unit); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
virtual bool Active() { return true; } |
140 |
|
|
virtual void Trigger(); |
141 |
|
|
virtual void Increment(); |
142 |
|
|
virtual float GetLevel() { return Level; } |
143 |
|
|
}; |
144 |
iliev |
2218 |
|
145 |
iliev |
2221 |
class LFOv1Unit: public LFOUnit { |
146 |
|
|
public: |
147 |
|
|
::sfz::LFO lfoInfo; |
148 |
|
|
|
149 |
|
|
LFOv1Unit(SfzSignalUnitRack* rack): LFOUnit(rack) { pLfoInfo = &lfoInfo; } |
150 |
|
|
|
151 |
|
|
virtual void Trigger(); |
152 |
|
|
}; |
153 |
|
|
|
154 |
iliev |
2219 |
class LFOv2Unit: public LFOUnit { |
155 |
|
|
public: |
156 |
|
|
LFOv2Unit(SfzSignalUnitRack* rack): LFOUnit(rack) { } |
157 |
|
|
|
158 |
|
|
virtual void Trigger(); |
159 |
|
|
}; |
160 |
iliev |
2218 |
|
161 |
iliev |
2221 |
class AmpLFOUnit: public LFOv1Unit { |
162 |
|
|
public: |
163 |
|
|
AmpLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { } |
164 |
|
|
|
165 |
|
|
virtual void Trigger(); |
166 |
|
|
}; |
167 |
iliev |
2219 |
|
168 |
iliev |
2221 |
class PitchLFOUnit: public LFOv1Unit { |
169 |
|
|
public: |
170 |
|
|
PitchLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { } |
171 |
|
|
|
172 |
|
|
virtual void Trigger(); |
173 |
|
|
}; |
174 |
iliev |
2219 |
|
175 |
iliev |
2221 |
class FilLFOUnit: public LFOv1Unit { |
176 |
|
|
public: |
177 |
|
|
FilLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { } |
178 |
|
|
|
179 |
|
|
virtual void Trigger(); |
180 |
|
|
}; |
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
iliev |
2218 |
class EndpointUnit : public EndpointSignalUnit { |
185 |
|
|
public: |
186 |
|
|
Voice* pVoice; |
187 |
|
|
|
188 |
|
|
EndpointUnit(SfzSignalUnitRack* rack); |
189 |
|
|
|
190 |
|
|
virtual void Trigger(); |
191 |
|
|
|
192 |
|
|
/** The endpoint should be active until the volume EG is active. */ |
193 |
|
|
virtual bool Active(); |
194 |
|
|
|
195 |
|
|
virtual float GetVolume(); |
196 |
|
|
virtual float GetFilterCutoff(); |
197 |
|
|
virtual float GetPitch(); |
198 |
|
|
virtual float GetResonance(); |
199 |
iliev |
2219 |
virtual float GetPan(); |
200 |
iliev |
2218 |
|
201 |
|
|
SfzSignalUnitRack* const GetRack(); |
202 |
iliev |
2219 |
|
203 |
|
|
virtual float CalculateResonance(float res) { |
204 |
|
|
return GetResonance() + res; |
205 |
|
|
} |
206 |
iliev |
2218 |
}; |
207 |
|
|
|
208 |
|
|
|
209 |
|
|
class SfzSignalUnitRack : public SignalUnitRack { |
210 |
|
|
private: |
211 |
|
|
EndpointUnit suEndpoint; |
212 |
|
|
EGv1Unit suVolEG; |
213 |
iliev |
2220 |
PitchEGUnit suPitchEG; |
214 |
iliev |
2218 |
|
215 |
iliev |
2221 |
AmpLFOUnit suAmpLFO; |
216 |
|
|
PitchLFOUnit suPitchLFO; |
217 |
|
|
FilLFOUnit suFilLFO; |
218 |
|
|
|
219 |
iliev |
2218 |
FixedArray<EGv2Unit*> EGs; |
220 |
|
|
|
221 |
|
|
// used for optimization - contains only the ones that are modulating volume |
222 |
|
|
FixedArray<EGv2Unit*> volEGs; |
223 |
|
|
|
224 |
|
|
// used for optimization - contains only the ones that are modulating pitch |
225 |
|
|
FixedArray<EGv2Unit*> pitchEGs; |
226 |
|
|
|
227 |
iliev |
2219 |
|
228 |
|
|
FixedArray<LFOv2Unit*> LFOs; |
229 |
|
|
|
230 |
|
|
// used for optimization - contains only the ones that are modulating filter cutoff |
231 |
|
|
FixedArray<LFOv2Unit*> filLFOs; |
232 |
|
|
|
233 |
|
|
// used for optimization - contains only the ones that are modulating resonance |
234 |
|
|
FixedArray<LFOv2Unit*> resLFOs; |
235 |
|
|
|
236 |
|
|
// used for optimization - contains only the ones that are modulating pan |
237 |
|
|
FixedArray<LFOv2Unit*> panLFOs; |
238 |
|
|
|
239 |
iliev |
2218 |
|
240 |
|
|
public: |
241 |
|
|
Voice* const pVoice; |
242 |
|
|
|
243 |
|
|
/** |
244 |
|
|
* @param Voice The voice to which this rack belongs. |
245 |
|
|
*/ |
246 |
|
|
SfzSignalUnitRack(Voice* voice); |
247 |
|
|
~SfzSignalUnitRack(); |
248 |
|
|
|
249 |
|
|
virtual EndpointSignalUnit* GetEndpointUnit(); |
250 |
|
|
|
251 |
|
|
virtual void Trigger(); |
252 |
|
|
virtual void EnterFadeOutStage(); |
253 |
|
|
|
254 |
|
|
friend class EndpointUnit; |
255 |
|
|
}; |
256 |
|
|
}} // namespace LinuxSampler::sfz |
257 |
|
|
|
258 |
|
|
#endif /* __LS_SFZSIGNALUNITRACK_H__ */ |
259 |
|
|
|