comparison stk/src/Envelope.cpp @ 0:4606bd505630 tip

first import
author Fiore Martin <f.martin@qmul.ac.uk>
date Sat, 13 Jun 2015 15:08:10 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4606bd505630
1 /***************************************************/
2 /*! \class Envelope
3 \brief STK linear line envelope class.
4
5 This class implements a simple linear line envelope generator
6 which is capable of ramping to an arbitrary target value by a
7 specified \e rate. It also responds to simple \e keyOn and \e
8 keyOff messages, ramping to 1.0 on keyOn and to 0.0 on keyOff.
9
10 by Perry R. Cook and Gary P. Scavone, 1995--2014.
11 */
12 /***************************************************/
13
14 #include "../include/Envelope.h"
15
16 namespace stk {
17
18 Envelope :: Envelope( void ) : Generator()
19 {
20 target_ = 0.0;
21 value_ = 0.0;
22 rate_ = 0.001;
23 state_ = 0;
24 Stk::addSampleRateAlert( this );
25 }
26
27 Envelope :: ~Envelope( void )
28 {
29 Stk::removeSampleRateAlert( this );
30 }
31
32 Envelope& Envelope :: operator= ( const Envelope& e )
33 {
34 if ( this != &e ) {
35 target_ = e.target_;
36 value_ = e.value_;
37 rate_ = e.rate_;
38 state_ = e.state_;
39 }
40
41 return *this;
42 }
43
44 void Envelope :: sampleRateChanged( StkFloat newRate, StkFloat oldRate )
45 {
46 if ( !ignoreSampleRateChange_ )
47 rate_ = oldRate * rate_ / newRate;
48 }
49
50 void Envelope :: setRate( StkFloat rate )
51 {
52 if ( rate < 0.0 ) {
53 oStream_ << "Envelope::setRate: argument must be >= 0.0!";
54 handleError( StkError::WARNING ); return;
55 }
56
57 rate_ = rate;
58 }
59
60 void Envelope :: setTime( StkFloat time )
61 {
62 if ( time <= 0.0 ) {
63 oStream_ << "Envelope::setTime: argument must be > 0.0!";
64 handleError( StkError::WARNING ); return;
65 }
66
67 rate_ = 1.0 / ( time * Stk::sampleRate() );
68 }
69
70 void Envelope :: setTarget( StkFloat target )
71 {
72 target_ = target;
73 if ( value_ != target_ ) state_ = 1;
74 }
75
76 void Envelope :: setValue( StkFloat value )
77 {
78 state_ = 0;
79 target_ = value;
80 value_ = value;
81 lastFrame_[0] = value_;
82 }
83
84 } // stk namespace