add apply

add apply to vbancmd and channel modules.

add apply to readme
This commit is contained in:
onyx-and-iris 2022-03-11 19:21:26 +00:00
parent 127ef1e10f
commit 3e0152082b
3 changed files with 44 additions and 16 deletions

View File

@ -1,6 +1,6 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/onyx-and-iris/vban-cmd-python/blob/dev/LICENSE)
# VBAN CMD
This package offers a Python interface for [Voicemeeter VBAN TEXT](https://vb-audio.com/Voicemeeter/VBANProtocol_Specifications.pdf#page=19) as well as the [Voicemeeter RT Packet Service](https://vb-audio.com/Voicemeeter/VBANProtocol_Specifications.pdf#page=27) which allows a client to send and receive parameter values over a network.
This package offers a Python interface for [Voicemeeter VBAN TEXT](https://vb-audio.com/Voicemeeter/VBANProtocol_Specifications.pdf#page=19) as well as the [Voicemeeter RT Packet Service](https://vb-audio.com/Voicemeeter/VBANProtocol_Specifications.pdf#page=27) which allows a client to send and receive parameter values over a local network.
It may be used standalone or to extend the [Voicemeeter Remote Python API](https://github.com/onyx-and-iris/voicemeeter-api-python)
@ -31,14 +31,6 @@ With development dependencies:
pip install -e .['development']
```
#### Connection:
For sending a text command several configuration options are available:
- `ip`: remote address
- `streamname`: default 'Command1'
- `port`: default 6990
- `channel`: from 0 to 255
- `bps`: bitrate of stream, default 0 should be safe for most cases.
#### Use with a context manager:
It is advised to use this code with a context manager.
Parameter coverage is not as extensive for the RT Packet Service as with the Remote API.
@ -81,9 +73,13 @@ A *kind* specifies a major Voicemeeter version. Currently this encompasses
- `banana`
- `potato`
#### `vbancmd.connect(kind_id, ip=ip) -> '(VbanCmd)'`
Factory function for remotes.
#### `vbancmd.connect(kind_id, **kwargs) -> '(VbanCmd)'`
Factory function for remotes. Keyword arguments include:
- `ip`: remote pc you wish to send requests to.
- `streamname`: default 'Command1'
- `port`: default 6990
- `channel`: from 0 to 255
- `bps`: bitrate of stream, default 0 should be safe for most cases.
### `VbanCmd` (higher level)
@ -106,13 +102,18 @@ Hides Voicemeeter if it's shown. No effect otherwise.
Closes Voicemeeter.
#### `vban.restart()`
Restarts Voicemeeter's audio engine.
#### `vban.sendtext(cmd)`
Sends a TEXT command, for example:
#### `vban.apply(mapping)`
Updates values through a dict.
Example:
```python
# Use ';' or ',' for delimiters.
vban.sendtext('Strip[0].Mute=1;Strip[3].A3=0;Bus[2].Mute=0;Bus[3].Eq.On=1')
vban.apply({
'strip-2': dict(A1=True, B1=True, gain=-6.0),
'bus-2': dict(mute=True),
})
```
### `Strip`
The following properties are gettable and settable:
- `mono`: boolean
@ -150,6 +151,13 @@ Used for updating the RT data packet, used internally by the Interface.
vban.public_packet = vban._get_rt()
```
#### `vban.sendtext(cmd)`
Sends a multi parameter TEXT string command, for example:
```python
# Use ';' or ',' for delimiters.
vban.sendtext('Strip[0].Mute=1;Strip[3].A3=0;Bus[2].Mute=0;Bus[3].Eq.On=1')
```
### `Errors`
- `errors.VMCMDErrors`: Base VMCMD error class.

View File

@ -73,3 +73,10 @@ class Channel(abc.ABC):
def public_packet(self):
""" Returns an RT data packet. """
return self._remote.public_packet
def apply(self, mapping):
""" Sets all parameters of a dict for the strip. """
for key, val in mapping.items():
if not hasattr(self, key):
raise VMCMDErrors(f'Invalid {self.identifier} attribute: {key}')
setattr(self, key, val)

View File

@ -74,7 +74,7 @@ class VbanCmd(abc.ABC):
while self.running:
if self._rt_register_socket in self.ready_to_write:
self._rt_register_socket.sendto(
self._register_rt_header.header + bytes(1), (socket.gethostbyname(self._ip), self._port)
self._register_rt_header.header, (socket.gethostbyname(self._ip), self._port)
)
count = int.from_bytes(self._register_rt_header.framecounter, 'little') + 1
self._register_rt_header.framecounter = count.to_bytes(4, 'little')
@ -185,6 +185,19 @@ class VbanCmd(abc.ABC):
""" Restarts Voicemeeter's audio engine. """
self.set_rt('Command', 'Restart', 1)
def apply(self, mapping: dict):
""" Sets all parameters of a di """
for key, submapping in mapping.items():
obj, index = key.split('-')
if obj in ('strip'):
target = self.strip[int(index)]
elif obj in ('bus'):
target = self.bus[int(index)]
else:
raise ValueError(obj)
target.apply(submapping)
def close(self):
""" sets thread flag, closes sockets """
self.running = False