History

Merge branch 'master' into feature/pitchshift

Paul Brossier committed 7 years ago

Commit 633400d2 parents 5b46bc3 f19db54230 files · +12450 −4607Browse files

Showing the changes to python/lib/gen_code.py (1 of 230 files). Show all

Unified · Split

python/lib/gen_code.py+65−23
@@ -2,6 +2,7 @@ aubiodefvalue = { · 1 unmodified line
22 # we have some clean up to do
33 'buf_size': 'Py_default_vector_length',
44 'win_s': 'Py_default_vector_length',
5+ 'size': 'Py_default_vector_length',
56 # and here too
67 'hop_size': 'Py_default_vector_length / 2',
78 'hop_s': 'Py_default_vector_length / 2',
@@ -84,6 +85,7 @@ objoutsize = { · 76 unmodified lines
8485 'filterbank': 'self->n_filters',
8586 'tss': 'self->buf_size',
8687 'pitchshift': 'self->hop_size',
88+ 'dct': 'self->size',
8789 }
8890
8991 objinputsize = {
@@ -179,6 +181,10 @@ class MappedObject(object): · 89 unmodified lines
179181 self.do_inputs = [get_params_types_names(self.do_proto)[1]]
180182 self.do_outputs = get_params_types_names(self.do_proto)[2:]
181183 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
182188 self.struct_outputs = ";\n ".join(struct_output_str)
183189
184190 #print ("input_params: ", map(split_type, get_input_params(self.do_proto)))
@@ -186,17 +192,26 @@ class MappedObject(object): · 1 unmodified line
186192
187193 def gen_code(self):
188194 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
200215 return out
201216
202217 def gen_struct(self):
@@ -380,12 +395,12 @@ Py_{shortname}_del (Py_{shortname} * self, PyObject * unused) · 177 unmodified lines
380395 """.format(del_fn = del_fn)
381396 return out
382397
383− def gen_do(self):
398+ def gen_do(self, method = 'do'):
384399 out = """
385400 // do {shortname}
386401 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__)
389404 input_params = self.do_inputs
390405 output_params = self.do_outputs
391406 #print input_params
@@ -461,30 +476,51 @@ Py_{shortname}_do (Py_{shortname} * self, PyObject * args) · 69 unmodified lines
461476 // {shortname} setters
462477 """.format(**self.__dict__)
463478 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])
466483 method_name = get_name(set_param)
467484 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])
469490 out += """
470491 static PyObject *
471492 Pyaubio_{shortname}_set_{param} (Py_{shortname} *self, PyObject *args)
472493 {{
473494 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 += """
475500
476− if (!PyArg_ParseTuple (args, "{pyparamtype}", &{param})) {{
501+ if (!PyArg_ParseTuple (args, "{pyparamtypes}", {refs})) {{
477502 return NULL;
478503 }}
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});
480508
481509 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+ }}
483518 return NULL;
484519 }}
485520 Py_RETURN_NONE;
486521 }}
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__)
488524 return out
489525
490526 def gen_get(self):
@@ -525,6 +561,12 @@ static PyMethodDef Py_{shortname}_methods[] = {{""".format(**self.__dict__) · 34 unmodified lines
525561 out += """
526562 {{"{shortname}", (PyCFunction) Py{name},
527563 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)
528570 out += """
529571 {NULL} /* sentinel */
530572 };
@@ -550,7 +592,7 @@ PyTypeObject Py_{shortname}Type = {{ · 19 unmodified lines
550592 0,
551593 0,
552594 0,
553− (ternaryfunc)Py_{shortname}_do,
595+ (ternaryfunc)Pyaubio_{shortname}_do,
554596 0,
555597 0,
556598 0,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t