From dab519be9fea22196b864f7b2c7cc0d8e4e89400 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 12 Jul 2023 10:24:03 +0100 Subject: [PATCH] implement midi, text vban streams kindmaps updated factory tests updated. closes #2 --- CHANGELOG.md | 19 ++++++++++++- pyproject.toml | 2 +- tests/test_factory.py | 12 ++++++++ vban_cmd/kinds.py | 6 ++-- vban_cmd/vban.py | 66 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 97 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ad74ee..4b64b02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,29 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass - [x] -## [2.2.0] - 2023-07-11 +## [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 - user configs may now extend other user configs. check `config extends` section in README. +## [2.2.0] - 2023-07-08 + +### Added + +- button, vban classes implemented +- \__repr\__() method added to base class + ## [2.1.2] - 2023-07-05 ### Added diff --git a/pyproject.toml b/pyproject.toml index 363e43b..695fcc0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vban-cmd" -version = "2.3.1" +version = "2.3.2" description = "Python interface for the VBAN RT Packet Service (Sendtext)" authors = ["onyx-and-iris "] license = "MIT" diff --git a/tests/test_factory.py b/tests/test_factory.py index cded736..74eceed 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -14,9 +14,13 @@ class TestRemoteFactories: assert hasattr(vban, "strip") assert hasattr(vban, "bus") assert hasattr(vban, "command") + assert hasattr(vban, "button") + assert hasattr(vban, "vban") assert len(vban.strip) == 3 assert len(vban.bus) == 2 + assert len(vban.button) == 80 + assert len(vban.vban.instream) == 6 and len(vban.vban.outstream) == 5 @pytest.mark.skipif( data.name != "banana", @@ -26,9 +30,13 @@ class TestRemoteFactories: assert hasattr(vban, "strip") assert hasattr(vban, "bus") assert hasattr(vban, "command") + assert hasattr(vban, "button") + assert hasattr(vban, "vban") assert len(vban.strip) == 5 assert len(vban.bus) == 5 + assert len(vban.button) == 80 + assert len(vban.vban.instream) == 10 and len(vban.vban.outstream) == 9 @pytest.mark.skipif( data.name != "potato", @@ -38,6 +46,10 @@ class TestRemoteFactories: assert hasattr(vban, "strip") assert hasattr(vban, "bus") assert hasattr(vban, "command") + assert hasattr(vban, "button") + assert hasattr(vban, "vban") assert len(vban.strip) == 8 assert len(vban.bus) == 8 + assert len(vban.button) == 80 + assert len(vban.vban.instream) == 10 and len(vban.vban.outstream) == 9 diff --git a/vban_cmd/kinds.py b/vban_cmd/kinds.py index 43b14e1..31d6275 100644 --- a/vban_cmd/kinds.py +++ b/vban_cmd/kinds.py @@ -62,7 +62,7 @@ class BasicMap(KindMapClass): name: str ins: tuple = (2, 1) outs: tuple = (1, 1) - vban: tuple = (4, 4) + vban: tuple = (4, 4, 1, 1) @dataclass @@ -70,7 +70,7 @@ class BananaMap(KindMapClass): name: str ins: tuple = (3, 2) outs: tuple = (3, 2) - vban: tuple = (8, 8) + vban: tuple = (8, 8, 1, 1) @dataclass @@ -78,7 +78,7 @@ class PotatoMap(KindMapClass): name: str ins: tuple = (5, 3) outs: tuple = (5, 3) - vban: tuple = (8, 8) + vban: tuple = (8, 8, 1, 1) def kind_factory(kind_id): diff --git a/vban_cmd/vban.py b/vban_cmd/vban.py index e5e985e..e5fc438 100644 --- a/vban_cmd/vban.py +++ b/vban_cmd/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 +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 creating instream/outstream tuples""" + 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): """if VBAN disabled there can be no communication with it"""