/[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 2219 - (show annotations) (download) (as text)
Thu Jul 28 12:35:49 2011 UTC (12 years, 8 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 7948 byte(s)
* sfz engine: implemented opcodes lfoN_delay,
  lfoN_freq, lfoN_pan, lfoN_cutoff, lfoN_resonance

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 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 EGv1Unit(SfzSignalUnitRack* rack): EGUnit<EGADSR>(rack) { }
108 virtual void Trigger();
109 };
110
111 class EGv2Unit: public EGUnit< ::LinuxSampler::sfz::EG> {
112 public:
113 EGv2Unit(SfzSignalUnitRack* rack): EGUnit< ::LinuxSampler::sfz::EG>(rack) { }
114 virtual void Trigger();
115 };
116
117 class LFOUnit: public SfzSignalUnit {
118 public:
119 ::sfz::LFO* pLfoInfo;
120 LFOSigned lfo;
121
122 LFOUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pLfoInfo(NULL), lfo(1200.0f) { }
123 LFOUnit(const LFOUnit& Unit): SfzSignalUnit(Unit), lfo(1200.0f) { Copy(Unit); }
124 void operator=(const LFOUnit& Unit) { Copy(Unit); }
125
126 void Copy(const LFOUnit& Unit) {
127 pLfoInfo = Unit.pLfoInfo;
128
129 SfzSignalUnit::Copy(Unit);
130 }
131
132 virtual bool Active() { return true; }
133 virtual void Trigger();
134 virtual void Increment();
135 virtual float GetLevel() { return Level; }
136 };
137
138 class LFOv2Unit: public LFOUnit {
139 public:
140 LFOv2Unit(SfzSignalUnitRack* rack): LFOUnit(rack) { }
141
142 virtual void Trigger();
143 };
144
145
146
147 class EndpointUnit : public EndpointSignalUnit {
148 public:
149 Voice* pVoice;
150
151 EndpointUnit(SfzSignalUnitRack* rack);
152
153 virtual void Trigger();
154
155 /** The endpoint should be active until the volume EG is active. */
156 virtual bool Active();
157
158 virtual float GetVolume();
159 virtual float GetFilterCutoff();
160 virtual float GetPitch();
161 virtual float GetResonance();
162 virtual float GetPan();
163
164 SfzSignalUnitRack* const GetRack();
165
166 virtual float CalculateResonance(float res) {
167 return GetResonance() + res;
168 }
169 };
170
171
172 class SfzSignalUnitRack : public SignalUnitRack {
173 private:
174 EndpointUnit suEndpoint;
175 EGv1Unit suVolEG;
176
177 FixedArray<EGv2Unit*> EGs;
178
179 // used for optimization - contains only the ones that are modulating volume
180 FixedArray<EGv2Unit*> volEGs;
181
182 // used for optimization - contains only the ones that are modulating pitch
183 FixedArray<EGv2Unit*> pitchEGs;
184
185
186 FixedArray<LFOv2Unit*> LFOs;
187
188 // used for optimization - contains only the ones that are modulating filter cutoff
189 FixedArray<LFOv2Unit*> filLFOs;
190
191 // used for optimization - contains only the ones that are modulating resonance
192 FixedArray<LFOv2Unit*> resLFOs;
193
194 // used for optimization - contains only the ones that are modulating pan
195 FixedArray<LFOv2Unit*> panLFOs;
196
197
198 public:
199 Voice* const pVoice;
200
201 /**
202 * @param Voice The voice to which this rack belongs.
203 */
204 SfzSignalUnitRack(Voice* voice);
205 ~SfzSignalUnitRack();
206
207 virtual EndpointSignalUnit* GetEndpointUnit();
208
209 virtual void Trigger();
210 virtual void EnterFadeOutStage();
211
212 friend class EndpointUnit;
213 };
214 }} // namespace LinuxSampler::sfz
215
216 #endif /* __LS_SFZSIGNALUNITRACK_H__ */
217

  ViewVC Help
Powered by ViewVC