1
/*******************************************/
2
/* Envelope Class, Perry R. Cook, 1995-96 */
4
/* This is the base class for envelopes. */
5
/* This one is capable of ramping state */
6
/* from where it is to a target value by */
7
/* a rate. It also responds to simple */
8
/* KeyOn and KeyOff messages, ramping to */
9
/* 1.0 on keyon and to 0.0 on keyoff. */
10
/* There are two tick (update value) */
11
/* methods, one returns the value, and */
12
/* other returns 0 if the envelope is at */
13
/* the target value (the state bit). */
14
/*******************************************/
18
Envelope :: Envelope() : Object()
20
target = (MY_FLOAT) 0.0;
21
value = (MY_FLOAT) 0.0;
22
rate = (MY_FLOAT) 0.001;
26
Envelope :: ~Envelope()
30
void Envelope :: keyOn()
32
target = (MY_FLOAT) 1.0;
33
if (value != target) state = 1;
36
void Envelope :: keyOff()
38
target = (MY_FLOAT) 0.0;
39
if (value != target) state = 1;
42
void Envelope :: setRate(MY_FLOAT aRate)
45
printf("negative rates not allowed!!, correcting\n");
51
void Envelope :: setTime(MY_FLOAT aTime)
54
printf("negative times not allowed!!, correcting\n");
55
rate = ONE_OVER_SRATE / -aTime ;
57
else rate = ONE_OVER_SRATE / aTime ;
60
void Envelope :: setTarget(MY_FLOAT aTarget)
63
if (value != target) state = 1;
66
void Envelope :: setValue(MY_FLOAT aValue)
73
MY_FLOAT Envelope :: tick()
78
if (value >= target) {
85
if (value <= target) {
94
int Envelope :: informTick()
100
MY_FLOAT Envelope :: lastOut()
105
/************ Test Main ************************/
114
for (i=0;i<10;i++) printf("%lf\n",test.tick());
117
while (test.informTick()) printf("%lf\n",test.lastOut());
120
while(test.informTick()) printf("%lf\n",test.lastOut());