|
CLAM-Development
1.3
|
00001 /* 00002 * Copyright (c) 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 __INSTRUMENT__ 00023 #define __INSTRUMENT__ 00024 00025 #include "ProcessingComposite.hxx" 00026 #include "ADSR.hxx" 00027 #include "Oscillator.hxx" 00028 #include "AudioMultiplier.hxx" 00029 #include "ControlMapper.hxx" 00030 #include "ControlMultiplier.hxx" 00031 00032 namespace CLAM 00033 { 00034 class Instrument: public ProcessingComposite 00035 { 00036 private: 00037 AudioOutPort mOut; 00038 enum Status { 00039 eDone = 0, 00040 eBusy = 1 00041 } mStatus; 00042 00043 int mId; 00044 00045 protected: 00046 FloatInControl mStateIn; 00047 FloatInControl mNoteIn; 00048 FloatInControl mVelocityIn; 00049 00050 FloatOutControl mStateOut; 00051 FloatOutControl mNoteOut; 00052 FloatOutControl mVelocityOut; 00053 00054 public: 00055 friend class Dispatcher; 00056 00057 void SetId(int id) { mId = id; } 00058 00059 Instrument() 00060 : mOut("AudioOut",this) 00061 , mStatus( eDone ) 00062 , mStateIn( "StateIn", this, &Instrument::UpdateState ) 00063 , mNoteIn( "Note", this, &Instrument::UpdateNote ) 00064 , mVelocityIn( "Velocity", this, &Instrument::UpdateVel ) 00065 00066 , mStateOut( "State", this ) 00067 , mNoteOut( "NoteOut", this ) 00068 , mVelocityOut( "VelocityOut", this ) 00069 { 00070 } 00071 00072 void LinkStateOutWithInControl(Processing* inProc, unsigned inId) 00073 { 00074 GetOutControl(0).AddLink( inProc->GetInControl(inId)); 00075 // LinkOutWithInControl( 0, inProc, inId ); 00076 } 00077 00078 void UpdateState( TControlData value ) 00079 { 00080 if ( value == 0.0 ) 00081 { 00082 mStateOut.SendControl( mId ); 00083 mStatus = eDone; 00084 } 00085 else 00086 mStatus = eBusy; 00087 } 00088 00089 void UpdateNote( TControlData value ) 00090 { 00091 mNoteOut.SendControl( value ); 00092 } 00093 00094 void UpdateVel( TControlData value ) 00095 { 00096 mVelocityOut.SendControl( value ); 00097 } 00098 00099 public: 00100 virtual bool Do(Audio& audio) = 0; 00101 bool Do(void) 00102 { 00103 bool ret = Do(mOut.GetAudio()); 00104 mOut.Produce(); 00105 return ret; 00106 } 00107 const char * GetClassName() const {return "Instrument";} 00108 }; 00109 } 00110 00111 #endif 00112
1.7.6.1