add ChannelState interface, use it in the meta functions.

reword busmodes bitwise logic.

comment out ratelimit, this will probably get permanently removed.
This commit is contained in:
2026-03-01 03:37:57 +00:00
parent 2f3cd0e07f
commit ff5ac193c8
5 changed files with 191 additions and 96 deletions

View File

@@ -117,45 +117,49 @@ class BusLevel(IRemote):
def _make_bus_mode_mixin():
"""Creates a mixin of Bus Modes."""
modestates = {
'normal': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
'amix': [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
'repeat': [0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2],
'bmix': [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3],
'composite': [0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0],
'tvmix': [1, 0, 1, 4, 5, 4, 5, 0, 1, 0, 1],
'upmix21': [0, 2, 2, 4, 4, 6, 6, 0, 0, 2, 2],
'upmix41': [1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3],
'upmix61': [0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8],
'centeronly': [1, 0, 1, 0, 1, 0, 1, 8, 9, 8, 9],
'lfeonly': [0, 2, 2, 0, 0, 2, 2, 8, 8, 10, 10],
'rearonly': [1, 2, 3, 0, 1, 2, 3, 8, 9, 10, 11],
}
mode_names = [
'normal',
'amix',
'repeat',
'bmix',
'composite',
'tvmix',
'upmix21',
'upmix41',
'upmix61',
'centeronly',
'lfeonly',
'rearonly',
]
def identifier(self) -> str:
return f'bus[{self.index}].mode'
def get(self):
states = [
(
int.from_bytes(
self.public_packets[NBS.zero].busstate[self.index], 'little'
)
& val
)
>> 4
for val in self._modes.modevals
"""Get current bus mode using ChannelState for clean bit extraction."""
mode_cache_items = [
(k, v)
for k, v in self._remote.cache.items()
if k.startswith(f'{self.identifier}.') and v == 1
]
for k, v in modestates.items():
if states == v:
return k
if mode_cache_items:
latest_cached = mode_cache_items[-1][0]
mode_name = latest_cached.split('.')[-1]
return mode_name
bus_state = self.public_packets[NBS.zero].states.bus[self.index]
# Extract bus mode from bits 4-7 (mask 0xF0, shift right by 4)
mode_value = (bus_state._state & 0x000000F0) >> 4
return mode_names[mode_value] if mode_value < len(mode_names) else 'normal'
return type(
'BusModeMixin',
(IRemote,),
{
'identifier': property(identifier),
'modestates': modestates,
**{mode.name: bus_mode_prop(mode.name) for mode in BusModes},
'get': get,
},