annotate stk/src/Envelope.cpp @ 1:2ca5d7440b5c tip

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