CLAM-Development  1.4.0
Instrument.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 __INSTRUMENT__
23 #define __INSTRUMENT__
24 
25 #include "ProcessingComposite.hxx"
26 #include "ADSR.hxx"
27 #include "Oscillator.hxx"
28 #include "AudioMultiplier.hxx"
29 #include "ControlMapper.hxx"
30 #include "ControlMultiplier.hxx"
31 
32 namespace CLAM
33 {
35  {
36  private:
37  AudioOutPort mOut;
38  enum Status {
39  eDone = 0,
40  eBusy = 1
41  } mStatus;
42 
43  int mId;
44 
45  protected:
49 
53 
54  public:
55  friend class Dispatcher;
56 
57  void SetId(int id) { mId = id; }
58 
60  : mOut("AudioOut",this)
61  , mStatus( eDone )
62  , mStateIn( "StateIn", this, &Instrument::UpdateState )
63  , mNoteIn( "Note", this, &Instrument::UpdateNote )
64  , mVelocityIn( "Velocity", this, &Instrument::UpdateVel )
65 
66  , mStateOut( "State", this )
67  , mNoteOut( "NoteOut", this )
68  , mVelocityOut( "VelocityOut", this )
69  {
70  }
71 
72  void LinkStateOutWithInControl(Processing* inProc, unsigned inId)
73  {
74  GetOutControl(0).AddLink( inProc->GetInControl(inId));
75 // LinkOutWithInControl( 0, inProc, inId );
76  }
77 
78  void UpdateState( TControlData value )
79  {
80  if ( value == 0.0 )
81  {
82  mStateOut.SendControl( mId );
83  mStatus = eDone;
84  }
85  else
86  mStatus = eBusy;
87  }
88 
89  void UpdateNote( TControlData value )
90  {
91  mNoteOut.SendControl( value );
92  }
93 
94  void UpdateVel( TControlData value )
95  {
96  mVelocityOut.SendControl( value );
97  }
98 
99  public:
100  virtual bool Do(Audio& audio) = 0;
101  bool Do(void)
102  {
103  bool ret = Do(mOut.GetAudio());
104  mOut.Produce();
105  return ret;
106  }
107  const char * GetClassName() const {return "Instrument";}
108  };
109 }
110 
111 #endif
112