/[svn]/linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2229 by iliev, Thu Aug 4 19:02:36 2011 UTC revision 2299 by iliev, Sun Dec 11 20:50:31 2011 UTC
# Line 32  Line 32 
32  #include "../common/SineLFO.h"  #include "../common/SineLFO.h"
33    
34  namespace LinuxSampler { namespace sfz {  namespace LinuxSampler { namespace sfz {
35      const int MaxUnitCount = 1000;      const int MaxUnitCount = 200;
36      const int maxEgCount = 100; // Maximum number of v2 envelope generators      const int maxEgCount = 30; // Maximum number of v2 envelope generators
37      const int maxLfoCount = 100; // Maximum number of v2 LFOs      const int maxLfoCount = 30; // Maximum number of v2 LFOs
38            
39      class Voice;      class Voice;
40      class SfzSignalUnitRack;      class SfzSignalUnitRack;
# Line 66  namespace LinuxSampler { namespace sfz { Line 66  namespace LinuxSampler { namespace sfz {
66              virtual void Trigger();              virtual void Trigger();
67                            
68              void SetCCs(::sfz::Array<int>& pCC);              void SetCCs(::sfz::Array<int>& pCC);
69                void SetCCs(::sfz::Array<float>& pCC);
70              void SetCCs(ArrayList< ::sfz::CC>& cc);              void SetCCs(ArrayList< ::sfz::CC>& cc);
71                
72                virtual void AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth, float Step);
73                
74                int GetCurveCount();
75                ::sfz::Curve* GetCurve(int idx);
76                
77                double GetSampleRate();
78        };
79        
80        class CurveCCUnit: public CCUnit {
81            public:
82                CurveCCUnit(SfzSignalUnitRack* rack, Listener* l = NULL): CCUnit(rack, l) { }
83                
84                virtual float Normalize(uint8_t val, short int curve = -1) {
85                    if (curve == -1) return val / 127.0f;
86                    return GetCurve(curve)->v[val];
87                }
88        };
89        
90        
91        
92        class SmoothCCUnit: public CurveCCUnit {
93            protected:
94                RTList<Smoother>* pSmoothers;
95            public:
96                SmoothCCUnit(SfzSignalUnitRack* rack, Listener* l = NULL): CurveCCUnit(rack, l), pSmoothers(NULL) { }
97                virtual ~SmoothCCUnit();
98                
99                virtual void AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth, float Step);
100                virtual void RemoveAllCCs() { CurveCCUnit::RemoveAllCCs(); pSmoothers->clear(); }
101                virtual void InitCCList(Pool<CC>* pCCPool, Pool<Smoother>* pSmootherPool);
102                
103                void InitSmoothers(Pool<Smoother>* pSmootherPool);
104        };
105        
106        
107        class EqUnitSupport {
108            public:
109                EqUnitSupport(SfzSignalUnitRack* pRack, Voice* pVoice = NULL);
110                
111                SmoothCCUnit suEq1GainOnCC;
112                SmoothCCUnit suEq2GainOnCC;
113                SmoothCCUnit suEq3GainOnCC;
114                
115                SmoothCCUnit suEq1FreqOnCC;
116                SmoothCCUnit suEq2FreqOnCC;
117                SmoothCCUnit suEq3FreqOnCC;
118                
119                SmoothCCUnit suEq1BwOnCC;
120                SmoothCCUnit suEq2BwOnCC;
121                SmoothCCUnit suEq3BwOnCC;
122                
123                void SetVoice(Voice* pVoice);
124                void ImportUnits(SfzSignalUnitRack* pRack);
125                void ResetUnits();
126                void InitCCLists(Pool<CCSignalUnit::CC>* pCCPool, Pool<Smoother>* pSmootherPool);
127        };
128        
129        
130        class XFInCCUnit: public CCUnit {
131            public:
132                XFInCCUnit(SfzSignalUnitRack* rack, Listener* l = NULL): CCUnit(rack, l) { }
133                
134                virtual bool Active() { return !pCtrls->isEmpty(); }
135                virtual void Calculate();
136                virtual void SetCrossFadeCCs(::sfz::Array<int>& loCCs, ::sfz::Array<int>& hiCCs);
137        };
138        
139        
140        class XFOutCCUnit: public XFInCCUnit {
141            public:
142                XFOutCCUnit(SfzSignalUnitRack* rack, Listener* l = NULL): XFInCCUnit(rack, l) { }
143                
144                virtual void Calculate();
145      };      };
146            
147            
# Line 126  namespace LinuxSampler { namespace sfz { Line 201  namespace LinuxSampler { namespace sfz {
201              EGv1Unit(SfzSignalUnitRack* rack): EGUnit<EGADSR>(rack), depth(0) { }              EGv1Unit(SfzSignalUnitRack* rack): EGUnit<EGADSR>(rack), depth(0) { }
202      };      };
203            
204      class EGv2Unit: public EGUnit< ::LinuxSampler::sfz::EG> {      class EGv2Unit: public EGUnit< ::LinuxSampler::sfz::EG>, public EqUnitSupport {
205          protected:          protected:
206              ::sfz::EG egInfo;              ::sfz::EG egInfo;
207          public:          public:
208              EGv2Unit(SfzSignalUnitRack* rack): EGUnit< ::LinuxSampler::sfz::EG>(rack) { }              CCUnit suAmpOnCC;
209                CCUnit suVolOnCC;
210                CCUnit suPitchOnCC;
211                CCUnit suCutoffOnCC;
212                CCUnit suResOnCC;
213                CurveCCUnit suPanOnCC;
214                
215                EGv2Unit(SfzSignalUnitRack* rack);
216              virtual void Trigger();              virtual void Trigger();
217      };      };
218            
# Line 200  namespace LinuxSampler { namespace sfz { Line 282  namespace LinuxSampler { namespace sfz {
282              ::sfz::LFO*  pLfoInfo;              ::sfz::LFO*  pLfoInfo;
283              AbstractLfo* pLFO;              AbstractLfo* pLFO;
284              FadeEGUnit   suFadeEG;              FadeEGUnit   suFadeEG;
285              CCUnit       suFreqOnCC;              SmoothCCUnit suDepthOnCC;
286                SmoothCCUnit suFreqOnCC;
287                            
288              LFOUnit(SfzSignalUnitRack* rack);              LFOUnit(SfzSignalUnitRack* rack);
289              LFOUnit(const LFOUnit& Unit);              LFOUnit(const LFOUnit& Unit);
# Line 213  namespace LinuxSampler { namespace sfz { Line 296  namespace LinuxSampler { namespace sfz {
296                  SfzSignalUnit::Copy(Unit);                  SfzSignalUnit::Copy(Unit);
297              }              }
298                            
             virtual bool  Active() { return pLfoInfo->freq > 0; }  
