Commit 49be549b authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Fixing bugs and improving Python binding and jupyter examples

parent 397181d0
......@@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [
{
......@@ -64,13 +64,13 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "057eb3bfb4fc4828a5db5914ab4d00ae",
"model_id": "ab9e1c96bb1b4c2aaea9c95d6ee930e8",
"version_major": 2,
"version_minor": 0
},
......@@ -103,13 +103,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b03c42298f59475083c9dfe7012f1c1c",
"model_id": "878c6d78501a48f0916f2488a270ac8a",
"version_major": 2,
"version_minor": 0
},
......@@ -151,23 +151,23 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Direct sound, early reflections, diffuse decay, source directivity, air absorption, atmospheric temporal variations, scattering, diffraction, near-field effects, doppler shifts, spherical spreading loss, transmission, absorption'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"DS, ER, DD, DIR, AA, TV, SC, DIF, NF, DP, SL, TR, AB\n",
"Direct sound, early reflections, diffuse decay, source directivity, air absorption, atmospheric temporal variations, scattering, diffraction, near-field effects, doppler shifts, spherical spreading loss, transmission, absorption\n"
]
}
],
"source": [
"global_am = va.get_global_auralization_mode()\n",
"va.get_auralization_mode_str( global_am )"
"print( global_am )\n",
"global_am_long = va.get_global_auralization_mode( False )\n",
"print( global_am_long )"
]
},
{
......@@ -181,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -215,14 +215,14 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'path_0': 'C:/data', 'path_1': 'C:/dev/VA/VACore/conf', 'path_2': 'C:/dev/VA/VACore/data', 'path_3': 'C:/data/InsideSceneData', 'path_4': 'C:\\\\dev\\\\VA\\\\VAPython\\\\examples\\\\jupyter'}\n",
"{'path_0': 'C:/data', 'path_1': 'C:/dev/VA/VACore/conf', 'path_2': 'C:/dev/VA/VACore/data', 'path_3': 'C:/data/InsideSceneData'}\n",
"client working directory: C:\\dev\\VA\\VAPython\\examples\\jupyter\n"
]
}
......@@ -246,13 +246,13 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6899a1855f3a497b8bc73393cb56aca1",
"model_id": "f7649c3b43d646d88712e9fea5ad8094",
"version_major": 2,
"version_minor": 0
},
......@@ -284,13 +284,13 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8127aca5a12c42f1ae547a52226c2f0d",
"model_id": "fb3c42c0da5f463c98a2f51e91095964",
"version_major": 2,
"version_minor": 0
},
......@@ -306,7 +306,8 @@
"output_type": "stream",
"text": [
"Calling BinauralFreeField:MyBinauralFreeField\n",
"Module returned an exception, could not get help\n"
"Module returned an exception, could not get help\n",
"Calling VACore\n"
]
}
],
......@@ -340,36 +341,172 @@
"metadata": {},
"source": [
"### Rendering modules\n",
"Rendering modules are special modules that can also be listed using `get_rendering_modules`. They are called through the module interface just as described above, however the module name has to be assembled by the type of renderer followed by a semicolon `:` and the name of the rendering module."
"Rendering modules are special modules that can also be listed using `get_rendering_modules`. They can be muted/unmuted individually and also have an own output gain control. Additionally all rendering modules have specialized parameter setter and getter."
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5a0ed7d50a8146ab8e54740b6f2c44c4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"allrendmods = va.get_rendering_modules();\n",
"\n",
"\n",
"# Dropdown menu\n",
"rendmodnames = list()\n",
"for mod in allrendmods[:] :\n",
" rendmodnames.append( mod[\"id\"] )\n",
"rendmods_dropdown_menu = widgets.Dropdown( options=rendmodnames )\n",
"\n",
"\n",
"# Mute toggle button\n",
"rendmod_mute_button = widgets.ToggleButton( description = 'Mute' )\n",
"\n",
"def on_rendmod_mute_button_clicked( b ) :\n",
" rendmod = allrendmods[ rendmods_dropdown_menu.index ]\n",
" if b.name == 'value' :\n",
" va.set_rendering_module_muted( mod[\"id\"], b.new )\n",
" \n",
"rendmod_mute_button.observe( on_rendmod_mute_button_clicked )\n",
"\n",
"\n",
"# Gain slider\n",
"rendmod_gain_slider = widgets.FloatSlider( \n",
" value = 1.0,\n",
" description = 'Gain:',\n",
" min = 0.0,\n",
" max = 1.0,\n",
" step = 0.1,\n",
" readout = True,\n",
" readout_format = '.1f' )\n",
"\n",
"def on_rendmod_gain_changed( s ) :\n",
" rendmod = allrendmods[ rendmods_dropdown_menu.index ]\n",
" if s.name == 'value' :\n",
" va.set_rendering_module_gain( rendmod[\"id\"], s.new )\n",
"\n",
"rendmod_gain_slider.observe( on_rendmod_gain_changed )\n",
"\n",
"\n",
"# Parameter getter\n",
"rendmod_button_params = widgets.Button( description = 'Parameters' )\n",
"\n",
"def on_rendmod_parameter( b ) :\n",
" rendmod = allrendmods[ rendmods_dropdown_menu.index ]\n",
" print( va.get_rendering_module_parameters( rendmod[\"id\"] ) )\n",
" \n",
"rendmod_button_params.on_click( on_rendmod_parameter )\n",
"\n",
"\n",
"# Horizontal box with widgets\n",
"rendmod_widget_box = widgets.HBox( [ rendmods_dropdown_menu, rendmod_mute_button, rendmod_gain_slider, rendmod_button_params ] )\n",
"display( rendmod_widget_box )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Reproduction modules\n",
"Reproduction modules are special modules that can also be listed using `get_reproduction_modules`. They can be muted/unmuted individually and also have an own output gain control. Additionally all reproduction modules have specialized parameter setter and getter."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "217211a8a5db48f3808a95f22bcdc056",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'enabled': 1, 'class': 'BinauralFreeField', 'description': '', 'id': 'MyBinauralFreeField'}\n",
"MyBinauralFreeField\n",
"Could not get rendering module parameters\n"
"{}\n"
]
}
],
"source": [
"allrmods = va.get_rendering_modules()\n",
"for rmod in allrmods :\n",
" print( rmod )\n",
" try :\n",
" print( rmod[\"id\"] )\n",
" magic_return = va.get_renderer_parameters( rmod[\"id\"], {} )\n",
" print( magic_return )\n",
" except:\n",
" print( 'Could not get rendering module parameters' )\n",
"allrepmods = va.get_reproduction_modules();\n",
"\n",
"\n",
"# Dropdown menu\n",
"repmodnames = list()\n",
"for mod in allrepmods[:] :\n",
" repmodnames.append( mod[\"id\"] )\n",
"repmods_dropdown_menu = widgets.Dropdown( options=repmodnames )\n",
"\n",
"\n",
"# Mute toggle button\n",
"repmod_mute_button = widgets.ToggleButton( description = 'Mute' )\n",
"\n",
"def on_repmod_mute_button_clicked( b ) :\n",
" repmod = allrepmods[ repmods_dropdown_menu.index ]\n",
" if b.name == 'value' :\n",
" va.set_reproduction_module_muted( mod[\"id\"], b.new )\n",
" \n",
"repmod_mute_button.observe( on_repmod_mute_button_clicked )\n",
"\n",
"\n",
"# Gain slider\n",
"repmod_gain_slider = widgets.FloatSlider( \n",
" value = 1.0,\n",
" description = 'Gain:',\n",
" min = 0.0,\n",
" max = 1.0,\n",
" step = 0.1,\n",
" readout = True,\n",
" readout_format = '.1f' )\n",
"\n",
"def on_repmod_gain_changed( s ) :\n",
" repmod = allrepmods[ repmods_dropdown_menu.index ]\n",
" if s.name == 'value' :\n",
" va.set_reproduction_module_gain( repmod[\"id\"], s.new )\n",
"\n",
"repmod_gain_slider.observe( on_repmod_gain_changed )\n",
"\n",
"\n",
"# Parameter getter\n",
"repmod_button_params = widgets.Button( description = 'Parameters' )\n",
"\n",
"def on_repmod_parameter( b ) :\n",
" repmod = allrepmods[ repmods_dropdown_menu.index ]\n",
" print( va.get_reproduction_module_parameters( repmod[\"id\"] ) )\n",
" \n",
"repmod_button_params.on_click( on_repmod_parameter )\n",
"\n",
"\n",
"# todo implement in VAPy"
"# Horizontal box with widgets\n",
"repmod_widget_box = widgets.HBox( [ repmods_dropdown_menu, repmod_mute_button, repmod_gain_slider, repmod_button_params ] )\n",
"display( repmod_widget_box )"
]
}
],
......
......@@ -129,7 +129,9 @@ static struct PyMethodDef va_methods[] =
{ "set_homogeneous_medium_parameters", ( PyCFunction ) set_homogeneous_medium_parameters, METH_FASTCALL, no_doc },
{ "create_acoustic_material", ( PyCFunction ) create_acoustic_material, METH_FASTCALL, no_doc },
{ "create_acoustic_material_from_file", ( PyCFunction ) create_acoustic_material_from_file, METH_FASTCALL, no_doc },
{ "create_acoustic_material_from_parameters", ( PyCFunction ) create_acoustic_material_from_parameters, METH_FASTCALL, no_doc },
{ "get_acoustic_material_infos", ( PyCFunction ) get_acoustic_material_infos, METH_FASTCALL, no_doc },
......@@ -143,13 +145,13 @@ static struct PyMethodDef va_methods[] =
{ "get_rendering_module_parameters", ( PyCFunction ) get_rendering_module_parameters, METH_FASTCALL, no_doc },
{ "set_rendering_module_parameters", ( PyCFunction ) set_rendering_module_parameters, METH_FASTCALL, no_doc },
{ "get_reprodution_modules", ( PyCFunction ) get_reproduction_modules, METH_FASTCALL, no_doc },
{ "set_reprodution_module_muted", ( PyCFunction ) set_reproduction_module_muted, METH_FASTCALL, no_doc },
{ "get_reprodution_module_muted", ( PyCFunction ) get_reproduction_module_muted, METH_FASTCALL, no_doc },
{ "set_reprodution_module_gain", ( PyCFunction ) set_reproduction_module_gain, METH_FASTCALL, no_doc },
{ "get_reprodution_module_gain", ( PyCFunction ) get_reproduction_module_gain, METH_FASTCALL, no_doc },
{ "get_reproduction_modules", ( PyCFunction ) get_reproduction_modules, METH_FASTCALL, no_doc },
{ "set_reproduction_module_muted", ( PyCFunction ) set_reproduction_module_muted, METH_FASTCALL, no_doc },
{ "get_reproduction_module_muted", ( PyCFunction ) get_reproduction_module_muted, METH_FASTCALL, no_doc },
{ "set_reproduction_module_gain", ( PyCFunction ) set_reproduction_module_gain, METH_FASTCALL, no_doc },
{ "get_reproduction_module_gain", ( PyCFunction ) get_reproduction_module_gain, METH_FASTCALL, no_doc },
{ "get_reproduction_module_parameters", ( PyCFunction ) get_reproduction_module_parameters, METH_FASTCALL, no_doc },
{ "set_reproduction_parameters", ( PyCFunction ) set_reproduction_module_parameters, METH_FASTCALL, no_doc },
{ "set_reproduction_module_parameters", ( PyCFunction ) set_reproduction_module_parameters, METH_FASTCALL, no_doc },
{ "lock_update", ( PyCFunction ) lock_update, METH_FASTCALL, no_doc },
......
......@@ -216,7 +216,8 @@ CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict )
CVAAcousticMaterial ConvertPythonDictToAcousticMaterial( PyObject* pMaterial )
{
CVAAcousticMaterial oMaterial;
oMaterial.
VA_EXCEPT_NOT_IMPLEMENTED;
return oMaterial;
}
......@@ -1935,7 +1936,7 @@ static PyObject* get_homogeneous_medium_parameters( PyObject*, PyObject** ppArgs
static const char * const _keywords[] = { "arguments", NULL };
static _PyArg_Parser _parser = { "|O!:get_homogeneous_medium_parameters", _keywords, 0 };
PyObject* pParamArgs = nullptr;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, pParamArgs ) )
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &pParamArgs ) )
return NULL;
CVAStruct oArgs = ConvertPythonDictToVAStruct( pParamArgs );
......@@ -2061,7 +2062,7 @@ static PyObject* 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,s:s,s:s,s:b,s:b,s:O!}",
PyObject* pInfo = Py_BuildValue( "{s:b,s:s,s:s,s:s,s:s,s:b,s:b,s:O}",
"enabled", oInfo.bEnabled,
"class", SaveStringToUnicodeConversion( oInfo.sClass ).c_str(),
"description", SaveStringToUnicodeConversion( oInfo.sDescription ).c_str(),
......@@ -2163,7 +2164,7 @@ static PyObject* get_rendering_module_parameters( PyObject*, PyObject** ppArgs,
static _PyArg_Parser _parser = { "s|O!:get_rendering_module_parameters", _keywords, 0 };
char* pcID = nullptr;
PyObject* pArgs = NULL;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &pcID, pArgs ) )
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &pcID, &pArgs ) )
return NULL;
std::string sID = pcID ? std::string( pcID ) : "";
......@@ -2453,11 +2454,18 @@ static PyObject* get_output_muted( PyObject*, PyObject* )
VAPY_CATCH_RETURN;
};
static PyObject* get_global_auralization_mode( PyObject*, PyObject* )
static PyObject* get_global_auralization_mode( PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
{
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "short_mode", NULL };
static _PyArg_Parser _parser = { "|b:get_global_auralization_mode", _keywords, 0 };
bool bShortMode = true;
if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &bShortMode ) )
return NULL;
const int iAM = g_pVANetClient->GetCoreInstance()->GetGlobalAuralizationMode();
const std::string sAM = SaveStringToUnicodeConversion( IVAInterface::GetAuralizationModeStr( iAM ) );
const std::string sAM = SaveStringToUnicodeConversion( IVAInterface::GetAuralizationModeStr( iAM, bShortMode ) );
return PyUnicode_FromString( sAM.c_str() );
......
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