Changeset 41b985f for python/lib


Ignore:
Timestamp:
Mar 12, 2017, 11:26:24 AM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
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.
Message:

Merge 'origin/master' into sampler

Conflicts:

.travis.yml
Makefile
examples/aubionotes.c
examples/parse_args.h
python/demos/demo_timestretch_online.py
python/lib/moresetuptools.py
python/tests/test_source.py
setup.py
src/io/source.c

Location:
python/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/__init__.py

    r71f2e5f r41b985f  
    22
    33import numpy
     4from ._aubio import __version__ as version
     5from ._aubio import float_type
    46from ._aubio import *
    5 from ._aubio import float_type
    67from .midiconv import *
    78from .slicing import *
  • python/lib/aubio/midiconv.py

    r71f2e5f r41b985f  
    1616    " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] "
    1717    _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            }
    2025    _valid_octaves = range(-1, 10)
    2126    if not isinstance(note, str_instances):
  • python/lib/gen_external.py

    r71f2e5f r41b985f  
    1515  'filter',
    1616  'filterbank',
    17   #'resampler',
    1817  # AUBIO_UNSTABLE
    1918  'hist',
     
    7978    return cpp_cmd
    8079
    81 def get_cpp_objects(header=header):
     80def get_cpp_objects(header=header, usedouble=False):
    8281    cpp_cmd = get_preprocessor()
    8382
    8483    macros = [('AUBIO_UNSTABLE', 1)]
     84    if usedouble:
     85        macros += [('HAVE_AUBIO_DOUBLE', 1)]
    8586
    8687    if not os.path.isfile(header):
     
    180181    elif not overwrite: return sorted(glob.glob(os.path.join(output_path, '*.c')))
    181182
    182     cpp_output, cpp_objects = get_cpp_objects(header)
     183    cpp_output, cpp_objects = get_cpp_objects(header, usedouble=usedouble)
    183184
    184185    lib = analyze_cpp_output(cpp_objects, cpp_output)
     
    251252        # no need to add header to list of sources
    252253
    253     return sources_list
     254    return sorted(sources_list)
    254255
    255256if __name__ == '__main__':
  • python/lib/moresetuptools.py

    r71f2e5f r41b985f  
    44import distutils, distutils.command.clean, distutils.dir_util
    55from .gen_external import generate_external, header, output_path
     6
     7def 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
     38def 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
    646
    747# inspired from https://gist.github.com/abergmeier/9488990
     
    2262
    2363    for package in packages:
     64        print("checking for {:s}".format(package))
    2465        cmd = ['pkg-config', '--libs', '--cflags', package]
    2566        try:
     
    5394    ext.libraries += ['aubio']
    5495
    55 def add_local_aubio_sources(ext):
     96def add_local_aubio_sources(ext, usedouble = False):
    5697    """ 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/")
    6199    aubio_sources = sorted(glob.glob(os.path.join('src', '**.c')))
    62100    aubio_sources += sorted(glob.glob(os.path.join('src', '*', '**.c')))
    63101    ext.sources += aubio_sources
     102
     103def add_local_macros(ext, usedouble = False):
    64104    # define macros (waf puts them in build/src/config.h)
    65105    for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',
     
    70110        ext.define_macros += [(define_macro, 1)]
    71111
     112def add_external_deps(ext, usedouble = False):
    72113    # loof for additional packages
    73114    print("Info: looking for *optional* additional packages")
    74115    packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample',
    75116                'jack',
    76                 'sndfile', 'samplerate',
     117                'sndfile',
     118                'samplerate',
    77119                'rubberband',
    78120                #'fftw3f',
    79121               ]
     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")
    80127    add_packages(packages, ext=ext)
    81128    if 'avcodec' in ext.libraries \
     
    116163def add_system_aubio(ext):
    117164    # 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)
    119167    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))
    121171
    122172class CleanGenerated(distutils.command.clean.clean):
    123173    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)
    126176
    127177from distutils.command.build_ext import build_ext as _build_ext
     
    145195
    146196    def build_extension(self, extension):
    147         if self.enable_double:
     197        if self.enable_double or 'HAVE_AUBIO_DOUBLE' in os.environ:
    148198            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')):
    155212                add_local_aubio_lib(extension)
    156213            else:
     214                # check for external dependencies
     215                add_external_deps(extension, usedouble=enable_double)
    157216                # 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)
    162218        # generate files python/gen/*.c, python/gen/aubio-generated.h
    163219        extension.sources += generate_external(header, output_path, overwrite = False,
    164                 usedouble=self.enable_double)
     220                usedouble=enable_double)
    165221        return _build_ext.build_extension(self, extension)
Note: See TracChangeset for help on using the changeset viewer.