Dispatcher.cxx

Go to the documentation of this file.
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 FloatOutControl("",this ) );
00051                         GetOutControl(k).AddLink(mInstruments[i]->GetInControl(j+1));
00052                         //LinkOutWithInControl( k , mInstruments[ i ], j+1);
00053                         k++;
00054                 }
00055         }
00056 
00057         return true;
00058 }
00059 
00060 void 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;
00071                 }
00072         }
00073 }
00074 
00075 void Dispatcher::Dispatch()
00076 {
00077         if( mVelocity == 0.0 ) 
00078         {
00079                 std::list<InstrStatus>::iterator it;
00080 
00081                 for (it=mInstrStatusList.begin();it!=mInstrStatusList.end();it++)
00082                 {
00083                         if ( ( (*it).mNote == mNote ) && ( (*it).mVelocity ) )
00084                         {
00085                                 InstrStatus status = (*it);
00086                                 (*it).mVelocity = 0;
00087                                 mValuesOut[ (*it).mId * mNInValues + 1]->SendControl( mVelocity );
00088                                 return;
00089                         }
00090                 }
00091         }
00092         else
00093         {
00094                 InstrStatus status = mInstrStatusList.front();
00095                 mInstrStatusList.pop_front();
00096                 status.mNote = int(mNote);
00097                 status.mVelocity = int(mVelocity);
00098                 mInstrStatusList.push_back(status);
00099 
00100                 mValuesOut[ status.mId * mNInValues + 1 ]->SendControl( mVelocity );
00101                 mValuesOut[ status.mId * mNInValues ]->SendControl( mNote );
00102         }
00103 }
00104 
00105 
Generated by  doxygen 1.6.3