CLAM-Development  1.4.0
Dispatcher.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 __DISPATCHER__
23 #define __DISPATCHER__
24 
25 #include "Array.hxx"
26 #include "Instrument.hxx"
27 
28 #include <algorithm>
29 
30 namespace CLAM
31 {
32 
34  {
35  public:
37  DYN_ATTRIBUTE (0, public, Array< Instrument* >, Instruments);
38  DYN_ATTRIBUTE (1, public, int, NInValues);
39 
40  protected:
41  void DefaultInit(void)
42  {
43  AddInstruments();
44  AddNInValues();
45  UpdateData();
46  }
47  };
48 
49  class Dispatcher:public Processing
50  {
51  private:
52  typedef DispatcherConfig Config;
53  struct InstrStatus
54  {
55  public:
56  int mNote;
57  int mVelocity;
58  int mId;
59  };
60 
61  Config mConfig;
62  Array< Instrument* > mInstruments;
63  Array< FloatOutControl* > mValuesOut;
64  FloatInControl mStateIn;
65  FloatInControl mNoteIn;
66  FloatInControl mVelocityIn;
67  int mNInValues;
68  int mMInstruments;
69  TControlData mVelocity;
70  TControlData mNote;
71  std::list< InstrStatus > mInstrStatusList;
72 
73  protected:
74 
75  void UpdateState( TControlData availableInstr );
76 
77  void UpdateVel( TControlData value )
78  {
79 // printf("UpdateVel = %f\n",value);
80  mVelocity = value;
81  }
82 
83  void UpdateNote( TControlData value )
84  {
85 // printf("UpdateNote = %f\n",value);
86  mNote = value;
87  Dispatch();
88  }
89 
90  void Dispatch(void);
91 
92  public:
93  Dispatcher( const Config& c = Config())
94  : mStateIn("",this,&Dispatcher::UpdateState)
95  , mNoteIn( "Note", this, &Dispatcher::UpdateNote)
96  , mVelocityIn( "Velocity", this, &Dispatcher::UpdateVel)
97  , mVelocity( 0 )
98  , mNote( 0 )
99  {
100  Configure( c );
101  }
102 
104 
105  const char * GetClassName() const {return "Dispatcher";}
106 
107  const ProcessingConfig &GetConfig() const { return mConfig; }
108 
109  bool ConcreteConfigure( const ProcessingConfig& c );
110 
111  bool Do(void) { return true; }
112 
113  };
114 }
115 
116 #endif
117