CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-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 __DISPATCHER__ 00023 #define __DISPATCHER__ 00024 00025 #include "Array.hxx" 00026 #include "Instrument.hxx" 00027 00028 #include <algorithm> 00029 00030 namespace CLAM 00031 { 00032 00033 class DispatcherConfig: public ProcessingConfig 00034 { 00035 public: 00036 DYNAMIC_TYPE_USING_INTERFACE (DispatcherConfig, 2, ProcessingConfig); 00037 DYN_ATTRIBUTE (0, public, Array< Instrument* >, Instruments); 00038 DYN_ATTRIBUTE (1, public, int, NInValues); 00039 00040 protected: 00041 void DefaultInit(void) 00042 { 00043 AddInstruments(); 00044 AddNInValues(); 00045 UpdateData(); 00046 } 00047 }; 00048 00049 class Dispatcher:public Processing 00050 { 00051 private: 00052 struct InstrStatus 00053 { 00054 public: 00055 int mNote; 00056 int mVelocity; 00057 int mId; 00058 }; 00059 00060 DispatcherConfig mConfig; 00061 Array< Instrument* > mInstruments; 00062 Array< OutControl* > mValuesOut; 00063 InControlTmpl< Dispatcher > mStateIn; 00064 InControlTmpl< Dispatcher > mNoteIn; 00065 InControlTmpl< Dispatcher > mVelocityIn; 00066 int mNInValues; 00067 int mMInstruments; 00068 TControlData mVelocity; 00069 TControlData mNote; 00070 std::list< InstrStatus > mInstrStatusList; 00071 00072 protected: 00073 00074 int UpdateState( TControlData availableInstr ); 00075 00076 int UpdateVel( TControlData value ) 00077 { 00078 // printf("UpdateVel = %f\n",value); 00079 mVelocity = value; 00080 00081 return 0; 00082 } 00083 00084 int UpdateNote( TControlData value ) 00085 { 00086 // printf("UpdateNote = %f\n",value); 00087 mNote = value; 00088 Dispatch(); 00089 00090 return 0; 00091 } 00092 00093 void Dispatch(void); 00094 00095 public: 00096 00097 Dispatcher(): 00098 mStateIn("",this,&Dispatcher::UpdateState), 00099 mNoteIn( "Note", this, &Dispatcher::UpdateNote ), 00100 mVelocityIn( "Velocity", this, &Dispatcher::UpdateVel ), 00101 mVelocity( 0 ), 00102 mNote( 0 ) 00103 { 00104 DispatcherConfig cfg; 00105 00106 Configure( cfg ); 00107 } 00108 00109 Dispatcher( const DispatcherConfig& c): 00110 mStateIn("",this,&Dispatcher::UpdateState), 00111 mNoteIn( "Note", this, &Dispatcher::UpdateNote ), 00112 mVelocityIn( "Velocity", this, &Dispatcher::UpdateVel ), 00113 mVelocity( 0 ), 00114 mNote( 0 ) 00115 { 00116 Configure( c ); 00117 } 00118 00119 ~Dispatcher(){} 00120 00121 const char * GetClassName() const {return "Dispatcher";} 00122 00123 const ProcessingConfig &GetConfig() const { return mConfig; } 00124 00125 bool ConcreteConfigure( const ProcessingConfig& c ); 00126 00127 bool Do(void) { return true; } 00128 00129 }; 00130 } 00131 00132 #endif 00133