CLAM-Development  1.4.0
MIDIDispatcher.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-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 __MIDIDISPATCHER__
23 #define __MIDIDISPATCHER__
24 
25 #include "Array.hxx"
26 #include "InControl.hxx"
27 #include "OutControl.hxx"
28 #include "Processing.hxx"
29 #include "ProcessingConfig.hxx"
30 
31 #include <algorithm>
32 
33 namespace CLAM
34 {
35 
37  {
38  public:
40  DYN_ATTRIBUTE ( 0, public, int, NumberOfInControls );
41  DYN_ATTRIBUTE ( 1, public, int, NumberOfVoices );
42 
43  protected:
44  void DefaultInit(void);
45  };
46 
47  class MIDIDispatcher : public Processing
48  {
49 
50  std::vector< FloatInControl* > mInputControls;
51  std::vector< FloatOutControl* > mOutputControls;
52 
53  void CreateControls();
54  void RemoveControls();
55 
56  private:
57  struct VoiceStatus
58  {
59  public:
60  int mNote;
61  int mVelocity;
62  int mId;
63  };
64 
65  MIDIDispatcherConfig mConfig;
66  FloatInControl mStateIn;
67  FloatInControl mNoteIn;
68  FloatInControl mVelocityIn;
69  int mNInControls;
70  int mNVoices;
71  TControlData mVelocity;
72  TControlData mNote;
73  std::list< VoiceStatus > mVoiceStatusList;
74 
75  protected:
76 
77  void UpdateState( TControlData availableInstr );
78 
79 
80  void UpdateVel( TControlData value )
81  {
82  mVelocity = value;
83  }
84 
85 
86  void UpdateNote( TControlData value )
87  {
88  mNote = value;
89  Dispatch();
90  }
91 
92  void Dispatch();
93 
94  public:
95 
97 
99 
100  virtual ~MIDIDispatcher(){ RemoveControls(); }
101 
102  const char * GetClassName() const {return "MIDIDispatcher";}
103 
104  const ProcessingConfig &GetConfig() const { return mConfig; }
105 
106  bool ConcreteConfigure( const ProcessingConfig& c );
107 
108  bool Do() { return true; }
109 
110  };
111 }
112 
113 #endif
114