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

Fixing bugs in python binding methods

parent 924d22be
Branches
Tags
No related merge requests found
%% Cell type:markdown id: tags:
# VA scene controller
This is a simple example and utility notebook that demonstrates the use of scene control mechanisms.
%% Cell type:markdown id: tags:
### Prerequisites
You can ignore this part, it is for preparation purposes only.
%% Cell type:code id: tags:
``` python
import sys
sys.path.append( '../../Lib/site-packages' )
import ipywidgets as widgets
import va
if not va.connect() :
raise 'Could not connect to VA server on localhost'
```
%% Cell type:markdown id: tags:
### Listeners
%% Cell type:code id: tags:
``` python
listener_ids = va.get_listener_ids()
listeners_dict = {}
for listener_id in listener_ids :
listeners_dict.update( { va.get_listener_name( listener_id ) : listener_id } )
listeners_dropdown_menu = widgets.Dropdown(
options = listeners_dict,
description = 'Listeners' )
if listener_ids :
first_listener_pos = va.get_listener_position( listener_ids[ 0 ] )
def on_listener_update( w ) :
listener_id = listeners_dropdown_menu.value
if listener_id :
listener_pos = [ listeners_input_pos_x.value, listeners_input_pos_y.value, listeners_input_pos_z.value ]
va.set_listener_position( listener_id, listener_pos )
listeners_input_pos_x = widgets.FloatText( description = 'X' )
listeners_input_pos_y = widgets.FloatText( description = 'Y' )
listeners_input_pos_z = widgets.FloatText( description = 'Z' )
listener_update_button = widgets.Button( description = 'Update' )
listener_update_button.on_click( on_listener_update )
def on_listener_select( d ) :
if d.type == 'change' and type( d.new ) is str :
listener_id = listeners_dropdown_menu.options[ d.new ]
listener_pos = va.get_listener_position( listener_id )
listeners_input_pos_x.value = listener_pos[ 0 ]
listeners_input_pos_y.value = listener_pos[ 1 ]
listeners_input_pos_z.value = listener_pos[ 2 ]
listeners_dropdown_menu.observe( on_listener_select )
listeners_input_widget_box = widgets.HBox( [ listeners_dropdown_menu, listeners_input_pos_x, listeners_input_pos_y, listeners_input_pos_z, listener_update_button ] )
display( listeners_input_widget_box )
```
%% Output
%% Cell type:markdown id: tags:
### Sources
%% Cell type:code id: tags:
``` python
sound_source_ids = va.get_sound_source_ids()
sound_sources_dict = {}
for source_id in sound_source_ids :
sound_sources_dict.update( { va.get_sound_source_name( source_id ) : source_id } )
sound_sources_dropdown_menu = widgets.Dropdown(
options = sound_sources_dict,
description = 'Sound sources' )
if sound_source_ids :
first_sound_source_pos = va.get_sound_source_position( sound_source_ids[ 0 ] )
def on_sound_source_update( w ) :
sound_source_id = sound_sources_dropdown_menu.value
if sound_source_id :
sound_source_pos = [ sound_source_input_pos_x.value, sound_source_input_pos_y.value, sound_source_input_pos_z.value ]
va.set_sound_source_position( sound_source_id, sound_source_pos )
sound_source_input_pos_x = widgets.FloatText( description = 'X' )
sound_source_input_pos_y = widgets.FloatText( description = 'Y' )
sound_source_input_pos_z = widgets.FloatText( description = 'Z' )
sound_source_update_button = widgets.Button( description = 'Update' )
sound_source_update_button.on_click( on_sound_source_update )
def on_sound_source_select( d ) :
if d.type == 'change' and type( d.new ) is str :
sound_source_id = sound_sources_dropdown_menu.options[ d.new ]
sound_source_pos = va.get_sound_source_position( sound_source_id )
sound_source_input_pos_x.value = sound_source_pos[ 0 ]
sound_source_input_pos_y.value = sound_source_pos[ 1 ]
sound_source_input_pos_z.value = sound_source_pos[ 2 ]
sound_sources_dropdown_menu.observe( on_sound_source_select )
sound_source_input_widget_box = widgets.HBox( [ sound_sources_dropdown_menu, sound_source_input_pos_x, sound_source_input_pos_y, sound_source_input_pos_z, sound_source_update_button ] )
display( sound_source_input_widget_box )
```
%% Output
......@@ -26,10 +26,10 @@ static PyObject* va_not_implemented( PyObject*, PyObject* )
static void RequireCoreAvailable()
{
if( !g_pVANetClient )
VA_EXCEPT2( CVAException::NETWORK_ERROR, "VA client not available, please connect first" );
VA_EXCEPT2( NETWORK_ERROR, "VA client not available, please connect first" );
if( !g_pVANetClient->GetCoreInstance() )
VA_EXCEPT2( CVAException::NETWORK_ERROR, "VA client available, but access to VA interface failed. Please reconnect." );
VA_EXCEPT2( NETWORK_ERROR, "VA client available, but access to VA interface failed. Please reconnect." );
};
std::string SaveStringToUnicodeConversion( const std::string& sInputString )
......@@ -112,7 +112,7 @@ CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict )
PyObject* pValue = PyList_GetItem( pValueList, i );
char* pcKeyName = nullptr;
if( !PyArg_Parse( pKey, "s", &pcKeyName ) )
VA_EXCEPT2( CVAException::INVALID_PARAMETER, "Invalid key '" + std::string( pcKeyName ) + "'" );
VA_EXCEPT2( INVALID_PARAMETER, "Invalid key '" + std::string( pcKeyName ) + "'" );
if( Py_None == pValue )
{
......@@ -134,7 +134,7 @@ CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict )
{
char* pcStringValue = nullptr;
if( !PyArg_Parse( pValue, "s", &pcStringValue ) )
VA_EXCEPT2( CVAException::INVALID_PARAMETER, "Invalid string value at key '" + std::string( pcKeyName ) + "': " + std::string( pcStringValue ) );
VA_EXCEPT2( INVALID_PARAMETER, "Invalid string value at key '" + std::string( pcKeyName ) + "': " + std::string( pcStringValue ) );
oReturn[ pcKeyName ] = std::string( pcStringValue );
}
else if( PyDict_Check( pValue ) )
......@@ -1854,7 +1854,7 @@ static PyObject* va_get_rendering_modules( PyObject*, PyObject* )
for( size_t i = 0; i < voInfos.size(); i++ )
{
CVAAudioRendererInfo& oInfo( voInfos[ i ] );
PyObject* pInfo = Py_BuildValue( "{s:b,s:s,s:s}",
PyObject* pInfo = Py_BuildValue( "{s:b,s:s,s:s, s:s}",
"enabled", oInfo.bEnabled,
"class", SaveStringToUnicodeConversion( oInfo.sClass ).c_str(),
"description", SaveStringToUnicodeConversion( oInfo.sDescription ).c_str(),
......@@ -1906,7 +1906,7 @@ static PyObject* va_set_rendering_module_muted( PyObject*, PyObject** ppArgs, Py
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "id", "muted", NULL };
static _PyArg_Parser _parser = { "i|b:set_rendering_module_muted", _keywords, 0 };
static _PyArg_Parser _parser = { "s|b:set_rendering_module_muted", _keywords, 0 };
char* pcID = nullptr;
bool bMuted = true;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &pcID, &bMuted ) )
......@@ -1947,7 +1947,7 @@ static PyObject* va_get_reproduction_modules( PyObject*, PyObject* )
for( size_t i = 0; i < voInfos.size(); i++ )
{
CVAAudioReproductionInfo& oInfo( voInfos[ i ] );
PyObject* pInfo = Py_BuildValue( "{s:b,s:s,s:s}",
PyObject* pInfo = Py_BuildValue( "{s:b,s:s,s:s,s:s}",
"enabled", oInfo.bEnabled,
"class", SaveStringToUnicodeConversion( oInfo.sClass ).c_str(),
"description", SaveStringToUnicodeConversion( oInfo.sDescription ).c_str(),
......@@ -1999,7 +1999,7 @@ static PyObject* va_set_reproduction_module_muted( PyObject*, PyObject** ppArgs,
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "id", "muted", NULL };
static _PyArg_Parser _parser = { "i|b:set_reproduction_module_muted", _keywords, 0 };
static _PyArg_Parser _parser = { "s|b:set_reproduction_module_muted", _keywords, 0 };
char* pcID = nullptr;
bool bMuted = true;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &pcID, &bMuted ) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment