Skip to content
Snippets Groups Projects

Fix the wheel target, change to stable Python ABI

Merged Pascal Palenda requested to merge fix/wheel-target into develop
13 files
+ 106
295
Compare changes
  • Side-by-side
  • Inline

Files

%% Cell type:markdown id: tags:
# VA core controller
This is an example how to control global VA core functionality
%% Cell type:markdown id: tags:
### Prerequisites
%% Cell type:code id: tags:
``` python
import sys
sys.path.append( '../../Lib/site-packages' )
sys.path.append( '../../dist/Lib/site-packages' )
import ipywidgets as widgets
import va
import VAPython as va
if not va.connect() :
raise 'Could not connect to local VA server'
else :
print( 'Successfully connected, server core version is: ' + va.get_version() )
```
%% Output
Successfully connected, server core version is: VACore v2017.d (debug)
%% Cell type:markdown id: tags:
## Control
%% Cell type:markdown id: tags:
### Output
%% Cell type:markdown id: tags:
#### Mute / unmute
You can mute and unmute the entire audio output by using `set_output_muted` and receive the current setting by `is_output_muted`. The setter uses the optional argument `True` or `False` and will mute the output if no argument is passed.
%% Cell type:code id: tags:
``` python
mute_output_button = widgets.ToggleButton( description = 'Output muted', value = va.get_output_muted() )
def on_mute_button_clicked( b ) :
if b.name == 'value' :
va.set_output_muted( b.new ) # True if toggle button appears 'active'
mute_output_button.observe( on_mute_button_clicked )
display( mute_output_button )
```
%% Output
%% Cell type:markdown id: tags:
#### Gain
The output gain or output volume of VA can be controlled by `set_output_gain` and received by `get_output_gain`. Gains or volumes are defined as a factore between 0 and 1. The same functions also exist for the audio inputs of the sound device.
%% Cell type:code id: tags:
``` python
output_gain_slider = widgets.FloatSlider(
value = va.get_output_gain(),
description = 'Output gain:',
min = 0.0,
max = 1.0,
step = 0.1,
readout = True,
readout_format = '.1f' )
def on_output_gain_changed( s ) :
if s.name == 'value' :
va.set_output_gain( s.new )
output_gain_slider.observe( on_output_gain_changed )
display( output_gain_slider )
```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-d87da51b8000> in <module>()
----> 1 output_gain_slider = widgets.FloatSlider(
2 value = va.get_output_gain(),
3 description = 'Output gain:',
4 min = 0.0,
5 max = 1.0,
NameError: name 'widgets' is not defined
%% Cell type:markdown id: tags:
#### Global auralization mode
The auralization mode is a bundle of flags to control the acoustic phenomena that should be considered during audio rendering. It's purpose is to demonstrate the audibility of certain aspects, like sound source directivity.
Auralization mode can be set globally, but also individually for rendering modules, sources and receivers.
%% Cell type:code id: tags:
``` python
global_am = va.get_global_auralization_mode()
print( global_am )
global_am_long = va.get_global_auralization_mode( False )
print( global_am_long )
```
%% Output
DS, ER, DD, DIR, AA, TV, SC, DIF, NF, DP, SL, TR, AB
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
%% Cell type:markdown id: tags:
### Macros
Macros can be defined to make your life easier. Don't mess around with file pathes too much, use macros. Don't rename output file names for recording and other exported information, use macros. You can test your macros using th method `substitute_macro` (see below), but you don't have to do it yourself. VA will always substitute macros where possible.
%% Cell type:code id: tags:
``` python
print( '$(DefaultHRIR): ' + va.substitute_macro( '$(DefaultHRIR)' ) )
print( '$(ProjectName): ' + va.substitute_macro( '$(ProjectName)' ) )
print( '$(data): ' + va.substitute_macro( '$(data)' ) )
print( '$(big_data_dir): ' + va.substitute_macro( '$(big_data_dir)' ) )
print( '$(conf): ' + va.substitute_macro( '$(conf)' ) )
```
%% Output
$(DefaultHRIR): HRIR\\ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.v17.ir.daff
$(ProjectName): MyVirtualAcousticsProject
$(data): $(data)
$(big_data_dir): C:\\data
$(conf): $(conf)
%% Cell type:markdown id: tags:
### Paths
Using search path is encouraged, as it makes it easier to move from one PC to another. You can get the available search paths and also add new search paths. Paths are always bound to the server PC.
%% Cell type:code id: tags:
``` python
print( va.get_search_paths() )
import os
current_working_dir = os.getcwd()
print( "client working directory: " + current_working_dir )
va.add_search_path( current_working_dir ); # only makes sense if client and server are running on same PC
```
%% Output
{'path_0': 'C:/data', 'path_1': 'C:/dev/VA/VACore/conf', 'path_2': 'C:/dev/VA/VACore/data', 'path_3': 'C:/data/InsideSceneData'}
client working directory: C:\dev\VA\VAPython\examples\jupyter
%% Cell type:markdown id: tags:
### Reset
Use `reset` to reset the entire scene.
%% Cell type:code id: tags:
``` python
reset_button = widgets.Button( description = 'Reset VA server' )
def on_reset_button_clicked( b ) :
va.reset()
reset_button.on_click( on_reset_button_clicked )
display( reset_button )
```
%% Output
%% Cell type:markdown id: tags:
## Modules
You can interact with any registered VA module using a magic struct. In Python, this struct is represented by a (nested) dictionary, that is translated to a VAStruct. This struct can be used to call modules and receive information in return. It is used to change any setting in a registered module. This way, no new interface methods for prototyping have to be added during development and testing.
%% Cell type:code id: tags:
``` python
allmods = va.get_modules()
modnames = list()
for mod in allmods[:] :
modnames.append( mod["name"] )
mods_dropdown_menu = widgets.Dropdown( options=modnames )
mod_call_button = widgets.Button( description = 'Call' )
mod_widget_box = widgets.HBox( [ mods_dropdown_menu, mod_call_button ] )
def on_mod_call( b ) :
mod = allmods[ mods_dropdown_menu.index ]
print( 'Calling ' + mod["name"] )
modnames.append( mod["name"] )
try :
va.call_module( mod["name"], { 'help': True } )
except :
print( 'Module returned an exception, could not get help' )
mod_call_button.on_click( on_mod_call )
display( mod_widget_box )
```
%% Output
Calling BinauralFreeField:MyBinauralFreeField
Module returned an exception, could not get help
Calling VACore
%% Cell type:markdown id: tags:
### Rendering modules
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 id: tags:
``` python
allrendmods = va.get_rendering_modules();
# Dropdown menu
rendmodnames = list()
for mod in allrendmods[:] :
rendmodnames.append( mod["id"] )
rendmods_dropdown_menu = widgets.Dropdown( options=rendmodnames )
# Mute toggle button
rendmod_mute_button = widgets.ToggleButton( description = 'Mute' )
def on_rendmod_mute_button_clicked( b ) :
rendmod = allrendmods[ rendmods_dropdown_menu.index ]
if b.name == 'value' :
va.set_rendering_module_muted( mod["id"], b.new )
rendmod_mute_button.observe( on_rendmod_mute_button_clicked )
# Gain slider
rendmod_gain_slider = widgets.FloatSlider(
value = 1.0,
description = 'Gain:',
min = 0.0,
max = 1.0,
step = 0.1,
readout = True,
readout_format = '.1f' )
def on_rendmod_gain_changed( s ) :
rendmod = allrendmods[ rendmods_dropdown_menu.index ]
if s.name == 'value' :
va.set_rendering_module_gain( rendmod["id"], s.new )
rendmod_gain_slider.observe( on_rendmod_gain_changed )
# Parameter getter
rendmod_button_params = widgets.Button( description = 'Parameters' )
def on_rendmod_parameter( b ) :
rendmod = allrendmods[ rendmods_dropdown_menu.index ]
print( va.get_rendering_module_parameters( rendmod["id"] ) )
rendmod_button_params.on_click( on_rendmod_parameter )
# Horizontal box with widgets
rendmod_widget_box = widgets.HBox( [ rendmods_dropdown_menu, rendmod_mute_button, rendmod_gain_slider, rendmod_button_params ] )
display( rendmod_widget_box )
```
%% Output
%% Cell type:markdown id: tags:
### Reproduction modules
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 id: tags:
``` python
allrepmods = va.get_reproduction_modules();
# Dropdown menu
repmodnames = list()
for mod in allrepmods[:] :
repmodnames.append( mod["id"] )
repmods_dropdown_menu = widgets.Dropdown( options=repmodnames )
# Mute toggle button
repmod_mute_button = widgets.ToggleButton( description = 'Mute' )
def on_repmod_mute_button_clicked( b ) :
repmod = allrepmods[ repmods_dropdown_menu.index ]
if b.name == 'value' :
va.set_reproduction_module_muted( mod["id"], b.new )
repmod_mute_button.observe( on_repmod_mute_button_clicked )
# Gain slider
repmod_gain_slider = widgets.FloatSlider(
value = 1.0,
description = 'Gain:',
min = 0.0,
max = 1.0,
step = 0.1,
readout = True,
readout_format = '.1f' )
def on_repmod_gain_changed( s ) :
repmod = allrepmods[ repmods_dropdown_menu.index ]
if s.name == 'value' :
va.set_reproduction_module_gain( repmod["id"], s.new )
repmod_gain_slider.observe( on_repmod_gain_changed )
# Parameter getter
repmod_button_params = widgets.Button( description = 'Parameters' )
def on_repmod_parameter( b ) :
repmod = allrepmods[ repmods_dropdown_menu.index ]
print( va.get_reproduction_module_parameters( repmod["id"] ) )
repmod_button_params.on_click( on_repmod_parameter )
# Horizontal box with widgets
repmod_widget_box = widgets.HBox( [ repmods_dropdown_menu, repmod_mute_button, repmod_gain_slider, repmod_button_params ] )
display( repmod_widget_box )
```
%% Output
{}
Loading