|
CLAM-Development
1.3
|
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 #include "ProcessingFactory.hxx" 00023 #include "MIDIDispatcher.hxx" 00024 00025 00026 namespace CLAM 00027 { 00028 00029 namespace Hidden 00030 { 00031 static const char * metadata[] = { 00032 "key", "MIDIDispatcher", 00033 "category", "MIDI", 00034 "description", "MIDIDispatcher", 00035 0 00036 }; 00037 static FactoryRegistrator<ProcessingFactory, MIDIDispatcher> reg = metadata; 00038 } 00039 00040 void MIDIDispatcherConfig::DefaultInit() 00041 { 00042 AddNumberOfVoices(); 00043 AddNumberOfInControls(); 00044 UpdateData(); 00045 SetNumberOfVoices( 2 ); 00046 SetNumberOfInControls( 2 ); 00047 } 00048 00049 00050 MIDIDispatcher::MIDIDispatcher( const MIDIDispatcherConfig& cfg ) 00051 : mStateIn("StateIn",this,&MIDIDispatcher::UpdateState) 00052 , mNoteIn( "Note", this, &MIDIDispatcher::UpdateNote ) 00053 , mVelocityIn( "Velocity", this, &MIDIDispatcher::UpdateVel ) 00054 , mVelocity( 0 ) 00055 , mNote( 0 ) 00056 { 00057 Configure( cfg ); 00058 } 00059 00060 bool MIDIDispatcher::ConcreteConfigure( const ProcessingConfig& cfg ) 00061 { 00062 00063 CopyAsConcreteConfig(mConfig, cfg); 00064 RemoveControls(); 00065 CreateControls(); 00066 00067 return true; 00068 } 00069 00070 00071 void MIDIDispatcher::UpdateState( TControlData availableInstr ) 00072 { 00073 std::list<VoiceStatus>::iterator it; 00074 00075 for (it=mVoiceStatusList.begin();it!=mVoiceStatusList.end();it++) 00076 { 00077 if ((*it).mId == availableInstr) 00078 { 00079 mVoiceStatusList.erase(it); 00080 VoiceStatus status = { -1,-1, int(availableInstr) }; 00081 mVoiceStatusList.push_front(status); 00082 return; 00083 } 00084 } 00085 } 00086 00087 00088 void MIDIDispatcher::Dispatch(void) 00089 { 00090 if( mVelocity == 0.0 ) 00091 { 00092 std::list<VoiceStatus>::iterator it; 00093 00094 for (it=mVoiceStatusList.begin();it!=mVoiceStatusList.end();it++) 00095 { 00096 if ( it->mNote != mNote ) continue; 00097 if ( !it->mVelocity ) continue; 00098 it->mVelocity = 0; 00099 mOutputControls[ it->mId * + 1]->SendControl( mVelocity ); 00100 return; 00101 } 00102 } 00103 else 00104 { 00105 VoiceStatus status = mVoiceStatusList.front(); 00106 mVoiceStatusList.pop_front(); 00107 status.mNote = int(mNote); 00108 status.mVelocity = int(mVelocity); 00109 mVoiceStatusList.push_back(status); 00110 00111 mOutputControls[ status.mId * mConfig.GetNumberOfInControls() + 1 ]->SendControl( mVelocity ); 00112 mOutputControls[ status.mId * mConfig.GetNumberOfInControls() ]->SendControl( mNote ); 00113 } 00114 } 00115 00116 void MIDIDispatcher::CreateControls() 00117 { 00118 00119 for (int i=0;i<mConfig.GetNumberOfInControls(); i++) 00120 { 00121 std::stringstream number; 00122 number << i; 00123 FloatInControl* inControl = new FloatInControl( "InControl " + number.str(), this ); 00124 mInputControls.push_back( inControl ); 00125 } 00126 00127 for( int i=0; i<mConfig.GetNumberOfInControls(); i++ ) 00128 mInputControls[i]->DoControl(0.); // set initial value for each InControl 00129 00130 for(int i = 0; i < mConfig.GetNumberOfVoices(); i++ ) 00131 { 00132 // mInstruments[ i ]->SetId(i); 00133 // mInstruments[ i ]->LinkStateOutWithInControl( this, 0 ) ; 00134 // 00135 VoiceStatus status = { -1, -1, i }; 00136 mVoiceStatusList.push_back(status); 00137 } 00138 00139 int k = 0; 00140 for (int i = 0; i < mConfig.GetNumberOfVoices(); i++ ) 00141 { 00142 for ( int j=0; j < mConfig.GetNumberOfInControls();j++) 00143 { 00144 std::stringstream number(""); 00145 number << i << j; 00146 mOutputControls.push_back( new FloatOutControl("a" + number.str(),this ) ); 00147 // GetOutControl(k).AddLink( mInstruments[i]->GetImConfig.GetInControl(j+1)); 00148 // LinkOutWithInControl( k , mInstruments[ i ], j+1); 00149 k++; 00150 } 00151 } 00152 } 00153 00154 void MIDIDispatcher::RemoveControls() 00155 { 00156 std::vector< FloatInControl* >::iterator itInControl; 00157 00158 for( itInControl=mInputControls.begin(); itInControl!=mInputControls.end(); itInControl++) 00159 delete *itInControl; 00160 00161 mInputControls.clear(); 00162 } 00163 00164 00165 } // namespace CLAM 00166
1.7.6.1