Changeset 41b985f for python/lib
- Timestamp:
- Mar 12, 2017, 11:26:24 AM (8 years ago)
- Branches:
- sampler
- Children:
- bde49c4a
- Parents:
- 71f2e5f (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- python/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/__init__.py
r71f2e5f r41b985f 2 2 3 3 import numpy 4 from ._aubio import __version__ as version 5 from ._aubio import float_type 4 6 from ._aubio import * 5 from ._aubio import float_type6 7 from .midiconv import * 7 8 from .slicing import * -
python/lib/aubio/midiconv.py
r71f2e5f r41b985f 16 16 " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] " 17 17 _valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11} 18 _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 19 'b': -1, u'♭': -1, u'\ufffd': -2} 18 _valid_modifiers = { 19 u'𝄫': -2, # double flat 20 u'♭': -1, 'b': -1, '\u266d': -1, # simple flat 21 u'♮': 0, '\u266e': 0, None: 0, # natural 22 '#': +1, u'♯': +1, '\u266f': +1, # sharp 23 u'𝄪': +2, # double sharp 24 } 20 25 _valid_octaves = range(-1, 10) 21 26 if not isinstance(note, str_instances): -
python/lib/gen_external.py
r71f2e5f r41b985f 15 15 'filter', 16 16 'filterbank', 17 #'resampler',18 17 # AUBIO_UNSTABLE 19 18 'hist', … … 79 78 return cpp_cmd 80 79 81 def get_cpp_objects(header=header ):80 def get_cpp_objects(header=header, usedouble=False): 82 81 cpp_cmd = get_preprocessor() 83 82 84 83 macros = [('AUBIO_UNSTABLE', 1)] 84 if usedouble: 85 macros += [('HAVE_AUBIO_DOUBLE', 1)] 85 86 86 87 if not os.path.isfile(header): … … 180 181 elif not overwrite: return sorted(glob.glob(os.path.join(output_path, '*.c'))) 181 182 182 cpp_output, cpp_objects = get_cpp_objects(header )183 cpp_output, cpp_objects = get_cpp_objects(header, usedouble=usedouble) 183 184 184 185 lib = analyze_cpp_output(cpp_objects, cpp_output) … … 251 252 # no need to add header to list of sources 252 253 253 return so urces_list254 return sorted(sources_list) 254 255 255 256 if __name__ == '__main__': -
python/lib/moresetuptools.py
r71f2e5f r41b985f 4 4 import distutils, distutils.command.clean, distutils.dir_util 5 5 from .gen_external import generate_external, header, output_path 6 7 def get_aubio_version(): 8 # read from VERSION 9 this_file_dir = os.path.dirname(os.path.abspath(__file__)) 10 version_file = os.path.join(this_file_dir, '..', '..', 'VERSION') 11 12 if not os.path.isfile(version_file): 13 raise SystemError("VERSION file not found.") 14 15 for l in open(version_file).readlines(): 16 #exec (l.strip()) 17 if l.startswith('AUBIO_MAJOR_VERSION'): 18 AUBIO_MAJOR_VERSION = int(l.split('=')[1]) 19 if l.startswith('AUBIO_MINOR_VERSION'): 20 AUBIO_MINOR_VERSION = int(l.split('=')[1]) 21 if l.startswith('AUBIO_PATCH_VERSION'): 22 AUBIO_PATCH_VERSION = int(l.split('=')[1]) 23 if l.startswith('AUBIO_VERSION_STATUS'): 24 AUBIO_VERSION_STATUS = l.split('=')[1].strip()[1:-1] 25 26 if AUBIO_MAJOR_VERSION is None or AUBIO_MINOR_VERSION is None \ 27 or AUBIO_PATCH_VERSION is None: 28 raise SystemError("Failed parsing VERSION file.") 29 30 verstr = '.'.join(map(str, [AUBIO_MAJOR_VERSION, 31 AUBIO_MINOR_VERSION, 32 AUBIO_PATCH_VERSION])) 33 34 if AUBIO_VERSION_STATUS is not None: 35 verstr += AUBIO_VERSION_STATUS 36 return verstr 37 38 def get_aubio_pyversion(): 39 # convert to version for python according to pep 440 40 # see https://www.python.org/dev/peps/pep-0440/ 41 verstr = get_aubio_version() 42 if '~alpha' in verstr: 43 verstr = verstr.split('~')[0] + 'a1' 44 # TODO: add rc, .dev, and .post suffixes, add numbering 45 return verstr 6 46 7 47 # inspired from https://gist.github.com/abergmeier/9488990 … … 22 62 23 63 for package in packages: 64 print("checking for {:s}".format(package)) 24 65 cmd = ['pkg-config', '--libs', '--cflags', package] 25 66 try: … … 53 94 ext.libraries += ['aubio'] 54 95 55 def add_local_aubio_sources(ext ):96 def add_local_aubio_sources(ext, usedouble = False): 56 97 """ build aubio inside python module instead of linking against libaubio """ 57 print("Warning: libaubio was not built with waf, adding src/") 58 # create an empty header, macros will be passed on the command line 59 fake_config_header = os.path.join('python', 'ext', 'config.h') 60 distutils.file_util.write_file(fake_config_header, "") 98 print("Info: libaubio was not installed or built locally with waf, adding src/") 61 99 aubio_sources = sorted(glob.glob(os.path.join('src', '**.c'))) 62 100 aubio_sources += sorted(glob.glob(os.path.join('src', '*', '**.c'))) 63 101 ext.sources += aubio_sources 102 103 def add_local_macros(ext, usedouble = False): 64 104 # define macros (waf puts them in build/src/config.h) 65 105 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H', … … 70 110 ext.define_macros += [(define_macro, 1)] 71 111 112 def add_external_deps(ext, usedouble = False): 72 113 # loof for additional packages 73 114 print("Info: looking for *optional* additional packages") 74 115 packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample', 75 116 'jack', 76 'sndfile', 'samplerate', 117 'sndfile', 118 'samplerate', 77 119 'rubberband', 78 120 #'fftw3f', 79 121 ] 122 # samplerate only works with float 123 if usedouble is False: 124 packages += ['samplerate'] 125 else: 126 print("Info: not adding libsamplerate in double precision mode") 80 127 add_packages(packages, ext=ext) 81 128 if 'avcodec' in ext.libraries \ … … 116 163 def add_system_aubio(ext): 117 164 # use pkg-config to find aubio's location 118 add_packages(['aubio'], ext) 165 aubio_version = get_aubio_version() 166 add_packages(['aubio = ' + aubio_version], ext) 119 167 if 'aubio' not in ext.libraries: 120 print("Error: libaubio not found") 168 print("Info: aubio " + aubio_version + " was not found by pkg-config") 169 else: 170 print("Info: using system aubio " + aubio_version + " found in " + ' '.join(ext.library_dirs)) 121 171 122 172 class CleanGenerated(distutils.command.clean.clean): 123 173 def run(self): 124 distutils.dir_util.remove_tree(output_path)125 distutils.command.clean.clean.run(self)174 if os.path.isdir(output_path): 175 distutils.dir_util.remove_tree(output_path) 126 176 127 177 from distutils.command.build_ext import build_ext as _build_ext … … 145 195 146 196 def build_extension(self, extension): 147 if self.enable_double :197 if self.enable_double or 'HAVE_AUBIO_DOUBLE' in os.environ: 148 198 extension.define_macros += [('HAVE_AUBIO_DOUBLE', 1)] 149 if os.path.isfile('src/aubio.h'): 150 # if aubio headers are found in this directory 151 add_local_aubio_header(extension) 152 # was waf used to build the shared lib? 153 if os.path.isdir(os.path.join('build','src')): 154 # link against build/src/libaubio, built with waf 199 enable_double = True 200 else: 201 enable_double = False 202 # seack for aubio headers and lib in PKG_CONFIG_PATH 203 add_system_aubio(extension) 204 # the lib was not installed on this system 205 if 'aubio' not in extension.libraries: 206 # use local src/aubio.h 207 if os.path.isfile(os.path.join('src', 'aubio.h')): 208 add_local_aubio_header(extension) 209 add_local_macros(extension) 210 # look for a local waf build 211 if os.path.isfile(os.path.join('build','src', 'fvec.c.1.o')): 155 212 add_local_aubio_lib(extension) 156 213 else: 214 # check for external dependencies 215 add_external_deps(extension, usedouble=enable_double) 157 216 # add libaubio sources and look for optional deps with pkg-config 158 add_local_aubio_sources(extension, usedouble=self.enable_double) 159 else: 160 # look for aubio headers and lib using pkg-config 161 add_system_aubio(extension) 217 add_local_aubio_sources(extension, usedouble=enable_double) 162 218 # generate files python/gen/*.c, python/gen/aubio-generated.h 163 219 extension.sources += generate_external(header, output_path, overwrite = False, 164 usedouble= self.enable_double)220 usedouble=enable_double) 165 221 return _build_ext.build_extension(self, extension)
Note: See TracChangeset
for help on using the changeset viewer.