00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 InControlTmpl< Instrument > mStateIn;
00047 InControlTmpl< Instrument > mNoteIn;
00048 InControlTmpl< Instrument > mVelocityIn;
00049
00050 OutControl mStateOut;
00051 OutControl mNoteOut;
00052 OutControl 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 GetOutControls().GetByNumber(0).AddLink( inProc->GetInControls().GetByNumber(inId));
00075
00076 }
00077
00078 int 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 return 0;
00089 }
00090
00091 int UpdateNote( TControlData value )
00092 {
00093 mNoteOut.SendControl( value );
00094
00095 return 0;
00096 }
00097
00098 int UpdateVel( TControlData value )
00099 {
00100 mVelocityOut.SendControl( value );
00101
00102 return 0;
00103 }
00104
00105 public:
00106 virtual bool Do(Audio& audio) = 0;
00107 bool Do(void)
00108 {
00109 bool ret = Do(mOut.GetAudio());
00110 mOut.Produce();
00111 return ret;
00112 }
00113 const char * GetClassName() const {return "Instrument";}
00114 };
00115 }
00116
00117 #endif
00118