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
00043 class LineSegment : public UnitGenerator {
00044 public:
00045     LineSegment();          
00046     LineSegment(float d, float s, float e, LineMode mode = kLine); 
00047 
00049     float start() { return mStart; }            
00050     float end() { return mEnd; }            
00051     float duration() { return mDuration; }  
00052     unsigned currentFrame() { return mCurrentFrame; };
00053 
00054     void setEnd(float end) { mEnd = end; }
00055     void setStart(float start) { mStart = start; mCurrentValue = mStart; }
00056     void setDuration(unsigned duration) { mDuration = (float)duration; }    
00057     void setDuration(float duration) { mDuration = duration; }
00058     void setMode(LineMode mode) { mMode = mode; }       
00059     
00061     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00063     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum, Port * scalePort, Port * offsetPort) throw (CException);
00064 
00065     void reset();               
00066     void trigger() { this->reset(); };      
00067     void dump();                
00068 
00069 protected:
00070 
00071     float mStart;           
00072     float mEnd;         
00073     float mDuration ;   
00074 
00075     LineMode mMode;     
00076     
00077     float mCurrentValue;            
00078     unsigned mCurrentFrame;     
00079     
00080 };
00081 
00083 typedef map<double, LineSegment *> Breakpoints;
00084 
00089 class Envelope : public UnitGenerator, public Scalable {
00090 public:
00091     Envelope() : UnitGenerator(), Scalable(1, 0), mDuration(0) {};
00092     Envelope(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(double t, unsigned int size, double x[], double y[]);
00095 
00096     virtual ~Envelope();
00097 
00099     bool isActive() { return (mCurrentMark < mDuration); };
00100 
00101     void addBreakpoint(double startTime, double value);
00102     
00103     void setInterpolationAtSegment(LineMode mode, unsigned idx); 
00104     void setDuration(float d);      
00105     void scaleTimes(float s);       
00106     
00107     void reset();                   
00108     void trigger();             
00109     void dump();
00111     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00112 
00113 protected:
00114     float mDuration;                
00115     float mCurrentMark;         
00116     Breakpoints mSegmentMap;
00117     LineSegment **mSegments;
00118     double *mValues;
00119     unsigned mSize;
00121     unsigned int privateNextBuffer(CPoint *breakpoint, LineSegment *segment, float *buffer, unsigned int numFrames);
00122     void createSegments();      
00123     void calculateSegments();       
00124 };
00125 
00127 
00149 class ADSR : public Envelope {
00150 
00151 public:
00152     
00153     ADSR() : Envelope() {};
00155     ADSR(float t, float a, float d, float s, float r);
00157     ADSR(float t, float i, float a, float d, float s, float r);
00158     ~ADSR() {};
00160     void setAttack(float attack);
00161     void setDecay(float decay);
00162     void setSustain(float sustain);
00163     void setRelease(float release);
00164 
00165     void release(void);     
00166 };
00167 
00169 
00190 class AR : public Envelope {
00191 
00192 public:
00194     AR() : Envelope() {};
00196     AR(float t, float a, float r);
00198     AR(float t, float i, float a, float r);
00199 
00200     ~AR() {};
00202     void setAttack(float attack);
00203     void setRelease(float release);
00204     void setAll(float d, float a, float r);
00206     void release(void);         
00207 };
00208 
00210 class Triangle : public Envelope {
00211 
00212 public:
00214     Triangle() : Envelope() {};
00216     Triangle(float duration, float amplitude);
00218     Triangle(float duration,  float initialDelay, float amplitude);
00220     ~Triangle() {};
00221 };
00222 
00226 class RandEnvelope : public Envelope {
00227 public:
00229     RandEnvelope(float frequency = 1, float amplitude = 1, float offset = 0, float step = 0);
00230     ~RandEnvelope() {};
00232     void setWalk(bool walk) { mWalk = walk; };
00233     void setAmplitude(float amplitude) { mAmplitude = amplitude; };
00234     void setFrequency(float frequency) { mFrequency = frequency; };
00235     void setStep(float step) { mStep = step; };
00236     void setOffset(float offset) { mOffset = offset; };
00237 
00238     bool isActive() { return true; };
00239     
00240     void reset() { };               
00241     void trigger() { };             
00242     void dump() {};             
00243 
00245     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00246 
00247 protected:
00248     float mLastVal;             
00249     float mFrequency;           
00250     float mAmplitude;           
00251     float mStep;                    
00252     float mOffset;              
00253     unsigned mCurrentIndex;     
00254     unsigned mSegmentLength;    
00255     bool mWalk;                 
00256     LineSegment mSegment;       
00257     
00258     void initSegment();         
00259     void nextSegment();         
00260 
00261 };
00262 
00263 }
00264 
00265 #endif
00266 

Generated on Fri Apr 6 20:18:13 2007 for CSL by  doxygen 1.4.5-20051010