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<float, LineSegment *> Breakpoints;
00083
00088
00089 class Envelope : public UnitGenerator, public Scalable {
00090 public:
00091 Envelope() : UnitGenerator(), Scalable(1, 0), mDuration(0), mSegments(0), mValues(0) { };
00092 Envelope(LineMode mode, float t, float x1, float y1, float x2 = NULL, float y2 = 1.0, float x3 = NULL, float y3 = 1.0,
00093 float x4 = NULL, float y4 = 1.0, float x5 = NULL, float y5 = 1.0, float x6 = NULL, float y6 = 1.0);
00094 Envelope(LineMode mode, float t, unsigned int size, float x[], float y[]);
00095 Envelope(float t, float x1, float y1, float x2 = NULL, float y2 = 1.0, float x3 = NULL, float y3 = 1.0,
00096 float x4 = NULL, float y4 = 1.0, float x5 = NULL, float y5 = 1.0, float x6 = NULL, float y6 = 1.0);
00097 Envelope(float t, unsigned int size, float x[], float y[]);
00098
00099 virtual ~Envelope();
00101 virtual bool isActive();
00102
00103 void addBreakpoint(float startTime, float value);
00104
00105 void setMode(LineMode mode);
00106
00107 virtual void setDuration(float d);
00108 virtual void scaleTimes(float s);
00109 virtual void scaleValues(float s);
00110
00111 virtual void reset();
00112 virtual void trigger();
00113 virtual void dump();
00115 virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00116
00117 protected:
00118 float mDuration;
00119 float mCurrentMark;
00120 Breakpoints mSegmentMap;
00121 LineSegment **mSegments;
00122 float *mValues;
00123 unsigned mSize;
00125 unsigned int privateNextBuffer(CPoint *breakpoint, LineSegment *segment, float *buffer, unsigned int numFrames);
00126 void createSegments();
00127 void calculateSegments();
00128 };
00129
00131
00153 class ADSR : public Envelope {
00154
00155 public:
00156 ADSR() : Envelope() { };
00158 ADSR(LineMode mode, float t, float a, float d, float s, float r);
00160 ADSR(LineMode mode, float t, float i, float a, float d, float s, float r);
00162 ADSR(float t, float a, float d, float s, float r);
00164 ADSR(float t, float i, float a, float d, float s, float r);
00165 ~ADSR() { };
00167 void setDuration(float d);
00168 void setDelay(float del);
00169 void setAttack(float attack);
00170 void setDecay(float decay);
00171 void setSustain(float sustain);
00172 void setRelease(float release);
00173
00174 void release(void);
00175 };
00176
00178
00199 class AR : public Envelope {
00200
00201 public:
00202 AR() : Envelope() { };
00204 AR(LineMode mode, float t, float a, float r);
00206 AR(LineMode mode, float t, float i, float a, float r);
00208 AR(float t, float a, float r);
00210 AR(float t, float i, float a, float r);
00211
00212 ~AR() { };
00214 void setDuration(float d);
00215 void setDelay(float del);
00216 void setAttack(float attack);
00217 void setRelease(float release);
00218 void setAll(float d, float a, float r);
00220 void release(void);
00221 };
00222
00226
00227 class Triangle : public Envelope {
00228
00229 public:
00230 Triangle() : Envelope() { };
00232 Triangle(LineMode mode, float duration, float amplitude);
00234 Triangle(LineMode mode, float duration, float initialDelay, float amplitude);
00236 Triangle(float duration, float amplitude = 1.0f);
00238 Triangle(float duration, float initialDelay, float amplitude);
00240 ~Triangle() { };
00241 };
00242
00246
00247 class RandEnvelope : public Envelope {
00248 public:
00249 RandEnvelope(float frequency = 1, float amplitude = 1, float offset = 0, float step = 0);
00250 ~RandEnvelope() { };
00252 void setWalk(bool walk) { mWalk = walk; };
00253 void setAmplitude(float amplitude) { mAmplitude = amplitude; };
00254 void setFrequency(float frequency) { mFrequency = frequency; };
00255 void setStep(float step) { mStep = step; };
00256 void setOffset(float offset) { mOffset = offset; };
00257
00258 virtual bool isActive() { return false; };
00260 void reset() { };
00261 void trigger() { };
00262 void dump() { };
00263 void setDuration(float d) { };
00264 void scaleTimes(float s) { };
00265
00267 void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00268
00269 protected:
00270 float mLastVal;
00271 float mFrequency;
00272 float mAmplitude;
00273 float mStep;
00274 float mOffset;
00275 unsigned mCurrentIndex;
00276 unsigned mSegmentLength;
00277 bool mWalk;
00278 LineSegment mSegment;
00279
00280 void initSegment();
00281 void nextSegment();
00282
00283 };
00284
00285 }
00286
00287 #endif
00288