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

Diff of /linuxsampler/trunk/src/engines/common/SignalUnit.h

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

revision 2207 by iliev, Fri Jul 15 15:43:49 2011 UTC revision 2217 by iliev, Tue Jul 26 15:51:30 2011 UTC
# Line 28  Line 28 
28    
29  namespace LinuxSampler {  namespace LinuxSampler {
30    
31        class SignalUnitRack;
32    
33      /**      /**
34       * A signal unit consist of internal signal generator (like envelope generator,       * A signal unit consist of internal signal generator (like envelope generator,
35       * low frequency oscillator, etc) with a number of generator parameters which       * low frequency oscillator, etc) with a number of generator parameters which
# Line 115  namespace LinuxSampler { Line 117  namespace LinuxSampler {
117          public:          public:
118              ArrayList<SignalUnit::Parameter> Params; // The list of parameters which are modulating the signal unit              ArrayList<SignalUnit::Parameter> Params; // The list of parameters which are modulating the signal unit
119                            
120              SignalUnit() : bActive(false), Level(0.0f), bCalculating(false), uiDelayTrigger(0) { }              SignalUnit(SignalUnitRack* rack): pRack(rack), bActive(false), Level(0.0f), bCalculating(false), uiDelayTrigger(0) { }
121              SignalUnit(const SignalUnit& Unit) { Copy(Unit); }              SignalUnit(const SignalUnit& Unit): pRack(Unit.pRack) { Copy(Unit); }
122              void operator=(const SignalUnit& Unit) { Copy(Unit); }              void operator=(const SignalUnit& Unit) { Copy(Unit); }
123                            
124              virtual void Copy(const SignalUnit& Unit) {              virtual void Copy(const SignalUnit& Unit) {
# Line 200  namespace LinuxSampler { Line 202  namespace LinuxSampler {
202               */               */
203              virtual uint DelayTrigger() { return uiDelayTrigger; }              virtual uint DelayTrigger() { return uiDelayTrigger; }
204                            
205                /**
206                 * A helper method which checks whether the delay
207                 * stage is finished.
208                 */
209                bool DelayStage();
210                
211          protected:          protected:
212                SignalUnitRack* const pRack;
213    
214              bool   bActive; /* Don't use it to check the active state of the unit!!!              bool   bActive; /* Don't use it to check the active state of the unit!!!
215                               * Use Active() instead! */                               * Use Active() instead! */
216              float  Level;              float  Level;
# Line 213  namespace LinuxSampler { Line 223  namespace LinuxSampler {
223                    
224      };      };
225            
226      class EndpointSignalUnit: virtual public SignalUnit {      class EndpointSignalUnit: public SignalUnit {
227          public:          public:
228                EndpointSignalUnit(SignalUnitRack* rack): SignalUnit(rack) { }
229    
230              /**              /**
231               * Gets the volume modulation value               * Gets the volume modulation value
232               * for the current time step (sample point).               * for the current time step (sample point).
# Line 239  namespace LinuxSampler { Line 251  namespace LinuxSampler {
251               */               */
252              virtual float GetResonance() = 0;              virtual float GetResonance() = 0;
253                            
254              virtual float CalculateFilterCutoff(float cutoff) = 0;              virtual float CalculateFilterCutoff(float cutoff) {
255                                cutoff *= GetFilterCutoff();
256              virtual float CalculatePitch(float pitch) = 0;                  return cutoff > 13500 ? 13500 : cutoff;
               
             virtual float CalculateResonance(float res) = 0;  
     };  
       
   
     class SignalUnitRack;  
   
     template <class O /* The signal unit's owner */>  
     class SignalUnitBase: virtual public SignalUnit {  
         public:  
             SignalUnitBase() : pOwner(NULL) { }  
             SignalUnitBase(const SignalUnitBase& Unit) { Copy(Unit); }  
             void operator=(const SignalUnitBase& Unit) { Copy(Unit); }  
               
             virtual void Copy(const SignalUnitBase& Unit) {  
                 if (this == &Unit) return;  
   
                 pOwner = Unit.pOwner;  
                 SignalUnit::Copy(Unit);  
257              }              }
   
         protected:  
             O* pOwner; // The owner to which this rack belongs.  
               
             SignalUnitRack* GetSignalUnitRack() { return pOwner->GetSignalUnitRack(); }  
           
         public:  
               
258                            
259              /**              virtual float CalculatePitch(float pitch) {
260               * The owner of the unit is set by the rack                  return GetPitch() * pitch;
261               * just before the call to the unit's trigger method.              }
              */  
             void SetOwner(O* Owner) { pOwner = Owner; }  
262                            
263              /**              virtual float CalculateResonance(float res) {
264               * A helper method which checks whether the delay                  return GetResonance() * res;
              * stage is finished.  
              */  
             bool DelayStage() {  
                 return (DelayTrigger() >= GetSignalUnitRack()->GetCurrentStep());  
265              }              }
266      };      };
267            
# Line 291  namespace LinuxSampler { Line 270  namespace LinuxSampler {
270       * The level of this unit corresponds to the controller changes       * The level of this unit corresponds to the controller changes
271       * and is normalized to be in the range from -1 to +1.       * and is normalized to be in the range from -1 to +1.
272       */       */
273      template<class O>      class CCSignalUnit: public SignalUnit {
     class CCSignalUnit: public SignalUnitBase<O> {  
274          private:          private:
275              uint8_t Ctrl; // The number of the MIDI controller which modulates this signal unit.              uint8_t Ctrl; // The number of the MIDI controller which modulates this signal unit.
276    
277          public:          public:
278              CCSignalUnit(uint8_t Controller) {              CCSignalUnit(SignalUnitRack* rack, uint8_t Controller): SignalUnit(rack) {
279                  Ctrl = Controller;                  Ctrl = Controller;
280              }              }
281                            
282              CCSignalUnit(const CCSignalUnit& Unit) { Copy(Unit); }              CCSignalUnit(const CCSignalUnit& Unit): SignalUnit(Unit) { Copy(Unit); }
283              void operator=(const CCSignalUnit& Unit) { Copy(Unit); }              void operator=(const CCSignalUnit& Unit) { SignalUnit::Copy(Unit); Copy(Unit); }
284                            
285              virtual void Copy(const CCSignalUnit& Unit) {              virtual void Copy(const CCSignalUnit& Unit) {
                 SignalUnitBase<O>::Copy(Unit);  
286                  Ctrl = Unit.Ctrl;                  Ctrl = Unit.Ctrl;
287              }              }
288                            
# Line 315  namespace LinuxSampler { Line 292  namespace LinuxSampler {
292                  if (Controller != Ctrl) return;                  if (Controller != Ctrl) return;
293                                    
294                  // Normalize the value so it belongs to the interval [-1, +1]                  // Normalize the value so it belongs to the interval [-1, +1]
295                  SignalUnitBase<O>::Level = 2 * Value;                  Level = 2 * Value;
296                  SignalUnitBase<O>::Level = SignalUnitBase<O>::Level/127.0f - 1.0f;                  Level = Level/127.0f - 1.0f;
297                                    
298                  if (!SignalUnitBase<O>::bActive) SignalUnitBase<O>::bActive = true;                  if (!bActive) bActive = true;
             }  
     };  
   
     /**  
      * Endpoint signal unit.  
      */  
     template<class O>  
     class EndpointSignalUnitBase : public SignalUnitBase<O>, public EndpointSignalUnit {  
         public:  
   
             virtual float CalculateFilterCutoff(float cutoff) {  
                 cutoff *= GetFilterCutoff();  
                 return cutoff > 13500 ? 13500 : cutoff;  
             }  
               
             virtual float CalculatePitch(float pitch) {  
                 return GetPitch() * pitch;  
             }  
               
             virtual float CalculateResonance(float res) {  
                 return GetResonance() * res;  
299              }              }
300      };      };
301            

Legend:
Removed from v.2207  
changed lines
  Added in v.2217

  ViewVC Help
Powered by ViewVC