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 |
|
|
|
30 |
|
|
namespace LinuxSampler { namespace sfz { |
31 |
|
|
const int MaxUnitCount = 1000; |
32 |
|
|
const int maxEgCount = 100; // Maximum number of v2 envelope generators |
33 |
|
|
const int maxLfoCount = 100; // Maximum number of v2 LFOs |
34 |
|
|
|
35 |
|
|
class Voice; |
36 |
|
|
class SfzSignalUnitRack; |
37 |
|
|
|
38 |
|
|
class SfzSignalUnit: public SignalUnit { |
39 |
|
|
public: |
40 |
|
|
Voice* pVoice; |
41 |
|
|
|
42 |
|
|
SfzSignalUnit(SfzSignalUnitRack* rack); |
43 |
|
|
SfzSignalUnit(const SfzSignalUnit& Unit): SignalUnit(Unit.pRack) { Copy(Unit); } |
44 |
|
|
|
45 |
|
|
void Copy(const SfzSignalUnit& Unit) { |
46 |
|
|
pVoice = Unit.pVoice; |
47 |
|
|
|
48 |
|
|
SignalUnit::Copy(Unit); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
double GetSampleRate(); |
52 |
|
|
}; |
53 |
|
|
|
54 |
|
|
template <class T> |
55 |
|
|
class EGUnit : public SfzSignalUnit { |
56 |
|
|
public: |
57 |
|
|
::sfz::EG* pEGInfo; |
58 |
|
|
T EG; |
59 |
|
|
|
60 |
|
|
EGUnit(SfzSignalUnitRack* rack): SfzSignalUnit(rack), pEGInfo(NULL) { } |
61 |
|
|
EGUnit(const EGUnit& Unit): SfzSignalUnit(Unit.pRack) { Copy(Unit); } |
62 |
|
|
void operator=(const EGUnit& Unit) { Copy(Unit); } |
63 |
|
|
|
64 |
|
|
void Copy(const EGUnit& Unit) { |
65 |
|
|
pEGInfo = Unit.pEGInfo; |
66 |
|
|
|
67 |
|
|
SfzSignalUnit::Copy(Unit); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
virtual bool Active() { return EG.active(); } |
71 |
|
|
virtual float GetLevel() { return EG.getLevel(); } |
72 |
|
|
|
73 |
|
|
virtual void EnterReleaseStage() { EG.update(EG::event_release, GetSampleRate()); } |
74 |
|
|
virtual void CancelRelease() { EG.update(EG::event_cancel_release, GetSampleRate()); } |
75 |
|
|
|
76 |
|
|
virtual void Increment() { |
77 |
|
|
if (DelayStage()) return; |
78 |
|
|
|
79 |
|
|
SfzSignalUnit::Increment(); |
80 |
|
|
if (!EG.active()) return; |
81 |
|
|
|
82 |
|
|
switch (EG.getSegmentType()) { |
83 |
|
|
case EG::segment_lin: |
84 |
|
|
EG.processLin(); |
85 |
|
|
break; |
86 |
|
|
case EG::segment_exp: |
87 |
|
|
EG.processExp(); |
88 |
|
|
break; |
89 |
|
|
case EG::segment_end: |
90 |
|
|
EG.getLevel(); |
91 |
|
|
break; // noop |
92 |
|
|
case EG::segment_pow: |
93 |
|
|
EG.processPow(); |
94 |
|
|
break; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
if (EG.active()) { |
98 |
|
|
EG.increment(1); |
99 |
|
|
if (!EG.toStageEndLeft()) EG.update(EG::event_stage_end, GetSampleRate()); |
100 |
|
|
} |
101 |
|
|
} |
102 |
|
|
}; |
103 |
|
|
|
104 |
|
|
class EGv1Unit: public EGUnit<EGADSR> { |
105 |
|
|
public: |
106 |
|
|
EGv1Unit(SfzSignalUnitRack* rack): EGUnit<EGADSR>(rack) { } |
107 |
|
|
virtual void Trigger(); |
108 |
|
|
}; |
109 |
|
|
|
110 |
|
|
class EGv2Unit: public EGUnit< ::LinuxSampler::sfz::EG> { |
111 |
|
|
public: |
112 |
|
|
EGv2Unit(SfzSignalUnitRack* rack): EGUnit< ::LinuxSampler::sfz::EG>(rack) { } |
113 |
|
|
virtual void Trigger(); |
114 |
|
|
}; |
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
class EndpointUnit : public EndpointSignalUnit { |
119 |
|
|
public: |
120 |
|
|
Voice* pVoice; |
121 |
|
|
|
122 |
|
|
EndpointUnit(SfzSignalUnitRack* rack); |
123 |
|
|
|
124 |
|
|
virtual void Trigger(); |
125 |
|
|
|
126 |
|
|
/** The endpoint should be active until the volume EG is active. */ |
127 |
|
|
virtual bool Active(); |
128 |
|
|
|
129 |
|
|
virtual float GetVolume(); |
130 |
|
|
virtual float GetFilterCutoff(); |
131 |
|
|
virtual float GetPitch(); |
132 |
|
|
virtual float GetResonance(); |
133 |
|
|
|
134 |
|
|
SfzSignalUnitRack* const GetRack(); |
135 |
|
|
}; |
136 |
|
|
|
137 |
|
|
|
138 |
|
|
class SfzSignalUnitRack : public SignalUnitRack { |
139 |
|
|
private: |
140 |
|
|
EndpointUnit suEndpoint; |
141 |
|
|
EGv1Unit suVolEG; |
142 |
|
|
|
143 |
|
|
FixedArray<EGv2Unit*> EGs; |
144 |
|
|
|
145 |
|
|
// used for optimization - contains only the ones that are modulating volume |
146 |
|
|
FixedArray<EGv2Unit*> volEGs; |
147 |
|
|
|
148 |
|
|
// used for optimization - contains only the ones that are modulating pitch |
149 |
|
|
FixedArray<EGv2Unit*> pitchEGs; |
150 |
|
|
|
151 |
|
|
|
152 |
|
|
public: |
153 |
|
|
Voice* const pVoice; |
154 |
|
|
|
155 |
|
|
/** |
156 |
|
|
* @param Voice The voice to which this rack belongs. |
157 |
|
|
*/ |
158 |
|
|
SfzSignalUnitRack(Voice* voice); |
159 |
|
|
~SfzSignalUnitRack(); |
160 |
|
|
|
161 |
|
|
virtual EndpointSignalUnit* GetEndpointUnit(); |
162 |
|
|
|
163 |
|
|
virtual void Trigger(); |
164 |
|
|
virtual void EnterFadeOutStage(); |
165 |
|
|
|
166 |
|
|
friend class EndpointUnit; |
167 |
|
|
}; |
168 |
|
|
}} // namespace LinuxSampler::sfz |
169 |
|
|
|
170 |
|
|
#endif /* __LS_SFZSIGNALUNITRACK_H__ */ |
171 |
|
|
|