MCPcopy Create free account
hub / github.com/MTG/essentia / push

Method push

src/python/pystreamingalgorithm.cpp:177–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175
176
177PyObject* PyStreamingAlgorithm::push(PyStreamingAlgorithm* self, PyObject* args) {
178 vector<PyObject*> argsV = unpack(args);
179 if (argsV.size() != 2) {
180 PyErr_SetString(PyExc_ValueError, "Algorithm.push requires 2 arguments");
181 return NULL;
182 }
183
184 if (!PyString_Check(argsV[0])) {
185 PyErr_SetString(PyExc_ValueError, "Algorithm.push requires a string as the first argument");
186 return NULL;
187 }
188
189 // name of the source to push onto
190 string name = PyString_AS_STRING(argsV[0]);
191
192 // check if source exists
193 if (!contains(self->algo->outputs(), name)) {
194 ostringstream msg;
195 msg << self->algo->name() << " does not have an input named " << name;
196 PyErr_SetString(PyExc_ValueError, msg.str().c_str());
197 return NULL;
198 }
199
200 SourceBase& src = self->algo->output(name);
201
202 // edt of given data
203 Edt tp = typeInfoToEdt(src.typeInfo());
204
205 #define PUSH_COPY(tname, type) { \
206 type* val = (type*)tname::fromPythonCopy(argsV[1]); \
207 src.push(*val); \
208 delete val; \
209 break; \
210 }
211
212 switch(tp) {
213 case INTEGER: PUSH_COPY(Integer, int);
214 case REAL: PUSH_COPY(PyReal, Real);
215 case STRING: PUSH_COPY(String, string);
216 case STEREOSAMPLE: PUSH_COPY(PyStereoSample, StereoSample);
217 case VECTOR_STRING: PUSH_COPY(VectorString, vector<string>);
218 case VECTOR_STEREOSAMPLE: PUSH_COPY(VectorStereoSample, vector<StereoSample>);
219
220 case VECTOR_REAL: {
221 RogueVector<Real>* val = (RogueVector<Real>*)VectorReal::fromPythonRef(argsV[1]);
222 src.push(*(vector<Real>*)val);
223 delete val;
224 break;
225 }
226
227 default:
228 ostringstream msg;
229 msg << "given value type not supported: " << edtToString(tp);
230 PyErr_SetString(PyExc_ValueError, msg.str().c_str()); return NULL;
231 }
232
233 #undef PUSH_COPY
234

Callers 15

TESTFunction · 0.45
testLeftMethod · 0.45
testRightMethod · 0.45
testMixMethod · 0.45
testSingleMethod · 0.45
finalProduceMethod · 0.45
finalProduceMethod · 0.45
processMethod · 0.45
processMethod · 0.45
processMethod · 0.45
finalProduceMethod · 0.45

Calls 7

unpackFunction · 0.85
containsFunction · 0.85
typeInfoToEdtFunction · 0.85
edtToStringFunction · 0.85
strMethod · 0.80
sizeMethod · 0.45
nameMethod · 0.45

Tested by 6

TESTFunction · 0.36
testLeftMethod · 0.36
testRightMethod · 0.36
testMixMethod · 0.36
testSingleMethod · 0.36