From 75176992a60fd98157da38ac115f324eb489e04f Mon Sep 17 00:00:00 2001 From: "Dipl.-Ing. Jonas Stienen" <jst@akustik.rwth-aachen.de> Date: Mon, 21 Aug 2017 10:29:19 +0200 Subject: [PATCH] Adding py example script and improving CMake dist execution (now including distutils call and auto-copy to dist folder) --- CMakeLists.txt | 63 ++++++++++++++++++++++------------- MANIFEST | 14 ++++++++ examples/va_example_simple.py | 28 ++++++++++++++++ 3 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 MANIFEST create mode 100644 examples/va_example_simple.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c15f51..45b6cb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,40 +19,57 @@ endif( ) add_definitions( -DPy_NO_ENABLE_SHARED ) -# Only add library here to check if it compiles. Use python distutils to actually compile the extension. +# Only add library here to check if it compiles in your preferred build env. CMake will run Python distutils to actually compile the extension, see below. add_library( VAPython STATIC "src/vasingleton.cpp" "src/vasingletondoc.hpp" "src/vasingletonmethods.hpp" "MANIFEST.in" "setup.py" ) target_link_libraries( VAPython ${VISTA_USE_PACKAGE_LIBRARIES} ) +# Run distutils after (useless) build in your dev env to compile the Python extension into 'dist' folder +set( BATCH_SCRIPT_EXTENSION "bat" ) +if( NOT WIN32 ) + set( BATCH_SCRIPT_EXTENSION "sh" ) +endif( ) +add_custom_command( TARGET VAPython POST_BUILD COMMAND "distutils_build.${BATCH_SCRIPT_EXTENSION}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running distutils" VERBATIM ) + # configure vista_configure_lib( VAPython ) vista_install( VAPython ) -set( VACS_INCLUDE_OUTDIR "${CMAKE_CURRENT_SOURCE_DIR}/include" ) vista_create_cmake_configs( VAPython ) vista_create_default_info_file( VAPython ) set_property( TARGET VAPython PROPERTY FOLDER "VA/Bindings" ) + # install -if( WIN32 ) - - # This is hacky, but Pythons distutils needs the dependend libraries below root folder to create a distributable package. - - install( FILES "${VABASE_LIBRARY_DIRS}/VABase.dll" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/bin" ) - install( FILES "${VANET_LIBRARY_DIRS}/VANet.dll" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/bin" ) - - foreach( VISTACORELIBS_LIBRARY_DIR ${VISTACORELIBS_LIBRARY_DIRS} ) - if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaBase.dll" ) - install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaBase.dll" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/bin" ) - endif( ) - if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaAspects.dll" ) - install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaAspects.dll" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/bin" ) - endif( ) - if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaInterProcComm.dll" ) - install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaInterProcComm.dll" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/bin" ) - endif( ) - endforeach( ) -else( ) - message( WARN "VAPython distribution preparation not implemented yet. Please provide required VA and ViSTA libraries on runtime." ) - # Please adapt for other OS or install VABase, VANet and VistaCoreLibs into your system (so VAPython can find the shared libraries) + +# Copy python extension if available. Requires successful distutils execution. +vista_install_files_by_extension( dist/Lib/site-packages "python/Lib/site-packages" "pyd" "egg-info" ) + +# install by copying DLL/SO next to python extension +set( SHARED_LIBRARY_EXTENSION "dll" ) +if( NOT WIN32 ) + set( SHARED_LIBRARY_EXTENSION "so" ) endif( ) + +# VA shared libs +install( FILES "${VABASE_LIBRARY_DIRS}/VABase.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" ) +install( FILES "${VANET_LIBRARY_DIRS}/VANet.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" ) + +# VistaCoreLibs shared libs +foreach( VISTACORELIBS_LIBRARY_DIR ${VISTACORELIBS_LIBRARY_DIRS} ) + if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaBase.${SHARED_LIBRARY_EXTENSION}" ) + install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaBase.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" ) + endif( ) + if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaAspects.${SHARED_LIBRARY_EXTENSION}" ) + install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaAspects.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" ) + endif( ) + if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaInterProcComm.${SHARED_LIBRARY_EXTENSION}" ) + install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaInterProcComm.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" ) + endif( ) +endforeach( ) + +# Tests +install( DIRECTORY "tests" DESTINATION "python" )# + +# Examples +install( DIRECTORY "tests" DESTINATION "python" ) diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..7770791 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,14 @@ +# file GENERATED by distutils, do NOT edit +LICENSE.md +MANIFEST.in +README.md +setup.py +bin\VABase.dll +bin\VANet.dll +bin\VistaAspects.dll +bin\VistaBase.dll +bin\VistaInterProcComm.dll +src\vasingleton.cpp +src\vasingletondoc.hpp +src\vasingletonmethods.hpp +tests\vatest.py diff --git a/examples/va_example_simple.py b/examples/va_example_simple.py new file mode 100644 index 0000000..f3d32d8 --- /dev/null +++ b/examples/va_example_simple.py @@ -0,0 +1,28 @@ +import os + +current_exec_dir = os.getcwd() + +import va + +va.connect # localhost +va.add_search_path( current_exec_dir ) # add current working path to find any file lying around here + +signal_source_id = va.create_audio_file_signal_source( "Bauer.wav" ) # Provide this file or any other file + +dir_id = va.load_directivity( "${DefaultDir}" ) + +sound_source_id = va.create_sound_source( "PySoundSource" ) +va.set_sound_source_signal_source( sound_source_id, signal_source_id ) +va.set_directivity( sound_source_id, dir_id ) +va.set_sound_source_position( sound_source_id, ( 1, 1.2, -1 ) ) # OpenGL axes convention, direction is lower front-right from listener pos (s.b.) + +hrir_id = va.load_hrir( "${DefaultHRIR}" ) + +listener_id = va.create_listener( "PyListener" ) +va.set_listener_hrir( listener_id, hrir_id ) +va.set_listener_position( listener_id, ( 0, 1.7, 0 ) ) # Ear height at 1.7m + +va.set_audio_file_signal_source_is_looping( signal_source_id, true ) +va.set_audio_file_signal_source_play_state( signal_source_id, "play" ) + +va.disconnect -- GitLab