CLAM-Development  1.4.0
Dispatcher.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 #include "Dispatcher.hxx"
23 
24 using namespace CLAM;
25 
27 {
28  CopyAsConcreteConfig(mConfig, c);
29  int i,j,k;
30 
31  mInstruments = mConfig.GetInstruments();
32  mNInValues = mConfig.GetNInValues();
33  mMInstruments = mInstruments.Size();
34 
35  for( i = 0; i < mMInstruments; i++ )
36  {
37  mInstruments[ i ]->SetId(i);
38  mInstruments[ i ]->LinkStateOutWithInControl( this, 0 ) ;
39 
40  InstrStatus status = {-1,-1,i};
41  mInstrStatusList.push_back(status);
42  }
43 
44  k = 0;
45 
46  for ( i = 0; i < mMInstruments; i++ )
47  {
48  for ( j = 0; j < mNInValues;j++)
49  {
50  mValuesOut.AddElem( new FloatOutControl("",this ) );
51  GetOutControl(k).AddLink(mInstruments[i]->GetInControl(j+1));
52  //LinkOutWithInControl( k , mInstruments[ i ], j+1);
53  k++;
54  }
55  }
56 
57  return true;
58 }
59 
60 void Dispatcher::UpdateState( TControlData availableInstr )
61 {
62  std::list<InstrStatus>::iterator it;
63  for (it=mInstrStatusList.begin();it!=mInstrStatusList.end();it++)
64  {
65  if ((*it).mId == availableInstr)
66  {
67  mInstrStatusList.erase(it);
68  InstrStatus status = { -1,-1, int(availableInstr) };
69  mInstrStatusList.push_front(status);
70  return;
71  }
72  }
73 }
74 
76 {
77  if( mVelocity == 0.0 )
78  {
79  std::list<InstrStatus>::iterator it;
80 
81  for (it=mInstrStatusList.begin();it!=mInstrStatusList.end();it++)
82  {
83  if ( ( (*it).mNote == mNote ) && ( (*it).mVelocity ) )
84  {
85  InstrStatus status = (*it);
86  (*it).mVelocity = 0;
87  mValuesOut[ (*it).mId * mNInValues + 1]->SendControl( mVelocity );
88  return;
89  }
90  }
91  }
92  else
93  {
94  InstrStatus status = mInstrStatusList.front();
95  mInstrStatusList.pop_front();
96  status.mNote = int(mNote);
97  status.mVelocity = int(mVelocity);
98  mInstrStatusList.push_back(status);
99 
100  mValuesOut[ status.mId * mNInValues + 1 ]->SendControl( mVelocity );
101  mValuesOut[ status.mId * mNInValues ]->SendControl( mNote );
102  }
103 }
104 
105