299              virtual void  Trigger();              virtual void  Trigger();
300              virtual void  Increment();              virtual void  Increment();
301              virtual float GetLevel() { return Level; }              virtual float GetLevel() { return Level; }
302              virtual void  ValueChanged(CCSignalUnit* pUnit);              
303                // CCSignalUnit::Listener interface implementation
304                virtual void ValueChanged(CCSignalUnit* pUnit);
305      };      };
306            
307      class LFOv1Unit: public LFOUnit {      class LFOv1Unit: public LFOUnit {
# Line 232  namespace LinuxSampler { namespace sfz { Line 316  namespace LinuxSampler { namespace sfz {
316              virtual void Trigger();              virtual void Trigger();
317      };      };
318            
319      class LFOv2Unit: public LFOUnit {      class LFOv2Unit: public LFOUnit, public EqUnitSupport {
320          protected:          protected:
321              FixedArray<AbstractLfo*> lfos;              FixedArray<AbstractLfo*> lfos;
322              LfoBase<LFOSigned>                       lfo0; // triangle              LfoBase<LFOSigned>                       lfo0; // triangle
# Line 246  namespace LinuxSampler { namespace sfz { Line 330  namespace LinuxSampler { namespace sfz {
330                            
331                            
332          public:          public:
333              CCUnit suPitchOnCC;              SmoothCCUnit suVolOnCC;
334                SmoothCCUnit suPitchOnCC;
335                SmoothCCUnit suPanOnCC;
336                SmoothCCUnit suCutoffOnCC;
337                SmoothCCUnit suResOnCC;
338                            
339              LFOv2Unit(SfzSignalUnitRack* rack);              LFOv2Unit(SfzSignalUnitRack* rack);
340                            
341              virtual void Trigger();              virtual void Trigger();
342                virtual bool  Active() { return true; }
343      };      };
344            
345      class AmpLFOUnit: public LFOv1Unit {      class AmpLFOUnit: public LFOv1Unit {
# Line 262  namespace LinuxSampler { namespace sfz { Line 351  namespace LinuxSampler { namespace sfz {
351            
352      class PitchLFOUnit: public LFOv1Unit {      class PitchLFOUnit: public LFOv1Unit {
353          public:          public:
354              CCUnit suDepthCC;              PitchLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack) { }
               
             PitchLFOUnit(SfzSignalUnitRack* rack): LFOv1Unit(rack), suDepthCC(rack) { }  
355                            
356              virtual void Trigger();              virtual void Trigger();
357      };      };
# Line 277  namespace LinuxSampler { namespace sfz { Line 364  namespace LinuxSampler { namespace sfz {
364      };      };
365            
366            
       
