CLAM-Development
1.1
|
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 "Dispatcher.hxx" 00023 00024 using namespace CLAM; 00025 00026 bool Dispatcher::ConcreteConfigure( const ProcessingConfig& c ) 00027 { 00028 CopyAsConcreteConfig(mConfig, c); 00029 int i,j,k; 00030 00031 mInstruments = mConfig.GetInstruments(); 00032 mNInValues = mConfig.GetNInValues(); 00033 mMInstruments = mInstruments.Size(); 00034 00035 for( i = 0; i < mMInstruments; i++ ) 00036 { 00037 mInstruments[ i ]->SetId(i); 00038 mInstruments[ i ]->LinkStateOutWithInControl( this, 0 ) ; 00039 00040 InstrStatus status = {-1,-1,i}; 00041 mInstrStatusList.push_back(status); 00042 } 00043 00044 k = 0; 00045 00046 for ( i = 0; i < mMInstruments; i++ ) 00047 { 00048 for ( j = 0; j < mNInValues;j++) 00049 { 00050 mValuesOut.AddElem( new OutControl("",this ) ); 00051 GetOutControls().GetByNumber(k).AddLink(mInstruments[i]->GetInControls().GetByNumber(j+1)); 00052 //LinkOutWithInControl( k , mInstruments[ i ], j+1); 00053 k++; 00054 } 00055 } 00056 00057 return true; 00058 } 00059 00060 int Dispatcher::UpdateState( TControlData availableInstr ) 00061 { 00062 std::list<InstrStatus>::iterator it; 00063 for (it=mInstrStatusList.begin();it!=mInstrStatusList.end();it++) 00064 { 00065 if ((*it).mId == availableInstr) 00066 { 00067 mInstrStatusList.erase(it); 00068 InstrStatus status = { -1,-1, int(availableInstr) }; 00069 mInstrStatusList.push_front(status); 00070 return 0; 00071 } 00072 } 00073 return 0; 00074 } 00075 00076 void Dispatcher::Dispatch(void) 00077 { 00078 if( mVelocity == 0.0 ) 00079 { 00080 std::list<InstrStatus>::iterator it; 00081 00082 for (it=mInstrStatusList.begin();it!=mInstrStatusList.end();it++) 00083 { 00084 if ( ( (*it).mNote == mNote ) && ( (*it).mVelocity ) ) 00085 { 00086 InstrStatus status = (*it); 00087 (*it).mVelocity = 0; 00088 mValuesOut[ (*it).mId * mNInValues + 1]->SendControl( mVelocity ); 00089 return; 00090 } 00091 } 00092 } 00093 else 00094 { 00095 InstrStatus status = mInstrStatusList.front(); 00096 mInstrStatusList.pop_front(); 00097 status.mNote = int(mNote); 00098 status.mVelocity = int(mVelocity); 00099 mInstrStatusList.push_back(status); 00100 00101 mValuesOut[ status.mId * mNInValues + 1 ]->SendControl( mVelocity ); 00102 mValuesOut[ status.mId * mNInValues ]->SendControl( mNote ); 00103 } 00104 } 00105 00106