CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Processing
Controls
Control2Data.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 "
Control2Data.hxx
"
23
24
namespace
CLAM {
25
26
void
Control2DataConfig::DefaultInit
(
void
)
27
{
28
AddNumControls();
29
UpdateData
();
30
SetNumControls(0);
31
}
32
33
Control2Data::Control2Data
(
const
Config
& c)
34
: mStop(
"stop"
,this)
35
{
36
Configure
(c);
37
}
38
39
bool
Control2Data::ConcreteConfigure
(
const
ProcessingConfig
& c)
40
{
41
CopyAsConcreteConfig
(
mConfig
, c);
42
int
nControls=
mConfig
.GetNumControls();
43
44
// Initializing InControlArray
45
mInArray
.
Resize
(nControls,
"array_control"
,
this
, &
Control2Data::EnqueueControl
);
46
47
// Buffer Queues initialization
48
BufferQueueInit
( nControls );
49
//Initialize mStop to false
50
mStop
.
DoControl
(0);
51
52
return
true
;
53
54
}
55
56
bool
Control2Data::Do
()
57
{
58
IdxList::iterator ListIt;
59
Mutex::ScopedLock
lock(
mControl2DataDoMutex
);
60
61
IdxList
qs =
GetQueues
();
62
if
(!qs.empty())
63
{
64
for
(ListIt=qs.begin();ListIt!=qs.end() ;ListIt++ )
65
{
66
TControlData
val =
PopControl
( (*ListIt) );
67
GenerateOutputData
((*ListIt),val);
68
}
69
}
70
return
!
mStop
.
GetLastValue
();
71
}
72
73
void
Control2Data::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
86
const
ProcessingConfig
&
Control2Data::GetConfig
()
const
87
{
88
return
mConfig
;
89
}
90
91
92
void
Control2Data::EnqueueControl
(
unsigned
id
,
TControlData
data)
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
104
Control2Data::IdxList
Control2Data::GetQueues
()
105
{
106
IdxList
modifiedQs;
107
std::vector<TQueue>::iterator it;
108
109
int
k = 0;
110
for
(it=
mDataQueues
.begin(); it !=
mDataQueues
.end() ; it++ )
111
{
112
if
(!(*it).empty())
113
{
114
modifiedQs.push_back(k);
115
}
116
k++;
117
}
118
return
modifiedQs;
119
}
120
121
bool
Control2Data::Empty
(
unsigned
id
)
122
{
123
Mutex::ScopedLock
lock(
mDataMutex
);
124
125
#ifdef HAVE_STANDARD_VECTOR_AT
126
return
mDataQueues
.at(
id
).empty();
127
#else
128
return
mDataQueues
[id].empty();
129
#endif
130
131
}
132
133
TControlData
Control2Data::PopControl
(
unsigned
id
)
134
{
135
Mutex::ScopedLock
lock(
mDataMutex
);
136
#ifdef HAVE_STANDARD_VECTOR_AT
137
TControlData
ret=
mDataQueues
.at(
id
).front();
138
#else
139
TControlData
ret=
mDataQueues
[id].front();
140
#endif
141
mDataQueues
[id].pop();
142
return
ret;
143
}
144
145
void
Control2Data::ControlCallbackId
(
int
id
,
TControlData
val)
146
{
147
EnqueueControl
(
id
,val);
148
}
149
150
};
//namespace CLAM
151
Generated by
1.8.1