From 9b2e38aab3e6cde4180749507f1d8c453b617cab Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 12 Jul 2023 09:45:33 +0100 Subject: [PATCH] implement midi, text vban streams kindmaps updated factory tests updated. closes #7 --- CHANGELOG.md | 10 +++++++ pyproject.toml | 2 +- tests/test_factory.py | 6 ++-- voicemeeterlib/kinds.py | 6 ++-- voicemeeterlib/vban.py | 66 +++++++++++++++++++++++++++++++++++++++-- 5 files changed, 80 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5903804..96f1f30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,16 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass - [x] +## [2.3.2] - 2023-07-12 + +### Added + +- vban.{instream,outstream} tuples now contain classes that represent MIDI and TEXT streams. + +### Fixed + +- apply_config() now performs a deep merge when extending a config with another. + ## [2.3.0] - 2023-07-11 ### Added diff --git a/pyproject.toml b/pyproject.toml index af94587..a96c099 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "voicemeeter-api" -version = "2.3.1" +version = "2.3.2" description = "A Python wrapper for the Voiceemeter API" authors = ["onyx-and-iris "] license = "MIT" diff --git a/tests/test_factory.py b/tests/test_factory.py index aa9465a..0b01c6f 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -22,7 +22,7 @@ class TestRemoteFactories: assert len(vm.strip) == 3 assert len(vm.bus) == 2 assert len(vm.button) == 80 - assert len(vm.vban.instream) == 4 and len(vm.vban.outstream) == 4 + assert len(vm.vban.instream) == 6 and len(vm.vban.outstream) == 5 @pytest.mark.skipif( data.name != "banana", @@ -42,7 +42,7 @@ class TestRemoteFactories: assert len(vm.strip) == 5 assert len(vm.bus) == 5 assert len(vm.button) == 80 - assert len(vm.vban.instream) == 8 and len(vm.vban.outstream) == 8 + assert len(vm.vban.instream) == 10 and len(vm.vban.outstream) == 9 @pytest.mark.skipif( data.name != "potato", @@ -63,4 +63,4 @@ class TestRemoteFactories: assert len(vm.strip) == 8 assert len(vm.bus) == 8 assert len(vm.button) == 80 - assert len(vm.vban.instream) == 8 and len(vm.vban.outstream) == 8 + assert len(vm.vban.instream) == 10 and len(vm.vban.outstream) == 9 diff --git a/voicemeeterlib/kinds.py b/voicemeeterlib/kinds.py index 65840ac..218d676 100644 --- a/voicemeeterlib/kinds.py +++ b/voicemeeterlib/kinds.py @@ -64,7 +64,7 @@ class BasicMap(KindMapClass): name: str ins: tuple = (2, 1) outs: tuple = (1, 1) - vban: tuple = (4, 4) + vban: tuple = (4, 4, 1, 1) asio: tuple = (0, 0) insert: int = 0 @@ -74,7 +74,7 @@ class BananaMap(KindMapClass): name: str ins: tuple = (3, 2) outs: tuple = (3, 2) - vban: tuple = (8, 8) + vban: tuple = (8, 8, 1, 1) asio: tuple = (6, 8) insert: int = 22 @@ -84,7 +84,7 @@ class PotatoMap(KindMapClass): name: str ins: tuple = (5, 3) outs: tuple = (5, 3) - vban: tuple = (8, 8) + vban: tuple = (8, 8, 1, 1) asio: tuple = (10, 8) insert: int = 34 diff --git a/voicemeeterlib/vban.py b/voicemeeterlib/vban.py index 383fe98..8655740 100644 --- a/voicemeeterlib/vban.py +++ b/voicemeeterlib/vban.py @@ -1,6 +1,7 @@ from abc import abstractmethod from .iremote import IRemote +from .kinds import kinds_all class VbanStream(IRemote): @@ -133,6 +134,21 @@ class VbanInstream(VbanStream): return super(VbanInstream, self).bit +class VbanAudioInstream(VbanInstream): + def __str__(self): + return f"{type(self).__name__}{self._remote.kind}{self.index}" + + +class VbanMidiInstream(VbanInstream): + def __str__(self): + return f"{type(self).__name__}{self._remote.kind}{self.index}" + + +class VbanTextInstream(VbanInstream): + def __str__(self): + return f"{type(self).__name__}{self._remote.kind}{self.index}" + + class VbanOutstream(VbanStream): """ class representing a vban outstream @@ -148,6 +164,52 @@ class VbanOutstream(VbanStream): return "out" +class VbanAudioOutstream(VbanOutstream): + def __str__(self): + return f"{type(self).__name__}{self._remote.kind}{self.index}" + + +class VbanMidiOutstream(VbanOutstream): + def __str__(self): + return f"{type(self).__name__}{self._remote.kind}{self.index}" + + +def _make_stream_pair(remote, kind): + num_instream, num_outstream, num_midi, num_text = kind.vban + + def _generate_streams(i, dir): + """generator function for instream/outstream types""" + if dir == "in": + if i < num_instream: + yield VbanAudioInstream + elif i < num_instream + num_midi: + yield VbanMidiInstream + else: + yield VbanTextInstream + else: + if i < num_outstream: + yield VbanAudioOutstream + else: + yield VbanMidiOutstream + + return ( + tuple( + cls(remote, i) + for i in range(num_instream + num_midi + num_text) + for cls in _generate_streams(i, "in") + ), + tuple( + cls(remote, i) + for i in range(num_outstream + num_midi) + for cls in _generate_streams(i, "out") + ), + ) + + +def _make_stream_pairs(remote): + return {kind.name: _make_stream_pair(remote, kind) for kind in kinds_all} + + class Vban: """ class representing the vban module @@ -157,9 +219,7 @@ class Vban: def __init__(self, remote): self.remote = remote - num_instream, num_outstream = remote.kind.vban - self.instream = tuple(VbanInstream(remote, i) for i in range(num_instream)) - self.outstream = tuple(VbanOutstream(remote, i) for i in range(num_outstream)) + self.instream, self.outstream = _make_stream_pairs(remote)[remote.kind.name] def enable(self): self.remote.set("vban.Enable", 1)