Showing the changes to python/lib/gen_code.py (1 of 230 files). Show all
Unified · Split
| @@ -2,6 +2,7 @@ aubiodefvalue = { · 1 unmodified line | ||
| 2 | 2 | # we have some clean up to do |
| 3 | 3 | 'buf_size': 'Py_default_vector_length', |
| 4 | 4 | 'win_s': 'Py_default_vector_length', |
| 5 | + 'size': 'Py_default_vector_length', | |
| 5 | 6 | # and here too |
| 6 | 7 | 'hop_size': 'Py_default_vector_length / 2', |
| 7 | 8 | 'hop_s': 'Py_default_vector_length / 2', |
| @@ -84,6 +85,7 @@ objoutsize = { · 76 unmodified lines | ||
| 84 | 85 | 'filterbank': 'self->n_filters', |
| 85 | 86 | 'tss': 'self->buf_size', |
| 86 | 87 | 'pitchshift': 'self->hop_size', |
| 88 | + 'dct': 'self->size', | |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | 91 | objinputsize = { |
| @@ -179,6 +181,10 @@ class MappedObject(object): · 89 unmodified lines | ||
| 179 | 181 | self.do_inputs = [get_params_types_names(self.do_proto)[1]] |
| 180 | 182 | self.do_outputs = get_params_types_names(self.do_proto)[2:] |
| 181 | 183 | struct_output_str = ["PyObject *{0[name]}; {1} c_{0[name]}".format(i, i['type'][:-1]) for i in self.do_outputs] |
| 184 | + if len(self.prototypes['rdo']): | |
| 185 | + rdo_outputs = get_params_types_names(prototypes['rdo'][0])[2:] | |
| 186 | + struct_output_str += ["PyObject *{0[name]}; {1} c_{0[name]}".format(i, i['type'][:-1]) for i in rdo_outputs] | |
| 187 | + self.outputs += rdo_outputs | |
| 182 | 188 | self.struct_outputs = ";\n ".join(struct_output_str) |
| 183 | 189 | |
| 184 | 190 | #print ("input_params: ", map(split_type, get_input_params(self.do_proto))) |
| @@ -186,17 +192,26 @@ class MappedObject(object): · 1 unmodified line | ||
| 186 | 192 | |
| 187 | 193 | def gen_code(self): |
| 188 | 194 | out = "" |
| 189 | − out += self.gen_struct() | |
| 190 | − out += self.gen_doc() | |
| 191 | − out += self.gen_new() | |
| 192 | − out += self.gen_init() | |
| 193 | − out += self.gen_del() | |
| 194 | − out += self.gen_do() | |
| 195 | − out += self.gen_memberdef() | |
| 196 | − out += self.gen_set() | |
| 197 | − out += self.gen_get() | |
| 198 | − out += self.gen_methodef() | |
| 199 | − out += self.gen_typeobject() | |
| 195 | + try: | |
| 196 | + out += self.gen_struct() | |
| 197 | + out += self.gen_doc() | |
| 198 | + out += self.gen_new() | |
| 199 | + out += self.gen_init() | |
| 200 | + out += self.gen_del() | |
| 201 | + out += self.gen_do() | |
| 202 | + if len(self.prototypes['rdo']): | |
| 203 | + self.do_proto = self.prototypes['rdo'][0] | |
| 204 | + self.do_inputs = [get_params_types_names(self.do_proto)[1]] | |
| 205 | + self.do_outputs = get_params_types_names(self.do_proto)[2:] | |
| 206 | + out += self.gen_do(method='rdo') | |
| 207 | + out += self.gen_memberdef() | |
| 208 | + out += self.gen_set() | |
| 209 | + out += self.gen_get() | |
| 210 | + out += self.gen_methodef() | |
| 211 | + out += self.gen_typeobject() | |
| 212 | + except Exception as e: | |
| 213 | + print ("Failed generating code for", self.shortname) | |
| 214 | + raise | |
| 200 | 215 | return out |
| 201 | 216 | |
| 202 | 217 | def gen_struct(self): |
| @@ -380,12 +395,12 @@ Py_{shortname}_del (Py_{shortname} * self, PyObject * unused) · 177 unmodified lines | ||
| 380 | 395 | """.format(del_fn = del_fn) |
| 381 | 396 | return out |
| 382 | 397 | |
| 383 | − def gen_do(self): | |
| 398 | + def gen_do(self, method = 'do'): | |
| 384 | 399 | out = """ |
| 385 | 400 | // do {shortname} |
| 386 | 401 | static PyObject* |
| 387 | −Py_{shortname}_do (Py_{shortname} * self, PyObject * args) | |
| 388 | −{{""".format(**self.__dict__) | |
| 402 | +Pyaubio_{shortname}_{method} (Py_{shortname} * self, PyObject * args) | |
| 403 | +{{""".format(method = method, **self.__dict__) | |
| 389 | 404 | input_params = self.do_inputs |
| 390 | 405 | output_params = self.do_outputs |
| 391 | 406 | #print input_params |
| @@ -461,30 +476,51 @@ Py_{shortname}_do (Py_{shortname} * self, PyObject * args) · 69 unmodified lines | ||
| 461 | 476 | // {shortname} setters |
| 462 | 477 | """.format(**self.__dict__) |
| 463 | 478 | for set_param in self.prototypes['set']: |
| 464 | − params = get_params_types_names(set_param)[1] | |
| 465 | − paramtype = params['type'] | |
| 479 | + params = get_params_types_names(set_param)[1:] | |
| 480 | + param = self.shortname.split('_set_')[-1] | |
| 481 | + paramdecls = "".join([""" | |
| 482 | + {0} {1};""".format(p['type'], p['name']) for p in params]) | |
| 466 | 483 | method_name = get_name(set_param) |
| 467 | 484 | param = method_name.split('aubio_'+self.shortname+'_set_')[-1] |
| 468 | − pyparamtype = pyargparse_chars[paramtype] | |
| 485 | + refs = ", ".join(["&%s" % p['name'] for p in params]) | |
| 486 | + paramlist = ", ".join(["%s" % p['name'] for p in params]) | |
| 487 | + if len(params): | |
| 488 | + paramlist = "," + paramlist | |
| 489 | + pyparamtypes = ''.join([pyargparse_chars[p['type']] for p in params]) | |
| 469 | 490 | out += """ |
| 470 | 491 | static PyObject * |
| 471 | 492 | Pyaubio_{shortname}_set_{param} (Py_{shortname} *self, PyObject *args) |
| 472 | 493 | {{ |
| 473 | 494 | uint_t err = 0; |
| 474 | − {paramtype} {param}; | |
| 495 | + {paramdecls} | |
| 496 | +""".format(param = param, paramdecls = paramdecls, **self.__dict__) | |
| 497 | + | |
| 498 | + if len(refs) and len(pyparamtypes): | |
| 499 | + out += """ | |
| 475 | 500 | |
| 476 | − if (!PyArg_ParseTuple (args, "{pyparamtype}", &{param})) {{ | |
| 501 | + if (!PyArg_ParseTuple (args, "{pyparamtypes}", {refs})) {{ | |
| 477 | 502 | return NULL; |
| 478 | 503 | }} |
| 479 | − err = aubio_{shortname}_set_{param} (self->o, {param}); | |
| 504 | +""".format(pyparamtypes = pyparamtypes, refs = refs) | |
| 505 | + | |
| 506 | + out += """ | |
| 507 | + err = aubio_{shortname}_set_{param} (self->o {paramlist}); | |
| 480 | 508 | |
| 481 | 509 | if (err > 0) {{ |
| 482 | − PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}"); | |
| 510 | + if (PyErr_Occurred() == NULL) {{ | |
| 511 | + PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}"); | |
| 512 | + }} else {{ | |
| 513 | + // change the RuntimeError into ValueError | |
| 514 | + PyObject *type, *value, *traceback; | |
| 515 | + PyErr_Fetch(&type, &value, &traceback); | |
| 516 | + PyErr_Restore(PyExc_ValueError, value, traceback); | |
| 517 | + }} | |
| 483 | 518 | return NULL; |
| 484 | 519 | }} |
| 485 | 520 | Py_RETURN_NONE; |
| 486 | 521 | }} |
| 487 | −""".format(param = param, paramtype = paramtype, pyparamtype = pyparamtype, **self.__dict__) | |
| 522 | +""".format(param = param, refs = refs, paramdecls = paramdecls, | |
| 523 | + pyparamtypes = pyparamtypes, paramlist = paramlist, **self.__dict__) | |
| 488 | 524 | return out |
| 489 | 525 | |
| 490 | 526 | def gen_get(self): |
| @@ -525,6 +561,12 @@ static PyMethodDef Py_{shortname}_methods[] = {{""".format(**self.__dict__) · 34 unmodified lines | ||
| 525 | 561 | out += """ |
| 526 | 562 | {{"{shortname}", (PyCFunction) Py{name}, |
| 527 | 563 | METH_NOARGS, ""}},""".format(name = name, shortname = shortname) |
| 564 | + for m in self.prototypes['rdo']: | |
| 565 | + name = get_name(m) | |
| 566 | + shortname = name.replace('aubio_%s_' % self.shortname, '') | |
| 567 | + out += """ | |
| 568 | + {{"{shortname}", (PyCFunction) Py{name}, | |
| 569 | + METH_VARARGS, ""}},""".format(name = name, shortname = shortname) | |
| 528 | 570 | out += """ |
| 529 | 571 | {NULL} /* sentinel */ |
| 530 | 572 | }; |
| @@ -550,7 +592,7 @@ PyTypeObject Py_{shortname}Type = {{ · 19 unmodified lines | ||
| 550 | 592 | 0, |
| 551 | 593 | 0, |
| 552 | 594 | 0, |
| 553 | − (ternaryfunc)Py_{shortname}_do, | |
| 595 | + (ternaryfunc)Pyaubio_{shortname}_do, | |
| 554 | 596 | 0, |
| 555 | 597 | 0, |
| 556 | 598 | 0, |