CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #ifndef __ADSR__ 00023 #define __ADSR__ 00024 00025 #include "Processing.hxx" 00026 #include "ProcessingData.hxx" 00027 #include "Audio.hxx" 00028 #include "OSDefines.hxx" 00029 #include "InControl.hxx" 00030 #include "AudioOutPort.hxx" 00031 #include "OutControl.hxx" 00032 00033 namespace CLAM 00034 { 00035 class ADSRConfig: public ProcessingConfig 00036 { 00037 public: 00038 DYNAMIC_TYPE_USING_INTERFACE (ADSRConfig, 5, ProcessingConfig); 00039 DYN_ATTRIBUTE (0, public, TData, AttackTime); 00040 DYN_ATTRIBUTE (1, public, TData, DecayTime); 00041 DYN_ATTRIBUTE (2, public, TData, SustainLevel); 00042 DYN_ATTRIBUTE (3, public, TData , ReleaseTime); 00043 DYN_ATTRIBUTE (4, public, TData , SampleRate); 00044 protected: 00045 void DefaultInit(void); 00046 }; 00047 00048 class ADSR: public Processing 00049 { 00050 public: 00051 AudioOutPort mOutput; 00052 enum Status { 00053 Attack = 0, 00054 Decay = 1, 00055 Sustain = 2, 00056 Release = 3, 00057 Done = 4, 00058 }; 00059 00060 private: 00061 InControlTmpl< ADSR > mAmplitude; 00062 ADSRConfig mConfig; 00063 TControlData mAmpValue; 00064 TData mAttackTime; 00065 TData mDecayTime; 00066 TData mSustainLevel; 00067 TData mReleaseTime; 00068 TData mSamplingRate; 00069 TData mLevel; 00070 TData mDLevel; 00071 Status mStatus; 00072 OutControl mState; 00073 00074 protected: 00075 void HandleAttack(void); 00076 00077 void HandleDecay(void); 00078 00079 void HandleRelease(void); 00080 00081 void HandleAmplitude(void) 00082 { 00083 if ( mAmpValue > 0 ) 00084 HandleAttack(); 00085 00086 if ( mAmpValue == 0 ) 00087 HandleRelease(); 00088 } 00089 00090 void UpdateState(void) 00091 { 00092 if( mStatus == Done ) 00093 mState.SendControl( 0 ); // Available instrument 00094 else 00095 mState.SendControl( 1 ); // Busy intrument 00096 } 00097 00098 int UpdateAmp( TControlData value ) 00099 { 00100 mAmpValue = value ; 00101 HandleAmplitude(); 00102 return 0; 00103 } 00104 00105 public: 00106 00107 ADSR(); 00108 00109 ADSR( const ADSRConfig& c ); 00110 00111 ~ADSR(){} 00112 00113 const char * GetClassName() const {return "ADSR";} 00114 00115 const ProcessingConfig &GetConfig() const { return mConfig; } 00116 00117 bool ConcreteConfigure( const ProcessingConfig& c ); 00118 00119 // Unsupervised mode 00120 bool Do(void); // { return true; } 00121 00122 bool Do( Audio& out); 00123 00124 }; 00125 } 00126 00127 #endif 00128