2022-06-16 14:07:12 +01:00
|
|
|
from abc import abstractmethod
|
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
from .iremote import IRemote
|
|
|
|
|
|
|
|
|
|
|
|
class Adapter(IRemote):
|
|
|
|
"""Adapter to the common interface."""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def ins(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def outs(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def input(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@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)
|
2025-01-15 12:40:31 +00:00
|
|
|
types = {1: 'mme', 3: 'wdm', 4: 'ks', 5: 'asio'}
|
|
|
|
return {'name': vals[0], 'type': types[vals[1]], 'id': vals[2]}
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
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:
|
2025-01-15 12:40:31 +00:00
|
|
|
return cls.getter(direction='in')
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
def num_outs(cls) -> int:
|
2025-01-15 12:40:31 +00:00
|
|
|
return cls.getter(direction='out')
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
DEVICE_cls = type(
|
2025-01-15 12:40:31 +00:00
|
|
|
f'Device{remote.kind}',
|
2022-06-16 14:07:12 +01:00
|
|
|
(cls,),
|
|
|
|
{
|
2025-01-15 12:40:31 +00:00
|
|
|
'ins': property(num_ins),
|
|
|
|
'outs': property(num_outs),
|
2022-06-16 14:07:12 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
return DEVICE_cls(remote)
|
|
|
|
|
|
|
|
def __str__(self):
|
2025-01-15 12:40:31 +00:00
|
|
|
return f'{type(self).__name__}'
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
def input(self, index: int) -> dict:
|
2025-01-15 12:40:31 +00:00
|
|
|
return self.getter(index=index, direction='in')
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
def output(self, index: int) -> dict:
|
2025-01-15 12:40:31 +00:00
|
|
|
return self.getter(index=index, direction='out')
|