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 | # we have some clean up to do | 2 | # we have some clean up to do |
| 3 | 'buf_size': 'Py_default_vector_length', | 3 | 'buf_size': 'Py_default_vector_length', |
| 4 | 'win_s': 'Py_default_vector_length', | 4 | 'win_s': 'Py_default_vector_length', |
| 5 | 'size': 'Py_default_vector_length', | ||
| 5 | # and here too | 6 | # and here too |
| 6 | 'hop_size': 'Py_default_vector_length / 2', | 7 | 'hop_size': 'Py_default_vector_length / 2', |
| 7 | 'hop_s': 'Py_default_vector_length / 2', | 8 | 'hop_s': 'Py_default_vector_length / 2', |
| @@ -84,6 +85,7 @@ objoutsize = { · 76 unmodified lines | |||
| 84 | 'filterbank': 'self->n_filters', | 85 | 'filterbank': 'self->n_filters', |
| 85 | 'tss': 'self->buf_size', | 86 | 'tss': 'self->buf_size', |
| 86 | 'pitchshift': 'self->hop_size', | 87 | 'pitchshift': 'self->hop_size', |
| 88 | 'dct': 'self->size', | ||
| 87 | } | 89 | } |
| 88 | 90 | ||
| 89 | objinputsize = { | 91 | objinputsize = { |
| @@ -179,6 +181,10 @@ class MappedObject(object): · 89 unmodified lines | |||
| 179 | self.do_inputs = [get_params_types_names(self.do_proto)[1]] | 181 | self.do_inputs = [get_params_types_names(self.do_proto)[1]] |
| 180 | self.do_outputs = get_params_types_names(self.do_proto)[2:] | 182 | self.do_outputs = get_params_types_names(self.do_proto)[2:] |
| 181 | struct_output_str = ["PyObject *{0[name]}; {1} c_{0[name]}".format(i, i['type'][:-1]) for i in self.do_outputs] | 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 | self.struct_outputs = ";\n ".join(struct_output_str) | 188 | self.struct_outputs = ";\n ".join(struct_output_str) |
| 183 | 189 | ||
| 184 | #print ("input_params: ", map(split_type, get_input_params(self.do_proto))) | 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 | def gen_code(self): | 193 | def gen_code(self): |
| 188 | out = "" | 194 | out = "" |
| 189 | out += self.gen_struct() | 195 | try: |
| 190 | out += self.gen_doc() | 196 | out += self.gen_struct() |
| 191 | out += self.gen_new() | 197 | out += self.gen_doc() |
| 192 | out += self.gen_init() | 198 | out += self.gen_new() |
| 193 | out += self.gen_del() | 199 | out += self.gen_init() |
| 194 | out += self.gen_do() | 200 | out += self.gen_del() |
| 195 | out += self.gen_memberdef() | 201 | out += self.gen_do() |
| 196 | out += self.gen_set() | 202 | if len(self.prototypes['rdo']): |
| 197 | out += self.gen_get() | 203 | self.do_proto = self.prototypes['rdo'][0] |
| 198 | out += self.gen_methodef() | 204 | self.do_inputs = [get_params_types_names(self.do_proto)[1]] |
| 199 | out += self.gen_typeobject() | 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 | return out | 215 | return out |
| 201 | 216 | ||
| 202 | def gen_struct(self): | 217 | def gen_struct(self): |
| @@ -380,12 +395,12 @@ Py_{shortname}_del (Py_{shortname} * self, PyObject * unused) · 177 unmodified lines | |||
| 380 | """.format(del_fn = del_fn) | 395 | """.format(del_fn = del_fn) |
| 381 | return out | 396 | return out |
| 382 | 397 | ||
| 383 | def gen_do(self): | 398 | def gen_do(self, method = 'do'): |
| 384 | out = """ | 399 | out = """ |
| 385 | // do {shortname} | 400 | // do {shortname} |
| 386 | static PyObject* | 401 | static PyObject* |
| 387 | Py_{shortname}_do (Py_{shortname} * self, PyObject * args) | 402 | Pyaubio_{shortname}_{method} (Py_{shortname} * self, PyObject * args) |
| 388 | {{""".format(**self.__dict__) | 403 | {{""".format(method = method, **self.__dict__) |
| 389 | input_params = self.do_inputs | 404 | input_params = self.do_inputs |
| 390 | output_params = self.do_outputs | 405 | output_params = self.do_outputs |
| 391 | #print input_params | 406 | #print input_params |
| @@ -461,30 +476,51 @@ Py_{shortname}_do (Py_{shortname} * self, PyObject * args) · 69 unmodified lines | |||
| 461 | // {shortname} setters | 476 | // {shortname} setters |
| 462 | """.format(**self.__dict__) | 477 | """.format(**self.__dict__) |
| 463 | for set_param in self.prototypes['set']: | 478 | for set_param in self.prototypes['set']: |
| 464 | params = get_params_types_names(set_param)[1] | 479 | params = get_params_types_names(set_param)[1:] |
| 465 | paramtype = params['type'] | 480 | param = self.shortname.split('_set_')[-1] |
| 481 | paramdecls = "".join([""" | ||
| 482 | {0} {1};""".format(p['type'], p['name']) for p in params]) | ||
| 466 | method_name = get_name(set_param) | 483 | method_name = get_name(set_param) |
| 467 | param = method_name.split('aubio_'+self.shortname+'_set_')[-1] | 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 | out += """ | 490 | out += """ |
| 470 | static PyObject * | 491 | static PyObject * |
| 471 | Pyaubio_{shortname}_set_{param} (Py_{shortname} *self, PyObject *args) | 492 | Pyaubio_{shortname}_set_{param} (Py_{shortname} *self, PyObject *args) |
| 472 | {{ | 493 | {{ |
| 473 | uint_t err = 0; | 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 | return NULL; | 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 | if (err > 0) {{ | 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 | return NULL; | 518 | return NULL; |
| 484 | }} | 519 | }} |
| 485 | Py_RETURN_NONE; | 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 | return out | 524 | return out |
| 489 | 525 | ||
| 490 | def gen_get(self): | 526 | def gen_get(self): |
| @@ -525,6 +561,12 @@ static PyMethodDef Py_{shortname}_methods[] = {{""".format(**self.__dict__) · 34 unmodified lines | |||
| 525 | out += """ | 561 | out += """ |
| 526 | {{"{shortname}", (PyCFunction) Py{name}, | 562 | {{"{shortname}", (PyCFunction) Py{name}, |
| 527 | METH_NOARGS, ""}},""".format(name = name, shortname = shortname) | 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 | out += """ | 570 | out += """ |
| 529 | {NULL} /* sentinel */ | 571 | {NULL} /* sentinel */ |
| 530 | }; | 572 | }; |
| @@ -550,7 +592,7 @@ PyTypeObject Py_{shortname}Type = {{ · 19 unmodified lines | |||
| 550 | 0, | 592 | 0, |
| 551 | 0, | 593 | 0, |
| 552 | 0, | 594 | 0, |
| 553 | (ternaryfunc)Py_{shortname}_do, | 595 | (ternaryfunc)Pyaubio_{shortname}_do, |
| 554 | 0, | 596 | 0, |
| 555 | 0, | 597 | 0, |
| 556 | 0, | 598 | 0, |