CLAM-Development  1.4.0
Controller.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-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 "Controller.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 
26 namespace CLAM
27 {
28 
29 namespace Hidden
30 {
31  static const char * metadata[] = {
32  "key", "Controller",
33  "category", "Controls",
34  "description", "Controller",
35  0
36  };
37  static FactoryRegistrator<ProcessingFactory, Controller> reg = metadata;
38 }
39 
41 {
42 
43 }
44 
45 
47 {
48  CopyAsConcreteConfig(mConfig, c);
49  int n = mConfig.GetNumControls();
50 
52  n == OutControls.Size(),
53  "Controller::ConcreteConfigure(): Size can not change.");
54 
55  if (!OutControls.Size())
56  OutControls.Resize(n,"Output",this);
57 
58  OutValues.resize(n);
59 
60  for (int k = 0; k < n ; k++ )
61  {
62  OutValues[k]=0.0;
63  }
64 
65  // Buffer Queues initialization
66 
67  BufferQueueInit( n );
68 
69  return true;
70 
71 }
72 
73 void Controller::BufferQueueInit( int ncontrols )
74 {
75  Mutex::ScopedLock lock( mDataMutex );
76 
77  mDataQueues.resize(0);
78  mDataQueues.reserve(ncontrols);
79  for (int j = 0; j < ncontrols ;j ++ )
80  {
81  mDataQueues.push_back( TQueue() );
82  }
83 
84 }
85 
87 {
88  return mConfig;
89 }
90 
91 
93 {
94  Mutex::ScopedLock lock( mDataMutex );
95 
96 #ifdef HAVE_STANDARD_VECTOR_AT
97  mDataQueues.at(id).push(data);
98 #else
99  mDataQueues[id].push(data);
100 #endif
101 
102 }
103 
105 {
106  TControlData val;
107 
108  Mutex::ScopedLock lock( mDataMutex );
109 
110 #ifdef HAVE_STANDARD_VECTOR_AT
111  val = OutValues.at(id);
112 #else
113  val = OutValues[id];
114 #endif
115 
116  return val;
117 }
118 
119 bool Controller::Empty(unsigned id)
120 {
121  Mutex::ScopedLock lock( mDataMutex );
122 
123 #ifdef HAVE_STANDARD_VECTOR_AT
124  return mDataQueues.at(id).empty();
125 #else
126  return mDataQueues[id].empty();
127 #endif
128 
129 }
130 
131 TControlData Controller::PopControl(unsigned id)
132 {
133  Mutex::ScopedLock lock( mDataMutex );
134 #ifdef HAVE_STANDARD_VECTOR_AT
135  TControlData ret=mDataQueues.at(id).front();
136 #else
137  TControlData ret=mDataQueues[id].front();
138 #endif
139  mDataQueues[id].pop();
140  return ret;
141 }
142 
143 
144 
145 }; //namespace CLAM
146