| 1 |
/***************************************************/ |
| 2 |
/*! \class ADSR |
| 3 |
\brief STK ADSR envelope class. |
| 4 |
|
| 5 |
This Envelope subclass implements a |
| 6 |
traditional ADSR (Attack, Decay, |
| 7 |
Sustain, Release) envelope. It |
| 8 |
responds to simple keyOn and keyOff |
| 9 |
messages, keeping track of its state. |
| 10 |
The \e state = ADSR::DONE after the |
| 11 |
envelope value reaches 0.0 in the |
| 12 |
ADSR::RELEASE state. |
| 13 |
|
| 14 |
by Perry R. Cook and Gary P. Scavone, 1995 - 2005. |
| 15 |
*/ |
| 16 |
/***************************************************/ |
| 17 |
|
| 18 |
#ifndef STK_ADSR_H |
| 19 |
#define STK_ADSR_H |
| 20 |
|
| 21 |
#include "Envelope.h" |
| 22 |
|
| 23 |
namespace Nyq |
| 24 |
{ |
| 25 |
|
| 26 |
class ADSR : public Envelope |
| 27 |
{ |
| 28 |
public: |
| 29 |
|
| 30 |
//! Envelope states. |
| 31 |
enum { ATTACK, DECAY, SUSTAIN, RELEASE, DONE }; |
| 32 |
|
| 33 |
//! Default constructor. |
| 34 |
ADSR(void); |
| 35 |
|
| 36 |
//! Class destructor. |
| 37 |
~ADSR(void); |
| 38 |
|
| 39 |
//! Set target = 1, state = \e ADSR::ATTACK. |
| 40 |
void keyOn(void); |
| 41 |
|
| 42 |
//! Set target = 0, state = \e ADSR::RELEASE. |
| 43 |
void keyOff(void); |
| 44 |
|
| 45 |
//! Set the attack rate. |
| 46 |
void setAttackRate(StkFloat rate); |
| 47 |
|
| 48 |
//! Set the decay rate. |
| 49 |
void setDecayRate(StkFloat rate); |
| 50 |
|
| 51 |
//! Set the sustain level. |
| 52 |
void setSustainLevel(StkFloat level); |
| 53 |
|
| 54 |
//! Set the release rate. |
| 55 |
void setReleaseRate(StkFloat rate); |
| 56 |
|
| 57 |
//! Set the attack rate based on a time duration. |
| 58 |
void setAttackTime(StkFloat time); |
| 59 |
|
| 60 |
//! Set the decay rate based on a time duration. |
| 61 |
void setDecayTime(StkFloat time); |
| 62 |
|
| 63 |
//! Set the release rate based on a time duration. |
| 64 |
void setReleaseTime(StkFloat time); |
| 65 |
|
| 66 |
//! Set sustain level and attack, decay, and release time durations. |
| 67 |
void setAllTimes(StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime); |
| 68 |
|
| 69 |
//! Set the target value. |
| 70 |
void setTarget(StkFloat target); |
| 71 |
|
| 72 |
//! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, DONE). |
| 73 |
int getState(void) const; |
| 74 |
|
| 75 |
//! Set to state = ADSR::SUSTAIN with current and target values of \e aValue. |
| 76 |
void setValue(StkFloat value); |
| 77 |
|
| 78 |
protected: |
| 79 |
|
| 80 |
StkFloat computeSample( void ); |
| 81 |
|
| 82 |
StkFloat attackRate_; |
| 83 |
StkFloat decayRate_; |
| 84 |
StkFloat sustainLevel_; |
| 85 |
StkFloat releaseRate_; |
| 86 |
}; |
| 87 |
|
| 88 |
} // namespace Nyq |
| 89 |
|
| 90 |
#endif |