Skip to content
Snippets Groups Projects
Commit 1227ed85 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Saving stage

parent 88524d79
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,11 @@ set( BATCH_SCRIPT_EXTENSION "bat" ) ...@@ -29,7 +29,11 @@ set( BATCH_SCRIPT_EXTENSION "bat" )
if( NOT WIN32 ) if( NOT WIN32 )
set( BATCH_SCRIPT_EXTENSION "sh" ) set( BATCH_SCRIPT_EXTENSION "sh" )
endif( ) endif( )
add_custom_command( TARGET VAPython POST_BUILD COMMAND "distutils_build.${BATCH_SCRIPT_EXTENSION}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running distutils" VERBATIM ) set( BATCH_SCRIPT_TYPE distutils_build_static )
if( BUILD_SHARED_LIBS )
set( BATCH_SCRIPT_TYPE distutils_build_shared )
endif( )
add_custom_command( TARGET VAPython POST_BUILD COMMAND "${BATCH_SCRIPT_TYPE}.${BATCH_SCRIPT_EXTENSION}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running distutils" VERBATIM )
# configure # configure
#vista_configure_lib( VAPython ) #vista_configure_lib( VAPython )
......
python.exe setup.py clean
python.exe setup.py build --force
python.exe setup.py install --prefix dist
python.exe setup.py sdist --formats=zip
rem later:
rem python.exe setup.py bdist_wininst
python.exe setup.py check
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# VA notebook test # VA notebook test
This is a simple test program that demonstrates the use of the VA Python binding within a jupyter notebook environment. This is a simple test program that demonstrates the use of the VA Python binding within a jupyter notebook environment.
## Before we start ## Before we start
Before we start scripting, let's make VA available for us. If it is not installed and available from everywhere, this is how you can add the `va` module folder: Before we start scripting, let's make VA available for us. If it is not installed and available from everywhere, this is how you can add the `va` module folder:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import sys import sys
sys.path.append( "../../dist/Lib/site-packages" ) # build sys.path.append( "../../dist/Lib/site-packages" ) # build
sys.path.append( "../Lib/site-packages" ) # deploy sys.path.append( "../Lib/site-packages" ) # deploy
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Start ## Start
We start by making va available for our script We start by making va available for our script
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import va import va
``` ```
%% Output
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-9508d0d3eded> in <module>()
----> 1 import va
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Ok. Now let's try to connect to the VA server that should be running on the same computer where this jupyter notebook is running. Ok. Now let's try to connect to the VA server that should be running on the same computer where this jupyter notebook is running.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We start by finding out where we are currently working and list the files available, i.e. to identify files that can be used as HRIR, audio file or directivity. We start by finding out where we are currently working and list the files available, i.e. to identify files that can be used as HRIR, audio file or directivity.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
connection_status = va.connect() connection_status = va.connect()
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We can check the connection by the following line We can check the connection by the following line
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
connected = va.is_connected() connected = va.is_connected()
if connected : if connected :
print( "VA connection ready!" ) print( "VA connection ready!" )
else : else :
print( "Something went wrong." ) print( "Something went wrong." )
``` ```
%% Output
VA connection ready!
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
... and also use different server names and ports ... and also use different server names and ports
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
if not connected : if not connected :
va.connect( "localhost", 12340 ) # these are the default arguments va.connect( "localhost", 12340 ) # these are the default arguments
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import os import os
current_working_dir = os.getcwd() current_working_dir = os.getcwd()
print( "working directory: " + current_working_dir ) print( "working directory: " + current_working_dir )
``` ```
%% Output
working directory: D:\Users\stienen\dev\VA\VAPython\examples\jupyter
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now lets add this folder to VA. This means that VA can find files that reside in this location. All you have to do is use a file name or a relative path from this base path. You can add as much folders as you like. Now lets add this folder to VA. This means that VA can find files that reside in this location. All you have to do is use a file name or a relative path from this base path. You can add as much folders as you like.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
va.add_search_path( current_working_dir ) va.add_search_path( current_working_dir )
``` ```
%% Cell type:code id: tags:
``` python
vamods = va.enumerate_modules()
print( vamods )
```
%% Cell type:code id: tags:
``` python
```
......
...@@ -4,7 +4,7 @@ module1 = Extension('va', ...@@ -4,7 +4,7 @@ module1 = Extension('va',
define_macros = [('VA_PYTHON_VERSION_MAJOR', '2017'), ('VA_PYTHON_VERSION_MINOR', 'c'), ('VABASE_STATIC', 1), ('VANET_STATIC', 1), ('VISTABASE_STATIC', 1), ('VISTAINTERPROCCOMM_STATIC', 1), ('VISTAASPECTS_STATIC',1)], define_macros = [('VA_PYTHON_VERSION_MAJOR', '2017'), ('VA_PYTHON_VERSION_MINOR', 'c'), ('VABASE_STATIC', 1), ('VANET_STATIC', 1), ('VISTABASE_STATIC', 1), ('VISTAINTERPROCCOMM_STATIC', 1), ('VISTAASPECTS_STATIC',1)],
include_dirs = ['../VABase/include','../VANet/include'], include_dirs = ['../VABase/include','../VANet/include'],
libraries = ['VABase', 'VANet', 'VistaBase', 'VistaAspects', 'VistaInterProcComm', 'winmm', 'ws2_32' ], libraries = ['VABase', 'VANet', 'VistaBase', 'VistaAspects', 'VistaInterProcComm', 'winmm', 'ws2_32' ],
library_dirs = ['../build_win32-x64.vc14_static/lib','../../ViSTA/build_static_win32-x64.vc14/lib'], library_dirs = ['../build_win32-x64.vc14/lib','../../ViSTA/build_win32-x64.vc14/lib'],
sources = ['src/vasingleton.cpp'] ) sources = ['src/vasingleton.cpp'] )
setup (name = 'va', setup (name = 'va',
......
...@@ -49,9 +49,9 @@ static struct PyMethodDef va_methods[] = ...@@ -49,9 +49,9 @@ static struct PyMethodDef va_methods[] =
{ "set_signal_source_parameters", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc }, { "set_signal_source_parameters", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc },
{ "get_signal_source_parameters", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc }, { "get_signal_source_parameters", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc },
{ "is_scene_locked", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc }, { "is_scene_locked", ( PyCFunction ) va_is_scene_locked, METH_FASTCALL, va_no_doc },
{ "lock_scene", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc }, { "lock_scene", ( PyCFunction ) va_lock_scene, METH_FASTCALL, va_no_doc },
{ "unlock_scene", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc }, { "unlock_scene", ( PyCFunction ) va_unlock_scene, METH_FASTCALL, va_no_doc },
{ "get_sound_source_ids", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc }, { "get_sound_source_ids", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc },
{ "create_sound_source", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc }, { "create_sound_source", ( PyCFunction ) va_not_implemented, METH_FASTCALL, va_no_doc },
......
#include <Python.h> #include <Python.h>
#include <VANetClient.h> #include <VANetClient.h>
#include <VACore.h> #include <VACore.h>
#include <VAStruct.h>
#include <VAException.h> #include <VAException.h>
#include <string.h> #include <string.h>
...@@ -32,6 +33,21 @@ static void RequireCoreAvailable() ...@@ -32,6 +33,21 @@ static void RequireCoreAvailable()
VA_EXCEPT2(CVAException::NETWORK_ERROR, "VA client available, but access to VA interface failed. Please reconnect."); VA_EXCEPT2(CVAException::NETWORK_ERROR, "VA client available, but access to VA interface failed. Please reconnect.");
}; };
//! Helper to convert recursively from VAStruct to Python dict
PyObject* ConvertVAStructToPythonDict( const CVAStruct& oInStruct )
{
return PyLong_FromLong( -1 );
};
//! Helper to convert recursively from Python dict to VAStruct
CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict )
{
return CVAStruct();
};
// ------------------------------- Python module extension methods
static PyObject* va_connect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_connect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{ {
if (!g_pVANetClient) if (!g_pVANetClient)
...@@ -105,7 +121,7 @@ static PyObject* va_enumerate_modules(PyObject* pSelf, PyObject** ppArgs, Py_ssi ...@@ -105,7 +121,7 @@ static PyObject* va_enumerate_modules(PyObject* pSelf, PyObject** ppArgs, Py_ssi
for (size_t i = 0; i < voModuleInfos.size(); i++) for (size_t i = 0; i < voModuleInfos.size(); i++)
{ {
CVAModuleInfo& oModule(voModuleInfos[i]); CVAModuleInfo& oModule(voModuleInfos[i]);
PyObject* pModuleInfo = Py_BuildValue("{s:i,s:s,s:s}", "index", i, "name", oModule.sName, "description", oModule.sDesc); PyObject* pModuleInfo = Py_BuildValue("{s:i,s:s,s:s}", "index", i, "name", oModule.sName.c_str(), "description", oModule.sDesc.c_str() );
PyList_SetItem(pModuleList, i, pModuleInfo); // steals reference PyList_SetItem(pModuleList, i, pModuleInfo); // steals reference
} }
...@@ -117,7 +133,23 @@ static PyObject* va_enumerate_modules(PyObject* pSelf, PyObject** ppArgs, Py_ssi ...@@ -117,7 +133,23 @@ static PyObject* va_enumerate_modules(PyObject* pSelf, PyObject** ppArgs, Py_ssi
static PyObject* va_call_module(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_call_module(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{ {
VAPY_REQUIRE_CONN_TRY; VAPY_REQUIRE_CONN_TRY;
VA_EXCEPT_NOT_IMPLEMENTED;
static const char * const _keywords[] = { "module_name", "arguments", NULL };
static _PyArg_Parser _parser = { "so:call_module", _keywords, 0 };
char* pcModuleName = nullptr;
PyObject* pArguments = nullptr;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &pcModuleName, &pArguments ) )
return NULL;
std::string sModuleName = std::string( pcModuleName );
CVAStruct oArgs = ConvertPythonDictToVAStruct( pArguments );
CVAStruct oReturn;
g_pVANetClient->GetCoreInstance()->CallModule( sModuleName, oArgs, oReturn );
return ConvertVAStructToPythonDict( oReturn );
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
...@@ -147,3 +179,25 @@ static PyObject* va_create_listener(PyObject* pSelf, PyObject** ppArgs, Py_ssize ...@@ -147,3 +179,25 @@ static PyObject* va_create_listener(PyObject* pSelf, PyObject** ppArgs, Py_ssize
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_is_scene_locked( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
{
VAPY_REQUIRE_CONN_TRY;
return PyLong_FromLong( g_pVANetClient->GetCoreInstance()->IsSceneLocked() );
VAPY_CATCH_RETURN;
};
static PyObject* va_lock_scene( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
{
VAPY_REQUIRE_CONN_TRY
g_pVANetClient->GetCoreInstance()->LockScene();
return PyLong_FromLong( 1 );
VAPY_CATCH_RETURN;
};
static PyObject* va_unlock_scene( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
{
VAPY_REQUIRE_CONN_TRY;
return PyLong_FromLong( g_pVANetClient->GetCoreInstance()->UnlockScene() );
VAPY_CATCH_RETURN;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment