Envelope.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #ifndef CSL_Envelope_H
00019 #define CSL_Envelope_H
00020 
00021 #include "CSL_Core.h"
00022 #include "CPoint.h"
00023 
00024 namespace csl {
00025 
00029 
00030 #ifdef CSL_ENUMS
00031 typedef enum {          
00032     kLine,      
00033     kExpon,     
00034 } LineMode;
00035 #else
00036     #define kLine 1
00037     #define kExpon 2
00038     typedef int LineMode;
00039 #endif
00040 
00044 
00045 class LineSegment : public UnitGenerator {
00046 public:
00047     LineSegment();          
00048     LineSegment(float d, float s, float e, LineMode mode = kLine); 
00049 
00051     float start() { return mStart; }        
00052     float end() { return mEnd; }            
00053     float duration() { return mDuration; }  
00054     unsigned currentFrame() { return mCurrentFrame; };
00055 
00056     void setEnd(float tend) { mEnd = tend; }
00057     void setStart(float tstart) { mStart = tstart; mCurrentValue = mStart; }
00058     void setDuration(unsigned tduration) { mDuration = (float) tduration; } 
00059     void setDuration(float tduration) { mDuration = tduration; }
00060     void setMode(LineMode tmode) { mMode = tmode; }     
00061     
00063     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00065     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum, Port * scalePort, Port * offsetPort) throw (CException);
00066 
00067     void reset();               
00068     void trigger() { this->reset(); };      
00069     void dump();                
00070 
00071 protected:
00072     float mStart;               
00073     float mEnd;                 
00074     float mDuration ;           
00075     LineMode mMode;             
00076     float mCurrentValue;        
00077     unsigned mCurrentFrame;     
00078 };
00079 
00081 
00082 typedef map<double, LineSegment *> Breakpoints;
00083 
00088 
00089 class Envelope : public UnitGenerator, public Scalable {
00090 public:
00091     Envelope() : UnitGenerator(), Scalable(1, 0), mDuration(0) { };
00092     Envelope(LineMode mode, double t, double x1, double y1, double x2 = NULL, double y2 = 1.0, double x3 = NULL, double y3 = 1.0,
00093                 double x4 = NULL, double y4 = 1.0, double x5 = NULL, double y5 = 1.0, double x6 = NULL, double y6 = 1.0);
00094     Envelope(LineMode mode, double t, unsigned int size, double x[], double y[]);
00095     Envelope(double t, double x1, double y1, double x2 = NULL, double y2 = 1.0, double x3 = NULL, double y3 = 1.0,
00096                 double x4 = NULL, double y4 = 1.0, double x5 = NULL, double y5 = 1.0, double x6 = NULL, double y6 = 1.0);
00097     Envelope(double t, unsigned int size, double x[], double y[]);
00098 
00099     virtual ~Envelope();
00101     virtual bool isActive();
00102 
00103     void addBreakpoint(double startTime, double value);
00104     
00105     void setMode(LineMode mode);
00106 //  void setInterpolationAtSegment(LineMode mode, unsigned idx); ///< allows to specify interpolation other than linear for a segment.
00107     virtual void setDuration(float d);      
00108     virtual void scaleTimes(float s);       
00109     
00110     virtual void reset();                   
00111     virtual void trigger();             
00112     virtual void dump();
00114     virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00115 
00116 protected:
00117     float mDuration;                
00118     float mCurrentMark;         
00119     Breakpoints mSegmentMap;
00120     LineSegment **mSegments;
00121     double *mValues;
00122     unsigned mSize;
00124     unsigned int privateNextBuffer(CPoint *breakpoint, LineSegment *segment, float *buffer, unsigned int numFrames);
00125     void createSegments();      
00126     void calculateSegments();       
00127 };
00128 
00130 
00152 class ADSR : public Envelope {
00153 
00154 public: 
00155     ADSR() : Envelope() { };
00157     ADSR(LineMode mode, float t, float a, float d, float s, float r);
00159     ADSR(LineMode mode, float t, float i, float a, float d, float s, float r);
00161     ADSR(float t, float a, float d, float s, float r);
00163     ADSR(float t, float i, float a, float d, float s, float r);
00164     ~ADSR() { };
00166     void setAttack(float attack);
00167     void setDecay(float decay);
00168     void setSustain(float sustain);
00169     void setRelease(float release);
00170 
00171     void release(void);     
00172 };
00173 
00175 
00196 class AR : public Envelope {
00197 
00198 public:         
00199     AR() : Envelope() { };
00201     AR(LineMode mode, float t, float a, float r);
00203     AR(LineMode mode, float t, float i, float a, float r);
00205     AR(float t, float a, float r);
00207     AR(float t, float i, float a, float r);
00208 
00209     ~AR() { };
00211     void setAttack(float attack);
00212     void setRelease(float release);
00213     void setAll(float d, float a, float r);
00215     void release(void);         
00216 };
00217 
00221 
00222 class Triangle : public Envelope {
00223 
00224 public:         
00225     Triangle() : Envelope() { };
00227     Triangle(LineMode mode, float duration, float amplitude);
00229     Triangle(LineMode mode, float duration,  float initialDelay, float amplitude);
00231     Triangle(float duration, float amplitude);
00233     Triangle(float duration,  float initialDelay, float amplitude);
00235     ~Triangle() { };
00236 };
00237 
00241 
00242 class RandEnvelope : public Envelope {
00243 public:                                     
00244     RandEnvelope(float frequency = 1, float amplitude = 1, float offset = 0, float step = 0);
00245     ~RandEnvelope() { };
00247     void setWalk(bool walk) { mWalk = walk; };
00248     void setAmplitude(float amplitude) { mAmplitude = amplitude; };
00249     void setFrequency(float frequency) { mFrequency = frequency; };
00250     void setStep(float step) { mStep = step; };
00251     void setOffset(float offset) { mOffset = offset; };
00252 
00253     virtual bool isActive() { return false; };
00255     void reset() { };               
00256     void trigger() { };             
00257     void dump() { };                
00258     void setDuration(float d) { };  
00259     void scaleTimes(float s) { };   
00260 
00262     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00263 
00264 protected:
00265     float mLastVal;             
00266     float mFrequency;           
00267     float mAmplitude;           
00268     float mStep;                    
00269     float mOffset;              
00270     unsigned mCurrentIndex;     
00271     unsigned mSegmentLength;    
00272     bool mWalk;                 
00273     LineSegment mSegment;       
00274     
00275     void initSegment();         
00276     void nextSegment();         
00277 
00278 };
00279 
00280 }
00281 
00282 #endif
00283 

Generated on Thu Sep 17 23:14:16 2009 for CSL by  doxygen 1.5.8