mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2026-03-03 08:49:09 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 55b3125e10 | |||
| 7b3340042c | |||
| 6ea0859180 | |||
| 81ed963bea | |||
| 0b99b6a67f | |||
| 86d0aa91c3 | |||
| cf66ae252c | |||
| 42f6f29d1e | |||
| a210766b7b | |||
| 7d741d6e8b | |||
| 8be9d3cb7f | |||
| 23b99cb66b | |||
| 2fd7b8ad8b | |||
| c851cb5abe | |||
| dc681f50d0 | |||
| a0ec00652b |
2
.gitignore
vendored
2
.gitignore
vendored
@ -159,3 +159,5 @@ config.toml
|
||||
vban.toml
|
||||
|
||||
.vscode/
|
||||
|
||||
PING_FEATURE.md
|
||||
10
CHANGELOG.md
10
CHANGELOG.md
@ -11,6 +11,16 @@ 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
|
||||
|
||||
49
README.md
49
README.md
@ -41,14 +41,14 @@ Load VBAN connection info from toml config. A valid `vban.toml` might look like
|
||||
|
||||
```toml
|
||||
[connection]
|
||||
ip = "gamepc.local"
|
||||
host = "localhost"
|
||||
port = 6980
|
||||
streamname = "Command1"
|
||||
```
|
||||
|
||||
It should be placed in \<user home directory\> / "Documents" / "Voicemeeter" / "configs"
|
||||
|
||||
Alternatively you may pass `ip`, `port`, `streamname` as keyword arguments.
|
||||
Alternatively you may pass `host`, `port`, `streamname` as keyword arguments.
|
||||
|
||||
#### `__main__.py`
|
||||
|
||||
@ -85,7 +85,7 @@ def main():
|
||||
KIND_ID = 'banana'
|
||||
|
||||
with vban_cmd.api(
|
||||
KIND_ID, ip='gamepc.local', port=6980, streamname='Command1'
|
||||
KIND_ID, host='localhost', port=6980, streamname='Command1'
|
||||
) as vban:
|
||||
do = ManyThings(vban)
|
||||
do.things()
|
||||
@ -349,6 +349,40 @@ 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:
|
||||
@ -440,7 +474,7 @@ example:
|
||||
import vban_cmd
|
||||
|
||||
opts = {
|
||||
'ip': '<ip address>',
|
||||
'host': '<ip address>',
|
||||
'streamname': 'Command1',
|
||||
'port': 6980,
|
||||
}
|
||||
@ -507,14 +541,15 @@ print(vban.event.get())
|
||||
|
||||
You may pass the following optional keyword arguments:
|
||||
|
||||
- `ip`: str='localhost', ip or hostname of remote machine
|
||||
- `host`: 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
|
||||
- `timeout`: int=5, amount of time (seconds) to wait for an incoming RT data packet (parameter states).
|
||||
- `script_ratelimit`: float=0.05, default to 20 script requests per second. This affects 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.
|
||||
|
||||
@ -557,7 +592,7 @@ import vban_cmd
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
opts = {'ip': 'ip.local', 'port': 6980, 'streamname': 'Command1'}
|
||||
opts = {'host': 'localhost', 'port': 6980, 'streamname': 'Command1'}
|
||||
with vban_cmd.api('banana', **opts) as vban:
|
||||
...
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "vban-cmd"
|
||||
version = "2.7.0"
|
||||
version = "2.9.2"
|
||||
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.35.0"
|
||||
poethepoet = ">=0.42.0"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pytest = "^8.3.4"
|
||||
|
||||
68
uv.lock
generated
Normal file
68
uv.lock
generated
Normal file
@ -0,0 +1,68 @@
|
||||
version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.10"
|
||||
|
||||
[[package]]
|
||||
name = "tomli"
|
||||
version = "2.4.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/82/30/31573e9457673ab10aa432461bee537ce6cef177667deca369efb79df071/tomli-2.4.0.tar.gz", hash = "sha256:aa89c3f6c277dd275d8e243ad24f3b5e701491a860d5121f2cdd399fbb31fc9c", size = 17477, upload-time = "2026-01-11T11:22:38.165Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/3c/d9/3dc2289e1f3b32eb19b9785b6a006b28ee99acb37d1d47f78d4c10e28bf8/tomli-2.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:b5ef256a3fd497d4973c11bf142e9ed78b150d36f5773f1ca6088c230ffc5867", size = 153663, upload-time = "2026-01-11T11:21:45.27Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/51/32/ef9f6845e6b9ca392cd3f64f9ec185cc6f09f0a2df3db08cbe8809d1d435/tomli-2.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:5572e41282d5268eb09a697c89a7bee84fae66511f87533a6f88bd2f7b652da9", size = 148469, upload-time = "2026-01-11T11:21:46.873Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d6/c2/506e44cce89a8b1b1e047d64bd495c22c9f71f21e05f380f1a950dd9c217/tomli-2.4.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:551e321c6ba03b55676970b47cb1b73f14a0a4dce6a3e1a9458fd6d921d72e95", size = 236039, upload-time = "2026-01-11T11:21:48.503Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/40/e1b65986dbc861b7e986e8ec394598187fa8aee85b1650b01dd925ca0be8/tomli-2.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5e3f639a7a8f10069d0e15408c0b96a2a828cfdec6fca05296ebcdcc28ca7c76", size = 243007, upload-time = "2026-01-11T11:21:49.456Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9c/6f/6e39ce66b58a5b7ae572a0f4352ff40c71e8573633deda43f6a379d56b3e/tomli-2.4.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1b168f2731796b045128c45982d3a4874057626da0e2ef1fdd722848b741361d", size = 240875, upload-time = "2026-01-11T11:21:50.755Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/aa/ad/cb089cb190487caa80204d503c7fd0f4d443f90b95cf4ef5cf5aa0f439b0/tomli-2.4.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:133e93646ec4300d651839d382d63edff11d8978be23da4cc106f5a18b7d0576", size = 246271, upload-time = "2026-01-11T11:21:51.81Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0b/63/69125220e47fd7a3a27fd0de0c6398c89432fec41bc739823bcc66506af6/tomli-2.4.0-cp311-cp311-win32.whl", hash = "sha256:b6c78bdf37764092d369722d9946cb65b8767bfa4110f902a1b2542d8d173c8a", size = 96770, upload-time = "2026-01-11T11:21:52.647Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1e/0d/a22bb6c83f83386b0008425a6cd1fa1c14b5f3dd4bad05e98cf3dbbf4a64/tomli-2.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:d3d1654e11d724760cdb37a3d7691f0be9db5fbdaef59c9f532aabf87006dbaa", size = 107626, upload-time = "2026-01-11T11:21:53.459Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2f/6d/77be674a3485e75cacbf2ddba2b146911477bd887dda9d8c9dfb2f15e871/tomli-2.4.0-cp311-cp311-win_arm64.whl", hash = "sha256:cae9c19ed12d4e8f3ebf46d1a75090e4c0dc16271c5bce1c833ac168f08fb614", size = 94842, upload-time = "2026-01-11T11:21:54.831Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3c/43/7389a1869f2f26dba52404e1ef13b4784b6b37dac93bac53457e3ff24ca3/tomli-2.4.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:920b1de295e72887bafa3ad9f7a792f811847d57ea6b1215154030cf131f16b1", size = 154894, upload-time = "2026-01-11T11:21:56.07Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e9/05/2f9bf110b5294132b2edf13fe6ca6ae456204f3d749f623307cbb7a946f2/tomli-2.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7d6d9a4aee98fac3eab4952ad1d73aee87359452d1c086b5ceb43ed02ddb16b8", size = 149053, upload-time = "2026-01-11T11:21:57.467Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e8/41/1eda3ca1abc6f6154a8db4d714a4d35c4ad90adc0bcf700657291593fbf3/tomli-2.4.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:36b9d05b51e65b254ea6c2585b59d2c4cb91c8a3d91d0ed0f17591a29aaea54a", size = 243481, upload-time = "2026-01-11T11:21:58.661Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d2/6d/02ff5ab6c8868b41e7d4b987ce2b5f6a51d3335a70aa144edd999e055a01/tomli-2.4.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1c8a885b370751837c029ef9bc014f27d80840e48bac415f3412e6593bbc18c1", size = 251720, upload-time = "2026-01-11T11:22:00.178Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7b/57/0405c59a909c45d5b6f146107c6d997825aa87568b042042f7a9c0afed34/tomli-2.4.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8768715ffc41f0008abe25d808c20c3d990f42b6e2e58305d5da280ae7d1fa3b", size = 247014, upload-time = "2026-01-11T11:22:01.238Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2c/0e/2e37568edd944b4165735687cbaf2fe3648129e440c26d02223672ee0630/tomli-2.4.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:7b438885858efd5be02a9a133caf5812b8776ee0c969fea02c45e8e3f296ba51", size = 251820, upload-time = "2026-01-11T11:22:02.727Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5a/1c/ee3b707fdac82aeeb92d1a113f803cf6d0f37bdca0849cb489553e1f417a/tomli-2.4.0-cp312-cp312-win32.whl", hash = "sha256:0408e3de5ec77cc7f81960c362543cbbd91ef883e3138e81b729fc3eea5b9729", size = 97712, upload-time = "2026-01-11T11:22:03.777Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/69/13/c07a9177d0b3bab7913299b9278845fc6eaaca14a02667c6be0b0a2270c8/tomli-2.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:685306e2cc7da35be4ee914fd34ab801a6acacb061b6a7abca922aaf9ad368da", size = 108296, upload-time = "2026-01-11T11:22:04.86Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/18/27/e267a60bbeeee343bcc279bb9e8fbed0cbe224bc7b2a3dc2975f22809a09/tomli-2.4.0-cp312-cp312-win_arm64.whl", hash = "sha256:5aa48d7c2356055feef06a43611fc401a07337d5b006be13a30f6c58f869e3c3", size = 94553, upload-time = "2026-01-11T11:22:05.854Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/34/91/7f65f9809f2936e1f4ce6268ae1903074563603b2a2bd969ebbda802744f/tomli-2.4.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:84d081fbc252d1b6a982e1870660e7330fb8f90f676f6e78b052ad4e64714bf0", size = 154915, upload-time = "2026-01-11T11:22:06.703Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/20/aa/64dd73a5a849c2e8f216b755599c511badde80e91e9bc2271baa7b2cdbb1/tomli-2.4.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:9a08144fa4cba33db5255f9b74f0b89888622109bd2776148f2597447f92a94e", size = 149038, upload-time = "2026-01-11T11:22:07.56Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9e/8a/6d38870bd3d52c8d1505ce054469a73f73a0fe62c0eaf5dddf61447e32fa/tomli-2.4.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c73add4bb52a206fd0c0723432db123c0c75c280cbd67174dd9d2db228ebb1b4", size = 242245, upload-time = "2026-01-11T11:22:08.344Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/59/bb/8002fadefb64ab2669e5b977df3f5e444febea60e717e755b38bb7c41029/tomli-2.4.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1fb2945cbe303b1419e2706e711b7113da57b7db31ee378d08712d678a34e51e", size = 250335, upload-time = "2026-01-11T11:22:09.951Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a5/3d/4cdb6f791682b2ea916af2de96121b3cb1284d7c203d97d92d6003e91c8d/tomli-2.4.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:bbb1b10aa643d973366dc2cb1ad94f99c1726a02343d43cbc011edbfac579e7c", size = 245962, upload-time = "2026-01-11T11:22:11.27Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f2/4a/5f25789f9a460bd858ba9756ff52d0830d825b458e13f754952dd15fb7bb/tomli-2.4.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:4cbcb367d44a1f0c2be408758b43e1ffb5308abe0ea222897d6bfc8e8281ef2f", size = 250396, upload-time = "2026-01-11T11:22:12.325Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/aa/2f/b73a36fea58dfa08e8b3a268750e6853a6aac2a349241a905ebd86f3047a/tomli-2.4.0-cp313-cp313-win32.whl", hash = "sha256:7d49c66a7d5e56ac959cb6fc583aff0651094ec071ba9ad43df785abc2320d86", size = 97530, upload-time = "2026-01-11T11:22:13.865Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3b/af/ca18c134b5d75de7e8dc551c5234eaba2e8e951f6b30139599b53de9c187/tomli-2.4.0-cp313-cp313-win_amd64.whl", hash = "sha256:3cf226acb51d8f1c394c1b310e0e0e61fecdd7adcb78d01e294ac297dd2e7f87", size = 108227, upload-time = "2026-01-11T11:22:15.224Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/22/c3/b386b832f209fee8073c8138ec50f27b4460db2fdae9ffe022df89a57f9b/tomli-2.4.0-cp313-cp313-win_arm64.whl", hash = "sha256:d20b797a5c1ad80c516e41bc1fb0443ddb5006e9aaa7bda2d71978346aeb9132", size = 94748, upload-time = "2026-01-11T11:22:16.009Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f3/c4/84047a97eb1004418bc10bdbcfebda209fca6338002eba2dc27cc6d13563/tomli-2.4.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:26ab906a1eb794cd4e103691daa23d95c6919cc2fa9160000ac02370cc9dd3f6", size = 154725, upload-time = "2026-01-11T11:22:17.269Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a8/5d/d39038e646060b9d76274078cddf146ced86dc2b9e8bbf737ad5983609a0/tomli-2.4.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:20cedb4ee43278bc4f2fee6cb50daec836959aadaf948db5172e776dd3d993fc", size = 148901, upload-time = "2026-01-11T11:22:18.287Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/73/e5/383be1724cb30f4ce44983d249645684a48c435e1cd4f8b5cded8a816d3c/tomli-2.4.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:39b0b5d1b6dd03684b3fb276407ebed7090bbec989fa55838c98560c01113b66", size = 243375, upload-time = "2026-01-11T11:22:19.154Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/31/f0/bea80c17971c8d16d3cc109dc3585b0f2ce1036b5f4a8a183789023574f2/tomli-2.4.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a26d7ff68dfdb9f87a016ecfd1e1c2bacbe3108f4e0f8bcd2228ef9a766c787d", size = 250639, upload-time = "2026-01-11T11:22:20.168Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2c/8f/2853c36abbb7608e3f945d8a74e32ed3a74ee3a1f468f1ffc7d1cb3abba6/tomli-2.4.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:20ffd184fb1df76a66e34bd1b36b4a4641bd2b82954befa32fe8163e79f1a702", size = 246897, upload-time = "2026-01-11T11:22:21.544Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/49/f0/6c05e3196ed5337b9fe7ea003e95fd3819a840b7a0f2bf5a408ef1dad8ed/tomli-2.4.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:75c2f8bbddf170e8effc98f5e9084a8751f8174ea6ccf4fca5398436e0320bc8", size = 254697, upload-time = "2026-01-11T11:22:23.058Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f3/f5/2922ef29c9f2951883525def7429967fc4d8208494e5ab524234f06b688b/tomli-2.4.0-cp314-cp314-win32.whl", hash = "sha256:31d556d079d72db7c584c0627ff3a24c5d3fb4f730221d3444f3efb1b2514776", size = 98567, upload-time = "2026-01-11T11:22:24.033Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7b/31/22b52e2e06dd2a5fdbc3ee73226d763b184ff21fc24e20316a44ccc4d96b/tomli-2.4.0-cp314-cp314-win_amd64.whl", hash = "sha256:43e685b9b2341681907759cf3a04e14d7104b3580f808cfde1dfdb60ada85475", size = 108556, upload-time = "2026-01-11T11:22:25.378Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/48/3d/5058dff3255a3d01b705413f64f4306a141a8fd7a251e5a495e3f192a998/tomli-2.4.0-cp314-cp314-win_arm64.whl", hash = "sha256:3d895d56bd3f82ddd6faaff993c275efc2ff38e52322ea264122d72729dca2b2", size = 96014, upload-time = "2026-01-11T11:22:26.138Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b8/4e/75dab8586e268424202d3a1997ef6014919c941b50642a1682df43204c22/tomli-2.4.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:5b5807f3999fb66776dbce568cc9a828544244a8eb84b84b9bafc080c99597b9", size = 163339, upload-time = "2026-01-11T11:22:27.143Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/06/e3/b904d9ab1016829a776d97f163f183a48be6a4deb87304d1e0116a349519/tomli-2.4.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:c084ad935abe686bd9c898e62a02a19abfc9760b5a79bc29644463eaf2840cb0", size = 159490, upload-time = "2026-01-11T11:22:28.399Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e3/5a/fc3622c8b1ad823e8ea98a35e3c632ee316d48f66f80f9708ceb4f2a0322/tomli-2.4.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0f2e3955efea4d1cfbcb87bc321e00dc08d2bcb737fd1d5e398af111d86db5df", size = 269398, upload-time = "2026-01-11T11:22:29.345Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fd/33/62bd6152c8bdd4c305ad9faca48f51d3acb2df1f8791b1477d46ff86e7f8/tomli-2.4.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0e0fe8a0b8312acf3a88077a0802565cb09ee34107813bba1c7cd591fa6cfc8d", size = 276515, upload-time = "2026-01-11T11:22:30.327Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/4b/ff/ae53619499f5235ee4211e62a8d7982ba9e439a0fb4f2f351a93d67c1dd2/tomli-2.4.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:413540dce94673591859c4c6f794dfeaa845e98bf35d72ed59636f869ef9f86f", size = 273806, upload-time = "2026-01-11T11:22:32.56Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/47/71/cbca7787fa68d4d0a9f7072821980b39fbb1b6faeb5f5cf02f4a5559fa28/tomli-2.4.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:0dc56fef0e2c1c470aeac5b6ca8cc7b640bb93e92d9803ddaf9ea03e198f5b0b", size = 281340, upload-time = "2026-01-11T11:22:33.505Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f5/00/d595c120963ad42474cf6ee7771ad0d0e8a49d0f01e29576ee9195d9ecdf/tomli-2.4.0-cp314-cp314t-win32.whl", hash = "sha256:d878f2a6707cc9d53a1be1414bbb419e629c3d6e67f69230217bb663e76b5087", size = 108106, upload-time = "2026-01-11T11:22:34.451Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/de/69/9aa0c6a505c2f80e519b43764f8b4ba93b5a0bbd2d9a9de6e2b24271b9a5/tomli-2.4.0-cp314-cp314t-win_amd64.whl", hash = "sha256:2add28aacc7425117ff6364fe9e06a183bb0251b03f986df0e78e974047571fd", size = 120504, upload-time = "2026-01-11T11:22:35.764Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/9f/f1668c281c58cfae01482f7114a4b88d345e4c140386241a1a24dcc9e7bc/tomli-2.4.0-cp314-cp314t-win_arm64.whl", hash = "sha256:2b1e3b80e1d5e52e40e9b924ec43d81570f0e7d09d11081b797bc4692765a3d4", size = 99561, upload-time = "2026-01-11T11:22:36.624Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/23/d1/136eb2cb77520a31e1f64cbae9d33ec6df0d78bdf4160398e86eec8a8754/tomli-2.4.0-py3-none-any.whl", hash = "sha256:1f776e7d669ebceb01dee46484485f43a4048746235e683bcdffacdf1fb4785a", size = 14477, upload-time = "2026-01-11T11:22:37.446Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vban-cmd"
|
||||
version = "2.9.1"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "tomli", marker = "python_full_version < '3.11'" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [{ name = "tomli", marker = "python_full_version < '3.11'", specifier = ">=2.0.1,<3.0" }]
|
||||
@ -11,6 +11,7 @@ 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 +27,7 @@ class FactoryBuilder:
|
||||
"""
|
||||
|
||||
BuilderProgress = IntEnum(
|
||||
'BuilderProgress', 'strip bus command macrobutton vban', start=0
|
||||
'BuilderProgress', 'strip bus command macrobutton vban recorder', start=0
|
||||
)
|
||||
|
||||
def __init__(self, factory, kind: KindMapClass):
|
||||
@ -38,6 +39,7 @@ 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__)
|
||||
|
||||
@ -72,24 +74,30 @@ 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 = {
|
||||
'ip': 'localhost',
|
||||
'host': 'localhost',
|
||||
'port': 6980,
|
||||
'streamname': 'Command1',
|
||||
'bps': 256000,
|
||||
'channel': 0,
|
||||
'ratelimit': 0.01,
|
||||
'timeout': 5,
|
||||
'script_ratelimit': 0.05, # 20 commands per second, to avoid overloading Voicemeeter
|
||||
'timeout': 5, # timeout on socket operations, in seconds
|
||||
'disable_rt_listeners': 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
|
||||
@ -166,7 +174,7 @@ class BananaFactory(FactoryBase):
|
||||
@property
|
||||
def steps(self) -> Iterable:
|
||||
"""steps required to build the interface for a kind"""
|
||||
return self._steps
|
||||
return self._steps + (self.builder.make_recorder,)
|
||||
|
||||
|
||||
class PotatoFactory(FactoryBase):
|
||||
@ -188,7 +196,7 @@ class PotatoFactory(FactoryBase):
|
||||
@property
|
||||
def steps(self) -> Iterable:
|
||||
"""steps required to build the interface for a kind"""
|
||||
return self._steps
|
||||
return self._steps + (self.builder.make_recorder,)
|
||||
|
||||
|
||||
def vbancmd_factory(kind_id: str, **kwargs) -> VbanCmd:
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import abc
|
||||
import logging
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -123,6 +122,8 @@ class IRemote(abc.ABC):
|
||||
def apply(self, data):
|
||||
"""Sets all parameters of a dict for the channel."""
|
||||
|
||||
script = ''
|
||||
|
||||
def fget(attr, val):
|
||||
if attr == 'mode':
|
||||
return (f'mode.{val}', 1)
|
||||
@ -138,14 +139,9 @@ class IRemote(abc.ABC):
|
||||
val = 1 if val else 0
|
||||
|
||||
self._remote.cache[self._cmd(attr)] = val
|
||||
self._remote._script += f'{self._cmd(attr)}={val};'
|
||||
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)
|
||||
self._remote.sendtext(script)
|
||||
|
||||
@ -8,11 +8,15 @@ VBAN_PROTOCOL_SERVICE = 0x60
|
||||
|
||||
VBAN_SERVICE_RTPACKETREGISTER = 32
|
||||
VBAN_SERVICE_RTPACKET = 33
|
||||
VBAN_SERVICE_PING = 0
|
||||
VBAN_SERVICE_PONG = 0 # PONG uses same service type as PING
|
||||
VBAN_SERVICE_MASK = 0xE0
|
||||
VBAN_PROTOCOL_MASK = 0xE0
|
||||
VBAN_SERVICE_REQUESTREPLY = 0x02
|
||||
VBAN_SERVICE_FNCT_REPLY = 0x02
|
||||
|
||||
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
|
||||
|
||||
@ -154,7 +158,7 @@ class VbanResponseHeader:
|
||||
# Validate this is an RTPacket response
|
||||
if parsed['format_nbc'] != VBAN_SERVICE_RTPACKET:
|
||||
raise ValueError(
|
||||
f'Not a RTPacket response packet: {parsed["format_nbc"]:02x}'
|
||||
f'Not an RTPacket response packet: {parsed["format_nbc"]:02x}'
|
||||
)
|
||||
|
||||
return cls(**parsed)
|
||||
@ -207,6 +211,92 @@ class VbanMatrixResponseHeader:
|
||||
return header, payload
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanPingHeader:
|
||||
"""Represents the header of a PING packet"""
|
||||
|
||||
name: str = 'PING0'
|
||||
format_sr: int = VBAN_PROTOCOL_SERVICE
|
||||
format_nbs: int = 0
|
||||
format_nbc: int = VBAN_SERVICE_PING
|
||||
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')[:16].ljust(16, b'\x00')
|
||||
|
||||
@classmethod
|
||||
def to_bytes(cls, framecounter: int = 0) -> bytes:
|
||||
"""Creates the PING header bytes only."""
|
||||
header = cls(framecounter=framecounter)
|
||||
|
||||
data = bytearray()
|
||||
data.extend(header.vban)
|
||||
data.extend(header.format_sr.to_bytes(1, 'little'))
|
||||
data.extend(header.format_nbs.to_bytes(1, 'little'))
|
||||
data.extend(header.format_nbc.to_bytes(1, 'little'))
|
||||
data.extend(header.format_bit.to_bytes(1, 'little'))
|
||||
data.extend(header.streamname)
|
||||
data.extend(header.framecounter.to_bytes(4, 'little'))
|
||||
return bytes(data)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VbanPongHeader:
|
||||
"""Represents the header of a PONG response packet"""
|
||||
|
||||
name: str = 'PING0'
|
||||
format_sr: int = VBAN_PROTOCOL_SERVICE
|
||||
format_nbs: int = 0
|
||||
format_nbc: int = VBAN_SERVICE_PONG
|
||||
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')[:16].ljust(16, 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'] != VBAN_SERVICE_PONG:
|
||||
raise ValueError(f'Not a PONG response packet: {parsed["format_nbc"]:02x}')
|
||||
|
||||
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'] != VBAN_SERVICE_PONG:
|
||||
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 VbanRequestHeader:
|
||||
"""Represents the header of a request packet"""
|
||||
@ -238,7 +328,7 @@ class VbanRequestHeader:
|
||||
|
||||
@property
|
||||
def streamname(self) -> bytes:
|
||||
return self.name.encode() + bytes(16 - len(self.name))
|
||||
return self.name.encode()[:16].ljust(16, b'\x00')
|
||||
|
||||
@classmethod
|
||||
def to_bytes(
|
||||
|
||||
124
vban_cmd/packet/ping0.py
Normal file
124
vban_cmd/packet/ping0.py
Normal file
@ -0,0 +1,124 @@
|
||||
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()
|
||||
|
||||
data = bytearray()
|
||||
data.extend(payload.bit_type.to_bytes(4, 'little'))
|
||||
data.extend(payload.bit_feature.to_bytes(4, 'little'))
|
||||
data.extend(payload.bit_feature_ex.to_bytes(4, 'little'))
|
||||
data.extend(payload.preferred_rate.to_bytes(4, 'little'))
|
||||
data.extend(payload.min_rate.to_bytes(4, 'little'))
|
||||
data.extend(payload.max_rate.to_bytes(4, 'little'))
|
||||
data.extend(payload.color_rgb.to_bytes(4, 'little'))
|
||||
data.extend(payload.version)
|
||||
data.extend(payload.gps_position)
|
||||
data.extend(payload.user_position)
|
||||
data.extend(payload.lang_code)
|
||||
data.extend(payload.reserved)
|
||||
data.extend(payload.reserved_ex)
|
||||
data.extend(payload.distant_ip)
|
||||
data.extend(payload.distant_port.to_bytes(2, 'little'))
|
||||
data.extend(payload.distant_reserved.to_bytes(2, 'little'))
|
||||
data.extend(payload.device_name)
|
||||
data.extend(payload.manufacturer_name)
|
||||
data.extend(payload.application_name)
|
||||
data.extend(payload.host_name)
|
||||
data.extend(payload.user_name)
|
||||
data.extend(payload.user_comment)
|
||||
return bytes(data)
|
||||
|
||||
@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
|
||||
138
vban_cmd/recorder.py
Normal file
138
vban_cmd/recorder.py
Normal file
@ -0,0 +1,138 @@
|
||||
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())}'
|
||||
)
|
||||
@ -1,6 +1,23 @@
|
||||
import time
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
def ratelimit(func):
|
||||
"""ratelimit decorator for {VbanCmd}.sendtext, to prevent flooding the network with script requests."""
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
self, *rem = args
|
||||
if self.script_ratelimit > 0:
|
||||
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 cache_bool(func, param):
|
||||
"""Check cache for a bool prop"""
|
||||
|
||||
|
||||
@ -5,14 +5,19 @@ import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import Union
|
||||
from typing import Mapping, Union
|
||||
|
||||
from .enums import NBS
|
||||
from .error import VBANCMDError
|
||||
from .error import VBANCMDConnectionError, VBANCMDError
|
||||
from .event import Event
|
||||
from .packet.headers import VbanMatrixResponseHeader, VbanRequestHeader
|
||||
from .packet.headers import (
|
||||
VbanMatrixResponseHeader,
|
||||
VbanPongHeader,
|
||||
VbanRequestHeader,
|
||||
)
|
||||
from .packet.ping0 import VbanPing0Payload, VbanServerType
|
||||
from .subject import Subject
|
||||
from .util import bump_framecounter, deep_merge
|
||||
from .util import bump_framecounter, deep_merge, ratelimit
|
||||
from .worker import Producer, Subscriber, Updater
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -33,21 +38,23 @@ class VbanCmd(abc.ABC):
|
||||
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['ip']:
|
||||
if not kwargs['host']:
|
||||
kwargs |= self._conn_from_toml()
|
||||
for attr, val in kwargs.items():
|
||||
setattr(self, attr, val)
|
||||
|
||||
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
|
||||
|
||||
@abc.abstractmethod
|
||||
def __str__(self):
|
||||
@ -86,7 +93,11 @@ class VbanCmd(abc.ABC):
|
||||
self.logout()
|
||||
|
||||
def login(self) -> None:
|
||||
"""Starts the subscriber and updater threads (unless disable_rt_listeners is True) and logs into Voicemeeter."""
|
||||
"""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()
|
||||
|
||||
if not self.disable_rt_listeners:
|
||||
self.event.info()
|
||||
|
||||
@ -102,7 +113,7 @@ class VbanCmd(abc.ABC):
|
||||
self.producer.start()
|
||||
|
||||
self.logger.info(
|
||||
"Successfully logged into VBANCMD {kind} with ip='{ip}', port={port}, streamname='{streamname}'".format(
|
||||
"Successfully logged into VBANCMD {kind} with host='{host}', port={port}, streamname='{streamname}'".format(
|
||||
**self.__dict__
|
||||
)
|
||||
)
|
||||
@ -120,6 +131,97 @@ 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, timeout: float = None) -> None:
|
||||
"""Send a PING packet and wait for PONG response to verify connectivity."""
|
||||
if timeout is None:
|
||||
timeout = min(self.timeout, 3.0)
|
||||
|
||||
ping_packet = VbanPing0Payload.create_packet(self._get_next_framecounter())
|
||||
|
||||
original_timeout = self.sock.gettimeout()
|
||||
self.sock.settimeout(0.5)
|
||||
|
||||
try:
|
||||
self.sock.sendto(ping_packet, (socket.gethostbyname(self.host), self.port))
|
||||
self.logger.debug(f'PING sent to {self.host}:{self.port}')
|
||||
|
||||
start_time = time.time()
|
||||
response_count = 0
|
||||
while time.time() - start_time < timeout:
|
||||
try:
|
||||
data, addr = self.sock.recvfrom(2048)
|
||||
response_count += 1
|
||||
|
||||
self.logger.debug(
|
||||
f'Received packet #{response_count} from {addr}: {len(data)} bytes'
|
||||
)
|
||||
self.logger.debug(
|
||||
f'Response header: {data[: min(32, len(data))].hex()}'
|
||||
)
|
||||
|
||||
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 # Exit after successful PONG response
|
||||
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')
|
||||
|
||||
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'
|
||||
)
|
||||
|
||||
except socket.gaierror as e:
|
||||
raise VBANCMDConnectionError(
|
||||
f'Unable to resolve hostname {self.host}'
|
||||
) from e
|
||||
except Exception as e:
|
||||
raise VBANCMDConnectionError(f'PING failed: {e}') from e
|
||||
finally:
|
||||
self.sock.settimeout(original_timeout)
|
||||
|
||||
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(
|
||||
@ -127,18 +229,18 @@ class VbanCmd(abc.ABC):
|
||||
name=self.streamname,
|
||||
bps_index=self.BPS_OPTS.index(self.bps),
|
||||
channel=self.channel,
|
||||
framecounter=self._framecounter,
|
||||
framecounter=self._get_next_framecounter(),
|
||||
payload=payload,
|
||||
),
|
||||
(socket.gethostbyname(self.ip), self.port),
|
||||
(socket.gethostbyname(self.host), self.port),
|
||||
)
|
||||
self._framecounter = bump_framecounter(self._framecounter)
|
||||
|
||||
def _set_rt(self, cmd: str, val: Union[str, float]):
|
||||
"""Sends a string request command over a network."""
|
||||
self._send_request(f'{cmd}={val};')
|
||||
self.cache[cmd] = val
|
||||
|
||||
@ratelimit
|
||||
def sendtext(self, script) -> str | None:
|
||||
"""Sends a multiple parameter string over a network."""
|
||||
self._send_request(script)
|
||||
@ -146,14 +248,16 @@ class VbanCmd(abc.ABC):
|
||||
|
||||
if self.disable_rt_listeners and script.endswith(('?', '?;')):
|
||||
try:
|
||||
response = VbanMatrixResponseHeader.extract_payload(
|
||||
self.sock.recv(1024)
|
||||
)
|
||||
return response
|
||||
data, _ = self.sock.recvfrom(2048)
|
||||
payload = VbanMatrixResponseHeader.extract_payload(data)
|
||||
except ValueError as e:
|
||||
self.logger.warning(f'Error extracting matrix response: {e}')
|
||||
|
||||
time.sleep(self.DELAY)
|
||||
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
|
||||
return payload
|
||||
|
||||
@property
|
||||
def type(self) -> str:
|
||||
@ -185,12 +289,8 @@ class VbanCmd(abc.ABC):
|
||||
while self.pdirty:
|
||||
time.sleep(self.DELAY)
|
||||
|
||||
def apply(self, data: dict):
|
||||
"""
|
||||
Sets all parameters of a dict
|
||||
|
||||
minor delay between each recursion
|
||||
"""
|
||||
def apply(self, data: Mapping):
|
||||
"""Set all parameters of a dict"""
|
||||
|
||||
def target(key):
|
||||
match key.split('-'):
|
||||
@ -210,7 +310,9 @@ class VbanCmd(abc.ABC):
|
||||
raise ValueError(ERR_MSG)
|
||||
return target[int(index)]
|
||||
|
||||
[target(key).apply(di).then_wait() for key, di in data.items()]
|
||||
for key, di in data.items():
|
||||
target(key).apply(di)
|
||||
time.sleep(self.DELAY)
|
||||
|
||||
def apply_config(self, name):
|
||||
"""applies a config from memory"""
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import logging
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
|
||||
@ -13,7 +12,6 @@ from .packet.headers import (
|
||||
)
|
||||
from .packet.nbs0 import VbanPacketNBS0
|
||||
from .packet.nbs1 import VbanPacketNBS1
|
||||
from .util import bump_framecounter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -26,24 +24,18 @@ 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():
|
||||
try:
|
||||
for nbs in NBS:
|
||||
sub_packet = VbanSubscribeHeader().to_bytes(nbs, self._framecounter)
|
||||
self._remote.sock.sendto(
|
||||
sub_packet, (self._remote.ip, self._remote.port)
|
||||
sub_packet = VbanSubscribeHeader().to_bytes(
|
||||
nbs, self._remote._get_next_framecounter()
|
||||
)
|
||||
self._remote.sock.sendto(
|
||||
sub_packet, (self._remote.host, self._remote.port)
|
||||
)
|
||||
self._framecounter = bump_framecounter(self._framecounter)
|
||||
|
||||
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):
|
||||
@ -66,7 +58,6 @@ 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
|
||||
@ -77,27 +68,22 @@ class Producer(threading.Thread):
|
||||
|
||||
def _get_rt(self) -> VbanPacket:
|
||||
"""Attempt to fetch data packet until a valid one found"""
|
||||
|
||||
while True:
|
||||
if resp := self._fetch_rt_packet():
|
||||
return resp
|
||||
|
||||
def _fetch_rt_packet(self) -> VbanPacket | None:
|
||||
try:
|
||||
data, _ = self._remote.sock.recvfrom(2048)
|
||||
if len(data) < HEADER_SIZE:
|
||||
return
|
||||
continue
|
||||
except TimeoutError as e:
|
||||
self.logger.exception(f'{type(e).__name__}: {e}')
|
||||
raise VBANCMDConnectionError(
|
||||
f'timeout waiting for response from {self._remote.ip}:{self._remote.port}'
|
||||
f'timeout waiting for response from {self._remote.host}:{self._remote.port}'
|
||||
) from e
|
||||
|
||||
try:
|
||||
header = VbanResponseHeader.from_bytes(data[:HEADER_SIZE])
|
||||
except ValueError as e:
|
||||
self.logger.warning(f'Error parsing response packet: {e}')
|
||||
return None
|
||||
self.logger.debug(f'Error parsing response packet: {e}')
|
||||
continue
|
||||
|
||||
match header.format_nbs:
|
||||
case NBS.zero:
|
||||
@ -110,8 +96,6 @@ class Producer(threading.Thread):
|
||||
nbs=NBS.one, kind=self._remote.kind, data=data
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
def stopped(self):
|
||||
return self.stop_event.is_set()
|
||||
|
||||
@ -138,7 +122,6 @@ 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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user