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

Adding more methods

parent c9dd2de7
Branches
Tags
No related merge requests found
%% Cell type:markdown id: tags:
# VA notebook test
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 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:
``` python
import sys
sys.path.append( "../../dist/Lib/site-packages" ) # build
sys.path.append( "../Lib/site-packages" ) # deploy
```
%% Cell type:markdown id: tags:
## Start
We start by making va available for our script
%% Cell type:code id: tags:
``` python
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:
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:
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:
``` python
connection_status = va.connect()
```
%% Cell type:markdown id: tags:
We can check the connection by the following line
%% Cell type:code id: tags:
``` python
connected = va.is_connected()
if connected :
print( "VA connection ready!" )
else :
print( "Something went wrong." )
```
%% Cell type:markdown id: tags:
... and also use different server names and ports
%% Cell type:code id: tags:
``` python
if not connected :
va.connect( "localhost", 12340 ) # these are the default arguments
```
%% Cell type:code id: tags:
``` python
import os
current_working_dir = os.getcwd()
print( "working directory: " + current_working_dir )
```
%% 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.
%% Cell type:code id: tags:
``` python
va.add_search_path( current_working_dir )
```
%% Cell type:code id: tags:
``` python
vamods = va.enumerate_modules()
vamods = va.get_modules()
print( vamods )
```
%% Cell type:code id: tags:
``` python
hw = va.get_hardware_configuration()
print( hw )
```
%% Cell type:code id: tags:
``` python
core_conf = va.get_core_configuration()
print( core_conf )
```
......
......@@ -147,6 +147,9 @@ static struct PyMethodDef va_methods[] =
{ "set_core_clock", ( PyCFunction ) set_core_clock, METH_FASTCALL, no_doc },
{ "substitute_macro", ( PyCFunction ) substitute_macro, METH_FASTCALL, no_doc },
{ "find_file_path", ( PyCFunction ) find_file_path, METH_FASTCALL, no_doc },
{ "get_core_configuration", ( PyCFunction ) get_core_configuration, METH_FASTCALL, no_doc },
{ "get_hardware_configuration", ( PyCFunction ) get_hardware_configuration, METH_FASTCALL, no_doc },
{ "get_file_list", ( PyCFunction ) get_file_list, METH_FASTCALL, no_doc },
{ "get_log_level_str", ( PyCFunction ) get_log_level_str, METH_FASTCALL, no_doc },
{ "parse_auralization_mode_str", ( PyCFunction ) parse_auralization_mode_str, METH_FASTCALL, no_doc },
{ "get_auralization_mode_str", ( PyCFunction ) get_auralization_mode_str, METH_FASTCALL, no_doc },
......
......@@ -2153,6 +2153,50 @@ static PyObject* find_file_path( PyObject*, PyObject** ppArgs, Py_ssize_t nArgs,
VAPY_CATCH_RETURN;
};
static PyObject* get_core_configuration( PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
{
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "filter_enabled", NULL };
static _PyArg_Parser _parser = { "|b:get_core_configuration", _keywords, 0 };
bool bFilterEnabled = true;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &bFilterEnabled ) )
return NULL;
CVAStruct oCoreConfig = g_pVANetClient->GetCoreInstance()->GetCoreConfiguration( bFilterEnabled );
return ConvertVAStructToPythonDict( oCoreConfig );
VAPY_CATCH_RETURN;
};
static PyObject* get_hardware_configuration( PyObject*, PyObject**, Py_ssize_t, PyObject* )
{
VAPY_REQUIRE_CONN_TRY;
CVAStruct oHWConfig = g_pVANetClient->GetCoreInstance()->GetHardwareConfiguration();
return ConvertVAStructToPythonDict( oHWConfig );
VAPY_CATCH_RETURN;
};
static PyObject* get_file_list( PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
{
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "recursive", "filter_suffix_mask", NULL };
static _PyArg_Parser _parser = { "|bs:get_file_list", _keywords, 0 };
bool bFilterEnabled = true;
char* pcFilterSuffixMask = nullptr;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &bFilterEnabled, &pcFilterSuffixMask ) )
return NULL;
std::string sFilterSuffixMask = pcFilterSuffixMask ? std::string( pcFilterSuffixMask ) : "*";
CVAStruct oFileList = g_pVANetClient->GetCoreInstance()->GetFileList( bFilterEnabled, sFilterSuffixMask );
return ConvertVAStructToPythonDict( oFileList );
VAPY_CATCH_RETURN;
};
static PyObject* get_log_level_str( PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment