Mercurial > hg > svcore
comparison plugin/FeatureExtractionPluginHostAdapter.cpp @ 60:3086ff194ea0
* More structural work on feature extraction plugin C <-> C++ adapter
* Allow use of LADSPA/DSSI plugins with control outputs as feature extraction
plugins (DSSI with MIDI output still to come)
* Reorder labels on spectrogram status box
* Minor tweaks in doc etc.
author | Chris Cannam |
---|---|
date | Mon, 27 Mar 2006 15:03:02 +0000 |
parents | 9705a1978ecc |
children |
comparison
equal
deleted
inserted
replaced
59:9705a1978ecc | 60:3086ff194ea0 |
---|---|
76 } | 76 } |
77 | 77 |
78 FeatureExtractionPluginHostAdapter::ParameterList | 78 FeatureExtractionPluginHostAdapter::ParameterList |
79 FeatureExtractionPluginHostAdapter::getParameterDescriptors() const | 79 FeatureExtractionPluginHostAdapter::getParameterDescriptors() const |
80 { | 80 { |
81 //!!! | 81 ParameterList list; |
82 return ParameterList(); | 82 for (unsigned int i = 0; i < m_descriptor->parameterCount; ++i) { |
83 const SVPParameterDescriptor *spd = m_descriptor->parameters[i]; | |
84 ParameterDescriptor pd; | |
85 pd.name = spd->name; | |
86 pd.description = spd->description; | |
87 pd.unit = spd->unit; | |
88 pd.minValue = spd->minValue; | |
89 pd.maxValue = spd->maxValue; | |
90 pd.defaultValue = spd->defaultValue; | |
91 pd.isQuantized = spd->isQuantized; | |
92 pd.quantizeStep = spd->quantizeStep; | |
93 list.push_back(pd); | |
94 } | |
95 return list; | |
83 } | 96 } |
84 | 97 |
85 float | 98 float |
86 FeatureExtractionPluginHostAdapter::getParameter(std::string param) const | 99 FeatureExtractionPluginHostAdapter::getParameter(std::string param) const |
87 { | 100 { |
88 //!!! | 101 if (!m_handle) return 0.0; |
102 | |
103 for (unsigned int i = 0; i < m_descriptor->parameterCount; ++i) { | |
104 if (param == m_descriptor->parameters[i]->name) { | |
105 return m_descriptor->getParameter(m_handle, i); | |
106 } | |
107 } | |
108 | |
89 return 0.0; | 109 return 0.0; |
90 } | 110 } |
91 | 111 |
92 void | 112 void |
93 FeatureExtractionPluginHostAdapter::setParameter(std::string param, | 113 FeatureExtractionPluginHostAdapter::setParameter(std::string param, |
94 float value) | 114 float value) |
95 { | 115 { |
96 //!!! | 116 if (!m_handle) return; |
117 | |
118 for (unsigned int i = 0; i < m_descriptor->parameterCount; ++i) { | |
119 if (param == m_descriptor->parameters[i]->name) { | |
120 m_descriptor->setParameter(m_handle, i, value); | |
121 return; | |
122 } | |
123 } | |
97 } | 124 } |
98 | 125 |
99 FeatureExtractionPluginHostAdapter::ProgramList | 126 FeatureExtractionPluginHostAdapter::ProgramList |
100 FeatureExtractionPluginHostAdapter::getPrograms() const | 127 FeatureExtractionPluginHostAdapter::getPrograms() const |
101 { | 128 { |
102 //!!! | 129 ProgramList list; |
103 return ProgramList(); | 130 |
131 for (unsigned int i = 0; i < m_descriptor->programCount; ++i) { | |
132 list.push_back(m_descriptor->programs[i]); | |
133 } | |
134 | |
135 return list; | |
104 } | 136 } |
105 | 137 |
106 std::string | 138 std::string |
107 FeatureExtractionPluginHostAdapter::getCurrentProgram() const | 139 FeatureExtractionPluginHostAdapter::getCurrentProgram() const |
108 { | 140 { |
109 //!!! | 141 if (!m_handle) return ""; |
110 return ""; | 142 |
143 int pn = m_descriptor->getCurrentProgram(m_handle); | |
144 return m_descriptor->programs[pn]; | |
111 } | 145 } |
112 | 146 |
113 void | 147 void |
114 FeatureExtractionPluginHostAdapter::selectProgram(std::string program) | 148 FeatureExtractionPluginHostAdapter::selectProgram(std::string program) |
115 { | 149 { |
116 //!!! | 150 if (!m_handle) return; |
151 | |
152 for (unsigned int i = 0; i < m_descriptor->programCount; ++i) { | |
153 if (program == m_descriptor->programs[i]) { | |
154 m_descriptor->selectProgram(m_handle, i); | |
155 return; | |
156 } | |
157 } | |
117 } | 158 } |
118 | 159 |
119 size_t | 160 size_t |
120 FeatureExtractionPluginHostAdapter::getPreferredStepSize() const | 161 FeatureExtractionPluginHostAdapter::getPreferredStepSize() const |
121 { | 162 { |
131 } | 172 } |
132 | 173 |
133 FeatureExtractionPluginHostAdapter::OutputList | 174 FeatureExtractionPluginHostAdapter::OutputList |
134 FeatureExtractionPluginHostAdapter::getOutputDescriptors() const | 175 FeatureExtractionPluginHostAdapter::getOutputDescriptors() const |
135 { | 176 { |
136 //!!! | 177 OutputList list; |
137 return OutputList(); | 178 if (!m_handle) return list; |
179 | |
180 unsigned int count = m_descriptor->getOutputCount(m_handle); | |
181 | |
182 for (unsigned int i = 0; i < count; ++i) { | |
183 SVPOutputDescriptor *sd = m_descriptor->getOutputDescriptor(m_handle, i); | |
184 OutputDescriptor d; | |
185 d.name = sd->name; | |
186 d.description = sd->description; | |
187 d.unit = sd->unit; | |
188 d.hasFixedValueCount = sd->hasFixedValueCount; | |
189 d.valueCount = sd->valueCount; | |
190 for (unsigned int j = 0; j < sd->valueCount; ++j) { | |
191 d.valueNames.push_back(sd->valueNames[i]); | |
192 } | |
193 d.hasKnownExtents = sd->hasKnownExtents; | |
194 d.minValue = sd->minValue; | |
195 d.maxValue = sd->maxValue; | |
196 d.isQuantized = sd->isQuantized; | |
197 d.quantizeStep = sd->quantizeStep; | |
198 | |
199 switch (sd->sampleType) { | |
200 case svpOneSamplePerStep: | |
201 d.sampleType = OutputDescriptor::OneSamplePerStep; break; | |
202 case svpFixedSampleRate: | |
203 d.sampleType = OutputDescriptor::FixedSampleRate; break; | |
204 case svpVariableSampleRate: | |
205 d.sampleType = OutputDescriptor::VariableSampleRate; break; | |
206 } | |
207 | |
208 d.sampleRate = sd->sampleRate; | |
209 | |
210 list.push_back(d); | |
211 | |
212 m_descriptor->releaseOutputDescriptor(sd); | |
213 } | |
214 | |
215 return list; | |
138 } | 216 } |
139 | 217 |
140 FeatureExtractionPluginHostAdapter::FeatureSet | 218 FeatureExtractionPluginHostAdapter::FeatureSet |
141 FeatureExtractionPluginHostAdapter::process(float **inputBuffers, | 219 FeatureExtractionPluginHostAdapter::process(float **inputBuffers, |
142 RealTime timestamp) | 220 RealTime timestamp) |
143 { | 221 { |
144 //!!! | 222 FeatureSet fs; |
145 return FeatureSet(); | 223 if (!m_handle) return fs; |
224 | |
225 int sec = timestamp.sec; | |
226 int nsec = timestamp.nsec; | |
227 | |
228 SVPFeatureList **features = m_descriptor->process(m_handle, | |
229 inputBuffers, | |
230 sec, nsec); | |
231 | |
232 convertFeatures(features, fs); | |
233 m_descriptor->releaseFeatureSet(features); | |
234 return fs; | |
146 } | 235 } |
147 | 236 |
148 FeatureExtractionPluginHostAdapter::FeatureSet | 237 FeatureExtractionPluginHostAdapter::FeatureSet |
149 FeatureExtractionPluginHostAdapter::getRemainingFeatures() | 238 FeatureExtractionPluginHostAdapter::getRemainingFeatures() |
150 { | 239 { |
151 //!!! | 240 FeatureSet fs; |
152 return FeatureSet(); | 241 if (!m_handle) return fs; |
153 } | 242 |
154 | 243 SVPFeatureList **features = m_descriptor->getRemainingFeatures(m_handle); |
244 | |
245 convertFeatures(features, fs); | |
246 m_descriptor->releaseFeatureSet(features); | |
247 return fs; | |
248 } | |
249 | |
250 void | |
251 FeatureExtractionPluginHostAdapter::convertFeatures(SVPFeatureList **features, | |
252 FeatureSet &fs) | |
253 { | |
254 for (unsigned int i = 0; features[i]; ++i) { | |
255 | |
256 SVPFeatureList &list = *features[i]; | |
257 | |
258 if (list.featureCount > 0) { | |
259 | |
260 for (unsigned int j = 0; j < list.featureCount; ++j) { | |
261 | |
262 Feature feature; | |
263 feature.hasTimestamp = list.features[j].hasTimestamp; | |
264 feature.timestamp = RealTime(list.features[j].sec, | |
265 list.features[j].nsec); | |
266 | |
267 for (unsigned int k = 0; k < list.features[j].valueCount; ++k) { | |
268 feature.values.push_back(list.features[j].values[k]); | |
269 } | |
270 | |
271 feature.label = list.features[j].label; | |
272 | |
273 fs[i].push_back(feature); | |
274 } | |
275 } | |
276 } | |
277 } | |
278 |