367      class EndpointUnit: public EndpointSignalUnit {      class EndpointUnit: public EndpointSignalUnit {
368            private:
369                float xfCoeff; // crossfade coefficient
370                float pitchVeltrackRatio;
371                
372          public:          public:
373              Voice* pVoice;              Voice* pVoice;
374                XFInCCUnit   suXFInCC;
375                XFOutCCUnit  suXFOutCC;
376                SmoothCCUnit suPanOnCC;
377    
378              EndpointUnit(SfzSignalUnitRack* rack);              EndpointUnit(SfzSignalUnitRack* rack);
379    
380              virtual void Trigger();              virtual void Trigger();
381    
382              /** The endpoint should be active until the volume EG is active. */              /**
383                 * The endpoint should be active until the volume EG is active.
384                 * This method determines the end of the voice playback.
385                 */
386              virtual bool Active();              virtual bool Active();
387                            
388              virtual float GetVolume();              virtual float GetVolume();
# Line 300  namespace LinuxSampler { namespace sfz { Line 396  namespace LinuxSampler { namespace sfz {
396              virtual float CalculateResonance(float res) {              virtual float CalculateResonance(float res) {
397                  return GetResonance() + res;                  return GetResonance() + res;
398              }              }
399                
400                virtual float CalculateFilterCutoff(float cutoff);
401                
402                float  GetInfluence(::sfz::Array< ::sfz::optional<float> >& cc);
403                float  GetInfluence(::sfz::Array< ::sfz::optional<int> >& cc);
404      };      };
405            
406            
407      class SfzSignalUnitRack : public SignalUnitRack {      class SfzSignalUnitRack : public SignalUnitRack, public EqUnitSupport {
408          private:          private:
409              EndpointUnit  suEndpoint;              EndpointUnit  suEndpoint;
410              AmpEGUnit     suVolEG;              AmpEGUnit     suVolEG;
# Line 314  namespace LinuxSampler { namespace sfz { Line 415  namespace LinuxSampler { namespace sfz {
415              PitchLFOUnit suPitchLFO;              PitchLFOUnit suPitchLFO;
416              FilLFOUnit   suFilLFO;              FilLFOUnit   suFilLFO;
417                            
418                // SFZ v2
419                
420                SmoothCCUnit suVolOnCC;
421                SmoothCCUnit suPitchOnCC;
422                SmoothCCUnit suCutoffOnCC;
423                SmoothCCUnit suResOnCC;
424                
425              FixedArray<EGv2Unit*> EGs;              FixedArray<EGv2Unit*> EGs;
426                            
427              // used for optimization - contains only the ones that are modulating volume              // used for optimization - contains only the ones that are modulating volume
# Line 322  namespace LinuxSampler { namespace sfz { Line 430  namespace LinuxSampler { namespace sfz {
430              // used for optimization - contains only the ones that are modulating pitch              // used for optimization - contains only the ones that are modulating pitch
431              FixedArray<EGv2Unit*> pitchEGs;              FixedArray<EGv2Unit*> pitchEGs;
432                            
433                // used for optimization - contains only the ones that are modulating filter cutoff
434                FixedArray<EGv2Unit*> filEGs;
435                
436                // used for optimization - contains only the ones that are modulating resonance
437                FixedArray<EGv2Unit*> resEGs;
438                
439                // used for optimization - contains only the ones that are modulating pan
440                FixedArray<EGv2Unit*> panEGs;
441                
442                // used for optimization - contains only the ones that are modulating EQ
443                FixedArray<EGv2Unit*> eqEGs;
444                
445                            
446              FixedArray<LFOv2Unit*> LFOs;              FixedArray<LFOv2Unit*> LFOs;
447                            
448                // used for optimization - contains only the ones that are modulating volume
449                FixedArray<LFOv2Unit*> volLFOs;
450                
451              // used for optimization - contains only the ones that are modulating pitch              // used for optimization - contains only the ones that are modulating pitch
452              FixedArray<LFOv2Unit*> pitchLFOs;              FixedArray<LFOv2Unit*> pitchLFOs;
453                            
# Line 337  namespace LinuxSampler { namespace sfz { Line 460  namespace LinuxSampler { namespace sfz {
460              // used for optimization - contains only the ones that are modulating pan              // used for optimization - contains only the ones that are modulating pan
461              FixedArray<LFOv2Unit*> panLFOs;              FixedArray<LFOv2Unit*> panLFOs;
462                            
463                // used for optimization - contains only the ones that are modulating EQ
464                FixedArray<LFOv2Unit*> eqLFOs;
465                
466    
467          public:          public:
468              Voice* const pVoice;              Voice* const pVoice;
# Line 352  namespace LinuxSampler { namespace sfz { Line 478  namespace LinuxSampler { namespace sfz {
478              virtual void Trigger();              virtual void Trigger();
479              virtual void EnterFadeOutStage();              virtual void EnterFadeOutStage();
480                            
481                /** Called when the engine is set and the engine's pools are ready to use. */
482                void InitRTLists();
483                
484                /** Invoked when the voice gone inactive. */
485                void Reset();
486                
487                virtual void UpdateEqSettings(EqSupport* pEqSupport);
488                
489              friend class EndpointUnit;              friend class EndpointUnit;
490      };      };
491  }} // namespace LinuxSampler::sfz  }} // namespace LinuxSampler::sfz

Legend:
Removed from v.2229  
changed lines
  Added in v.2299

  ViewVC Help
Powered by ViewVC