mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2026-03-18 07:49:10 +00:00
Compare commits
No commits in common. "dev" and "v2.6.0" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -159,5 +159,3 @@ config.toml
|
||||
vban.toml
|
||||
|
||||
.vscode/
|
||||
|
||||
PING_FEATURE.md
|
||||
28
CHANGELOG.md
28
CHANGELOG.md
@ -11,34 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
||||
|
||||
- [x]
|
||||
|
||||
## [2.9.0] - 2026-03-02
|
||||
|
||||
### Added
|
||||
|
||||
- Recorder class, see [Recorder](https://github.com/onyx-and-iris/vban-cmd-python?tab=readme-ov-file#recorder) in README.
|
||||
- Ping/pong implemented. If a pong is not received {VbanCmd}.login() will fail fast. This prevents the rt listener threads from starting up.
|
||||
- It has the added benefit of automatically detecting the type of VBAN server (Voicemeeter or Matrix).
|
||||
- A thread lock around the framecounter to improve thread safety since it can be accessed by both the main thread and the Producer thread.
|
||||
|
||||
|
||||
## [2.7.0] - 2026-03-01
|
||||
|
||||
### Added
|
||||
|
||||
- new kind `matrix` has been added, it does two things:
|
||||
- scales the interface according to `potato` kind, in practice this has no affect but it's required by the builder classes.
|
||||
- disables the rt listener threads since we aren't expecting to receive any from a Matrix VBAN server.
|
||||
- however, matrix responses may still be received with the {VbanCmd}.sendtext() method.
|
||||
|
||||
### Changed
|
||||
|
||||
- `outbound` kwarg has been renamed to `disable_rt_listeners`. Since it's job is to disable the listener threads for incoming RT packets this new name is more descriptive.
|
||||
- dataclasses representing packet headers and packets with ident:0 and ident:1 have been moved into an internal packet module.
|
||||
|
||||
### Removed
|
||||
|
||||
- {VbanCmd}.sendtext() @script decorator removed. It's purpose was to attempt to convert a dictionary to a script but it was poorly implemented and there exists the {VbanCmd}.apply() method already.
|
||||
|
||||
## [2.6.0] - 2026-02-26
|
||||
|
||||
### Added
|
||||
|
||||
78
README.md
78
README.md
@ -8,19 +8,19 @@
|
||||
|
||||
# VBAN CMD
|
||||
|
||||
This python interface allows you to send Voicemeeter/Matrix commands over a network.
|
||||
This python interface allows you to transmit Voicemeeter parameters over a network.
|
||||
|
||||
It offers the same public API as [Voicemeeter Remote Python API](https://github.com/onyx-and-iris/voicemeeter-api-python).
|
||||
It may be used standalone or to extend the [Voicemeeter Remote Python API](https://github.com/onyx-and-iris/voicemeeter-api-python)
|
||||
|
||||
Only the VBAN SERVICE/TEXT subprotocols are supported, there is no support for AUDIO or MIDI in this package.
|
||||
There is no support for audio transfer in this package, only parameters.
|
||||
|
||||
For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
|
||||
|
||||
## Tested against
|
||||
|
||||
- Basic 1.1.2.2
|
||||
- Banana 2.1.2.2
|
||||
- Potato 3.1.2.2
|
||||
- Basic 1.0.8.8
|
||||
- Banana 2.0.6.8
|
||||
- Potato 3.0.2.8
|
||||
|
||||
## Requirements
|
||||
|
||||
@ -29,9 +29,7 @@ For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
|
||||
|
||||
## Installation
|
||||
|
||||
```console
|
||||
pip install vban-cmd
|
||||
```
|
||||
`pip install vban-cmd`
|
||||
|
||||
## `Use`
|
||||
|
||||
@ -41,14 +39,14 @@ Load VBAN connection info from toml config. A valid `vban.toml` might look like
|
||||
|
||||
```toml
|
||||
[connection]
|
||||
host = "localhost"
|
||||
ip = "gamepc.local"
|
||||
port = 6980
|
||||
streamname = "Command1"
|
||||
```
|
||||
|
||||
It should be placed in \<user home directory\> / "Documents" / "Voicemeeter" / "configs"
|
||||
|
||||
Alternatively you may pass `host`, `port`, `streamname` as keyword arguments.
|
||||
Alternatively you may pass `ip`, `port`, `streamname` as keyword arguments.
|
||||
|
||||
#### `__main__.py`
|
||||
|
||||
@ -85,7 +83,7 @@ def main():
|
||||
KIND_ID = 'banana'
|
||||
|
||||
with vban_cmd.api(
|
||||
KIND_ID, host='localhost', port=6980, streamname='Command1'
|
||||
KIND_ID, ip='gamepc.local', port=6980, streamname='Command1'
|
||||
) as vban:
|
||||
do = ManyThings(vban)
|
||||
do.things()
|
||||
@ -115,8 +113,6 @@ Pass the kind of Voicemeeter as an argument. KIND_ID may be:
|
||||
- `banana`
|
||||
- `potato`
|
||||
|
||||
A fourth kind `matrix` has been added, if you pass it as a KIND_ID you are expected to use the [{VbanCmd}.sendtext()](https://github.com/onyx-and-iris/vban-cmd-python?tab=readme-ov-file#vbansendtextscript) method for sending text requests.
|
||||
|
||||
## `Available commands`
|
||||
|
||||
### Strip
|
||||
@ -349,40 +345,6 @@ vban.strip[0].fadeto(-10.3, 1000)
|
||||
vban.bus[3].fadeby(-5.6, 500)
|
||||
```
|
||||
|
||||
### Recorder
|
||||
|
||||
The following methods are available
|
||||
|
||||
- `play()`
|
||||
- `stop()`
|
||||
- `pause()`
|
||||
- `record()`
|
||||
- `ff()`
|
||||
- `rew()`
|
||||
- `load(filepath)`: raw string
|
||||
- `goto(time_string)`: time string in format `hh:mm:ss`
|
||||
|
||||
The following properties are available
|
||||
|
||||
- `samplerate`: int, (22050, 24000, 32000, 44100, 48000, 88200, 96000, 176400, 192000)
|
||||
- `bitresolution`: int, (8, 16, 24, 32)
|
||||
- `channel`: int, from 1 to 8
|
||||
- `kbps`: int, (32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320)
|
||||
- `gain`: float, from -60.0 to 12.0
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
vban.recorder.play()
|
||||
vban.recorder.stop()
|
||||
|
||||
# filepath as raw string
|
||||
vban.recorder.load(r'C:\music\mytune.mp3')
|
||||
|
||||
# set the goto time to 1m 30s
|
||||
vban.recorder.goto('00:01:30')
|
||||
```
|
||||
|
||||
### Command
|
||||
|
||||
Certain 'special' commands are defined by the API as performing actions rather than setting values. The following methods are available:
|
||||
@ -474,7 +436,7 @@ example:
|
||||
import vban_cmd
|
||||
|
||||
opts = {
|
||||
'host': '<ip address>',
|
||||
'ip': '<ip address>',
|
||||
'streamname': 'Command1',
|
||||
'port': 6980,
|
||||
}
|
||||
@ -541,17 +503,15 @@ print(vban.event.get())
|
||||
|
||||
You may pass the following optional keyword arguments:
|
||||
|
||||
- `host`: str='localhost', ip or hostname of remote machine
|
||||
- `ip`: str='localhost', ip or hostname of remote machine
|
||||
- `port`: int=6980, vban udp port of remote machine.
|
||||
- `streamname`: str='Command1', name of the stream to connect to.
|
||||
- `bps`: int=256000, bps rate of the stream.
|
||||
- `channel`: int=0, channel on which to send the UDP requests.
|
||||
- `pdirty`: boolean=False, parameter updates
|
||||
- `ldirty`: boolean=False, level updates
|
||||
- `script_ratelimit`: float | None=None, ratelimit for vban.sendtext() specifically.
|
||||
- `timeout`: int=5, timeout for socket operations.
|
||||
- `disable_rt_listeners`: boolean=False, set `True` if you don't wish to receive RT packets.
|
||||
- You can still send Matrix string requests ending with `?` and receive a response.
|
||||
- `timeout`: int=5, amount of time (seconds) to wait for an incoming RT data packet (parameter states).
|
||||
- `outbound`: boolean=False, set `True` if you are only interested in sending commands. (no rt packets will be received)
|
||||
|
||||
#### `vban.pdirty`
|
||||
|
||||
@ -569,14 +529,6 @@ Sends a script block as a string request, for example:
|
||||
vban.sendtext('Strip[0].Mute=1;Bus[0].Mono=1')
|
||||
```
|
||||
|
||||
You can even use it to send matrix commands:
|
||||
|
||||
```python
|
||||
vban.sendtext('Point(ASIO128.IN[1..4],ASIO128.OUT[1]).dBGain = -3.0')
|
||||
|
||||
vban.sendtext('Command.Version = ?')
|
||||
```
|
||||
|
||||
## Errors
|
||||
|
||||
- `errors.VBANCMDError`: Base VBANCMD Exception class.
|
||||
@ -592,7 +544,7 @@ import vban_cmd
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
opts = {'host': 'localhost', 'port': 6980, 'streamname': 'Command1'}
|
||||
opts = {'ip': 'ip.local', 'port': 6980, 'streamname': 'Command1'}
|
||||
with vban_cmd.api('banana', **opts) as vban:
|
||||
...
|
||||
```
|
||||
|
||||
@ -103,7 +103,7 @@ class App(tk.Tk):
|
||||
def main():
|
||||
KIND_ID = 'banana'
|
||||
conn = {
|
||||
'host': os.environ.get('VBANCMD_HOST', 'localhost'),
|
||||
'ip': os.environ.get('VBANCMD_IP', 'localhost'),
|
||||
'port': int(os.environ.get('VBANCMD_PORT', 6980)),
|
||||
'streamname': os.environ.get('VBANCMD_STREAMNAME', 'Command1'),
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ class Observer:
|
||||
def main():
|
||||
KIND_ID = 'potato'
|
||||
conn = {
|
||||
'host': os.environ.get('VBANCMD_HOST', 'localhost'),
|
||||
'ip': os.environ.get('VBANCMD_IP', 'localhost'),
|
||||
'port': int(os.environ.get('VBANCMD_PORT', 6980)),
|
||||
'streamname': os.environ.get('VBANCMD_STREAMNAME', 'Command1'),
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ class App:
|
||||
def main():
|
||||
KIND_ID = 'banana'
|
||||
conn = {
|
||||
'host': os.environ.get('VBANCMD_HOST', 'localhost'),
|
||||
'ip': os.environ.get('VBANCMD_IP', 'localhost'),
|
||||
'port': int(os.environ.get('VBANCMD_PORT', 6980)),
|
||||
'streamname': os.environ.get('VBANCMD_STREAMNAME', 'Command1'),
|
||||
}
|
||||
|
||||
42
poetry.lock
generated
42
poetry.lock
generated
@ -1,4 +1,4 @@
|
||||
# This file is automatically @generated by Poetry 2.2.1 and should not be changed by hand.
|
||||
# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "cachetools"
|
||||
@ -55,7 +55,7 @@ description = "Backport of PEP 654 (exception groups)"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["dev"]
|
||||
markers = "python_version == \"3.10\""
|
||||
markers = "python_version < \"3.11\""
|
||||
files = [
|
||||
{file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"},
|
||||
{file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"},
|
||||
@ -66,16 +66,21 @@ test = ["pytest (>=6)"]
|
||||
|
||||
[[package]]
|
||||
name = "filelock"
|
||||
version = "3.20.3"
|
||||
version = "3.16.1"
|
||||
description = "A platform independent file lock."
|
||||
optional = false
|
||||
python-versions = ">=3.10"
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "filelock-3.20.3-py3-none-any.whl", hash = "sha256:4b0dda527ee31078689fc205ec4f1c1bf7d56cf88b6dc9426c4f230e46c2dce1"},
|
||||
{file = "filelock-3.20.3.tar.gz", hash = "sha256:18c57ee915c7ec61cff0ecf7f0f869936c7c30191bb0cf406f1341778d0834e1"},
|
||||
{file = "filelock-3.16.1-py3-none-any.whl", hash = "sha256:2082e5703d51fbf98ea75855d9d5527e33d8ff23099bec374a134febee6946b0"},
|
||||
{file = "filelock-3.16.1.tar.gz", hash = "sha256:c249fbfcd5db47e5e2d6d62198e565475ee65e4831e2561c8e313fa7eb961435"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo (>=2024.8.6)", "sphinx (>=8.0.2)", "sphinx-autodoc-typehints (>=2.4.1)"]
|
||||
testing = ["covdefaults (>=2.3)", "coverage (>=7.6.1)", "diff-cover (>=9.2)", "pytest (>=8.3.3)", "pytest-asyncio (>=0.24)", "pytest-cov (>=5)", "pytest-mock (>=3.14)", "pytest-timeout (>=2.3.1)", "virtualenv (>=20.26.4)"]
|
||||
typing = ["typing-extensions (>=4.12.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "iniconfig"
|
||||
version = "2.0.0"
|
||||
@ -238,7 +243,7 @@ description = "A lil' TOML parser"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["main", "dev"]
|
||||
markers = "python_version == \"3.10\""
|
||||
markers = "python_version < \"3.11\""
|
||||
files = [
|
||||
{file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"},
|
||||
{file = "tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6"},
|
||||
@ -304,38 +309,37 @@ test = ["devpi-process (>=1.0.2)", "pytest (>=8.3.3)", "pytest-mock (>=3.14)"]
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.15.0"
|
||||
description = "Backported and Experimental Type Hints for Python 3.9+"
|
||||
version = "4.12.2"
|
||||
description = "Backported and Experimental Type Hints for Python 3.8+"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
markers = "python_version == \"3.10\""
|
||||
markers = "python_version < \"3.11\""
|
||||
files = [
|
||||
{file = "typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"},
|
||||
{file = "typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466"},
|
||||
{file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"},
|
||||
{file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "virtualenv"
|
||||
version = "20.36.1"
|
||||
version = "20.29.0"
|
||||
description = "Virtual Python Environment builder"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "virtualenv-20.36.1-py3-none-any.whl", hash = "sha256:575a8d6b124ef88f6f51d56d656132389f961062a9177016a50e4f507bbcc19f"},
|
||||
{file = "virtualenv-20.36.1.tar.gz", hash = "sha256:8befb5c81842c641f8ee658481e42641c68b5eab3521d8e092d18320902466ba"},
|
||||
{file = "virtualenv-20.29.0-py3-none-any.whl", hash = "sha256:c12311863497992dc4b8644f8ea82d3b35bb7ef8ee82e6630d76d0197c39baf9"},
|
||||
{file = "virtualenv-20.29.0.tar.gz", hash = "sha256:6345e1ff19d4b1296954cee076baaf58ff2a12a84a338c62b02eda39f20aa982"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
distlib = ">=0.3.7,<1"
|
||||
filelock = {version = ">=3.20.1,<4", markers = "python_version >= \"3.10\""}
|
||||
filelock = ">=3.12.2,<4"
|
||||
platformdirs = ">=3.9.1,<5"
|
||||
typing-extensions = {version = ">=4.13.2", markers = "python_version < \"3.11\""}
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2,!=7.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"]
|
||||
test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8) ; platform_python_implementation == \"PyPy\" or platform_python_implementation == \"GraalVM\" or platform_python_implementation == \"CPython\" and sys_platform == \"win32\" and python_version >= \"3.13\"", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10) ; platform_python_implementation == \"CPython\""]
|
||||
test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"]
|
||||
|
||||
[[package]]
|
||||
name = "virtualenv-pyenv"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "vban-cmd"
|
||||
version = "2.10.3"
|
||||
version = "2.6.0"
|
||||
description = "Python interface for the VBAN RT Packet Service (Sendtext)"
|
||||
authors = [{ name = "Onyx and Iris", email = "code@onyxandiris.online" }]
|
||||
license = { text = "MIT" }
|
||||
@ -9,7 +9,7 @@ requires-python = ">=3.10"
|
||||
dependencies = ["tomli (>=2.0.1,<3.0) ; python_version < '3.11'"]
|
||||
|
||||
[tool.poetry.requires-plugins]
|
||||
poethepoet = ">=0.42.0"
|
||||
poethepoet = "^0.35.0"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pytest = "^8.3.4"
|
||||
|
||||
@ -11,7 +11,7 @@ from vban_cmd.kinds import request_kind_map as kindmap
|
||||
KIND_ID = os.environ.get('KIND', 'potato')
|
||||
|
||||
opts = {
|
||||
'host': os.getenv('VBANCMD_HOST', 'localhost'),
|
||||
'ip': os.getenv('VBANCMD_IP', 'localhost'),
|
||||
'streamname': os.getenv('VBANCMD_STREAMNAME', 'Command1'),
|
||||
'port': int(os.getenv('VBANCMD_PORT', 6980)),
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ from typing import Union
|
||||
|
||||
from .enums import NBS, BusModes
|
||||
from .iremote import IRemote
|
||||
from .meta import bus_mode_prop, channel_bool_prop, channel_int_prop, channel_label_prop
|
||||
from .meta import bus_mode_prop, channel_bool_prop, channel_label_prop
|
||||
|
||||
|
||||
class Bus(IRemote):
|
||||
@ -90,9 +90,20 @@ class BusLevel(IRemote):
|
||||
def getter(self):
|
||||
"""Returns a tuple of level values for the channel."""
|
||||
|
||||
def fget(i):
|
||||
return round((((1 << 16) - 1) - i) * -0.01, 1)
|
||||
|
||||
if not self._remote.stopped() and self._remote.event.ldirty:
|
||||
return self._remote.cache['bus_level'][self.range[0] : self.range[-1]]
|
||||
return self.public_packets[NBS.zero].levels.bus[self.range[0] : self.range[-1]]
|
||||
return tuple(
|
||||
fget(i)
|
||||
for i in self._remote.cache['bus_level'][self.range[0] : self.range[-1]]
|
||||
)
|
||||
return tuple(
|
||||
fget(i)
|
||||
for i in self._remote._get_levels(self.public_packets[NBS.zero])[1][
|
||||
self.range[0] : self.range[-1]
|
||||
]
|
||||
)
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
@ -117,49 +128,45 @@ class BusLevel(IRemote):
|
||||
def _make_bus_mode_mixin():
|
||||
"""Creates a mixin of Bus Modes."""
|
||||
|
||||
mode_names = [
|
||||
'normal',
|
||||
'amix',
|
||||
'repeat',
|
||||
'bmix',
|
||||
'composite',
|
||||
'tvmix',
|
||||
'upmix21',
|
||||
'upmix41',
|
||||
'upmix61',
|
||||
'centeronly',
|
||||
'lfeonly',
|
||||
'rearonly',
|
||||
]
|
||||
modestates = {
|
||||
'normal': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
'amix': [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
|
||||
'repeat': [0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2],
|
||||
'bmix': [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3],
|
||||
'composite': [0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0],
|
||||
'tvmix': [1, 0, 1, 4, 5, 4, 5, 0, 1, 0, 1],
|
||||
'upmix21': [0, 2, 2, 4, 4, 6, 6, 0, 0, 2, 2],
|
||||
'upmix41': [1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3],
|
||||
'upmix61': [0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8],
|
||||
'centeronly': [1, 0, 1, 0, 1, 0, 1, 8, 9, 8, 9],
|
||||
'lfeonly': [0, 2, 2, 0, 0, 2, 2, 8, 8, 10, 10],
|
||||
'rearonly': [1, 2, 3, 0, 1, 2, 3, 8, 9, 10, 11],
|
||||
}
|
||||
|
||||
def identifier(self) -> str:
|
||||
return f'bus[{self.index}].mode'
|
||||
|
||||
def get(self):
|
||||
"""Get current bus mode using ChannelState for clean bit extraction."""
|
||||
mode_cache_items = [
|
||||
(k, v)
|
||||
for k, v in self._remote.cache.items()
|
||||
if k.startswith(f'{self.identifier}.') and v == 1
|
||||
states = [
|
||||
(
|
||||
int.from_bytes(
|
||||
self.public_packets[NBS.zero].busstate[self.index], 'little'
|
||||
)
|
||||
& val
|
||||
)
|
||||
>> 4
|
||||
for val in self._modes.modevals
|
||||
]
|
||||
|
||||
if mode_cache_items:
|
||||
latest_cached = mode_cache_items[-1][0]
|
||||
mode_name = latest_cached.split('.')[-1]
|
||||
return mode_name
|
||||
|
||||
bus_state = self.public_packets[NBS.zero].states.bus[self.index]
|
||||
|
||||
# Extract bus mode from bits 4-7 (mask 0xF0, shift right by 4)
|
||||
mode_value = (bus_state._state & 0x000000F0) >> 4
|
||||
|
||||
return mode_names[mode_value] if mode_value < len(mode_names) else 'normal'
|
||||
for k, v in modestates.items():
|
||||
if states == v:
|
||||
return k
|
||||
|
||||
return type(
|
||||
'BusModeMixin',
|
||||
(IRemote,),
|
||||
{
|
||||
'identifier': property(identifier),
|
||||
'modestates': modestates,
|
||||
**{mode.name: bus_mode_prop(mode.name) for mode in BusModes},
|
||||
'get': get,
|
||||
},
|
||||
@ -181,8 +188,7 @@ def bus_factory(phys_bus, remote, i) -> Union[PhysicalBus, VirtualBus]:
|
||||
'eq': BusEQ.make(remote, i),
|
||||
'levels': BusLevel(remote, i),
|
||||
'mode': BUSMODEMIXIN_cls(remote, i),
|
||||
**{param: channel_bool_prop(param) for param in ('mute',)},
|
||||
**{param: channel_int_prop(param) for param in ('mono',)},
|
||||
**{param: channel_bool_prop(param) for param in ['mute', 'mono']},
|
||||
'label': channel_label_prop(),
|
||||
},
|
||||
)(remote, i)
|
||||
|
||||
@ -1,18 +1,6 @@
|
||||
from .packet.enums import ServiceTypes, SubProtocols
|
||||
|
||||
|
||||
class VBANCMDError(Exception):
|
||||
"""Base VBANCMD Exception class."""
|
||||
|
||||
|
||||
class VBANCMDConnectionError(VBANCMDError):
|
||||
"""Exception raised when connection/timeout errors occur"""
|
||||
|
||||
|
||||
class VBANCMDPacketError(VBANCMDError):
|
||||
"""Exception raised when packet parsing errors occur"""
|
||||
|
||||
def __init__(self, message: str, protocol: SubProtocols, type_: ServiceTypes):
|
||||
super().__init__(message)
|
||||
self.protocol = protocol
|
||||
self.type = type_
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import abc
|
||||
import logging
|
||||
from enum import IntEnum
|
||||
from functools import cached_property
|
||||
@ -10,7 +11,6 @@ from .error import VBANCMDError
|
||||
from .kinds import KindMapClass
|
||||
from .kinds import request_kind_map as kindmap
|
||||
from .macrobutton import MacroButton
|
||||
from .recorder import Recorder
|
||||
from .strip import request_strip_obj as strip
|
||||
from .vban import request_vban_obj as vban
|
||||
from .vbancmd import VbanCmd
|
||||
@ -26,7 +26,7 @@ class FactoryBuilder:
|
||||
"""
|
||||
|
||||
BuilderProgress = IntEnum(
|
||||
'BuilderProgress', 'strip bus command macrobutton vban recorder', start=0
|
||||
'BuilderProgress', 'strip bus command macrobutton vban', start=0
|
||||
)
|
||||
|
||||
def __init__(self, factory, kind: KindMapClass):
|
||||
@ -38,7 +38,6 @@ class FactoryBuilder:
|
||||
f'Finished building commands for {self._factory}',
|
||||
f'Finished building macrobuttons for {self._factory}',
|
||||
f'Finished building vban in/out streams for {self._factory}',
|
||||
f'Finished building recorder for {self._factory}',
|
||||
)
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
@ -73,30 +72,24 @@ class FactoryBuilder:
|
||||
self._factory.vban = vban(self._factory)
|
||||
return self
|
||||
|
||||
def make_recorder(self):
|
||||
self._factory.recorder = Recorder.make(self._factory)
|
||||
return self
|
||||
|
||||
|
||||
class FactoryBase(VbanCmd):
|
||||
"""Base class for factories, subclasses VbanCmd."""
|
||||
|
||||
def __init__(self, kind_id: str, **kwargs):
|
||||
defaultkwargs = {
|
||||
'host': 'localhost',
|
||||
'ip': 'localhost',
|
||||
'port': 6980,
|
||||
'streamname': 'Command1',
|
||||
'bps': 256000,
|
||||
'channel': 0,
|
||||
'script_ratelimit': None, # if None or 0, no rate limit applied to script commands
|
||||
'timeout': 5, # timeout on socket operations, in seconds
|
||||
'disable_rt_listeners': False,
|
||||
'ratelimit': 0.01,
|
||||
'timeout': 5,
|
||||
'outbound': False,
|
||||
'sync': False,
|
||||
'pdirty': False,
|
||||
'ldirty': False,
|
||||
}
|
||||
if 'ip' in kwargs:
|
||||
defaultkwargs['host'] = kwargs.pop('ip') # for backwards compatibility
|
||||
if 'subs' in kwargs:
|
||||
defaultkwargs |= kwargs.pop('subs') # for backwards compatibility
|
||||
kwargs = defaultkwargs | kwargs
|
||||
@ -121,6 +114,11 @@ class FactoryBase(VbanCmd):
|
||||
+ f"({self.kind}, ip='{self.ip}', port={self.port}, streamname='{self.streamname}')"
|
||||
)
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def steps(self):
|
||||
pass
|
||||
|
||||
@cached_property
|
||||
def configs(self):
|
||||
self._configs = configs(self.kind.name)
|
||||
@ -168,7 +166,7 @@ class BananaFactory(FactoryBase):
|
||||
@property
|
||||
def steps(self) -> Iterable:
|
||||
"""steps required to build the interface for a kind"""
|
||||
return self._steps + (self.builder.make_recorder,)
|
||||
return self._steps
|
||||
|
||||
|
||||
class PotatoFactory(FactoryBase):
|
||||
@ -190,7 +188,7 @@ class PotatoFactory(FactoryBase):
|
||||
@property
|
||||
def steps(self) -> Iterable:
|
||||
"""steps required to build the interface for a kind"""
|
||||
return self._steps + (self.builder.make_recorder,)
|
||||
return self._steps
|
||||
|
||||
|
||||
def vbancmd_factory(kind_id: str, **kwargs) -> VbanCmd:
|
||||
@ -204,13 +202,7 @@ def vbancmd_factory(kind_id: str, **kwargs) -> VbanCmd:
|
||||
_factory = BasicFactory
|
||||
case 'banana':
|
||||
_factory = BananaFactory
|
||||
case 'potato' | 'matrix':
|
||||
# matrix is a special kind where:
|
||||
# - we don't need to scale the interface with the builder (in other words kind is arbitrary).
|
||||
# - we don't ever need to use real-time listeners, so we disable them to avoid confusion
|
||||
if kind_id == 'matrix':
|
||||
kwargs['disable_rt_listeners'] = True
|
||||
kind_id = 'potato'
|
||||
case 'potato':
|
||||
_factory = PotatoFactory
|
||||
case _:
|
||||
raise ValueError(f"Unknown Voicemeeter kind '{kind_id}'")
|
||||
|
||||
@ -1,9 +1,83 @@
|
||||
import abc
|
||||
import logging
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Modes:
|
||||
"""Channel Modes"""
|
||||
|
||||
_mute: hex = 0x00000001
|
||||
_solo: hex = 0x00000002
|
||||
_mono: hex = 0x00000004
|
||||
_mc: hex = 0x00000008
|
||||
|
||||
_amix: hex = 0x00000010
|
||||
_repeat: hex = 0x00000020
|
||||
_bmix: hex = 0x00000030
|
||||
_composite: hex = 0x00000040
|
||||
_tvmix: hex = 0x00000050
|
||||
_upmix21: hex = 0x00000060
|
||||
_upmix41: hex = 0x00000070
|
||||
_upmix61: hex = 0x00000080
|
||||
_centeronly: hex = 0x00000090
|
||||
_lfeonly: hex = 0x000000A0
|
||||
_rearonly: hex = 0x000000B0
|
||||
|
||||
_mask: hex = 0x000000F0
|
||||
|
||||
_on: hex = 0x00000100 # eq.on
|
||||
_cross: hex = 0x00000200
|
||||
_ab: hex = 0x00000800 # eq.ab
|
||||
|
||||
_busa: hex = 0x00001000
|
||||
_busa1: hex = 0x00001000
|
||||
_busa2: hex = 0x00002000
|
||||
_busa3: hex = 0x00004000
|
||||
_busa4: hex = 0x00008000
|
||||
_busa5: hex = 0x00080000
|
||||
|
||||
_busb: hex = 0x00010000
|
||||
_busb1: hex = 0x00010000
|
||||
_busb2: hex = 0x00020000
|
||||
_busb3: hex = 0x00040000
|
||||
|
||||
_pan0: hex = 0x00000000
|
||||
_pancolor: hex = 0x00100000
|
||||
_panmod: hex = 0x00200000
|
||||
_panmask: hex = 0x00F00000
|
||||
|
||||
_postfx_r: hex = 0x01000000
|
||||
_postfx_d: hex = 0x02000000
|
||||
_postfx1: hex = 0x04000000
|
||||
_postfx2: hex = 0x08000000
|
||||
|
||||
_sel: hex = 0x10000000
|
||||
_monitor: hex = 0x20000000
|
||||
|
||||
@property
|
||||
def modevals(self):
|
||||
return (
|
||||
val
|
||||
for val in [
|
||||
self._amix,
|
||||
self._repeat,
|
||||
self._bmix,
|
||||
self._composite,
|
||||
self._tvmix,
|
||||
self._upmix21,
|
||||
self._upmix41,
|
||||
self._upmix61,
|
||||
self._centeronly,
|
||||
self._lfeonly,
|
||||
self._rearonly,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class IRemote(abc.ABC):
|
||||
"""
|
||||
Common interface between base class and extended (higher) classes
|
||||
@ -15,6 +89,7 @@ class IRemote(abc.ABC):
|
||||
self._remote = remote
|
||||
self.index = index
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
self._modes = Modes()
|
||||
|
||||
def getter(self, param):
|
||||
cmd = self._cmd(param)
|
||||
@ -50,16 +125,27 @@ class IRemote(abc.ABC):
|
||||
|
||||
def fget(attr, val):
|
||||
if attr == 'mode':
|
||||
return (getattr(self, attr), val, 1)
|
||||
return (self, attr, val)
|
||||
return (f'mode.{val}', 1)
|
||||
elif attr == 'knob':
|
||||
return ('', val)
|
||||
return (attr, val)
|
||||
|
||||
for attr, val in data.items():
|
||||
if not isinstance(val, dict):
|
||||
if attr in dir(self): # avoid calling getattr (with hasattr)
|
||||
target, attr, val = fget(attr, val)
|
||||
setattr(target, attr, val)
|
||||
else:
|
||||
self.logger.error(f'invalid attribute {attr} for {self}')
|
||||
attr, val = fget(attr, val)
|
||||
if isinstance(val, bool):
|
||||
val = 1 if val else 0
|
||||
|
||||
self._remote.cache[self._cmd(attr)] = val
|
||||
self._remote._script += f'{self._cmd(attr)}={val};'
|
||||
else:
|
||||
target = getattr(self, attr)
|
||||
target.apply(val)
|
||||
|
||||
self._remote.sendtext(self._remote._script)
|
||||
return self
|
||||
|
||||
def then_wait(self):
|
||||
self._remote._script = str()
|
||||
time.sleep(self._remote.DELAY)
|
||||
|
||||
101
vban_cmd/meta.py
101
vban_cmd/meta.py
@ -1,8 +1,7 @@
|
||||
from functools import partial
|
||||
|
||||
from .enums import NBS, BusModes
|
||||
from .packet.enums import ChannelModes
|
||||
from .util import cache_bool, cache_float, cache_int, cache_string
|
||||
from .enums import NBS
|
||||
from .util import cache_bool, cache_float, cache_string
|
||||
|
||||
|
||||
def channel_bool_prop(param):
|
||||
@ -12,23 +11,17 @@ def channel_bool_prop(param):
|
||||
def fget(self):
|
||||
cmd = self._cmd(param)
|
||||
self.logger.debug(f'getter: {cmd}')
|
||||
|
||||
states = self.public_packets[NBS.zero].states
|
||||
channel_states = (
|
||||
states.strip if 'strip' in type(self).__name__.lower() else states.bus
|
||||
return (
|
||||
not int.from_bytes(
|
||||
getattr(
|
||||
self.public_packets[NBS.zero],
|
||||
f'{"strip" if "strip" in type(self).__name__.lower() else "bus"}state',
|
||||
)[self.index],
|
||||
'little',
|
||||
)
|
||||
& getattr(self._modes, f'_{param.lower()}')
|
||||
== 0
|
||||
)
|
||||
channel_state = channel_states[self.index]
|
||||
|
||||
if param.lower() == 'mute':
|
||||
return channel_state.mute
|
||||
elif param.lower() == 'solo':
|
||||
return channel_state.solo
|
||||
elif param.lower() == 'mono':
|
||||
return channel_state.mono
|
||||
elif param.lower() == 'mc':
|
||||
return channel_state.mc
|
||||
else:
|
||||
return channel_state.get_mode(getattr(ChannelModes, param.upper()).value)
|
||||
|
||||
def fset(self, val):
|
||||
self.setter(param, 1 if val else 0)
|
||||
@ -36,48 +29,18 @@ def channel_bool_prop(param):
|
||||
return property(fget, fset)
|
||||
|
||||
|
||||
def channel_int_prop(param):
|
||||
"""meta function for channel integer parameters"""
|
||||
|
||||
@partial(cache_int, param=param)
|
||||
def fget(self):
|
||||
cmd = self._cmd(param)
|
||||
self.logger.debug(f'getter: {cmd}')
|
||||
|
||||
states = self.public_packets[NBS.zero].states
|
||||
channel_states = (
|
||||
states.strip if 'strip' in type(self).__name__.lower() else states.bus
|
||||
)
|
||||
channel_state = channel_states[self.index]
|
||||
|
||||
# Special case: bus mono is an integer (0-2) encoded using bits 2 and 9
|
||||
if param.lower() == 'mono' and 'bus' in type(self).__name__.lower():
|
||||
bit_2 = (channel_state._state >> 2) & 1
|
||||
bit_9 = (channel_state._state >> 9) & 1
|
||||
return (bit_9 << 1) | bit_2
|
||||
else:
|
||||
return channel_state.get_mode_int(
|
||||
getattr(ChannelModes, param.upper()).value
|
||||
)
|
||||
|
||||
def fset(self, val):
|
||||
self.setter(param, val)
|
||||
|
||||
return property(fget, fset)
|
||||
|
||||
|
||||
def channel_label_prop():
|
||||
"""meta function for channel label parameters"""
|
||||
|
||||
@partial(cache_string, param='label')
|
||||
def fget(self) -> str:
|
||||
if 'strip' in type(self).__name__.lower():
|
||||
return self.public_packets[NBS.zero].labels.strip[self.index]
|
||||
else:
|
||||
return self.public_packets[NBS.zero].labels.bus[self.index]
|
||||
return getattr(
|
||||
self.public_packets[NBS.zero],
|
||||
f'{"strip" if "strip" in type(self).__name__.lower() else "bus"}labels',
|
||||
)[self.index]
|
||||
|
||||
def fset(self, val: str):
|
||||
self.setter('label', f'"{val}"')
|
||||
self.setter('label', str(val))
|
||||
|
||||
return property(fget, fset)
|
||||
|
||||
@ -89,10 +52,13 @@ def strip_output_prop(param):
|
||||
def fget(self):
|
||||
cmd = self._cmd(param)
|
||||
self.logger.debug(f'getter: {cmd}')
|
||||
|
||||
strip_state = self.public_packets[NBS.zero].states.strip[self.index]
|
||||
|
||||
return strip_state.get_mode(getattr(ChannelModes, f'BUS{param.upper()}').value)
|
||||
return (
|
||||
not int.from_bytes(
|
||||
self.public_packets[NBS.zero].stripstate[self.index], 'little'
|
||||
)
|
||||
& getattr(self._modes, f'_bus{param.lower()}')
|
||||
== 0
|
||||
)
|
||||
|
||||
def fset(self, val):
|
||||
self.setter(param, 1 if val else 0)
|
||||
@ -107,15 +73,16 @@ def bus_mode_prop(param):
|
||||
def fget(self):
|
||||
cmd = self._cmd(param)
|
||||
self.logger.debug(f'getter: {cmd}')
|
||||
|
||||
bus_state = self.public_packets[NBS.zero].states.bus[self.index]
|
||||
|
||||
# Extract current bus mode from bits 4-7
|
||||
current_mode = (bus_state._state & 0x000000F0) >> 4
|
||||
|
||||
expected_mode = getattr(BusModes, param.lower())
|
||||
|
||||
return current_mode == expected_mode
|
||||
return [
|
||||
(
|
||||
int.from_bytes(
|
||||
self.public_packets[NBS.zero].busstate[self.index], 'little'
|
||||
)
|
||||
& val
|
||||
)
|
||||
>> 4
|
||||
for val in self._modes.modevals
|
||||
] == self.modestates[param]
|
||||
|
||||
def fset(self, val):
|
||||
self.setter(param, 1 if val else 0)
|
||||
|
||||
697
vban_cmd/packet.py
Normal file
697
vban_cmd/packet.py
Normal file
@ -0,0 +1,697 @@
|
||||
import struct
|
||||
from dataclasses import dataclass
|
||||
from typing import NamedTuple
|
||||
|
||||
from .enums import NBS
|
||||
from .kinds import KindMapClass
|
||||
from .util import comp
|
||||
|
||||
VBAN_PROTOCOL_TXT = 0x40
|
||||
VBAN_PROTOCOL_SERVICE = 0x60
|
||||
|
||||
VBAN_SERVICE_RTPACKETREGISTER = 32
|
||||
VBAN_SERVICE_RTPACKET = 33
|
||||
VBAN_SERVICE_MASK = 0xE0
|
||||
|
||||
MAX_PACKET_SIZE = 1436
|
||||
HEADER_SIZE = 4 + 1 + 1 + 1 + 1 + 16
|
||||
VMPARAMSTRIP_SIZE = 174
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRtPacket:
|
||||
"""Represents the body of a VBAN RT data packet"""
|
||||
|
||||
nbs: NBS
|
||||
_kind: KindMapClass
|
||||
_voicemeeterType: bytes
|
||||
_reserved: bytes
|
||||
_buffersize: bytes
|
||||
_voicemeeterVersion: bytes
|
||||
_optionBits: bytes
|
||||
_samplerate: bytes
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRtPacketNBS0(VbanRtPacket):
|
||||
"""Represents the body of a VBAN RT data packet with NBS 0"""
|
||||
|
||||
_inputLeveldB100: bytes
|
||||
_outputLeveldB100: bytes
|
||||
_TransportBit: bytes
|
||||
_stripState: bytes
|
||||
_busState: bytes
|
||||
_stripGaindB100Layer1: bytes
|
||||
_stripGaindB100Layer2: bytes
|
||||
_stripGaindB100Layer3: bytes
|
||||
_stripGaindB100Layer4: bytes
|
||||
_stripGaindB100Layer5: bytes
|
||||
_stripGaindB100Layer6: bytes
|
||||
_stripGaindB100Layer7: bytes
|
||||
_stripGaindB100Layer8: bytes
|
||||
_busGaindB100: bytes
|
||||
_stripLabelUTF8c60: bytes
|
||||
_busLabelUTF8c60: bytes
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, nbs: NBS, kind: KindMapClass, data: bytes):
|
||||
return cls(
|
||||
nbs=nbs,
|
||||
_kind=kind,
|
||||
_voicemeeterType=data[28:29],
|
||||
_reserved=data[29:30],
|
||||
_buffersize=data[30:32],
|
||||
_voicemeeterVersion=data[32:36],
|
||||
_optionBits=data[36:40],
|
||||
_samplerate=data[40:44],
|
||||
_inputLeveldB100=data[44:112],
|
||||
_outputLeveldB100=data[112:240],
|
||||
_TransportBit=data[240:244],
|
||||
_stripState=data[244:276],
|
||||
_busState=data[276:308],
|
||||
_stripGaindB100Layer1=data[308:324],
|
||||
_stripGaindB100Layer2=data[324:340],
|
||||
_stripGaindB100Layer3=data[340:356],
|
||||
_stripGaindB100Layer4=data[356:372],
|
||||
_stripGaindB100Layer5=data[372:388],
|
||||
_stripGaindB100Layer6=data[388:404],
|
||||
_stripGaindB100Layer7=data[404:420],
|
||||
_stripGaindB100Layer8=data[420:436],
|
||||
_busGaindB100=data[436:452],
|
||||
_stripLabelUTF8c60=data[452:932],
|
||||
_busLabelUTF8c60=data[932:1412],
|
||||
)
|
||||
|
||||
def _generate_levels(self, levelarray) -> tuple:
|
||||
return tuple(
|
||||
int.from_bytes(levelarray[i : i + 2], 'little')
|
||||
for i in range(0, len(levelarray), 2)
|
||||
)
|
||||
|
||||
@property
|
||||
def strip_levels(self):
|
||||
return self._generate_levels(self._inputLeveldB100)
|
||||
|
||||
@property
|
||||
def bus_levels(self):
|
||||
return self._generate_levels(self._outputLeveldB100)
|
||||
|
||||
def pdirty(self, other) -> bool:
|
||||
"""True iff any defined parameter has changed"""
|
||||
|
||||
return not (
|
||||
self._stripState == other._stripState
|
||||
and self._busState == other._busState
|
||||
and self._stripGaindB100Layer1 == other._stripGaindB100Layer1
|
||||
and self._stripGaindB100Layer2 == other._stripGaindB100Layer2
|
||||
and self._stripGaindB100Layer3 == other._stripGaindB100Layer3
|
||||
and self._stripGaindB100Layer4 == other._stripGaindB100Layer4
|
||||
and self._stripGaindB100Layer5 == other._stripGaindB100Layer5
|
||||
and self._stripGaindB100Layer6 == other._stripGaindB100Layer6
|
||||
and self._stripGaindB100Layer7 == other._stripGaindB100Layer7
|
||||
and self._stripGaindB100Layer8 == other._stripGaindB100Layer8
|
||||
and self._busGaindB100 == other._busGaindB100
|
||||
and self._stripLabelUTF8c60 == other._stripLabelUTF8c60
|
||||
and self._busLabelUTF8c60 == other._busLabelUTF8c60
|
||||
)
|
||||
|
||||
def ldirty(self, strip_cache, bus_cache) -> bool:
|
||||
self._strip_comp, self._bus_comp = (
|
||||
tuple(not val for val in comp(strip_cache, self.strip_levels)),
|
||||
tuple(not val for val in comp(bus_cache, self.bus_levels)),
|
||||
)
|
||||
return any(any(li) for li in (self._strip_comp, self._bus_comp))
|
||||
|
||||
@property
|
||||
def voicemeetertype(self) -> str:
|
||||
"""returns voicemeeter type as a string"""
|
||||
type_ = ('basic', 'banana', 'potato')
|
||||
return type_[int.from_bytes(self._voicemeeterType, 'little') - 1]
|
||||
|
||||
@property
|
||||
def voicemeeterversion(self) -> tuple:
|
||||
"""returns voicemeeter version as a tuple"""
|
||||
return tuple(
|
||||
reversed(
|
||||
tuple(
|
||||
int.from_bytes(self._voicemeeterVersion[i : i + 1], 'little')
|
||||
for i in range(4)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def samplerate(self) -> int:
|
||||
"""returns samplerate as an int"""
|
||||
return int.from_bytes(self._samplerate, 'little')
|
||||
|
||||
@property
|
||||
def inputlevels(self) -> tuple:
|
||||
"""returns the entire level array across all inputs for a kind"""
|
||||
return self.strip_levels[0 : self._kind.num_strip_levels]
|
||||
|
||||
@property
|
||||
def outputlevels(self) -> tuple:
|
||||
"""returns the entire level array across all outputs for a kind"""
|
||||
return self.bus_levels[0 : self._kind.num_bus_levels]
|
||||
|
||||
@property
|
||||
def stripstate(self) -> tuple:
|
||||
"""returns tuple of strip states accessable through bit modes"""
|
||||
return tuple(self._stripState[i : i + 4] for i in range(0, 32, 4))
|
||||
|
||||
@property
|
||||
def busstate(self) -> tuple:
|
||||
"""returns tuple of bus states accessable through bit modes"""
|
||||
return tuple(self._busState[i : i + 4] for i in range(0, 32, 4))
|
||||
|
||||
"""
|
||||
these functions return an array of gainlayers[i] across all strips
|
||||
ie stripgainlayer1 = [strip[0].gainlayer[0], strip[1].gainlayer[0], strip[2].gainlayer[0]...]
|
||||
"""
|
||||
|
||||
@property
|
||||
def gainlayers(self) -> tuple:
|
||||
"""returns tuple of all strip gain layers as tuples"""
|
||||
return tuple(
|
||||
tuple(
|
||||
round(
|
||||
int.from_bytes(
|
||||
getattr(self, f'_stripGaindB100Layer{layer}')[i : i + 2],
|
||||
'little',
|
||||
signed=True,
|
||||
)
|
||||
* 0.01,
|
||||
2,
|
||||
)
|
||||
for i in range(0, 16, 2)
|
||||
)
|
||||
for layer in range(1, 9)
|
||||
)
|
||||
|
||||
@property
|
||||
def busgain(self) -> tuple:
|
||||
"""returns tuple of bus gains"""
|
||||
return tuple(
|
||||
round(
|
||||
int.from_bytes(self._busGaindB100[i : i + 2], 'little', signed=True)
|
||||
* 0.01,
|
||||
2,
|
||||
)
|
||||
for i in range(0, 16, 2)
|
||||
)
|
||||
|
||||
@property
|
||||
def striplabels(self) -> tuple:
|
||||
"""returns tuple of strip labels"""
|
||||
return tuple(
|
||||
self._stripLabelUTF8c60[i : i + 60].decode().split('\x00')[0]
|
||||
for i in range(0, 480, 60)
|
||||
)
|
||||
|
||||
@property
|
||||
def buslabels(self) -> tuple:
|
||||
"""returns tuple of bus labels"""
|
||||
return tuple(
|
||||
self._busLabelUTF8c60[i : i + 60].decode().split('\x00')[0]
|
||||
for i in range(0, 480, 60)
|
||||
)
|
||||
|
||||
|
||||
class Audibility(NamedTuple):
|
||||
knob: float
|
||||
comp: float
|
||||
gate: float
|
||||
denoiser: float
|
||||
|
||||
|
||||
class Positions(NamedTuple):
|
||||
pan_x: float
|
||||
pan_y: float
|
||||
color_x: float
|
||||
color_y: float
|
||||
fx1: float
|
||||
fx2: float
|
||||
|
||||
|
||||
class EqGains(NamedTuple):
|
||||
bass: float
|
||||
mid: float
|
||||
treble: float
|
||||
|
||||
|
||||
class ParametricEQSettings(NamedTuple):
|
||||
on: bool
|
||||
type: int
|
||||
gain: float
|
||||
freq: float
|
||||
q: float
|
||||
|
||||
|
||||
class Sends(NamedTuple):
|
||||
reverb: float
|
||||
delay: float
|
||||
fx1: float
|
||||
fx2: float
|
||||
|
||||
|
||||
class CompressorSettings(NamedTuple):
|
||||
gain_in: float
|
||||
attack_ms: float
|
||||
release_ms: float
|
||||
n_knee: float
|
||||
ratio: float
|
||||
threshold: float
|
||||
c_enabled: bool
|
||||
makeup: bool
|
||||
gain_out: float
|
||||
|
||||
|
||||
class GateSettings(NamedTuple):
|
||||
threshold_in: float
|
||||
damping_max: float
|
||||
bp_sidechain: bool
|
||||
attack_ms: float
|
||||
hold_ms: float
|
||||
release_ms: float
|
||||
|
||||
|
||||
class DenoiserSettings(NamedTuple):
|
||||
threshold: float
|
||||
|
||||
|
||||
class PitchSettings(NamedTuple):
|
||||
enabled: bool
|
||||
dry_wet: float
|
||||
value: float
|
||||
formant_lo: float
|
||||
formant_med: float
|
||||
formant_high: float
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanVMParamStrip:
|
||||
"""Represents the VBAN_VMPARAMSTRIP_PACKET structure"""
|
||||
|
||||
_mode: bytes
|
||||
_dblevel: bytes
|
||||
_audibility: bytes
|
||||
_pos3D_x: bytes
|
||||
_pos3D_y: bytes
|
||||
_posColor_x: bytes
|
||||
_posColor_y: bytes
|
||||
_EQgain1: bytes
|
||||
_EQgain2: bytes
|
||||
_EQgain3: bytes
|
||||
|
||||
# First channel parametric EQ
|
||||
_PEQ_eqOn: bytes
|
||||
_PEQ_eqtype: bytes
|
||||
_PEQ_eqgain: bytes
|
||||
_PEQ_eqfreq: bytes
|
||||
_PEQ_eqq: bytes
|
||||
|
||||
_audibility_c: bytes
|
||||
_audibility_g: bytes
|
||||
_audibility_d: bytes
|
||||
_posMod_x: bytes
|
||||
_posMod_y: bytes
|
||||
_send_reverb: bytes
|
||||
_send_delay: bytes
|
||||
_send_fx1: bytes
|
||||
_send_fx2: bytes
|
||||
_dblimit: bytes
|
||||
_nKaraoke: bytes
|
||||
|
||||
_COMP_gain_in: bytes
|
||||
_COMP_attack_ms: bytes
|
||||
_COMP_release_ms: bytes
|
||||
_COMP_n_knee: bytes
|
||||
_COMP_comprate: bytes
|
||||
_COMP_threshold: bytes
|
||||
_COMP_c_enabled: bytes
|
||||
_COMP_c_auto: bytes
|
||||
_COMP_gain_out: bytes
|
||||
|
||||
_GATE_dBThreshold_in: bytes
|
||||
_GATE_dBDamping_max: bytes
|
||||
_GATE_BP_Sidechain: bytes
|
||||
_GATE_attack_ms: bytes
|
||||
_GATE_hold_ms: bytes
|
||||
_GATE_release_ms: bytes
|
||||
|
||||
_DenoiserThreshold: bytes
|
||||
_PitchEnabled: bytes
|
||||
_Pitch_DryWet: bytes
|
||||
_Pitch_Value: bytes
|
||||
_Pitch_formant_lo: bytes
|
||||
_Pitch_formant_med: bytes
|
||||
_Pitch_formant_high: bytes
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes):
|
||||
return cls(
|
||||
_mode=data[0:4],
|
||||
_dblevel=data[4:8],
|
||||
_audibility=data[8:10],
|
||||
_pos3D_x=data[10:12],
|
||||
_pos3D_y=data[12:14],
|
||||
_posColor_x=data[14:16],
|
||||
_posColor_y=data[16:18],
|
||||
_EQgain1=data[18:20],
|
||||
_EQgain2=data[20:22],
|
||||
_EQgain3=data[22:24],
|
||||
_PEQ_eqOn=data[24:30],
|
||||
_PEQ_eqtype=data[30:36],
|
||||
_PEQ_eqgain=data[36:60],
|
||||
_PEQ_eqfreq=data[60:84],
|
||||
_PEQ_eqq=data[84:108],
|
||||
_audibility_c=data[108:110],
|
||||
_audibility_g=data[110:112],
|
||||
_audibility_d=data[112:114],
|
||||
_posMod_x=data[114:116],
|
||||
_posMod_y=data[116:118],
|
||||
_send_reverb=data[118:120],
|
||||
_send_delay=data[120:122],
|
||||
_send_fx1=data[122:124],
|
||||
_send_fx2=data[124:126],
|
||||
_dblimit=data[126:128],
|
||||
_nKaraoke=data[128:130],
|
||||
_COMP_gain_in=data[130:132],
|
||||
_COMP_attack_ms=data[132:134],
|
||||
_COMP_release_ms=data[134:136],
|
||||
_COMP_n_knee=data[136:138],
|
||||
_COMP_comprate=data[138:140],
|
||||
_COMP_threshold=data[140:142],
|
||||
_COMP_c_enabled=data[142:144],
|
||||
_COMP_c_auto=data[144:146],
|
||||
_COMP_gain_out=data[146:148],
|
||||
_GATE_dBThreshold_in=data[148:150],
|
||||
_GATE_dBDamping_max=data[150:152],
|
||||
_GATE_BP_Sidechain=data[152:154],
|
||||
_GATE_attack_ms=data[154:156],
|
||||
_GATE_hold_ms=data[156:158],
|
||||
_GATE_release_ms=data[158:160],
|
||||
_DenoiserThreshold=data[160:162],
|
||||
_PitchEnabled=data[162:164],
|
||||
_Pitch_DryWet=data[164:166],
|
||||
_Pitch_Value=data[166:168],
|
||||
_Pitch_formant_lo=data[168:170],
|
||||
_Pitch_formant_med=data[170:172],
|
||||
_Pitch_formant_high=data[172:174],
|
||||
)
|
||||
|
||||
@property
|
||||
def mode(self) -> int:
|
||||
return int.from_bytes(self._mode, 'little')
|
||||
|
||||
@property
|
||||
def audibility(self) -> Audibility:
|
||||
return Audibility(
|
||||
round(int.from_bytes(self._audibility, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._audibility_c, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._audibility_g, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._audibility_d, 'little', signed=True) * 0.01, 2),
|
||||
)
|
||||
|
||||
@property
|
||||
def positions(self) -> Positions:
|
||||
return Positions(
|
||||
round(int.from_bytes(self._pos3D_x, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._pos3D_y, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posColor_x, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posColor_y, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posMod_x, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posMod_y, 'little', signed=True) * 0.01, 2),
|
||||
)
|
||||
|
||||
@property
|
||||
def eqgains(self) -> EqGains:
|
||||
return EqGains(
|
||||
*[
|
||||
round(
|
||||
int.from_bytes(getattr(self, f'_EQgain{i}'), 'little', signed=True)
|
||||
* 0.01,
|
||||
2,
|
||||
)
|
||||
for i in range(1, 4)
|
||||
]
|
||||
)
|
||||
|
||||
@property
|
||||
def parametric_eq(self) -> tuple[ParametricEQSettings, ...]:
|
||||
return tuple(
|
||||
ParametricEQSettings(
|
||||
on=bool(int.from_bytes(self._PEQ_eqOn[i : i + 1], 'little')),
|
||||
type=int.from_bytes(self._PEQ_eqtype[i : i + 1], 'little'),
|
||||
freq=struct.unpack('<f', self._PEQ_eqfreq[i * 4 : (i + 1) * 4])[0],
|
||||
gain=struct.unpack('<f', self._PEQ_eqgain[i * 4 : (i + 1) * 4])[0],
|
||||
q=struct.unpack('<f', self._PEQ_eqq[i * 4 : (i + 1) * 4])[0],
|
||||
)
|
||||
for i in range(6)
|
||||
)
|
||||
|
||||
@property
|
||||
def sends(self) -> Sends:
|
||||
return Sends(
|
||||
round(int.from_bytes(self._send_reverb, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._send_delay, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._send_fx1, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._send_fx2, 'little', signed=True) * 0.01, 2),
|
||||
)
|
||||
|
||||
@property
|
||||
def karaoke(self) -> int:
|
||||
return int.from_bytes(self._nKaraoke, 'little')
|
||||
|
||||
@property
|
||||
def compressor(self) -> CompressorSettings:
|
||||
return CompressorSettings(
|
||||
gain_in=round(
|
||||
int.from_bytes(self._COMP_gain_in, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
attack_ms=round(int.from_bytes(self._COMP_attack_ms, 'little') * 0.1, 2),
|
||||
release_ms=round(int.from_bytes(self._COMP_release_ms, 'little') * 0.1, 2),
|
||||
n_knee=round(int.from_bytes(self._COMP_n_knee, 'little') * 0.01, 2),
|
||||
ratio=round(int.from_bytes(self._COMP_comprate, 'little') * 0.01, 2),
|
||||
threshold=round(
|
||||
int.from_bytes(self._COMP_threshold, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
c_enabled=bool(int.from_bytes(self._COMP_c_enabled, 'little')),
|
||||
makeup=bool(int.from_bytes(self._COMP_c_auto, 'little')),
|
||||
gain_out=round(
|
||||
int.from_bytes(self._COMP_gain_out, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
)
|
||||
|
||||
@property
|
||||
def gate(self) -> GateSettings:
|
||||
return GateSettings(
|
||||
threshold_in=round(
|
||||
int.from_bytes(self._GATE_dBThreshold_in, 'little', signed=True) * 0.01,
|
||||
2,
|
||||
),
|
||||
damping_max=round(
|
||||
int.from_bytes(self._GATE_dBDamping_max, 'little', signed=True) * 0.01,
|
||||
2,
|
||||
),
|
||||
bp_sidechain=round(
|
||||
int.from_bytes(self._GATE_BP_Sidechain, 'little') * 0.1, 2
|
||||
),
|
||||
attack_ms=round(int.from_bytes(self._GATE_attack_ms, 'little') * 0.1, 2),
|
||||
hold_ms=round(int.from_bytes(self._GATE_hold_ms, 'little') * 0.1, 2),
|
||||
release_ms=round(int.from_bytes(self._GATE_release_ms, 'little') * 0.1, 2),
|
||||
)
|
||||
|
||||
@property
|
||||
def denoiser(self) -> DenoiserSettings:
|
||||
return DenoiserSettings(
|
||||
threshold=round(
|
||||
int.from_bytes(self._DenoiserThreshold, 'little', signed=True) * 0.01, 2
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def pitch(self) -> PitchSettings:
|
||||
return PitchSettings(
|
||||
enabled=bool(int.from_bytes(self._PitchEnabled, 'little')),
|
||||
dry_wet=round(
|
||||
int.from_bytes(self._Pitch_DryWet, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
value=round(
|
||||
int.from_bytes(self._Pitch_Value, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
formant_lo=round(
|
||||
int.from_bytes(self._Pitch_formant_lo, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
formant_med=round(
|
||||
int.from_bytes(self._Pitch_formant_med, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
formant_high=round(
|
||||
int.from_bytes(self._Pitch_formant_high, 'little', signed=True) * 0.01,
|
||||
2,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRtPacketNBS1(VbanRtPacket):
|
||||
"""Represents the body of a VBAN RT data packet with NBS 1"""
|
||||
|
||||
strips: tuple[VbanVMParamStrip, ...]
|
||||
|
||||
@classmethod
|
||||
def from_bytes(
|
||||
cls,
|
||||
nbs: NBS,
|
||||
kind: KindMapClass,
|
||||
data: bytes,
|
||||
):
|
||||
return cls(
|
||||
nbs=nbs,
|
||||
_kind=kind,
|
||||
_voicemeeterType=data[28:29],
|
||||
_reserved=data[29:30],
|
||||
_buffersize=data[30:32],
|
||||
_voicemeeterVersion=data[32:36],
|
||||
_optionBits=data[36:40],
|
||||
_samplerate=data[40:44],
|
||||
strips=tuple(
|
||||
VbanVMParamStrip.from_bytes(
|
||||
data[44 + i * VMPARAMSTRIP_SIZE : 44 + (i + 1) * VMPARAMSTRIP_SIZE]
|
||||
)
|
||||
for i in range(16)
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class SubscribeHeader:
|
||||
"""Represents the header of an RT subscription packet"""
|
||||
|
||||
nbs: NBS = NBS.zero
|
||||
name: str = 'Register-RTP'
|
||||
timeout: int = 15
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def format_sr(self) -> bytes:
|
||||
return VBAN_PROTOCOL_SERVICE.to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def format_nbs(self) -> bytes:
|
||||
return (self.nbs.value & 0xFF).to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def format_nbc(self) -> bytes:
|
||||
return VBAN_SERVICE_RTPACKETREGISTER.to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def format_bit(self) -> bytes:
|
||||
return (self.timeout & 0xFF).to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode('ascii') + bytes(16 - len(self.name))
|
||||
|
||||
@classmethod
|
||||
def to_bytes(cls, nbs: NBS, framecounter: int) -> bytes:
|
||||
header = cls(nbs=nbs)
|
||||
|
||||
data = bytearray()
|
||||
data.extend(header.vban)
|
||||
data.extend(header.format_sr)
|
||||
data.extend(header.format_nbs)
|
||||
data.extend(header.format_nbc)
|
||||
data.extend(header.format_bit)
|
||||
data.extend(header.streamname)
|
||||
data.extend(framecounter.to_bytes(4, 'little'))
|
||||
return bytes(data)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRtPacketHeader:
|
||||
"""Represents the header of an RT response packet"""
|
||||
|
||||
name: str = 'Voicemeeter-RTP'
|
||||
format_sr: int = VBAN_PROTOCOL_SERVICE
|
||||
format_nbs: int = 0
|
||||
format_nbc: int = VBAN_SERVICE_RTPACKET
|
||||
format_bit: int = 0
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode('ascii') + bytes(16 - len(self.name))
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes):
|
||||
if len(data) < HEADER_SIZE:
|
||||
raise ValueError('Data is too short to be a valid VbanRTPPacketHeader')
|
||||
|
||||
name = data[8:24].rstrip(b'\x00').decode('utf-8')
|
||||
return cls(
|
||||
name=name,
|
||||
format_sr=data[4] & VBAN_SERVICE_MASK,
|
||||
format_nbs=data[5],
|
||||
format_nbc=data[6],
|
||||
format_bit=data[7],
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class RequestHeader:
|
||||
"""Represents the header of an RT request packet"""
|
||||
|
||||
name: str
|
||||
bps_index: int
|
||||
channel: int
|
||||
framecounter: int = 0
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def sr(self) -> bytes:
|
||||
return (VBAN_PROTOCOL_TXT + self.bps_index).to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def nbs(self) -> bytes:
|
||||
return (0).to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def nbc(self) -> bytes:
|
||||
return (self.channel).to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def bit(self) -> bytes:
|
||||
return (0x10).to_bytes(1, 'little')
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode() + bytes(16 - len(self.name))
|
||||
|
||||
@classmethod
|
||||
def to_bytes(
|
||||
cls, name: str, bps_index: int, channel: int, framecounter: int
|
||||
) -> bytes:
|
||||
header = cls(
|
||||
name=name, bps_index=bps_index, channel=channel, framecounter=framecounter
|
||||
)
|
||||
|
||||
data = bytearray()
|
||||
data.extend(header.vban)
|
||||
data.extend(header.sr)
|
||||
data.extend(header.nbs)
|
||||
data.extend(header.nbc)
|
||||
data.extend(header.bit)
|
||||
data.extend(header.streamname)
|
||||
data.extend(header.framecounter.to_bytes(4, 'little'))
|
||||
return bytes(data)
|
||||
@ -1,83 +0,0 @@
|
||||
from enum import Flag
|
||||
|
||||
|
||||
class SubProtocols(Flag):
|
||||
"""Sub Protocols - Bit flags that can be combined"""
|
||||
|
||||
AUDIO = 0x00
|
||||
SERIAL = 0x20
|
||||
TEXT = 0x40
|
||||
SERVICE = 0x60
|
||||
MASK = 0xE0
|
||||
|
||||
|
||||
class ServiceTypes(Flag):
|
||||
"""Service Types - Bit flags that can be combined"""
|
||||
|
||||
PING = 0
|
||||
PONG = 0
|
||||
CHATUTF8 = 1
|
||||
RTPACKETREGISTER = 32
|
||||
RTPACKET = 33
|
||||
REQUESTREPLY = 0x02 # A Matrix reply
|
||||
FNCT_REPLY = 0x80 # An RTPacket reply
|
||||
|
||||
|
||||
class StreamTypes(Flag):
|
||||
"""Stream Types - Bit flags that can be combined"""
|
||||
|
||||
ASCII = 0x00
|
||||
UTF8 = 0x10
|
||||
WCHAR = 0x20
|
||||
|
||||
|
||||
class ChannelModes(Flag):
|
||||
"""Channel Modes - Bit flags that can be combined"""
|
||||
|
||||
MUTE = 0x00000001
|
||||
SOLO = 0x00000002
|
||||
MONO = 0x00000004
|
||||
MC = 0x00000008
|
||||
|
||||
AMIX = 0x00000010
|
||||
REPEAT = 0x00000020
|
||||
BMIX = 0x00000030
|
||||
COMPOSITE = 0x00000040
|
||||
TVMIX = 0x00000050
|
||||
UPMIX21 = 0x00000060
|
||||
UPMIX41 = 0x00000070
|
||||
UPMIX61 = 0x00000080
|
||||
CENTERONLY = 0x00000090
|
||||
LFEONLY = 0x000000A0
|
||||
REARONLY = 0x000000B0
|
||||
|
||||
MASK = 0x000000F0
|
||||
|
||||
ON = 0x00000100 # eq.on
|
||||
CROSS = 0x00000200
|
||||
AB = 0x00000800 # eq.ab
|
||||
|
||||
BUSA = 0x00001000
|
||||
BUSA1 = 0x00001000
|
||||
BUSA2 = 0x00002000
|
||||
BUSA3 = 0x00004000
|
||||
BUSA4 = 0x00008000
|
||||
BUSA5 = 0x00080000
|
||||
|
||||
BUSB = 0x00010000
|
||||
BUSB1 = 0x00010000
|
||||
BUSB2 = 0x00020000
|
||||
BUSB3 = 0x00040000
|
||||
|
||||
PAN0 = 0x00000000
|
||||
PANCOLOR = 0x00100000
|
||||
PANMOD = 0x00200000
|
||||
PANMASK = 0x00F00000
|
||||
|
||||
POSTFX_R = 0x01000000
|
||||
POSTFX_D = 0x02000000
|
||||
POSTFX1 = 0x04000000
|
||||
POSTFX2 = 0x08000000
|
||||
|
||||
SEL = 0x10000000
|
||||
MONITOR = 0x20000000
|
||||
@ -1,394 +0,0 @@
|
||||
import struct
|
||||
from dataclasses import dataclass
|
||||
|
||||
from vban_cmd.enums import NBS
|
||||
from vban_cmd.error import VBANCMDPacketError
|
||||
from vban_cmd.kinds import KindMapClass
|
||||
|
||||
from .enums import ServiceTypes, StreamTypes, SubProtocols
|
||||
|
||||
PINGPONG_PACKET_SIZE = 704 # Size of the PING/PONG header + payload in bytes
|
||||
MAX_PACKET_SIZE = 1436
|
||||
HEADER_SIZE = 4 + 1 + 1 + 1 + 1 + 16
|
||||
|
||||
STREAMNAME_MAX_LENGTH = 16
|
||||
# fmt: off
|
||||
BPS_OPTS = [
|
||||
0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
|
||||
38400, 57600, 115200, 128000, 230400, 250000, 256000, 460800, 921600,
|
||||
1000000, 1500000, 2000000, 3000000,
|
||||
]
|
||||
# fmt: on
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanPingHeader:
|
||||
"""Represents the header of a PING packet"""
|
||||
|
||||
name: str = 'PING0'
|
||||
format_sr: int = SubProtocols.SERVICE.value
|
||||
format_nbs: int = 0
|
||||
format_nbc: int = ServiceTypes.PING.value
|
||||
format_bit: int = 0
|
||||
framecounter: int = 0
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode('ascii')[:STREAMNAME_MAX_LENGTH].ljust(
|
||||
STREAMNAME_MAX_LENGTH, b'\x00'
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def to_bytes(cls, framecounter: int = 0) -> bytes:
|
||||
"""Creates the PING header bytes only."""
|
||||
header = cls(framecounter=framecounter)
|
||||
|
||||
return struct.pack(
|
||||
'<4s4B16sI',
|
||||
header.vban,
|
||||
header.format_sr,
|
||||
header.format_nbs,
|
||||
header.format_nbc,
|
||||
header.format_bit,
|
||||
header.streamname,
|
||||
header.framecounter,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanPongHeader:
|
||||
"""Represents the header of a PONG response packet"""
|
||||
|
||||
name: str = 'PING0'
|
||||
format_sr: int = SubProtocols.SERVICE.value
|
||||
format_nbs: int = 0
|
||||
format_nbc: int = ServiceTypes.PONG.value
|
||||
format_bit: int = 0
|
||||
framecounter: int = 0
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode('ascii')[:STREAMNAME_MAX_LENGTH].ljust(
|
||||
STREAMNAME_MAX_LENGTH, b'\x00'
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes):
|
||||
"""Parse a PONG response packet from bytes."""
|
||||
parsed = _parse_vban_service_header(data)
|
||||
|
||||
# PONG responses use the same service type as PING (0x00)
|
||||
# and are identified by having payload data
|
||||
if parsed['format_nbc'] != ServiceTypes.PONG.value:
|
||||
raise VBANCMDPacketError(
|
||||
f'Not a PONG response packet: {parsed["format_nbc"]:02x}',
|
||||
protocol=SubProtocols(parsed['format_sr'] & SubProtocols.MASK.value),
|
||||
type_=ServiceTypes(parsed['format_nbc']),
|
||||
)
|
||||
|
||||
return cls(**parsed)
|
||||
|
||||
@classmethod
|
||||
def is_pong_response(cls, data: bytes) -> bool:
|
||||
"""Check if packet is a PONG response by analyzing the actual response format."""
|
||||
try:
|
||||
parsed = _parse_vban_service_header(data)
|
||||
|
||||
# Validate this is a service protocol packet with PING/PONG service type
|
||||
if parsed['format_nbc'] != ServiceTypes.PONG.value:
|
||||
return False
|
||||
|
||||
if parsed['name'] not in ['PING0', 'VBAN Service']:
|
||||
return False
|
||||
|
||||
# PONG should have payload data (same size as PING)
|
||||
return len(data) >= PINGPONG_PACKET_SIZE
|
||||
|
||||
except (ValueError, Exception):
|
||||
return False
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRTPacket:
|
||||
"""Represents the header of an incoming RTPacket"""
|
||||
|
||||
nbs: NBS
|
||||
_kind: KindMapClass
|
||||
_voicemeeterType: bytes
|
||||
_reserved: bytes
|
||||
_buffersize: bytes
|
||||
_voicemeeterVersion: bytes
|
||||
_optionBits: bytes
|
||||
_samplerate: bytes
|
||||
|
||||
@property
|
||||
def voicemeetertype(self) -> str:
|
||||
"""returns voicemeeter type as a string"""
|
||||
return ['', 'basic', 'banana', 'potato'][
|
||||
int.from_bytes(self._voicemeeterType, 'little')
|
||||
]
|
||||
|
||||
@property
|
||||
def voicemeeterversion(self) -> tuple:
|
||||
"""returns voicemeeter version as a tuple"""
|
||||
return tuple(self._voicemeeterVersion[i] for i in range(3, -1, -1))
|
||||
|
||||
@property
|
||||
def samplerate(self) -> int:
|
||||
"""returns samplerate as an int"""
|
||||
return int.from_bytes(self._samplerate, 'little')
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRTSubscribeHeader:
|
||||
"""Represents the header of an RT subscription packet"""
|
||||
|
||||
_nbs: NBS = NBS.zero
|
||||
name: str = 'Register-RTP'
|
||||
timeout: int = 15
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def sr(self) -> int:
|
||||
return SubProtocols.SERVICE.value
|
||||
|
||||
@property
|
||||
def nbs(self) -> int:
|
||||
return self._nbs.value & 0xFF
|
||||
|
||||
@property
|
||||
def nbc(self) -> int:
|
||||
return ServiceTypes.RTPACKETREGISTER.value
|
||||
|
||||
@property
|
||||
def bit(self) -> int:
|
||||
return self.timeout & 0xFF
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode()[:STREAMNAME_MAX_LENGTH].ljust(
|
||||
STREAMNAME_MAX_LENGTH, b'\x00'
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def to_bytes(cls, nbs: NBS, framecounter: int) -> bytes:
|
||||
header = cls(_nbs=nbs)
|
||||
|
||||
return struct.pack(
|
||||
'<4s4B16sI',
|
||||
header.vban,
|
||||
header.sr,
|
||||
header.nbs,
|
||||
header.nbc,
|
||||
header.bit,
|
||||
header.streamname,
|
||||
framecounter,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRTRequestHeader:
|
||||
"""Represents the header of an RT request packet"""
|
||||
|
||||
name: str
|
||||
bps: int
|
||||
channel: int
|
||||
framecounter: int = 0
|
||||
|
||||
def __post_init__(self):
|
||||
if self.bps not in BPS_OPTS:
|
||||
raise ValueError(
|
||||
f'Invalid bps value: {self.bps}. Must be one of {BPS_OPTS}'
|
||||
)
|
||||
self.bps_index = BPS_OPTS.index(self.bps)
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def sr(self) -> int:
|
||||
return self.bps_index | SubProtocols.TEXT.value
|
||||
|
||||
@property
|
||||
def nbs(self) -> int:
|
||||
return 0
|
||||
|
||||
@property
|
||||
def nbc(self) -> int:
|
||||
return self.channel
|
||||
|
||||
@property
|
||||
def bit(self) -> int:
|
||||
return StreamTypes.UTF8.value
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode()[:STREAMNAME_MAX_LENGTH].ljust(
|
||||
STREAMNAME_MAX_LENGTH, b'\x00'
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def to_bytes(cls, name: str, bps: int, channel: int, framecounter: int) -> bytes:
|
||||
header = cls(name=name, bps=bps, channel=channel, framecounter=framecounter)
|
||||
|
||||
return struct.pack(
|
||||
'<4s4B16sI',
|
||||
header.vban,
|
||||
header.sr,
|
||||
header.nbs,
|
||||
header.nbc,
|
||||
header.bit,
|
||||
header.streamname,
|
||||
header.framecounter,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def encode_with_payload(
|
||||
cls, name: str, bps: int, channel: int, framecounter: int, payload: str
|
||||
) -> bytes:
|
||||
"""Creates the complete packet with header and payload."""
|
||||
return cls.to_bytes(name, bps, channel, framecounter) + payload.encode()
|
||||
|
||||
|
||||
def _parse_vban_service_header(data: bytes) -> dict:
|
||||
"""Common parsing and validation for VBAN service protocol headers."""
|
||||
if len(data) < HEADER_SIZE:
|
||||
raise ValueError('Data is too short to be a valid VBAN header')
|
||||
|
||||
if data[:4] != b'VBAN':
|
||||
raise ValueError('Invalid VBAN magic bytes')
|
||||
|
||||
format_sr = data[4]
|
||||
format_nbs = data[5]
|
||||
format_nbc = data[6]
|
||||
format_bit = data[7]
|
||||
|
||||
# Verify this is a service protocol packet
|
||||
protocol = format_sr & SubProtocols.MASK.value
|
||||
if protocol != SubProtocols.SERVICE.value:
|
||||
raise VBANCMDPacketError(
|
||||
f'Invalid protocol in service header: {protocol:02x}',
|
||||
protocol=SubProtocols(protocol),
|
||||
)
|
||||
|
||||
# Extract stream name and frame counter
|
||||
name = data[8:24].rstrip(b'\x00').decode('utf-8', errors='ignore')
|
||||
framecounter = int.from_bytes(data[24:28], 'little')
|
||||
|
||||
return {
|
||||
'format_sr': format_sr,
|
||||
'format_nbs': format_nbs,
|
||||
'format_nbc': format_nbc,
|
||||
'format_bit': format_bit,
|
||||
'name': name,
|
||||
'framecounter': framecounter,
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRTResponseHeader:
|
||||
"""Represents the header of an RT response packet"""
|
||||
|
||||
name: str = 'Voicemeeter-RTP'
|
||||
format_sr: int = SubProtocols.SERVICE.value
|
||||
format_nbs: int = 0
|
||||
format_nbc: int = ServiceTypes.RTPACKET.value
|
||||
format_bit: int = 0
|
||||
framecounter: int = 0
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode()[:STREAMNAME_MAX_LENGTH].ljust(
|
||||
STREAMNAME_MAX_LENGTH, b'\x00'
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes):
|
||||
"""Parse a VbanResponseHeader from bytes."""
|
||||
parsed = _parse_vban_service_header(data)
|
||||
|
||||
# Validate this is an RTPacket response
|
||||
if parsed['format_nbc'] != ServiceTypes.RTPACKET.value:
|
||||
raise VBANCMDPacketError(
|
||||
f'Not an RTPacket response packet: {parsed["format_nbc"]:02x}',
|
||||
protocol=SubProtocols(parsed['format_sr'] & SubProtocols.MASK.value),
|
||||
type_=ServiceTypes(parsed['format_nbc']),
|
||||
)
|
||||
|
||||
return cls(**parsed)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanMatrixResponseHeader:
|
||||
"""Represents the header of a matrix response packet"""
|
||||
|
||||
name: str = 'Request Reply'
|
||||
format_sr: int = SubProtocols.SERVICE.value
|
||||
format_nbs: int = ServiceTypes.FNCT_REPLY.value
|
||||
format_nbc: int = ServiceTypes.REQUESTREPLY.value
|
||||
format_bit: int = 0
|
||||
framecounter: int = 0
|
||||
|
||||
@property
|
||||
def vban(self) -> bytes:
|
||||
return b'VBAN'
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode()[:STREAMNAME_MAX_LENGTH].ljust(
|
||||
STREAMNAME_MAX_LENGTH, b'\x00'
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes):
|
||||
"""Parse a matrix response packet from bytes."""
|
||||
parsed = _parse_vban_service_header(data)
|
||||
|
||||
# Validate this is a service reply packet (dual encoding scheme)
|
||||
if parsed['format_nbs'] != ServiceTypes.FNCT_REPLY.value:
|
||||
raise VBANCMDPacketError(
|
||||
f'Not a service reply packet: {parsed["format_nbs"]:02x}',
|
||||
protocol=SubProtocols(parsed['format_sr'] & SubProtocols.MASK.value),
|
||||
type_=ServiceTypes(parsed['format_nbs']),
|
||||
)
|
||||
|
||||
if parsed['format_nbc'] != ServiceTypes.REQUESTREPLY.value:
|
||||
raise VBANCMDPacketError(
|
||||
f'Not a request reply packet: {parsed["format_nbc"]:02x}',
|
||||
protocol=SubProtocols(parsed['format_sr'] & SubProtocols.MASK.value),
|
||||
type_=ServiceTypes(parsed['format_nbc']),
|
||||
)
|
||||
|
||||
return cls(**parsed)
|
||||
|
||||
@classmethod
|
||||
def extract_payload(cls, data: bytes) -> str:
|
||||
"""Extract the text payload from a matrix response packet."""
|
||||
if len(data) <= HEADER_SIZE:
|
||||
return ''
|
||||
|
||||
payload_bytes = data[HEADER_SIZE:]
|
||||
return payload_bytes.rstrip(b'\x00').decode('utf-8', errors='ignore')
|
||||
|
||||
@classmethod
|
||||
def parse_response(cls, data: bytes) -> tuple['VbanMatrixResponseHeader', str]:
|
||||
"""Parse a complete matrix response packet returning header and payload."""
|
||||
header = cls.from_bytes(data)
|
||||
payload = cls.extract_payload(data)
|
||||
return header, payload
|
||||
@ -1,260 +0,0 @@
|
||||
import struct
|
||||
from dataclasses import dataclass
|
||||
from functools import cached_property
|
||||
from typing import NamedTuple
|
||||
|
||||
from vban_cmd.enums import NBS
|
||||
from vban_cmd.kinds import KindMapClass
|
||||
from vban_cmd.util import comp
|
||||
|
||||
from .enums import ChannelModes
|
||||
from .headers import VbanRTPacket
|
||||
|
||||
|
||||
class Levels(NamedTuple):
|
||||
strip: tuple[float, ...]
|
||||
bus: tuple[float, ...]
|
||||
|
||||
|
||||
class ChannelState:
|
||||
"""Represents the processed state of a single strip or bus channel"""
|
||||
|
||||
def __init__(self, state_bytes: bytes):
|
||||
# Convert 4-byte state to integer once for efficient lookups
|
||||
self._state = int.from_bytes(state_bytes, 'little')
|
||||
|
||||
@classmethod
|
||||
def from_int(cls, state_int: int):
|
||||
"""Create ChannelState directly from integer for efficiency"""
|
||||
instance = cls.__new__(cls)
|
||||
instance._state = state_int
|
||||
return instance
|
||||
|
||||
def get_mode(self, mode_value: int) -> bool:
|
||||
"""Get boolean state for a specific mode"""
|
||||
return (self._state & mode_value) != 0
|
||||
|
||||
def get_mode_int(self, mode_value: int) -> int:
|
||||
"""Get integer state for a specific mode"""
|
||||
return self._state & mode_value
|
||||
|
||||
# Common boolean modes
|
||||
@property
|
||||
def mute(self) -> bool:
|
||||
return (self._state & ChannelModes.MUTE.value) != 0
|
||||
|
||||
@property
|
||||
def solo(self) -> bool:
|
||||
return (self._state & ChannelModes.SOLO.value) != 0
|
||||
|
||||
@property
|
||||
def mono(self) -> bool:
|
||||
return (self._state & ChannelModes.MONO.value) != 0
|
||||
|
||||
@property
|
||||
def mc(self) -> bool:
|
||||
return (self._state & ChannelModes.MC.value) != 0
|
||||
|
||||
# EQ modes
|
||||
@property
|
||||
def eq_on(self) -> bool:
|
||||
return (self._state & ChannelModes.ON.value) != 0
|
||||
|
||||
@property
|
||||
def eq_ab(self) -> bool:
|
||||
return (self._state & ChannelModes.AB.value) != 0
|
||||
|
||||
# Bus assignments (strip to bus routing)
|
||||
@property
|
||||
def busa1(self) -> bool:
|
||||
return (self._state & ChannelModes.BUSA1.value) != 0
|
||||
|
||||
@property
|
||||
def busa2(self) -> bool:
|
||||
return (self._state & ChannelModes.BUSA2.value) != 0
|
||||
|
||||
@property
|
||||
def busa3(self) -> bool:
|
||||
return (self._state & ChannelModes.BUSA3.value) != 0
|
||||
|
||||
@property
|
||||
def busa4(self) -> bool:
|
||||
return (self._state & ChannelModes.BUSA4.value) != 0
|
||||
|
||||
@property
|
||||
def busb1(self) -> bool:
|
||||
return (self._state & ChannelModes.BUSB1.value) != 0
|
||||
|
||||
@property
|
||||
def busb2(self) -> bool:
|
||||
return (self._state & ChannelModes.BUSB2.value) != 0
|
||||
|
||||
@property
|
||||
def busb3(self) -> bool:
|
||||
return (self._state & ChannelModes.BUSB3.value) != 0
|
||||
|
||||
|
||||
class States(NamedTuple):
|
||||
strip: tuple[ChannelState, ...]
|
||||
bus: tuple[ChannelState, ...]
|
||||
|
||||
|
||||
class Labels(NamedTuple):
|
||||
strip: tuple[str, ...]
|
||||
bus: tuple[str, ...]
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRTPacketNBS0(VbanRTPacket):
|
||||
"""Represents the body of a VBAN RTPacket with ident:0"""
|
||||
|
||||
_inputLeveldB100: bytes
|
||||
_outputLeveldB100: bytes
|
||||
_TransportBit: bytes
|
||||
_stripState: bytes
|
||||
_busState: bytes
|
||||
_stripGaindB100Layer1: bytes
|
||||
_stripGaindB100Layer2: bytes
|
||||
_stripGaindB100Layer3: bytes
|
||||
_stripGaindB100Layer4: bytes
|
||||
_stripGaindB100Layer5: bytes
|
||||
_stripGaindB100Layer6: bytes
|
||||
_stripGaindB100Layer7: bytes
|
||||
_stripGaindB100Layer8: bytes
|
||||
_busGaindB100: bytes
|
||||
_stripLabelUTF8c60: bytes
|
||||
_busLabelUTF8c60: bytes
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, nbs: NBS, kind: KindMapClass, data: bytes):
|
||||
return cls(
|
||||
nbs=nbs,
|
||||
_kind=kind,
|
||||
_voicemeeterType=data[28:29],
|
||||
_reserved=data[29:30],
|
||||
_buffersize=data[30:32],
|
||||
_voicemeeterVersion=data[32:36],
|
||||
_optionBits=data[36:40],
|
||||
_samplerate=data[40:44],
|
||||
_inputLeveldB100=data[44:112],
|
||||
_outputLeveldB100=data[112:240],
|
||||
_TransportBit=data[240:244],
|
||||
_stripState=data[244:276],
|
||||
_busState=data[276:308],
|
||||
_stripGaindB100Layer1=data[308:324],
|
||||
_stripGaindB100Layer2=data[324:340],
|
||||
_stripGaindB100Layer3=data[340:356],
|
||||
_stripGaindB100Layer4=data[356:372],
|
||||
_stripGaindB100Layer5=data[372:388],
|
||||
_stripGaindB100Layer6=data[388:404],
|
||||
_stripGaindB100Layer7=data[404:420],
|
||||
_stripGaindB100Layer8=data[420:436],
|
||||
_busGaindB100=data[436:452],
|
||||
_stripLabelUTF8c60=data[452:932],
|
||||
_busLabelUTF8c60=data[932:1412],
|
||||
)
|
||||
|
||||
def pdirty(self, other) -> bool:
|
||||
"""True iff any defined parameter has changed"""
|
||||
return (
|
||||
self._stripState != other._stripState
|
||||
or self._busState != other._busState
|
||||
or self._stripGaindB100Layer1 != other._stripGaindB100Layer1
|
||||
or self._stripGaindB100Layer2 != other._stripGaindB100Layer2
|
||||
or self._stripGaindB100Layer3 != other._stripGaindB100Layer3
|
||||
or self._stripGaindB100Layer4 != other._stripGaindB100Layer4
|
||||
or self._stripGaindB100Layer5 != other._stripGaindB100Layer5
|
||||
or self._stripGaindB100Layer6 != other._stripGaindB100Layer6
|
||||
or self._stripGaindB100Layer7 != other._stripGaindB100Layer7
|
||||
or self._stripGaindB100Layer8 != other._stripGaindB100Layer8
|
||||
or self._busGaindB100 != other._busGaindB100
|
||||
or self._stripLabelUTF8c60 != other._stripLabelUTF8c60
|
||||
or self._busLabelUTF8c60 != other._busLabelUTF8c60
|
||||
)
|
||||
|
||||
def ldirty(self, strip_cache, bus_cache) -> bool:
|
||||
"""True iff any level has changed, ignoring changes when levels are very quiet"""
|
||||
self._strip_comp, self._bus_comp = (
|
||||
tuple(not val for val in comp(strip_cache, self.strip_levels)),
|
||||
tuple(not val for val in comp(bus_cache, self.bus_levels)),
|
||||
)
|
||||
return any(self._strip_comp) or any(self._bus_comp)
|
||||
|
||||
@cached_property
|
||||
def strip_levels(self) -> tuple[float, ...]:
|
||||
"""Returns strip levels in dB"""
|
||||
strip_raw = struct.unpack('<34h', self._inputLeveldB100)
|
||||
return tuple(round(val * 0.01, 1) for val in strip_raw)[
|
||||
: self._kind.num_strip_levels
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def bus_levels(self) -> tuple[float, ...]:
|
||||
"""Returns bus levels in dB"""
|
||||
bus_raw = struct.unpack('<64h', self._outputLeveldB100)
|
||||
return tuple(round(val * 0.01, 1) for val in bus_raw)[
|
||||
: self._kind.num_bus_levels
|
||||
]
|
||||
|
||||
@property
|
||||
def levels(self) -> Levels:
|
||||
"""Returns strip and bus levels as a namedtuple"""
|
||||
return Levels(strip=self.strip_levels, bus=self.bus_levels)
|
||||
|
||||
@cached_property
|
||||
def states(self) -> States:
|
||||
"""returns States object with processed strip and bus channel states"""
|
||||
strip_states = struct.unpack('<8I', self._stripState)
|
||||
bus_states = struct.unpack('<8I', self._busState)
|
||||
return States(
|
||||
strip=tuple(ChannelState.from_int(state) for state in strip_states),
|
||||
bus=tuple(ChannelState.from_int(state) for state in bus_states),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def gainlayers(self) -> tuple:
|
||||
"""returns tuple of all strip gain layers as tuples"""
|
||||
layer_data = []
|
||||
for layer in range(1, 9):
|
||||
layer_bytes = getattr(self, f'_stripGaindB100Layer{layer}')
|
||||
layer_raw = struct.unpack('<8h', layer_bytes)
|
||||
layer_data.append(tuple(round(val * 0.01, 2) for val in layer_raw))
|
||||
return tuple(layer_data)
|
||||
|
||||
@cached_property
|
||||
def busgain(self) -> tuple:
|
||||
"""returns tuple of bus gains"""
|
||||
bus_gain_raw = struct.unpack('<8h', self._busGaindB100)
|
||||
return tuple(round(val * 0.01, 2) for val in bus_gain_raw)
|
||||
|
||||
@cached_property
|
||||
def labels(self) -> Labels:
|
||||
"""returns Labels namedtuple of strip and bus labels"""
|
||||
|
||||
def _extract_labels_from_bytes(label_bytes: bytes) -> tuple[str, ...]:
|
||||
"""Extract null-terminated UTF-8 labels from 60-byte chunks"""
|
||||
labels = []
|
||||
for i in range(0, len(label_bytes), 60):
|
||||
chunk = label_bytes[i : i + 60]
|
||||
null_pos = chunk.find(b'\x00')
|
||||
if null_pos == -1:
|
||||
try:
|
||||
label = chunk.decode('utf-8', errors='replace').rstrip('\x00')
|
||||
except UnicodeDecodeError:
|
||||
label = ''
|
||||
else:
|
||||
try:
|
||||
label = (
|
||||
chunk[:null_pos].decode('utf-8', errors='replace')
|
||||
if null_pos > 0
|
||||
else ''
|
||||
)
|
||||
except UnicodeDecodeError:
|
||||
label = ''
|
||||
labels.append(label)
|
||||
return tuple(labels)
|
||||
|
||||
return Labels(
|
||||
strip=_extract_labels_from_bytes(self._stripLabelUTF8c60),
|
||||
bus=_extract_labels_from_bytes(self._busLabelUTF8c60),
|
||||
)
|
||||
@ -1,358 +0,0 @@
|
||||
import struct
|
||||
from dataclasses import dataclass
|
||||
from functools import cached_property
|
||||
from typing import NamedTuple
|
||||
|
||||
from vban_cmd.enums import NBS
|
||||
from vban_cmd.kinds import KindMapClass
|
||||
|
||||
from .headers import VbanRTPacket
|
||||
|
||||
VMPARAMSTRIP_SIZE = 174
|
||||
|
||||
|
||||
class Audibility(NamedTuple):
|
||||
knob: float
|
||||
comp: float
|
||||
gate: float
|
||||
denoiser: float
|
||||
|
||||
|
||||
class Positions(NamedTuple):
|
||||
pan_x: float
|
||||
pan_y: float
|
||||
color_x: float
|
||||
color_y: float
|
||||
fx1: float
|
||||
fx2: float
|
||||
|
||||
|
||||
class EqGains(NamedTuple):
|
||||
bass: float
|
||||
mid: float
|
||||
treble: float
|
||||
|
||||
|
||||
class ParametricEQSettings(NamedTuple):
|
||||
on: bool
|
||||
type: int
|
||||
gain: float
|
||||
freq: float
|
||||
q: float
|
||||
|
||||
|
||||
class Sends(NamedTuple):
|
||||
reverb: float
|
||||
delay: float
|
||||
fx1: float
|
||||
fx2: float
|
||||
|
||||
|
||||
class CompressorSettings(NamedTuple):
|
||||
gain_in: float
|
||||
attack_ms: float
|
||||
release_ms: float
|
||||
n_knee: float
|
||||
ratio: float
|
||||
threshold: float
|
||||
c_enabled: bool
|
||||
makeup: bool
|
||||
gain_out: float
|
||||
|
||||
|
||||
class GateSettings(NamedTuple):
|
||||
threshold_in: float
|
||||
damping_max: float
|
||||
bp_sidechain: bool
|
||||
attack_ms: float
|
||||
hold_ms: float
|
||||
release_ms: float
|
||||
|
||||
|
||||
class DenoiserSettings(NamedTuple):
|
||||
threshold: float
|
||||
|
||||
|
||||
class PitchSettings(NamedTuple):
|
||||
enabled: bool
|
||||
dry_wet: float
|
||||
value: float
|
||||
formant_lo: float
|
||||
formant_med: float
|
||||
formant_high: float
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanVMParamStrip:
|
||||
"""Represents the VBAN_VMPARAMSTRIP_PACKET structure"""
|
||||
|
||||
_mode: bytes
|
||||
_dblevel: bytes
|
||||
_audibility: bytes
|
||||
_pos3D_x: bytes
|
||||
_pos3D_y: bytes
|
||||
_posColor_x: bytes
|
||||
_posColor_y: bytes
|
||||
_EQgain1: bytes
|
||||
_EQgain2: bytes
|
||||
_EQgain3: bytes
|
||||
|
||||
# First channel parametric EQ
|
||||
_PEQ_eqOn: bytes
|
||||
_PEQ_eqtype: bytes
|
||||
_PEQ_eqgain: bytes
|
||||
_PEQ_eqfreq: bytes
|
||||
_PEQ_eqq: bytes
|
||||
|
||||
_audibility_c: bytes
|
||||
_audibility_g: bytes
|
||||
_audibility_d: bytes
|
||||
_posMod_x: bytes
|
||||
_posMod_y: bytes
|
||||
_send_reverb: bytes
|
||||
_send_delay: bytes
|
||||
_send_fx1: bytes
|
||||
_send_fx2: bytes
|
||||
_dblimit: bytes
|
||||
_nKaraoke: bytes
|
||||
|
||||
_COMP_gain_in: bytes
|
||||
_COMP_attack_ms: bytes
|
||||
_COMP_release_ms: bytes
|
||||
_COMP_n_knee: bytes
|
||||
_COMP_comprate: bytes
|
||||
_COMP_threshold: bytes
|
||||
_COMP_c_enabled: bytes
|
||||
_COMP_c_auto: bytes
|
||||
_COMP_gain_out: bytes
|
||||
|
||||
_GATE_dBThreshold_in: bytes
|
||||
_GATE_dBDamping_max: bytes
|
||||
_GATE_BP_Sidechain: bytes
|
||||
_GATE_attack_ms: bytes
|
||||
_GATE_hold_ms: bytes
|
||||
_GATE_release_ms: bytes
|
||||
|
||||
_DenoiserThreshold: bytes
|
||||
_PitchEnabled: bytes
|
||||
_Pitch_DryWet: bytes
|
||||
_Pitch_Value: bytes
|
||||
_Pitch_formant_lo: bytes
|
||||
_Pitch_formant_med: bytes
|
||||
_Pitch_formant_high: bytes
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes):
|
||||
return cls(
|
||||
_mode=data[0:4],
|
||||
_dblevel=data[4:8],
|
||||
_audibility=data[8:10],
|
||||
_pos3D_x=data[10:12],
|
||||
_pos3D_y=data[12:14],
|
||||
_posColor_x=data[14:16],
|
||||
_posColor_y=data[16:18],
|
||||
_EQgain1=data[18:20],
|
||||
_EQgain2=data[20:22],
|
||||
_EQgain3=data[22:24],
|
||||
_PEQ_eqOn=data[24:30],
|
||||
_PEQ_eqtype=data[30:36],
|
||||
_PEQ_eqgain=data[36:60],
|
||||
_PEQ_eqfreq=data[60:84],
|
||||
_PEQ_eqq=data[84:108],
|
||||
_audibility_c=data[108:110],
|
||||
_audibility_g=data[110:112],
|
||||
_audibility_d=data[112:114],
|
||||
_posMod_x=data[114:116],
|
||||
_posMod_y=data[116:118],
|
||||
_send_reverb=data[118:120],
|
||||
_send_delay=data[120:122],
|
||||
_send_fx1=data[122:124],
|
||||
_send_fx2=data[124:126],
|
||||
_dblimit=data[126:128],
|
||||
_nKaraoke=data[128:130],
|
||||
_COMP_gain_in=data[130:132],
|
||||
_COMP_attack_ms=data[132:134],
|
||||
_COMP_release_ms=data[134:136],
|
||||
_COMP_n_knee=data[136:138],
|
||||
_COMP_comprate=data[138:140],
|
||||
_COMP_threshold=data[140:142],
|
||||
_COMP_c_enabled=data[142:144],
|
||||
_COMP_c_auto=data[144:146],
|
||||
_COMP_gain_out=data[146:148],
|
||||
_GATE_dBThreshold_in=data[148:150],
|
||||
_GATE_dBDamping_max=data[150:152],
|
||||
_GATE_BP_Sidechain=data[152:154],
|
||||
_GATE_attack_ms=data[154:156],
|
||||
_GATE_hold_ms=data[156:158],
|
||||
_GATE_release_ms=data[158:160],
|
||||
_DenoiserThreshold=data[160:162],
|
||||
_PitchEnabled=data[162:164],
|
||||
_Pitch_DryWet=data[164:166],
|
||||
_Pitch_Value=data[166:168],
|
||||
_Pitch_formant_lo=data[168:170],
|
||||
_Pitch_formant_med=data[170:172],
|
||||
_Pitch_formant_high=data[172:174],
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def mode(self) -> int:
|
||||
return int.from_bytes(self._mode, 'little')
|
||||
|
||||
@cached_property
|
||||
def karaoke(self) -> int:
|
||||
return int.from_bytes(self._nKaraoke, 'little')
|
||||
|
||||
@cached_property
|
||||
def audibility(self) -> Audibility:
|
||||
return Audibility(
|
||||
round(int.from_bytes(self._audibility, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._audibility_c, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._audibility_g, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._audibility_d, 'little', signed=True) * 0.01, 2),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def positions(self) -> Positions:
|
||||
return Positions(
|
||||
round(int.from_bytes(self._pos3D_x, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._pos3D_y, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posColor_x, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posColor_y, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posMod_x, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._posMod_y, 'little', signed=True) * 0.01, 2),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def eqgains(self) -> EqGains:
|
||||
return EqGains(
|
||||
*[
|
||||
round(
|
||||
int.from_bytes(getattr(self, f'_EQgain{i}'), 'little', signed=True)
|
||||
* 0.01,
|
||||
2,
|
||||
)
|
||||
for i in range(1, 4)
|
||||
]
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def parametric_eq(self) -> tuple[ParametricEQSettings, ...]:
|
||||
return tuple(
|
||||
ParametricEQSettings(
|
||||
on=bool(int.from_bytes(self._PEQ_eqOn[i : i + 1], 'little')),
|
||||
type=int.from_bytes(self._PEQ_eqtype[i : i + 1], 'little'),
|
||||
freq=struct.unpack('<f', self._PEQ_eqfreq[i * 4 : (i + 1) * 4])[0],
|
||||
gain=struct.unpack('<f', self._PEQ_eqgain[i * 4 : (i + 1) * 4])[0],
|
||||
q=struct.unpack('<f', self._PEQ_eqq[i * 4 : (i + 1) * 4])[0],
|
||||
)
|
||||
for i in range(6)
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def sends(self) -> Sends:
|
||||
return Sends(
|
||||
round(int.from_bytes(self._send_reverb, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._send_delay, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._send_fx1, 'little', signed=True) * 0.01, 2),
|
||||
round(int.from_bytes(self._send_fx2, 'little', signed=True) * 0.01, 2),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def compressor(self) -> CompressorSettings:
|
||||
return CompressorSettings(
|
||||
gain_in=round(
|
||||
int.from_bytes(self._COMP_gain_in, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
attack_ms=round(int.from_bytes(self._COMP_attack_ms, 'little') * 0.1, 2),
|
||||
release_ms=round(int.from_bytes(self._COMP_release_ms, 'little') * 0.1, 2),
|
||||
n_knee=round(int.from_bytes(self._COMP_n_knee, 'little') * 0.01, 2),
|
||||
ratio=round(int.from_bytes(self._COMP_comprate, 'little') * 0.01, 2),
|
||||
threshold=round(
|
||||
int.from_bytes(self._COMP_threshold, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
c_enabled=bool(int.from_bytes(self._COMP_c_enabled, 'little')),
|
||||
makeup=bool(int.from_bytes(self._COMP_c_auto, 'little')),
|
||||
gain_out=round(
|
||||
int.from_bytes(self._COMP_gain_out, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def gate(self) -> GateSettings:
|
||||
return GateSettings(
|
||||
threshold_in=round(
|
||||
int.from_bytes(self._GATE_dBThreshold_in, 'little', signed=True) * 0.01,
|
||||
2,
|
||||
),
|
||||
damping_max=round(
|
||||
int.from_bytes(self._GATE_dBDamping_max, 'little', signed=True) * 0.01,
|
||||
2,
|
||||
),
|
||||
bp_sidechain=round(
|
||||
int.from_bytes(self._GATE_BP_Sidechain, 'little') * 0.1, 2
|
||||
),
|
||||
attack_ms=round(int.from_bytes(self._GATE_attack_ms, 'little') * 0.1, 2),
|
||||
hold_ms=round(int.from_bytes(self._GATE_hold_ms, 'little') * 0.1, 2),
|
||||
release_ms=round(int.from_bytes(self._GATE_release_ms, 'little') * 0.1, 2),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def denoiser(self) -> DenoiserSettings:
|
||||
return DenoiserSettings(
|
||||
threshold=round(
|
||||
int.from_bytes(self._DenoiserThreshold, 'little', signed=True) * 0.01, 2
|
||||
)
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def pitch(self) -> PitchSettings:
|
||||
return PitchSettings(
|
||||
enabled=bool(int.from_bytes(self._PitchEnabled, 'little')),
|
||||
dry_wet=round(
|
||||
int.from_bytes(self._Pitch_DryWet, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
value=round(
|
||||
int.from_bytes(self._Pitch_Value, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
formant_lo=round(
|
||||
int.from_bytes(self._Pitch_formant_lo, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
formant_med=round(
|
||||
int.from_bytes(self._Pitch_formant_med, 'little', signed=True) * 0.01, 2
|
||||
),
|
||||
formant_high=round(
|
||||
int.from_bytes(self._Pitch_formant_high, 'little', signed=True) * 0.01,
|
||||
2,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanRTPacketNBS1(VbanRTPacket):
|
||||
"""Represents the body of a VBAN RTPacket with ident:1"""
|
||||
|
||||
strips: tuple[VbanVMParamStrip, ...]
|
||||
|
||||
@classmethod
|
||||
def from_bytes(
|
||||
cls,
|
||||
nbs: NBS,
|
||||
kind: KindMapClass,
|
||||
data: bytes,
|
||||
):
|
||||
return cls(
|
||||
nbs=nbs,
|
||||
_kind=kind,
|
||||
_voicemeeterType=data[28:29],
|
||||
_reserved=data[29:30],
|
||||
_buffersize=data[30:32],
|
||||
_voicemeeterVersion=data[32:36],
|
||||
_optionBits=data[36:40],
|
||||
_samplerate=data[40:44],
|
||||
strips=tuple(
|
||||
VbanVMParamStrip.from_bytes(
|
||||
data[44 + i * VMPARAMSTRIP_SIZE : 44 + (i + 1) * VMPARAMSTRIP_SIZE]
|
||||
)
|
||||
for i in range(16)
|
||||
),
|
||||
)
|
||||
@ -1,126 +0,0 @@
|
||||
import struct
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
from .headers import VbanPingHeader
|
||||
|
||||
# VBAN PING bitType constants
|
||||
VBANPING_TYPE_RECEPTOR = 0x00000001 # Simple receptor
|
||||
VBANPING_TYPE_TRANSMITTER = 0x00000002 # Simple Transmitter
|
||||
VBANPING_TYPE_RECEPTORSPOT = 0x00000004 # SPOT receptor
|
||||
VBANPING_TYPE_TRANSMITTERSPOT = 0x00000008 # SPOT transmitter
|
||||
VBANPING_TYPE_VIRTUALDEVICE = 0x00000010 # Virtual Device
|
||||
VBANPING_TYPE_VIRTUALMIXER = 0x00000020 # Virtual Mixer
|
||||
VBANPING_TYPE_MATRIX = 0x00000040 # MATRIX
|
||||
VBANPING_TYPE_DAW = 0x00000080 # Workstation
|
||||
VBANPING_TYPE_SERVER = 0x01000000 # VBAN SERVER
|
||||
|
||||
# VBAN PING bitfeature constants
|
||||
VBANPING_FEATURE_AUDIO = 0x00000001
|
||||
VBANPING_FEATURE_AOIP = 0x00000002
|
||||
VBANPING_FEATURE_VOIP = 0x00000004
|
||||
VBANPING_FEATURE_SERIAL = 0x00000100
|
||||
VBANPING_FEATURE_MIDI = 0x00000300
|
||||
VBANPING_FEATURE_FRAME = 0x00001000
|
||||
VBANPING_FEATURE_TXT = 0x00010000
|
||||
|
||||
|
||||
class VbanServerType(Enum):
|
||||
"""VBAN server types detected from PONG responses"""
|
||||
|
||||
UNKNOWN = 0
|
||||
VOICEMEETER = VBANPING_TYPE_VIRTUALMIXER
|
||||
MATRIX = VBANPING_TYPE_MATRIX
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanPing0Payload:
|
||||
"""Represents the VBAN PING0 payload structure as defined in the VBAN protocol documentation."""
|
||||
|
||||
def __init__(self):
|
||||
self.bit_type = VBANPING_TYPE_RECEPTOR
|
||||
self.bit_feature = VBANPING_FEATURE_TXT
|
||||
self.bit_feature_ex = 0x00000000
|
||||
self.preferred_rate = 48000
|
||||
self.min_rate = 8000
|
||||
self.max_rate = 192000
|
||||
self.color_rgb = 0x00FF0000
|
||||
self.version = b'\x01\x02\x03\x04'
|
||||
self.gps_position = b'\x00' * 8
|
||||
self.user_position = b'\x00' * 8
|
||||
self.lang_code = b'EN\x00\x00\x00\x00\x00\x00'
|
||||
self.reserved = b'\x00' * 8
|
||||
self.reserved_ex = b'\x00' * 64
|
||||
self.distant_ip = b'\x00' * 32
|
||||
self.distant_port = 0
|
||||
self.distant_reserved = 0
|
||||
self.device_name = b'VBAN-CMD-Python\x00'.ljust(64, b'\x00')
|
||||
self.manufacturer_name = b'Python-VBAN\x00'.ljust(64, b'\x00')
|
||||
self.application_name = b'vban-cmd\x00'.ljust(64, b'\x00')
|
||||
self.host_name = b'localhost\x00'.ljust(64, b'\x00')
|
||||
self.user_name = b'Python User\x00'.ljust(128, b'\x00')
|
||||
self.user_comment = b'VBAN CMD Python Client\x00'.ljust(128, b'\x00')
|
||||
|
||||
@classmethod
|
||||
def to_bytes(cls) -> bytes:
|
||||
"""Convert payload to bytes"""
|
||||
payload = cls()
|
||||
|
||||
return struct.pack(
|
||||
'<7I4s8s8s8s8s64s32s2H64s64s64s64s128s128s',
|
||||
payload.bit_type,
|
||||
payload.bit_feature,
|
||||
payload.bit_feature_ex,
|
||||
payload.preferred_rate,
|
||||
payload.min_rate,
|
||||
payload.max_rate,
|
||||
payload.color_rgb,
|
||||
payload.version,
|
||||
payload.gps_position,
|
||||
payload.user_position,
|
||||
payload.lang_code,
|
||||
payload.reserved,
|
||||
payload.reserved_ex,
|
||||
payload.distant_ip,
|
||||
payload.distant_port,
|
||||
payload.distant_reserved,
|
||||
payload.device_name,
|
||||
payload.manufacturer_name,
|
||||
payload.application_name,
|
||||
payload.host_name,
|
||||
payload.user_name,
|
||||
payload.user_comment,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_packet(cls, framecounter: int) -> bytes:
|
||||
"""Creates a complete PING packet with header and payload."""
|
||||
data = bytearray()
|
||||
data.extend(VbanPingHeader.to_bytes(framecounter))
|
||||
data.extend(cls.to_bytes())
|
||||
return bytes(data)
|
||||
|
||||
@staticmethod
|
||||
def detect_server_type(pong_data: bytes) -> VbanServerType:
|
||||
"""Detect server type from PONG response packet.
|
||||
|
||||
Args:
|
||||
pong_data: Raw bytes from PONG response packet
|
||||
|
||||
Returns:
|
||||
VbanServerType enum indicating the detected server type
|
||||
"""
|
||||
try:
|
||||
if len(pong_data) >= 32:
|
||||
frame_counter_bytes = pong_data[28:32]
|
||||
frame_counter = int.from_bytes(frame_counter_bytes, 'little')
|
||||
|
||||
if frame_counter == VbanServerType.MATRIX.value:
|
||||
return VbanServerType.MATRIX
|
||||
elif frame_counter == VbanServerType.VOICEMEETER.value:
|
||||
return VbanServerType.VOICEMEETER
|
||||
|
||||
return VbanServerType.UNKNOWN
|
||||
|
||||
except Exception:
|
||||
return VbanServerType.UNKNOWN
|
||||
@ -1,138 +0,0 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
from .error import VBANCMDError
|
||||
from .iremote import IRemote
|
||||
from .meta import action_fn
|
||||
|
||||
|
||||
class Recorder(IRemote):
|
||||
"""
|
||||
Implements the common interface
|
||||
|
||||
Defines concrete implementation for recorder
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def make(cls, remote):
|
||||
"""
|
||||
Factory function for recorder class.
|
||||
|
||||
Returns a Recorder class of a kind.
|
||||
"""
|
||||
Recorder_cls = type(
|
||||
f'Recorder{remote.kind}',
|
||||
(cls,),
|
||||
{
|
||||
**{
|
||||
param: action_fn(param)
|
||||
for param in [
|
||||
'play',
|
||||
'stop',
|
||||
'pause',
|
||||
'replay',
|
||||
'record',
|
||||
'ff',
|
||||
'rew',
|
||||
]
|
||||
},
|
||||
},
|
||||
)
|
||||
return Recorder_cls(remote)
|
||||
|
||||
def __str__(self):
|
||||
return f'{type(self).__name__}'
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return 'recorder'
|
||||
|
||||
@property
|
||||
def samplerate(self) -> int:
|
||||
return
|
||||
|
||||
@samplerate.setter
|
||||
def samplerate(self, val: int):
|
||||
opts = (22050, 24000, 32000, 44100, 48000, 88200, 96000, 176400, 192000)
|
||||
if val not in opts:
|
||||
self.logger.warning(f'samplerate got: {val} but expected a value in {opts}')
|
||||
self.setter('samplerate', val)
|
||||
|
||||
@property
|
||||
def bitresolution(self) -> int:
|
||||
return
|
||||
|
||||
@bitresolution.setter
|
||||
def bitresolution(self, val: int):
|
||||
opts = (8, 16, 24, 32)
|
||||
if val not in opts:
|
||||
self.logger.warning(
|
||||
f'bitresolution got: {val} but expected a value in {opts}'
|
||||
)
|
||||
self.setter('bitresolution', val)
|
||||
|
||||
@property
|
||||
def channel(self) -> int:
|
||||
return
|
||||
|
||||
@channel.setter
|
||||
def channel(self, val: int):
|
||||
if not 1 <= val <= 8:
|
||||
self.logger.warning(f'channel got: {val} but expected a value from 1 to 8')
|
||||
self.setter('channel', val)
|
||||
|
||||
@property
|
||||
def kbps(self):
|
||||
return
|
||||
|
||||
@kbps.setter
|
||||
def kbps(self, val: int):
|
||||
opts = (32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320)
|
||||
if val not in opts:
|
||||
self.logger.warning(f'kbps got: {val} but expected a value in {opts}')
|
||||
self.setter('kbps', val)
|
||||
|
||||
@property
|
||||
def gain(self) -> float:
|
||||
return
|
||||
|
||||
@gain.setter
|
||||
def gain(self, val: float):
|
||||
self.setter('gain', val)
|
||||
|
||||
def load(self, file: os.PathLike):
|
||||
try:
|
||||
# Convert to string, use forward slashes, and wrap in quotes for spaces
|
||||
file_path = f'"{os.fspath(file).replace(chr(92), "/")}"'
|
||||
self.setter('load', file_path)
|
||||
except UnicodeError:
|
||||
raise VBANCMDError('File full directory must be a raw string')
|
||||
|
||||
def goto(self, time_str):
|
||||
def get_sec():
|
||||
"""Get seconds from time string"""
|
||||
h, m, s = time_str.split(':')
|
||||
return int(h) * 3600 + int(m) * 60 + int(s)
|
||||
|
||||
time_str = str(time_str) # coerce the type
|
||||
if (
|
||||
re.match(
|
||||
r'^(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)$',
|
||||
time_str,
|
||||
)
|
||||
is not None
|
||||
):
|
||||
self.setter('goto', get_sec())
|
||||
else:
|
||||
self.logger.warning(
|
||||
"goto expects a string that matches the format 'hh:mm:ss'"
|
||||
)
|
||||
|
||||
def filetype(self, val: str):
|
||||
opts = {'wav': 1, 'aiff': 2, 'bwf': 3, 'mp3': 100}
|
||||
try:
|
||||
self.setter('filetype', opts[val.lower()])
|
||||
except KeyError:
|
||||
self.logger.warning(
|
||||
f'filetype got: {val} but expected a value in {list(opts.keys())}'
|
||||
)
|
||||
@ -540,11 +540,22 @@ class StripLevel(IRemote):
|
||||
def getter(self):
|
||||
"""Returns a tuple of level values for the channel."""
|
||||
|
||||
def fget(i):
|
||||
return round((((1 << 16) - 1) - i) * -0.01, 1)
|
||||
|
||||
if not self._remote.stopped() and self._remote.event.ldirty:
|
||||
return self._remote.cache['strip_level'][self.range[0] : self.range[-1]]
|
||||
return self.public_packets[NBS.zero].levels.strip[
|
||||
self.range[0] : self.range[-1]
|
||||
]
|
||||
return tuple(
|
||||
fget(i)
|
||||
for i in self._remote.cache['strip_level'][
|
||||
self.range[0] : self.range[-1]
|
||||
]
|
||||
)
|
||||
return tuple(
|
||||
fget(i)
|
||||
for i in self._remote._get_levels(self.public_packets[NBS.zero])[0][
|
||||
self.range[0] : self.range[-1]
|
||||
]
|
||||
)
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
|
||||
103
vban_cmd/util.py
103
vban_cmd/util.py
@ -1,62 +1,5 @@
|
||||
import socket
|
||||
import time
|
||||
from typing import Iterator
|
||||
|
||||
from .error import VBANCMDConnectionError
|
||||
|
||||
|
||||
def script_ratelimit(func):
|
||||
"""script_ratelimit decorator for {VbanCmd}.sendtext, to prevent flooding the network with script requests."""
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
self, *rem = args
|
||||
if self.script_ratelimit:
|
||||
now = time.time()
|
||||
elapsed = now - self._last_script_request_time
|
||||
if elapsed < self.script_ratelimit:
|
||||
time.sleep(self.script_ratelimit - elapsed)
|
||||
self._last_script_request_time = time.time()
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def pong_timeout(func):
|
||||
"""pong_timeout decorator for {VbanCmd}._handle_pong, to handle timeout logic and socket management."""
|
||||
|
||||
def wrapper(self, timeout: float = None):
|
||||
if timeout is None:
|
||||
timeout = min(self.timeout, 3.0)
|
||||
|
||||
original_timeout = self.sock.gettimeout()
|
||||
self.sock.settimeout(0.5)
|
||||
|
||||
try:
|
||||
start_time = time.time()
|
||||
response_count = 0
|
||||
|
||||
while time.time() - start_time < timeout:
|
||||
try:
|
||||
response_count += 1
|
||||
|
||||
if func(self):
|
||||
return
|
||||
|
||||
except socket.timeout:
|
||||
continue
|
||||
|
||||
self.logger.debug(
|
||||
f'PING timeout after {timeout}s, received {response_count} non-PONG packets'
|
||||
)
|
||||
raise VBANCMDConnectionError(
|
||||
f'PING timeout: No response from {self.host}:{self.port} after {timeout}s'
|
||||
)
|
||||
|
||||
finally:
|
||||
self.sock.settimeout(original_timeout)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def cache_bool(func, param):
|
||||
"""Check cache for a bool prop"""
|
||||
@ -72,27 +15,13 @@ def cache_bool(func, param):
|
||||
return wrapper
|
||||
|
||||
|
||||
def cache_int(func, param):
|
||||
"""Check cache for an int prop"""
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
self, *rem = args
|
||||
if self._cmd(param) in self._remote.cache:
|
||||
return self._remote.cache.pop(self._cmd(param))
|
||||
if self._remote.sync:
|
||||
self._remote.clear_dirty()
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def cache_string(func, param):
|
||||
"""Check cache for a string prop"""
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
self, *rem = args
|
||||
if self._cmd(param) in self._remote.cache:
|
||||
return self._remote.cache.pop(self._cmd(param)).strip('"')
|
||||
return self._remote.cache.pop(self._cmd(param))
|
||||
if self._remote.sync:
|
||||
self._remote.clear_dirty()
|
||||
return func(*args, **kwargs)
|
||||
@ -120,15 +49,39 @@ def depth(d):
|
||||
return 0
|
||||
|
||||
|
||||
def script(func):
|
||||
"""Convert dictionary to script"""
|
||||
|
||||
def wrapper(*args):
|
||||
remote, script = args
|
||||
if isinstance(script, dict):
|
||||
params = ''
|
||||
for key, val in script.items():
|
||||
obj, m2, *rem = key.split('-')
|
||||
index = int(m2) if m2.isnumeric() else int(*rem)
|
||||
params += ';'.join(
|
||||
f'{obj}{f".{m2}stream" if not m2.isnumeric() else ""}[{index}].{k}={int(v) if isinstance(v, bool) else v}'
|
||||
for k, v in val.items()
|
||||
)
|
||||
params += ';'
|
||||
script = params
|
||||
return func(remote, script)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def comp(t0: tuple, t1: tuple) -> Iterator[bool]:
|
||||
"""
|
||||
Generator function, accepts two tuples of dB values.
|
||||
Generator function, accepts two tuples.
|
||||
|
||||
Returns True when levels are equal (no change), False when different.
|
||||
Evaluates equality of each member in both tuples.
|
||||
"""
|
||||
|
||||
for a, b in zip(t0, t1):
|
||||
yield a == b
|
||||
if ((1 << 16) - 1) - b <= 7200:
|
||||
yield a == b
|
||||
else:
|
||||
yield True
|
||||
|
||||
|
||||
def deep_merge(dict1, dict2):
|
||||
|
||||
@ -5,19 +5,14 @@ import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import Mapping, Union
|
||||
from typing import Iterable, Union
|
||||
|
||||
from .enums import NBS
|
||||
from .error import VBANCMDConnectionError, VBANCMDError
|
||||
from .error import VBANCMDError
|
||||
from .event import Event
|
||||
from .packet.headers import (
|
||||
VbanMatrixResponseHeader,
|
||||
VbanPongHeader,
|
||||
VbanRTRequestHeader,
|
||||
)
|
||||
from .packet.ping0 import VbanPing0Payload, VbanServerType
|
||||
from .packet import RequestHeader
|
||||
from .subject import Subject
|
||||
from .util import bump_framecounter, deep_merge, pong_timeout, script_ratelimit
|
||||
from .util import bump_framecounter, deep_merge, script
|
||||
from .worker import Producer, Subscriber, Updater
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -27,39 +22,37 @@ class VbanCmd(abc.ABC):
|
||||
"""Abstract Base Class for Voicemeeter VBAN Command Interfaces"""
|
||||
|
||||
DELAY = 0.001
|
||||
# fmt: off
|
||||
BPS_OPTS = [
|
||||
0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
|
||||
38400, 57600, 115200, 128000, 230400, 250000, 256000, 460800, 921600,
|
||||
1000000, 1500000, 2000000, 3000000,
|
||||
]
|
||||
# fmt: on
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
self.event = Event({k: kwargs.pop(k) for k in ('pdirty', 'ldirty')})
|
||||
if not kwargs['host']:
|
||||
if not kwargs['ip']:
|
||||
kwargs |= self._conn_from_toml()
|
||||
for attr, val in kwargs.items():
|
||||
setattr(self, attr, val)
|
||||
|
||||
try:
|
||||
self._host_ip = socket.gethostbyname(self.host)
|
||||
except socket.gaierror as e:
|
||||
raise VBANCMDConnectionError(
|
||||
f'Unable to resolve hostname {self.host}'
|
||||
) from e
|
||||
|
||||
self._framecounter = 0
|
||||
self._framecounter_lock = threading.Lock()
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.sock.settimeout(self.timeout)
|
||||
self.subject = self.observer = Subject()
|
||||
self.cache = {}
|
||||
self._pdirty = False
|
||||
self._ldirty = False
|
||||
self._script = str()
|
||||
self.stop_event = None
|
||||
self.producer = None
|
||||
self._last_script_request_time = 0
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def steps(self):
|
||||
"""Steps required to build the interface for this Voicemeeter kind"""
|
||||
def __str__(self):
|
||||
"""Ensure subclasses override str magic method"""
|
||||
pass
|
||||
|
||||
def _conn_from_toml(self) -> dict:
|
||||
try:
|
||||
@ -93,13 +86,8 @@ class VbanCmd(abc.ABC):
|
||||
self.logout()
|
||||
|
||||
def login(self) -> None:
|
||||
"""Sends a PING packet to the VBAN server to verify connectivity and detect server type.
|
||||
If the server is detected as Matrix, RT listeners will be disabled for compatibility.
|
||||
"""
|
||||
self._ping()
|
||||
self._handle_pong()
|
||||
|
||||
if not self.disable_rt_listeners:
|
||||
"""Starts the subscriber and updater threads (unless in outbound mode)"""
|
||||
if not self.outbound:
|
||||
self.event.info()
|
||||
|
||||
self.stop_event = threading.Event()
|
||||
@ -114,7 +102,7 @@ class VbanCmd(abc.ABC):
|
||||
self.producer.start()
|
||||
|
||||
self.logger.info(
|
||||
"Successfully logged into VBANCMD {kind} with host='{host}', port={port}, streamname='{streamname}'".format(
|
||||
"Successfully logged into VBANCMD {kind} with ip='{ip}', port={port}, streamname='{streamname}'".format(
|
||||
**self.__dict__
|
||||
)
|
||||
)
|
||||
@ -132,104 +120,39 @@ class VbanCmd(abc.ABC):
|
||||
def stopped(self):
|
||||
return self.stop_event is None or self.stop_event.is_set()
|
||||
|
||||
def _get_next_framecounter(self) -> int:
|
||||
"""Thread-safe method to get and increment framecounter."""
|
||||
with self._framecounter_lock:
|
||||
current = self._framecounter
|
||||
self._framecounter = bump_framecounter(self._framecounter)
|
||||
return current
|
||||
|
||||
def _ping(self):
|
||||
"""Initiates the PING/PONG handshake with the VBAN server."""
|
||||
try:
|
||||
self.sock.sendto(
|
||||
VbanPing0Payload.create_packet(self._get_next_framecounter()),
|
||||
(self._host_ip, self.port),
|
||||
)
|
||||
self.logger.debug(f'PING sent to {self.host}:{self.port}')
|
||||
|
||||
except Exception as e:
|
||||
raise VBANCMDConnectionError(f'PING failed: {e}') from e
|
||||
|
||||
@pong_timeout
|
||||
def _handle_pong(self) -> bool:
|
||||
"""Handles incoming packets during the PING/PONG handshake, looking for a valid PONG response to confirm connectivity and detect server type.
|
||||
|
||||
Returns True if a valid PONG is received, False otherwise."""
|
||||
data, addr = self.sock.recvfrom(2048)
|
||||
|
||||
if VbanPongHeader.is_pong_response(data):
|
||||
self.logger.debug(f'PONG received from {addr}, connectivity confirmed')
|
||||
|
||||
server_type = VbanPing0Payload.detect_server_type(data)
|
||||
self._handle_server_type(server_type)
|
||||
|
||||
return True
|
||||
else:
|
||||
if len(data) >= 8:
|
||||
if data[:4] == b'VBAN':
|
||||
protocol = data[4] & 0xE0
|
||||
nbc = data[6]
|
||||
self.logger.debug(
|
||||
f'Non-PONG VBAN packet: protocol=0x{protocol:02x}, nbc=0x{nbc:02x}'
|
||||
)
|
||||
else:
|
||||
self.logger.debug('Non-VBAN packet received')
|
||||
|
||||
return False
|
||||
|
||||
def _handle_server_type(self, server_type: VbanServerType) -> None:
|
||||
"""Handle the detected server type by adjusting settings accordingly."""
|
||||
match server_type:
|
||||
case VbanServerType.VOICEMEETER:
|
||||
self.logger.debug(
|
||||
'Detected Voicemeeter VBAN server - RT listeners supported'
|
||||
)
|
||||
case VbanServerType.MATRIX:
|
||||
self.logger.info(
|
||||
'Detected Matrix VBAN server - disabling RT listeners for compatibility'
|
||||
)
|
||||
self.disable_rt_listeners = True
|
||||
case _:
|
||||
self.logger.debug(
|
||||
f'Unknown server type ({server_type}) - using default settings'
|
||||
)
|
||||
|
||||
def _send_request(self, payload: str) -> None:
|
||||
"""Sends a request packet over the network and bumps the framecounter."""
|
||||
self.sock.sendto(
|
||||
VbanRTRequestHeader.encode_with_payload(
|
||||
name=self.streamname,
|
||||
bps=self.bps,
|
||||
channel=self.channel,
|
||||
framecounter=self._get_next_framecounter(),
|
||||
payload=payload,
|
||||
),
|
||||
(self._host_ip, self.port),
|
||||
)
|
||||
|
||||
def _set_rt(self, cmd: str, val: Union[str, float]):
|
||||
"""Sends a string request command over a network."""
|
||||
self._send_request(f'{cmd}={val};')
|
||||
req_packet = RequestHeader.to_bytes(
|
||||
name=self.streamname,
|
||||
bps_index=self.BPS_OPTS.index(self.bps),
|
||||
channel=self.channel,
|
||||
framecounter=self._framecounter,
|
||||
)
|
||||
self.sock.sendto(
|
||||
req_packet + f'{cmd}={val};'.encode(),
|
||||
(socket.gethostbyname(self.ip), self.port),
|
||||
)
|
||||
self._framecounter = bump_framecounter(self._framecounter)
|
||||
|
||||
self.cache[cmd] = val
|
||||
|
||||
@script_ratelimit
|
||||
def sendtext(self, script) -> str | None:
|
||||
@script
|
||||
def sendtext(self, script):
|
||||
"""Sends a multiple parameter string over a network."""
|
||||
self._send_request(script)
|
||||
self.logger.debug(f'sendtext: {script}')
|
||||
req_packet = RequestHeader.to_bytes(
|
||||
name=self.streamname,
|
||||
bps_index=self.BPS_OPTS.index(self.bps),
|
||||
channel=self.channel,
|
||||
framecounter=self._framecounter,
|
||||
)
|
||||
self.sock.sendto(
|
||||
req_packet + script.encode(),
|
||||
(socket.gethostbyname(self.ip), self.port),
|
||||
)
|
||||
self._framecounter = bump_framecounter(self._framecounter)
|
||||
|
||||
if self.disable_rt_listeners and script.endswith(('?', '?;')):
|
||||
try:
|
||||
data, _ = self.sock.recvfrom(2048)
|
||||
return VbanMatrixResponseHeader.extract_payload(data)
|
||||
except ValueError as e:
|
||||
self.logger.warning(f'Error extracting matrix response: {e}')
|
||||
except TimeoutError as e:
|
||||
self.logger.exception(f'Timeout waiting for matrix response: {e}')
|
||||
raise VBANCMDConnectionError(
|
||||
f'Timeout waiting for response from {self.host}:{self.port}'
|
||||
) from e
|
||||
self.logger.debug(f'sendtext: {script}')
|
||||
time.sleep(self.DELAY)
|
||||
|
||||
@property
|
||||
def type(self) -> str:
|
||||
@ -261,8 +184,23 @@ class VbanCmd(abc.ABC):
|
||||
while self.pdirty:
|
||||
time.sleep(self.DELAY)
|
||||
|
||||
def apply(self, data: Mapping):
|
||||
"""Set all parameters of a dict"""
|
||||
def _get_levels(self, packet) -> Iterable:
|
||||
"""
|
||||
returns both level arrays (strip_levels, bus_levels) BEFORE math conversion
|
||||
|
||||
strip levels in PREFADER mode.
|
||||
"""
|
||||
return (
|
||||
packet.inputlevels,
|
||||
packet.outputlevels,
|
||||
)
|
||||
|
||||
def apply(self, data: dict):
|
||||
"""
|
||||
Sets all parameters of a dict
|
||||
|
||||
minor delay between each recursion
|
||||
"""
|
||||
|
||||
def target(key):
|
||||
match key.split('-'):
|
||||
@ -282,8 +220,7 @@ class VbanCmd(abc.ABC):
|
||||
raise ValueError(ERR_MSG)
|
||||
return target[int(index)]
|
||||
|
||||
for key, di in data.items():
|
||||
target(key).apply(di)
|
||||
[target(key).apply(di).then_wait() for key, di in data.items()]
|
||||
|
||||
def apply_config(self, name):
|
||||
"""applies a config from memory"""
|
||||
|
||||
@ -1,18 +1,21 @@
|
||||
import logging
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
|
||||
from .enums import NBS
|
||||
from .error import VBANCMDConnectionError, VBANCMDPacketError
|
||||
from .packet.enums import SubProtocols
|
||||
from .packet.headers import (
|
||||
from .error import VBANCMDConnectionError
|
||||
from .packet import (
|
||||
HEADER_SIZE,
|
||||
VbanRTPacket,
|
||||
VbanRTResponseHeader,
|
||||
VbanRTSubscribeHeader,
|
||||
VBAN_PROTOCOL_SERVICE,
|
||||
VBAN_SERVICE_RTPACKET,
|
||||
SubscribeHeader,
|
||||
VbanRtPacket,
|
||||
VbanRtPacketHeader,
|
||||
VbanRtPacketNBS0,
|
||||
VbanRtPacketNBS1,
|
||||
)
|
||||
from .packet.nbs0 import VbanRTPacketNBS0
|
||||
from .packet.nbs1 import VbanRTPacketNBS1
|
||||
from .util import bump_framecounter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -25,18 +28,24 @@ class Subscriber(threading.Thread):
|
||||
self._remote = remote
|
||||
self.stop_event = stop_event
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
self._framecounter = 0
|
||||
|
||||
def run(self):
|
||||
while not self.stopped():
|
||||
for nbs in NBS:
|
||||
sub_packet = VbanRTSubscribeHeader().to_bytes(
|
||||
nbs, self._remote._get_next_framecounter()
|
||||
)
|
||||
self._remote.sock.sendto(
|
||||
sub_packet, (self._remote._host_ip, self._remote.port)
|
||||
)
|
||||
try:
|
||||
for nbs in NBS:
|
||||
sub_packet = SubscribeHeader().to_bytes(nbs, self._framecounter)
|
||||
self._remote.sock.sendto(
|
||||
sub_packet, (self._remote.ip, self._remote.port)
|
||||
)
|
||||
self._framecounter = bump_framecounter(self._framecounter)
|
||||
|
||||
self.wait_until_stopped(10)
|
||||
self.wait_until_stopped(10)
|
||||
except socket.gaierror as e:
|
||||
self.logger.exception(f'{type(e).__name__}: {e}')
|
||||
raise VBANCMDConnectionError(
|
||||
f'unable to resolve hostname {self._remote.ip}'
|
||||
) from e
|
||||
self.logger.debug(f'terminating {self.name} thread')
|
||||
|
||||
def stopped(self):
|
||||
@ -59,48 +68,51 @@ class Producer(threading.Thread):
|
||||
self.queue = queue
|
||||
self.stop_event = stop_event
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
self._remote.sock.settimeout(self._remote.timeout)
|
||||
self._remote._public_packets = [None] * (max(NBS) + 1)
|
||||
_pp = self._get_rt()
|
||||
self._remote._public_packets[_pp.nbs] = _pp
|
||||
(
|
||||
self._remote.cache['strip_level'],
|
||||
self._remote.cache['bus_level'],
|
||||
) = self._remote.public_packets[NBS.zero].levels
|
||||
) = self._remote._get_levels(self._remote.public_packets[NBS.zero])
|
||||
|
||||
def _get_rt(self) -> VbanRTPacket:
|
||||
def _get_rt(self) -> VbanRtPacket:
|
||||
"""Attempt to fetch data packet until a valid one found"""
|
||||
|
||||
while True:
|
||||
try:
|
||||
data, _ = self._remote.sock.recvfrom(2048)
|
||||
if len(data) < HEADER_SIZE:
|
||||
continue
|
||||
except TimeoutError as e:
|
||||
self.logger.exception(f'{type(e).__name__}: {e}')
|
||||
raise VBANCMDConnectionError(
|
||||
f'timeout waiting for response from {self._remote.host}:{self._remote.port}'
|
||||
) from e
|
||||
if resp := self._fetch_rt_packet():
|
||||
return resp
|
||||
|
||||
try:
|
||||
header = VbanRTResponseHeader.from_bytes(data[:HEADER_SIZE])
|
||||
except VBANCMDPacketError as e:
|
||||
match e.protocol:
|
||||
case SubProtocols.SERVICE:
|
||||
# Silently ignore periodic SERVICE packets unrelated to vban-cmd
|
||||
pass
|
||||
case _:
|
||||
self.logger.debug(f'Error parsing response packet: {e}')
|
||||
continue
|
||||
def _fetch_rt_packet(self) -> VbanRtPacket | None:
|
||||
try:
|
||||
data, _ = self._remote.sock.recvfrom(2048)
|
||||
if len(data) < HEADER_SIZE:
|
||||
return
|
||||
|
||||
match header.format_nbs:
|
||||
response_header = VbanRtPacketHeader.from_bytes(data[:HEADER_SIZE])
|
||||
if (
|
||||
response_header.format_sr != VBAN_PROTOCOL_SERVICE
|
||||
or response_header.format_nbc != VBAN_SERVICE_RTPACKET
|
||||
):
|
||||
return
|
||||
|
||||
match response_header.format_nbs:
|
||||
case NBS.zero:
|
||||
return VbanRTPacketNBS0.from_bytes(
|
||||
return VbanRtPacketNBS0.from_bytes(
|
||||
nbs=NBS.zero, kind=self._remote.kind, data=data
|
||||
)
|
||||
|
||||
case NBS.one:
|
||||
return VbanRTPacketNBS1.from_bytes(
|
||||
return VbanRtPacketNBS1.from_bytes(
|
||||
nbs=NBS.one, kind=self._remote.kind, data=data
|
||||
)
|
||||
return None
|
||||
except TimeoutError as e:
|
||||
self.logger.exception(f'{type(e).__name__}: {e}')
|
||||
raise VBANCMDConnectionError(
|
||||
f'timeout waiting for RtPacket from {self._remote.ip}'
|
||||
) from e
|
||||
|
||||
def stopped(self):
|
||||
return self.stop_event.is_set()
|
||||
@ -128,6 +140,7 @@ class Producer(threading.Thread):
|
||||
self.queue.put('pdirty')
|
||||
if self._remote.event.ldirty:
|
||||
self.queue.put('ldirty')
|
||||
time.sleep(self._remote.ratelimit)
|
||||
self.logger.debug(f'terminating {self.name} thread')
|
||||
self.queue.put(None)
|
||||
|
||||
@ -164,6 +177,9 @@ class Updater(threading.Thread):
|
||||
(
|
||||
self._remote.cache['strip_level'],
|
||||
self._remote.cache['bus_level'],
|
||||
) = self._remote.public_packets[NBS.zero].levels
|
||||
) = (
|
||||
self._remote._public_packets[NBS.zero].inputlevels,
|
||||
self._remote._public_packets[NBS.zero].outputlevels,
|
||||
)
|
||||
self._remote.subject.notify(event)
|
||||
self.logger.debug(f'terminating {self.name} thread')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user