Fixing bugs in python binding methods

parent 924d22be
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# VA scene controller\n",
"This is a simple example and utility notebook that demonstrates the use of scene control mechanisms."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Prerequisites\n",
"You can ignore this part, it is for preparation purposes only."
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append( '../../Lib/site-packages' )\n",
"import ipywidgets as widgets\n",
"import va\n",
"if not va.connect() :\n",
" raise 'Could not connect to VA server on localhost'"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"### Listeners"
]
},
{
"cell_type": "code",
"execution_count": 181,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6f9ed2a29aa04c22996c8baa64f67a8f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"listener_ids = va.get_listener_ids()\n",
"listeners_dict = {}\n",
"for listener_id in listener_ids :\n",
" listeners_dict.update( { va.get_listener_name( listener_id ) : listener_id } )\n",
"\n",
"listeners_dropdown_menu = widgets.Dropdown( \n",
" options = listeners_dict,\n",
" description = 'Listeners' )\n",
"if listener_ids :\n",
" first_listener_pos = va.get_listener_position( listener_ids[ 0 ] )\n",
"\n",
"def on_listener_update( w ) :\n",
" listener_id = listeners_dropdown_menu.value\n",
" if listener_id :\n",
" listener_pos = [ listeners_input_pos_x.value, listeners_input_pos_y.value, listeners_input_pos_z.value ]\n",
" va.set_listener_position( listener_id, listener_pos )\n",
"\n",
"listeners_input_pos_x = widgets.FloatText( description = 'X' )\n",
"listeners_input_pos_y = widgets.FloatText( description = 'Y' )\n",
"listeners_input_pos_z = widgets.FloatText( description = 'Z' )\n",
"\n",
"listener_update_button = widgets.Button( description = 'Update' )\n",
"listener_update_button.on_click( on_listener_update )\n",
"\n",
"def on_listener_select( d ) :\n",
" if d.type == 'change' and type( d.new ) is str :\n",
" listener_id = listeners_dropdown_menu.options[ d.new ] \n",
" listener_pos = va.get_listener_position( listener_id )\n",
" listeners_input_pos_x.value = listener_pos[ 0 ]\n",
" listeners_input_pos_y.value = listener_pos[ 1 ]\n",
" listeners_input_pos_z.value = listener_pos[ 2 ]\n",
" \n",
"listeners_dropdown_menu.observe( on_listener_select )\n",
"\n",
"listeners_input_widget_box = widgets.HBox( [ listeners_dropdown_menu, listeners_input_pos_x, listeners_input_pos_y, listeners_input_pos_z, listener_update_button ] )\n",
"display( listeners_input_widget_box )"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"### Sources"
]
},
{
"cell_type": "code",
"execution_count": 183,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "826b9adcf6084a80b9894ccd81081eb6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sound_source_ids = va.get_sound_source_ids()\n",
"sound_sources_dict = {}\n",
"for source_id in sound_source_ids :\n",
" sound_sources_dict.update( { va.get_sound_source_name( source_id ) : source_id } )\n",
"\n",
"sound_sources_dropdown_menu = widgets.Dropdown( \n",
" options = sound_sources_dict,\n",
" description = 'Sound sources' )\n",
"if sound_source_ids :\n",
" first_sound_source_pos = va.get_sound_source_position( sound_source_ids[ 0 ] )\n",
"\n",
"def on_sound_source_update( w ) :\n",
" sound_source_id = sound_sources_dropdown_menu.value\n",
" if sound_source_id :\n",
" sound_source_pos = [ sound_source_input_pos_x.value, sound_source_input_pos_y.value, sound_source_input_pos_z.value ]\n",
" va.set_sound_source_position( sound_source_id, sound_source_pos )\n",
"\n",
"sound_source_input_pos_x = widgets.FloatText( description = 'X' )\n",
"sound_source_input_pos_y = widgets.FloatText( description = 'Y' )\n",
"sound_source_input_pos_z = widgets.FloatText( description = 'Z' )\n",
"\n",
"sound_source_update_button = widgets.Button( description = 'Update' )\n",
"sound_source_update_button.on_click( on_sound_source_update )\n",
"\n",
"def on_sound_source_select( d ) :\n",
" if d.type == 'change' and type( d.new ) is str :\n",
" sound_source_id = sound_sources_dropdown_menu.options[ d.new ] \n",
" sound_source_pos = va.get_sound_source_position( sound_source_id )\n",
" sound_source_input_pos_x.value = sound_source_pos[ 0 ]\n",
" sound_source_input_pos_y.value = sound_source_pos[ 1 ]\n",
" sound_source_input_pos_z.value = sound_source_pos[ 2 ]\n",
" \n",
"sound_sources_dropdown_menu.observe( on_sound_source_select )\n",
"\n",
"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 ] )\n",
"display( sound_source_input_widget_box )"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -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 ) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment