Commit 62889b54 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding more notebook control widgets

parent 01cacdbf
%% Cell type:markdown id: tags:
# VA simple acoustic scene
This is a simple example how to create a simple acoustic scene in VA using Python.
%% 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' )
```
%% Cell type:code id: tags:
``` python
import ipywidgets as widgets
```
%% Cell type:code id: tags:
``` python
import va
```
%% Cell type:markdown id: tags:
### Connect
%% Cell type:code id: tags:
``` python
va.connect();
```
%% Cell type:markdown id: tags:
## Control
%% Cell type:markdown id: tags:
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.is_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
%% 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:
## 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
......
......@@ -16,6 +16,7 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
......@@ -90,7 +91,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"connected = va.is_connected()\n",
......@@ -122,7 +125,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import os\n",
......@@ -151,7 +156,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"vamods = va.enumerate_modules()\n",
......@@ -173,6 +180,18 @@
"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,
......
Supports Markdown
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