/[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 2238 by iliev, Fri Aug 12 17:30:47 2011 UTC revision 2244 by iliev, Thu Aug 18 11:32:33 2011 UTC
# Line 24  Line 24 
24  #define __LS_SIGNALUNIT_H__  #define __LS_SIGNALUNIT_H__
25    
26  #include "../../common/ArrayList.h"  #include "../../common/ArrayList.h"
27    #include "../../common/Pool.h"
28    
29    
30  namespace LinuxSampler {  namespace LinuxSampler {
# Line 166  namespace LinuxSampler { Line 167  namespace LinuxSampler {
167              SignalUnit(SignalUnitRack* rack): pRack(rack), bActive(false), Level(0.0f), bCalculating(false), uiDelayTrigger(0) { }              SignalUnit(SignalUnitRack* rack): pRack(rack), bActive(false), Level(0.0f), bCalculating(false), uiDelayTrigger(0) { }
168              SignalUnit(const SignalUnit& Unit): pRack(Unit.pRack) { Copy(Unit); }              SignalUnit(const SignalUnit& Unit): pRack(Unit.pRack) { Copy(Unit); }
169              void operator=(const SignalUnit& Unit) { Copy(Unit); }              void operator=(const SignalUnit& Unit) { Copy(Unit); }
170                virtual ~SignalUnit() { }
171                            
172              void Copy(const SignalUnit& Unit) {              void Copy(const SignalUnit& Unit) {
173                  if (this == &Unit) return;                  if (this == &Unit) return;
# Line 373  namespace LinuxSampler { Line 375  namespace LinuxSampler {
375              bool isSmoothingOut() { return currentTimeStep < timeSteps; }              bool isSmoothingOut() { return currentTimeStep < timeSteps; }
376      };      };
377            
       
     const int MaxCCs = 10;  
       
378      /**      /**
379       * Continuous controller signal unit.       * Continuous controller signal unit.
380       * The level of this unit corresponds to the controllers changes       * The level of this unit corresponds to the controllers changes
# Line 389  namespace LinuxSampler { Line 388  namespace LinuxSampler {
388                      virtual void ValueChanged(CCSignalUnit* pUnit) = 0;                      virtual void ValueChanged(CCSignalUnit* pUnit) = 0;
389              };              };
390                            
         protected:  
391              class CC {              class CC {
392                  public:                  public:
393                      uint8_t   Controller;  ///< MIDI controller number.                      uint8_t   Controller;  ///< MIDI controller number.
# Line 419  namespace LinuxSampler { Line 417  namespace LinuxSampler {
417                      }                      }
418              };              };
419                            
420              FixedArray<CC> Ctrls; // The MIDI controllers which modulates this signal unit.          protected:
421                RTList<CC>* pCtrls; // The MIDI controllers which modulates this signal unit.
422              Listener* pListener;              Listener* pListener;
423              bool hasSmoothCtrls; // determines whether there are smooth controllers (used for optimization)              bool hasSmoothCtrls; // determines whether there are smooth controllers (used for optimization)
424              bool isSmoothingOut; // determines whether there is a CC which is in process of smoothing out (used for optimization)              bool isSmoothingOut; // determines whether there is a CC which is in process of smoothing out (used for optimization)
425    
426          public:          public:
427                            
428              CCSignalUnit(SignalUnitRack* rack, Listener* l = NULL): SignalUnit(rack), Ctrls(MaxCCs) {              CCSignalUnit(SignalUnitRack* rack, Listener* l = NULL): SignalUnit(rack), pCtrls(NULL) {
429                  pListener = l;                  pListener = l;
430                  hasSmoothCtrls = isSmoothingOut = false;                  hasSmoothCtrls = isSmoothingOut = false;
431              }              }
432                            
433              CCSignalUnit(const CCSignalUnit& Unit): SignalUnit(Unit.pRack), Ctrls(MaxCCs) { Copy(Unit); }              CCSignalUnit(const CCSignalUnit& Unit): SignalUnit(Unit.pRack), pCtrls(NULL) { Copy(Unit); }
434              void operator=(const CCSignalUnit& Unit) { Copy(Unit); }              void operator=(const CCSignalUnit& Unit) { Copy(Unit); }
435                            
436                virtual ~CCSignalUnit() {
437                    if (pCtrls != NULL) delete pCtrls;
438                }
439                
440              void Copy(const CCSignalUnit& Unit) {              void Copy(const CCSignalUnit& Unit) {
441                  Ctrls.copy(Unit.Ctrls);                  if (pCtrls != NULL) delete pCtrls;
442                    pCtrls = new RTList<CC>(*(Unit.pCtrls));
443                    if (pCtrls->poolIsEmpty() && pCtrls->count() < Unit.pCtrls->count()) {
444                        std::cerr << "Maximum number of CC reached!" << std::endl;
445                    }
446                    
447                  pListener = Unit.pListener;                  pListener = Unit.pListener;
448                  hasSmoothCtrls = Unit.hasSmoothCtrls;                  hasSmoothCtrls = Unit.hasSmoothCtrls;
449                  isSmoothingOut = Unit.isSmoothingOut;                  isSmoothingOut = Unit.isSmoothingOut;
450                  SignalUnit::Copy(Unit);                  SignalUnit::Copy(Unit);
451              }              }
452                            
453                virtual void InitCCList(Pool<CC>* pCCPool, Pool<Smoother>* pSmootherPool) {
454                    if (pCtrls != NULL) delete pCtrls;
455                    pCtrls = new RTList<CC>(pCCPool);
456                }
457                
458              void AddCC(uint8_t Controller, float Influence, short int Curve = -1, Smoother* pSmoother = NULL) {              void AddCC(uint8_t Controller, float Influence, short int Curve = -1, Smoother* pSmoother = NULL) {
459                  if(Ctrls.size() >= Ctrls.capacity()) {                  if(pCtrls->poolIsEmpty()) {
460                      std::cerr << "Maximum number of CC reached" << std::endl;                      std::cerr << "Maximum number of CC reached!" << std::endl;
461                      return;                      return;
462                  }                  }
463                  Ctrls.add(CC(Controller, Influence, Curve, pSmoother));                  *(pCtrls->allocAppend()) = CC(Controller, Influence, Curve, pSmoother);
464                  if (pSmoother != NULL) hasSmoothCtrls = true;                  if (pSmoother != NULL) hasSmoothCtrls = true;
465              }              }
466                            
467              virtual void RemoveAllCCs() { Ctrls.clear(); }              virtual void RemoveAllCCs() { pCtrls->clear(); }
468                            
469              int GetCCCount() { return Ctrls.size(); }              int GetCCCount() { return pCtrls->count(); }
470                            
471              virtual void Increment() {              virtual void Increment() {
472                  if (hasSmoothCtrls && isSmoothingOut) Calculate();                  if (hasSmoothCtrls && isSmoothingOut) Calculate();
# Line 467  namespace LinuxSampler { Line 480  namespace LinuxSampler {
480              virtual void ProcessCCEvent(uint8_t Controller, uint8_t Value) {              virtual void ProcessCCEvent(uint8_t Controller, uint8_t Value) {
481                  bool recalculate = false;                  bool recalculate = false;
482                                    
483                  for (int i = 0; i < Ctrls.size(); i++) {                  RTList<CC>::Iterator ctrl = pCtrls->first();
484                      if (Controller != Ctrls[i].Controller) continue;                  RTList<CC>::Iterator end  = pCtrls->end();
485                      if (Ctrls[i].Value == Value) continue;                  for(; ctrl != end; ++ctrl) {
486                      Ctrls[i].Value = Value;                      if (Controller != (*ctrl).Controller) continue;
487                      if (Ctrls[i].pSmoother != NULL) Ctrls[i].pSmoother->update(Value);                      if ((*ctrl).Value == Value) continue;
488                        (*ctrl).Value = Value;
489                        if ((*ctrl).pSmoother != NULL) (*ctrl).pSmoother->update(Value);
490                      if (!bActive) bActive = true;                      if (!bActive) bActive = true;
491                      recalculate = true;                      recalculate = true;
492                  }                  }
# Line 482  namespace LinuxSampler { Line 497  namespace LinuxSampler {
497              virtual void Calculate() {              virtual void Calculate() {
498                  float l = 0;                  float l = 0;
499                  isSmoothingOut = false;                  isSmoothingOut = false;
500                  for (int i = 0; i < Ctrls.size(); i++) {                  RTList<CC>::Iterator ctrl = pCtrls->first();
501                      if (Ctrls[i].pSmoother == NULL) {                  RTList<CC>::Iterator end  = pCtrls->end();
502                          l += Normalize(Ctrls[i].Value, Ctrls[i].Curve) * Ctrls[i].Influence;                  for(; ctrl != end; ++ctrl) {
503                        if ((*ctrl).pSmoother == NULL) {
504                            l += Normalize((*ctrl).Value, (*ctrl).Curve) * (*ctrl).Influence;
505                      } else {                      } else {
506                          if (Ctrls[i].pSmoother->isSmoothingOut()) isSmoothingOut = true;                          if ((*ctrl).pSmoother->isSmoothingOut()) isSmoothingOut = true;
507                          l += Normalize(Ctrls[i].pSmoother->render(), Ctrls[i].Curve) * Ctrls[i].Influence;                          l += Normalize((*ctrl).pSmoother->render(), (*ctrl).Curve) * (*ctrl).Influence;
508                      }                      }
509                  }                  }
510                  if (Level != l) {                  if (Level != l) {

Legend:
Removed from v.2238  
changed lines
  Added in v.2244

  ViewVC Help
Powered by ViewVC