Changeset c71e405 for interfaces/python
- Timestamp:
- Jul 11, 2012, 2:09:20 AM (13 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 1458de5, 451b05d
- Parents:
- c325a11
- Location:
- interfaces/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/gen_pyobject.py
rc325a11 rc71e405 25 25 # There is no way of knowing that output1 is actually input2. In the future, 26 26 # const could be used for the inputs in the C prototypes. 27 28 def write_msg(*args): 29 pass 30 # uncomment out for debugging 31 #print args 27 32 28 33 def split_type(arg): … … 226 231 """ % locals() 227 232 else: 228 print "ERROR, unknown type of parameter %s %s" % (ptype, pname)233 write_msg ("ERROR, unknown type of parameter %s %s" % (ptype, pname) ) 229 234 s += """\ 230 235 … … 346 351 % { 'pname': param[1], 'ptype': param[0], 'name': name} 347 352 else: 348 print "-- ERROR, unknown member type ", param353 write_msg ("-- ERROR, unknown member type ", param ) 349 354 s += """ 350 355 AUBIO_MEMBERS_STOP(%(name)s) … … 363 368 assert params[0][0] == "aubio_"+name+"_t*", \ 364 369 "get method is not in 'aubio_<name>_t" 365 print method366 print params[1:]370 write_msg (method ) 371 write_msg (params[1:]) 367 372 setter_args = "self->o, " +",".join([p[1] for p in params[1:]]) 368 373 parse_args = "" -
interfaces/python/generator.py
-
Property
mode
changed from
100644
to100755
rc325a11 rc71e405 4 4 5 5 import os, sys 6 from gen_pyobject import write_msg, gen_new_init, gen_do, gen_members, gen_methods, gen_finish 6 7 7 skip_objects = ['fft', 'pvoc', 'filter', 'filterbank', 'resampler'] 8 def get_cpp_objects(): 8 9 9 cpp_output = [l.strip() for l in os.popen('cpp -DAUBIO_UNSTABLE=1 -I../../build/src ../../src/aubio.h').readlines()]10 cpp_output = [l.strip() for l in os.popen('cpp -DAUBIO_UNSTABLE=1 -I../../build/src ../../src/aubio.h').readlines()] 10 11 11 cpp_output = filter(lambda y: len(y) > 1, cpp_output)12 cpp_output = filter(lambda y: not y.startswith('#'), cpp_output)12 cpp_output = filter(lambda y: len(y) > 1, cpp_output) 13 cpp_output = filter(lambda y: not y.startswith('#'), cpp_output) 13 14 14 i = 115 while 1:16 if i >= len(cpp_output): break17 if cpp_output[i-1].endswith(',') or cpp_output[i-1].endswith('{') or cpp_output[i].startswith('}'):18 cpp_output[i] = cpp_output[i-1] + ' ' + cpp_output[i]19 cpp_output.pop(i-1)20 else:21 i += 115 i = 1 16 while 1: 17 if i >= len(cpp_output): break 18 if cpp_output[i-1].endswith(',') or cpp_output[i-1].endswith('{') or cpp_output[i].startswith('}'): 19 cpp_output[i] = cpp_output[i-1] + ' ' + cpp_output[i] 20 cpp_output.pop(i-1) 21 else: 22 i += 1 22 23 23 typedefs = filter(lambda y: y.startswith ('typedef struct _aubio'), cpp_output)24 typedefs = filter(lambda y: y.startswith ('typedef struct _aubio'), cpp_output) 24 25 25 objects = [a.split()[3][:-1] for a in typedefs]26 cpp_objects = [a.split()[3][:-1] for a in typedefs] 26 27 27 print "-- INFO: %d objects in total" % len(objects) 28 return cpp_output, cpp_objects 28 29 29 generated_objects = [] 30 def generate_object_files(): 30 31 31 for this_object in objects: 32 lint = 0 33 34 if this_object[-2:] == '_t': 35 object_name = this_object[:-2] 36 else: 37 object_name = this_object 38 print "-- WARNING: %s does not end in _t" % this_object 32 generated_objects = [] 33 cpp_output, cpp_objects = get_cpp_objects() 34 skip_objects = ['fft', 'pvoc', 'filter', 'filterbank', 'resampler'] 39 35 40 if object_name[:len('aubio_')] != 'aubio_': 41 print "-- WARNING: %s does not start n aubio_" % this_object 36 write_msg("-- INFO: %d objects in total" % len(cpp_objects)) 42 37 43 print "-- INFO: looking at", object_name 44 object_methods = filter(lambda x: this_object in x, cpp_output) 45 object_methods = [a.strip() for a in object_methods] 46 object_methods = filter(lambda x: not x.startswith('typedef'), object_methods) 47 #for method in object_methods: 48 # print method 38 for this_object in cpp_objects: 39 lint = 0 40 41 if this_object[-2:] == '_t': 42 object_name = this_object[:-2] 43 else: 44 object_name = this_object 45 write_msg("-- WARNING: %s does not end in _t" % this_object) 49 46 50 new_methods = filter(lambda x: 'new_'+object_name in x, object_methods) 51 if len(new_methods) > 1: 52 print "-- WARNING: more than one new method for", object_name 53 for method in new_methods: 54 print method 55 elif len(new_methods) < 1: 56 print "-- WARNING: no new method for", object_name 57 elif 0: 58 for method in new_methods: 59 print method 47 if object_name[:len('aubio_')] != 'aubio_': 48 write_msg("-- WARNING: %s does not start n aubio_" % this_object) 60 49 61 del_methods = filter(lambda x: 'del_'+object_name in x, object_methods) 62 if len(del_methods) > 1: 63 print "-- WARNING: more than one del method for", object_name 64 for method in del_methods: 65 print method 66 elif len(del_methods) < 1: 67 print "-- WARNING: no del method for", object_name 50 write_msg("-- INFO: looking at", object_name) 51 object_methods = filter(lambda x: this_object in x, cpp_output) 52 object_methods = [a.strip() for a in object_methods] 53 object_methods = filter(lambda x: not x.startswith('typedef'), object_methods) 54 #for method in object_methods: 55 # write_msg(method) 56 new_methods = filter(lambda x: 'new_'+object_name in x, object_methods) 57 if len(new_methods) > 1: 58 write_msg("-- WARNING: more than one new method for", object_name) 59 for method in new_methods: 60 write_msg(method) 61 elif len(new_methods) < 1: 62 write_msg("-- WARNING: no new method for", object_name) 63 elif 0: 64 for method in new_methods: 65 write_msg(method) 68 66 69 do_methods = filter(lambda x: object_name+'_do' in x, object_methods) 70 if len(do_methods) > 1: 71 pass 72 #print "-- WARNING: more than one do method for", object_name 73 #for method in do_methods: 74 # print method 75 elif len(do_methods) < 1: 76 print "-- WARNING: no do method for", object_name 77 elif 0: 78 for method in do_methods: 79 print method 67 del_methods = filter(lambda x: 'del_'+object_name in x, object_methods) 68 if len(del_methods) > 1: 69 write_msg("-- WARNING: more than one del method for", object_name) 70 for method in del_methods: 71 write_msg(method) 72 elif len(del_methods) < 1: 73 write_msg("-- WARNING: no del method for", object_name) 80 74 81 # check do methods return void 82 for method in do_methods: 83 if (method.split()[0] != 'void'): 84 print "-- ERROR: _do method does not return void:", method 75 do_methods = filter(lambda x: object_name+'_do' in x, object_methods) 76 if len(do_methods) > 1: 77 pass 78 #write_msg("-- WARNING: more than one do method for", object_name) 79 #for method in do_methods: 80 # write_msg(method) 81 elif len(do_methods) < 1: 82 write_msg("-- WARNING: no do method for", object_name) 83 elif 0: 84 for method in do_methods: 85 write_msg(method) 85 86 86 get_methods = filter(lambda x: object_name+'_get_' in x, object_methods) 87 # check do methods return void 88 for method in do_methods: 89 if (method.split()[0] != 'void'): 90 write_msg("-- ERROR: _do method does not return void:", method ) 87 91 88 set_methods = filter(lambda x: object_name+'_set_' in x, object_methods) 89 for method in set_methods: 90 if (method.split()[0] != 'uint_t'): 91 print "-- ERROR: _set method does not return uint_t:", method 92 get_methods = filter(lambda x: object_name+'_get_' in x, object_methods) 92 93 93 other_methods = filter(lambda x: x not in new_methods, object_methods) 94 other_methods = filter(lambda x: x not in del_methods, other_methods) 95 other_methods = filter(lambda x: x not in do_methods, other_methods) 96 other_methods = filter(lambda x: x not in get_methods, other_methods) 97 other_methods = filter(lambda x: x not in set_methods, other_methods) 94 set_methods = filter(lambda x: object_name+'_set_' in x, object_methods) 95 for method in set_methods: 96 if (method.split()[0] != 'uint_t'): 97 write_msg("-- ERROR: _set method does not return uint_t:", method ) 98 98 99 if len(other_methods) > 0: 100 print "-- WARNING: some methods for", object_name, "were unidentified" 101 for method in other_methods: 102 print method 99 other_methods = filter(lambda x: x not in new_methods, object_methods) 100 other_methods = filter(lambda x: x not in del_methods, other_methods) 101 other_methods = filter(lambda x: x not in do_methods, other_methods) 102 other_methods = filter(lambda x: x not in get_methods, other_methods) 103 other_methods = filter(lambda x: x not in set_methods, other_methods) 103 104 104 # generate this_object 105 if not os.path.isdir('generated'): os.mkdir('generated') 106 from gen_pyobject import * 107 short_name = object_name[len('aubio_'):] 108 if short_name in skip_objects: 109 print "-- INFO: skipping object", short_name 110 continue 111 if 1: #try: 112 s = gen_new_init(new_methods[0], short_name) 113 s += gen_do(do_methods[0], short_name) 114 s += gen_members(new_methods[0], short_name) 115 s += gen_methods(get_methods, set_methods, short_name) 116 s += gen_finish(short_name) 117 fd = open('generated/gen-'+short_name+'.c', 'w') 118 fd.write(s) 119 #except Exception, e: 120 # print "-- ERROR:", type(e), str(e), "in", short_name 121 # continue 122 generated_objects += [this_object] 105 if len(other_methods) > 0: 106 write_msg("-- WARNING: some methods for", object_name, "were unidentified") 107 for method in other_methods: 108 write_msg(method) 123 109 124 110 125 s = """// generated list of generated objects 111 # generate this_object 112 if not os.path.isdir('generated'): os.mkdir('generated') 113 short_name = object_name[len('aubio_'):] 114 if short_name in skip_objects: 115 write_msg("-- INFO: skipping object", short_name ) 116 continue 117 if 1: #try: 118 s = gen_new_init(new_methods[0], short_name) 119 s += gen_do(do_methods[0], short_name) 120 s += gen_members(new_methods[0], short_name) 121 s += gen_methods(get_methods, set_methods, short_name) 122 s += gen_finish(short_name) 123 generated_filepath = 'generated/gen-'+short_name+'.c' 124 fd = open(generated_filepath, 'w') 125 fd.write(s) 126 #except Exception, e: 127 # write_msg("-- ERROR:", type(e), str(e), "in", short_name) 128 # continue 129 generated_objects += [this_object] 130 131 s = """// generated list of objects created with generator.py 126 132 127 133 """ 128 134 129 for each in generated_objects:130 s += "extern PyTypeObject Py_%sType;\n" % \131 each.replace('aubio_','').replace('_t','')135 for each in generated_objects: 136 s += "extern PyTypeObject Py_%sType;\n" % \ 137 each.replace('aubio_','').replace('_t','') 132 138 133 types_ready = []134 for each in generated_objects:135 types_ready.append(" PyType_Ready (&Py_%sType) < 0" % \136 each.replace('aubio_','').replace('_t','') )139 types_ready = [] 140 for each in generated_objects: 141 types_ready.append(" PyType_Ready (&Py_%sType) < 0" % \ 142 each.replace('aubio_','').replace('_t','') ) 137 143 138 s += """ 139 int 140 generated_types_ready (void) 141 { 142 return (""" 143 s += ('||\n').join(types_ready) 144 s += """); 145 } 146 """ 144 s += """ 145 int 146 generated_types_ready (void) 147 { 148 return ( 149 """ 150 s += ('\n ||').join(types_ready) 151 s += """); 152 } 153 """ 147 154 148 s += """149 void150 add_generated_objects ( PyObject *m )151 {"""152 for each in generated_objects:153 s += """ Py_INCREF (&Py_%(name)sType);154 PyModule_AddObject (m, "%(name)s", (PyObject *) & Py_%(name)sType);""" % \155 { 'name': ( each.replace('aubio_','').replace('_t','') ) }155 s += """ 156 void 157 add_generated_objects ( PyObject *m ) 158 {""" 159 for each in generated_objects: 160 s += """ Py_INCREF (&Py_%(name)sType); 161 PyModule_AddObject (m, "%(name)s", (PyObject *) & Py_%(name)sType);""" % \ 162 { 'name': ( each.replace('aubio_','').replace('_t','') ) } 156 163 157 s += """158 }"""164 s += """ 165 }""" 159 166 160 fd = open('generated/aubio-generated.h', 'w') 161 fd.write(s) 167 fd = open('generated/aubio-generated.h', 'w') 168 fd.write(s) 169 170 from os import listdir 171 generated_files = listdir('generated') 172 generated_files = filter(lambda x: x.endswith('.c'), generated_files) 173 generated_files = ['generated/'+f for f in generated_files] 174 return generated_files 175 176 if __name__ == '__main__': 177 generate_object_files() -
Property
mode
changed from
-
interfaces/python/setup.py
-
Property
mode
changed from
100644
to100755
rc325a11 rc71e405 1 #! /usr/bin/python 2 1 3 from distutils.core import setup, Extension 2 4 3 from os import listdir 4 generated_files = listdir('generated') 5 generated_files = filter(lambda x: x.endswith('.c'), generated_files) 6 generated_files = ['generated/'+f for f in generated_files] 5 from generator import generate_object_files 7 6 8 7 setup(name="_aubio", version="1.0", … … 20 19 "py-phasevoc.c", 21 20 # generated files 22 ] + generate d_files,21 ] + generate_object_files(), 23 22 include_dirs=['../../build/src', '../../src', '.' ], 24 23 library_dirs=['../../build/src', '../../src/.libs' ], -
Property
mode
changed from
Note: See TracChangeset
for help on using the changeset viewer.