mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2025-01-18 18:40:47 +00:00
add test conn, add settable attr to
add test connection into enter dunder TextRequestHeader dataclass name, bitrate and channel for outgoing string requests are now settable.
This commit is contained in:
parent
9e5b2067d1
commit
314ecbe6da
@ -154,15 +154,24 @@ class RegisterRTHeader:
|
|||||||
@dataclass
|
@dataclass
|
||||||
class TextRequestHeader:
|
class TextRequestHeader:
|
||||||
""" VBAN-TEXT request header """
|
""" VBAN-TEXT request header """
|
||||||
name='Command1'
|
name: str
|
||||||
|
bps_index: int
|
||||||
|
channel: int
|
||||||
vban: bytes='VBAN'.encode()
|
vban: bytes='VBAN'.encode()
|
||||||
sr: bytes=(0x52).to_bytes(1, 'little')
|
|
||||||
nbs: bytes=(0).to_bytes(1, 'little')
|
nbs: bytes=(0).to_bytes(1, 'little')
|
||||||
nbc: bytes=(0).to_bytes(1, 'little')
|
|
||||||
bit: bytes=(0x10).to_bytes(1, 'little')
|
bit: bytes=(0x10).to_bytes(1, 'little')
|
||||||
streamname: bytes=name.encode() + bytes(16-len(name))
|
|
||||||
framecounter: bytes=(0).to_bytes(4, 'little')
|
framecounter: bytes=(0).to_bytes(4, 'little')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sr(self):
|
||||||
|
return (0x40 + self.bps_index).to_bytes(1, 'little')
|
||||||
|
@property
|
||||||
|
def nbc(self):
|
||||||
|
return (self.channel).to_bytes(1, 'little')
|
||||||
|
@property
|
||||||
|
def streamname(self):
|
||||||
|
return self.name.encode() + bytes(16-len(self.name))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
header = self.vban
|
header = self.vban
|
||||||
|
@ -26,13 +26,18 @@ class VbanCmd(abc.ABC):
|
|||||||
self._bps = kwargs['bps']
|
self._bps = kwargs['bps']
|
||||||
self._channel = kwargs['channel']
|
self._channel = kwargs['channel']
|
||||||
self._delay = kwargs['delay']
|
self._delay = kwargs['delay']
|
||||||
self._max_polls = kwargs['max_polls']
|
|
||||||
self._bps_opts = \
|
self._bps_opts = \
|
||||||
[0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400,19200, 31250,
|
[0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
|
||||||
38400, 57600, 115200, 128000, 230400, 250000, 256000, 460800,921600,
|
38400, 57600, 115200, 128000, 230400, 250000, 256000, 460800,921600,
|
||||||
1000000, 1500000, 2000000, 3000000]
|
1000000, 1500000, 2000000, 3000000]
|
||||||
|
|
||||||
self._text_header = TextRequestHeader()
|
if self._channel not in range(256):
|
||||||
|
raise VMCMDErrors('Channel must be in range 0 to 255')
|
||||||
|
self._text_header = TextRequestHeader(
|
||||||
|
name=self._streamname,
|
||||||
|
bps_index=self._bps_opts.index(self._bps),
|
||||||
|
channel=self._channel
|
||||||
|
)
|
||||||
self._register_rt_header = RegisterRTHeader()
|
self._register_rt_header = RegisterRTHeader()
|
||||||
self.expected_packet = VBAN_VMRT_Packet_Header()
|
self.expected_packet = VBAN_VMRT_Packet_Header()
|
||||||
self.buff = None
|
self.buff = None
|
||||||
@ -46,8 +51,13 @@ class VbanCmd(abc.ABC):
|
|||||||
is_error = []
|
is_error = []
|
||||||
self.ready_to_read, self.ready_to_write, in_error = select.select(is_readable, is_writable, is_error, 60)
|
self.ready_to_read, self.ready_to_write, in_error = select.select(is_readable, is_writable, is_error, 60)
|
||||||
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
res = s.connect_ex((self._ip, self._port))
|
||||||
|
s.close()
|
||||||
|
if res:
|
||||||
|
raise VMCMDErrors('Could not connect to remote Voicemeeter')
|
||||||
|
|
||||||
self._rt_packet_socket.bind((socket.gethostbyname(socket.gethostname()), self._port))
|
self._rt_packet_socket.bind((socket.gethostbyname(socket.gethostname()), self._port))
|
||||||
worker = Thread(target=self._send_register_rt, daemon=True)
|
worker = Thread(target=self._send_register_rt, daemon=True)
|
||||||
worker.start()
|
worker.start()
|
||||||
@ -64,35 +74,36 @@ class VbanCmd(abc.ABC):
|
|||||||
sleep(10)
|
sleep(10)
|
||||||
|
|
||||||
def _fetch_rt_packet(self):
|
def _fetch_rt_packet(self):
|
||||||
data, _ = self._rt_packet_socket.recvfrom(1024*1024*2)
|
if self._rt_packet_socket in self.ready_to_write:
|
||||||
# check for packet data
|
data, _ = self._rt_packet_socket.recvfrom(1024*1024*2)
|
||||||
if len(data) > HEADER_SIZE:
|
# check for packet data
|
||||||
# check if packet is of type rt service
|
if len(data) > HEADER_SIZE:
|
||||||
if self.expected_packet.header == data[:HEADER_SIZE-4]:
|
# check if packet is of type rt service
|
||||||
return VBAN_VMRT_Packet_Data(
|
if self.expected_packet.header == data[:HEADER_SIZE-4]:
|
||||||
_voicemeeterType=data[28:29],
|
return VBAN_VMRT_Packet_Data(
|
||||||
_reserved=data[29:30],
|
_voicemeeterType=data[28:29],
|
||||||
_buffersize=data[30:32],
|
_reserved=data[29:30],
|
||||||
_voicemeeterVersion=data[32:36],
|
_buffersize=data[30:32],
|
||||||
_optionBits=data[36:40],
|
_voicemeeterVersion=data[32:36],
|
||||||
_samplerate=data[40:44],
|
_optionBits=data[36:40],
|
||||||
_inputLeveldB100=data[44:112],
|
_samplerate=data[40:44],
|
||||||
_outputLeveldB100=data[112:240],
|
_inputLeveldB100=data[44:112],
|
||||||
_TransportBit=data[240:244],
|
_outputLeveldB100=data[112:240],
|
||||||
_stripState=data[244:276],
|
_TransportBit=data[240:244],
|
||||||
_busState=data[276:308],
|
_stripState=data[244:276],
|
||||||
_stripGaindB100Layer1=data[308:324],
|
_busState=data[276:308],
|
||||||
_stripGaindB100Layer2=data[324:340],
|
_stripGaindB100Layer1=data[308:324],
|
||||||
_stripGaindB100Layer3=data[340:356],
|
_stripGaindB100Layer2=data[324:340],
|
||||||
_stripGaindB100Layer4=data[356:372],
|
_stripGaindB100Layer3=data[340:356],
|
||||||
_stripGaindB100Layer5=data[372:388],
|
_stripGaindB100Layer4=data[356:372],
|
||||||
_stripGaindB100Layer6=data[388:404],
|
_stripGaindB100Layer5=data[372:388],
|
||||||
_stripGaindB100Layer7=data[404:420],
|
_stripGaindB100Layer6=data[388:404],
|
||||||
_stripGaindB100Layer8=data[420:436],
|
_stripGaindB100Layer7=data[404:420],
|
||||||
_busGaindB100=data[436:452],
|
_stripGaindB100Layer8=data[420:436],
|
||||||
_stripLabelUTF8c60=data[452:932],
|
_busGaindB100=data[436:452],
|
||||||
_busLabelUTF8c60=data[932:1412],
|
_stripLabelUTF8c60=data[452:932],
|
||||||
)
|
_busLabelUTF8c60=data[932:1412],
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def public_packet(self):
|
def public_packet(self):
|
||||||
@ -106,7 +117,7 @@ class VbanCmd(abc.ABC):
|
|||||||
data = self._fetch_rt_packet()
|
data = self._fetch_rt_packet()
|
||||||
return data
|
return data
|
||||||
private_packet = fget()
|
private_packet = fget()
|
||||||
return private_packet if private_packet.__eq__(self.buff) else fget()
|
return private_packet if private_packet == self.buff else fget()
|
||||||
|
|
||||||
def set_rt(self, id_, param, val):
|
def set_rt(self, id_, param, val):
|
||||||
cmd = f'{id_}.{param}={val}'
|
cmd = f'{id_}.{param}={val}'
|
||||||
@ -157,7 +168,7 @@ def _make_remote(kind: NamedTuple) -> VbanCmd:
|
|||||||
def init(self, **kwargs):
|
def init(self, **kwargs):
|
||||||
defaultkwargs = {
|
defaultkwargs = {
|
||||||
'ip': None, 'port': 6990, 'streamname': 'Command1', 'bps': 0,
|
'ip': None, 'port': 6990, 'streamname': 'Command1', 'bps': 0,
|
||||||
'channel': 0, 'delay': 0.001, 'max_polls': 2
|
'channel': 0, 'delay': 0.001
|
||||||
}
|
}
|
||||||
kwargs = defaultkwargs | kwargs
|
kwargs = defaultkwargs | kwargs
|
||||||
VbanCmd.__init__(self, **kwargs)
|
VbanCmd.__init__(self, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user