/[svn]/linuxsampler/trunk/src/engines/common/SignalUnitRack.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/SignalUnitRack.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2298 - (hide annotations) (download) (as text)
Fri Dec 9 17:04:24 2011 UTC (12 years, 4 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 7917 byte(s)
* use different EQ effect instance for every voice

1 iliev 2205 /***************************************************************************
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_SIGNALUNITRACK_H__
24     #define __LS_SIGNALUNITRACK_H__
25    
26     #include "Event.h"
27     #include "SignalUnit.h"
28     #include "../../common/Pool.h"
29    
30    
31     namespace LinuxSampler {
32 iliev 2218
33 iliev 2296 class EqSupport {
34     private:
35     int BandCount;
36     int* GainIdxs; ///< the indices of the gain controls
37     int* FreqIdxs; ///< the indices of the frequency controls
38     int* BandwidthIdxs; ///< the indices of the bandwidth controls
39     Effect* pEffect;
40     Effect* pEffect2; // If the effect is mono we'll need two effects
41    
42     inline float check(optional<float> minimum, optional<float> maximum, float value) {
43     if (minimum) {
44     float min = *minimum;
45     if (value < min) value = min;
46     }
47     if (maximum) {
48     float max = *maximum;
49     if (value > max) value = max;
50     }
51    
52     return value;
53     }
54    
55     public:
56     EqSupport();
57     ~EqSupport();
58 iliev 2298
59     void PrintInfo();
60 iliev 2296
61     /**
62     * Searches for know EQ effects and create one if the search succeed.
63     * If the initialization is successful and EQ effect is selected,
64     * HasSupport() returns true;
65     */
66     void Install();
67    
68     void Uninstall();
69    
70     /** Returns true if an EQ is created and is ready for use. */
71     bool HasSupport() { return pEffect != NULL; }
72    
73     /** Reset the gains of all bands to 0dB. */
74     void Reset() {
75     if (!HasSupport()) return;
76     for (int i = 0; i < BandCount; i++) {
77     pEffect->InputControl(GainIdxs[i])->SetValue(0); // 0dB
78     if (pEffect2 != NULL) pEffect2->InputControl(GainIdxs[i])->SetValue(0); // 0dB
79     }
80     }
81    
82     void InitEffect(AudioOutputDevice* pDevice) {
83     if (pEffect != NULL) pEffect->InitEffect(pDevice);
84     if (pEffect2 != NULL) pEffect2->InitEffect(pDevice);
85     }
86    
87     int GetBandCount() { return BandCount; }
88    
89     void SetGain(int band, float gain);
90     void SetFreq(int band, float freq);
91     void SetBandwidth(int band, float octaves);
92    
93     AudioChannel* GetInChannelLeft() {
94     return pEffect->InputChannel(0);
95     }
96    
97     AudioChannel* GetInChannelRight() {
98     return pEffect2 != NULL ? pEffect2->InputChannel(0) : pEffect->InputChannel(1);
99     }
100    
101     AudioChannel* GetOutChannelLeft() {
102     return pEffect->OutputChannel(0);
103     }
104    
105     AudioChannel* GetOutChannelRight() {
106     return pEffect2 != NULL ? pEffect2->OutputChannel(0) : pEffect->OutputChannel(1);
107     }
108    
109     void RenderAudio(uint Samples) {
110     pEffect->RenderAudio(Samples);
111     if (pEffect2 != NULL) pEffect2->RenderAudio(Samples);
112     }
113     };
114    
115    
116    
117 iliev 2205 class SignalUnitRack {
118     protected:
119     uint CurrentStep; // The current time step
120 iliev 2297 bool bHasEq, releaseStageEntered;
121 iliev 2205
122     public:
123 iliev 2218 FixedArray<SignalUnit*> Units; // A list of all signal units in this rack
124 iliev 2217
125 iliev 2218 /**
126     * @param maxUnitCount We are using fixed size array because of the real-time safe requirements.
127     */
128 iliev 2297 SignalUnitRack(int maxUnitCount): CurrentStep(0), bHasEq(false),
129     releaseStageEntered(false), Units(maxUnitCount) { }
130 iliev 2218
131 iliev 2205 uint GetCurrentStep() { return CurrentStep; }
132    
133     virtual EndpointSignalUnit* GetEndpointUnit() = 0;
134    
135 iliev 2218 virtual void EnterFadeOutStage() = 0;
136    
137 iliev 2205 /**
138     * Will be called to increment the time with one sample point.
139     * Each unit should recalculate its current level on every call of this function.
140     */
141     virtual void Increment() {
142     CurrentStep++;
143    
144     for (int i = 0; i < Units.size(); i++) {
145     Units[i]->Increment();
146     }
147     }
148    
149     virtual void ProcessCCEvent(RTList<Event>::Iterator& itEvent) {
150     if ( !(itEvent->Type == Event::type_control_change && itEvent->Param.CC.Controller) ) return;
151     for (int i = 0; i < Units.size(); i++) {
152     Units[i]->ProcessCCEvent(itEvent->Param.CC.Controller, itEvent->Param.CC.Value);
153     }
154     }
155    
156     /** Initializes and triggers the rack. */
157     virtual void Trigger() {
158 iliev 2297 releaseStageEntered = false;
159 iliev 2205 CurrentStep = 0;
160     for (int i = 0; i < Units.size(); i++) {
161     Units[i]->Trigger();
162     }
163     }
164    
165 iliev 2217 /**
166     * When the rack belongs to a voice, this method is
167     * called when the voice enter the release stage.
168     */
169 iliev 2205 virtual void EnterReleaseStage() {
170 iliev 2297 releaseStageEntered = true;
171 iliev 2205 for (int i = 0; i < Units.size(); i++) {
172     Units[i]->EnterReleaseStage();
173     }
174     }
175    
176 iliev 2297 bool isReleaseStageEntered() { return releaseStageEntered; }
177    
178 iliev 2217 /**
179     * When the rack belongs to a voice, this method is
180     * called when the voice is of type which ignore note off.
181     */
182 iliev 2205 virtual void CancelRelease() {
183     for (int i = 0; i < Units.size(); i++) {
184     Units[i]->CancelRelease();
185     }
186     }
187 iliev 2296
188     /**
189     * Determines whether an equalization is applied to the voice.
190     * Used for optimization.
191     */
192     bool HasEq() { return bHasEq; }
193    
194     virtual void UpdateEqSettings(EqSupport* pEqSupport) = 0;
195 iliev 2205 };
196     } // namespace LinuxSampler
197    
198     #endif /* __LS_SIGNALUNITRACK_H__ */

  ViewVC Help
Powered by ViewVC