onyx-and-iris 842feb2407 remote is now our ABC - as it should be because it is the launching point of the interface.
it no longer inherits from CBindings.

move steps abstract method into Remote class. This is a much more meaningful abstraction - because it is the principle behaviour that distinguishes each kind of Remote.

add wrapper methods to CBindings. This provides a cleaner api for the Remote class.

import abc as namespace throughout the package.
2026-03-15 22:02:17 +00:00

73 lines
1.6 KiB
Python

import abc
from typing import Union
from .iremote import IRemote
class Adapter(IRemote):
"""Adapter to the common interface."""
@abc.abstractmethod
def ins(self):
pass
@abc.abstractmethod
def outs(self):
pass
@abc.abstractmethod
def input(self):
pass
@abc.abstractmethod
def output(self):
pass
def identifier(self):
pass
def getter(self, index: int = None, direction: str = None) -> Union[int, dict]:
if index is None:
return self._remote.get_num_devices(direction)
vals = self._remote.get_device_description(index, direction)
types = {1: 'mme', 3: 'wdm', 4: 'ks', 5: 'asio'}
return {'name': vals[0], 'type': types[vals[1]], 'id': vals[2]}
class Device(Adapter):
"""Defines concrete implementation for device"""
@classmethod
def make(cls, remote):
"""
Factory function for device.
Returns a Device class of a kind.
"""
def num_ins(cls) -> int:
return cls.getter(direction='in')
def num_outs(cls) -> int:
return cls.getter(direction='out')
DEVICE_cls = type(
f'Device{remote.kind}',
(cls,),
{
'ins': property(num_ins),
'outs': property(num_outs),
},
)
return DEVICE_cls(remote)
def __str__(self):
return f'{type(self).__name__}'
def input(self, index: int) -> dict:
return self.getter(index=index, direction='in')
def output(self, index: int) -> dict:
return self.getter(index=index, direction='out')