shithub: aubio

Download patch

ref: 09b1777a3a0889fdee5a7a0eb2c896daac0baba5
parent: 1f8e52247a4fe23baa0bbbc7e6cb4a934fed4ad2
author: Paul Brossier <piem@piem.org>
date: Wed Oct 21 11:40:23 EDT 2009

gen_pyobject.py: fix initialisation of strings and tempo output size

--- a/interfaces/python/gen_pyobject.py
+++ b/interfaces/python/gen_pyobject.py
@@ -40,7 +40,7 @@
     'tss':          ('self->hop_s', 'self->channels'),
     'mfcc':         ('self->n_coeffs', 'in->channels'),
     'beattracking': ('self->winlen', 'self->channels'),
-    'tempo':        ('self->buf_size', 'self->channels'),
+    'tempo':        ('1', 'self->channels'),
     'peakpicker':   ('1', 'self->channels'),
 }
 
@@ -146,10 +146,11 @@
 {
 """ % locals()
     for ptype, pname in newparams:
-        defval = aubioinitvalue[ptype]
+        initval = aubioinitvalue[ptype]
         s += """\
-  %(ptype)s %(pname)s = %(defval)s;
+  %(ptype)s %(pname)s = %(initval)s;
 """ % locals()
+    # now the actual PyArg_Parse
     s += """\
   Py_%(name)s *self;
   static char *kwlist[] = { %(paramnames)s, NULL };
@@ -168,17 +169,36 @@
     # TODO add parameters default values
     for ptype, pname in newparams:
         defval = aubiodefvalue[pname]
-        s += """\
+        if ptype == 'char_t*':
+            s += """\
 
   self->%(pname)s = %(defval)s;
+  if (%(pname)s != NULL) {
+    self->%(pname)s = %(pname)s;
+  }
+""" % locals()
+        elif ptype == 'uint_t':
+            s += """\
+
+  self->%(pname)s = %(defval)s;
   if (%(pname)s > 0) {
     self->%(pname)s = %(pname)s;
   } else if (%(pname)s < 0) {
     PyErr_SetString (PyExc_ValueError,
-        "can not use negative window size");
+        "can not use negative value for %(pname)s");
     return NULL;
   }
 """ % locals()
+        elif ptype == 'smpl_t':
+            s += """\
+
+  self->%(pname)s = %(defval)s;
+  if (%(pname)s != %(defval)s) {
+    self->%(pname)s = %(pname)s;
+  }
+""" % locals()
+        else:
+            print "ERROR, unknown type of parameter %s %s" % (ptype, pname)
     s += """\
 
   return (PyObject *) self;
@@ -279,9 +299,16 @@
     s = """
 AUBIO_MEMBERS_START(%(name)s)""" % locals()
     for param in newparams:
-        s += """
+        if param[0] == 'char_t*':
+            s += """
+  {"%(pname)s", T_STRING, offsetof (Py_%(name)s, %(pname)s), READONLY, ""},""" \
+        % { 'pname': param[1], 'ptype': param[0], 'name': name}
+        elif param[0] == 'uint_t':
+            s += """
   {"%(pname)s", T_INT, offsetof (Py_%(name)s, %(pname)s), READONLY, ""},""" \
         % { 'pname': param[1], 'ptype': param[0], 'name': name}
+        else:
+            print "-- ERROR, unknown member type ", param
     s += """
 AUBIO_MEMBERS_STOP(%(name)s)