Instrument.hxx

Go to the documentation of this file.
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                 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 //                      LinkOutWithInControl( 0, inProc, inId );
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 

Generated on Tue Aug 12 22:33:43 2008 for CLAM by  doxygen 1.5.5