CLAM-Development  1.4.0
ADSR.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef __ADSR__
23 #define __ADSR__
24 
25 #include "Processing.hxx"
26 #include "ProcessingData.hxx"
27 #include "Audio.hxx"
28 #include "OSDefines.hxx"
29 #include "InControl.hxx"
30 #include "AudioOutPort.hxx"
31 #include "OutControl.hxx"
32 
33 namespace CLAM
34 {
36  {
37  public:
39  DYN_ATTRIBUTE (0, public, TData, AttackTime);
40  DYN_ATTRIBUTE (1, public, TData, DecayTime);
41  DYN_ATTRIBUTE (2, public, TData, SustainLevel);
42  DYN_ATTRIBUTE (3, public, TData , ReleaseTime);
43  DYN_ATTRIBUTE (4, public, TData , SampleRate);
44  protected:
45  void DefaultInit(void);
46  };
47 
48  class ADSR: public Processing
49  {
50  public:
51  typedef ADSRConfig Config;
53  enum Status {
54  Attack = 0,
55  Decay = 1,
56  Sustain = 2,
57  Release = 3,
58  Done = 4,
59  };
60 
61  private:
62  FloatInControl mAmplitude;
63  ADSRConfig mConfig;
64  TControlData mAmpValue;
65  TData mAttackTime;
66  TData mDecayTime;
67  TData mSustainLevel;
68  TData mReleaseTime;
69  TData mSamplingRate;
70  TData mLevel;
71  TData mDLevel;
72  Status mStatus;
73  FloatOutControl mState;
74 
75  protected:
76  void HandleAttack();
77 
78  void HandleDecay();
79 
80  void HandleRelease();
81 
83  {
84  if ( mAmpValue > 0 )
85  HandleAttack();
86 
87  if ( mAmpValue == 0 )
88  HandleRelease();
89  }
90 
91  void UpdateState()
92  {
93  if( mStatus == Done )
94  mState.SendControl( 0 ); // Available instrument
95  else
96  mState.SendControl( 1 ); // Busy intrument
97  }
98 
99  void UpdateAmp( TControlData value )
100  {
101  mAmpValue = value ;
102  HandleAmplitude();
103  }
104 
105  public:
106  ADSR( const ADSRConfig& c = Config() );
107  ~ADSR(){}
108 
109  const char * GetClassName() const {return "ADSR";}
110 
111  const ProcessingConfig &GetConfig() const { return mConfig; }
112 
113  bool ConcreteConfigure( const ProcessingConfig& c );
114 
115  // Unsupervised mode
116  bool Do(void); // { return true; }
117 
118  bool Do( Audio& out);
119 
120  };
121 }
122 
123 #endif
124