mirror of
https://github.com/onyx-and-iris/vmr-http.git
synced 2026-04-06 18:09:11 +00:00
add docstrings
add documentation tags add some error handling
This commit is contained in:
45
src/vmr_http/web/busmode.py
Normal file
45
src/vmr_http/web/busmode.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""module for bus mode related endpoints."""
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, HTTPException
|
||||
|
||||
from vmr_http.dependencies import get_voicemeeter_client
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
_readable_busmodes = {
|
||||
'normal': 'Normal',
|
||||
'amix': 'Mix Down A',
|
||||
'bmix': 'Mix Down B',
|
||||
'repeat': 'Stereo Repeat',
|
||||
'composite': 'Composite',
|
||||
'tvmix': 'Up Mix TV',
|
||||
'upmix21': 'Up Mix 2.1',
|
||||
'upmix41': 'Up Mix 4.1',
|
||||
'upmix61': 'Up Mix 6.1',
|
||||
'centeronly': 'Center Only',
|
||||
'lfeonly': 'Low Frequency Effect Only',
|
||||
'rearonly': 'Rear Only',
|
||||
}
|
||||
_reversed_busmodes = {v: k for k, v in _readable_busmodes.items()}
|
||||
|
||||
|
||||
@router.get('/{index}')
|
||||
async def get_bus_mode(index: int, voicemeeter=Depends(get_voicemeeter_client)):
|
||||
"""Get the current bus mode for the specified bus index."""
|
||||
return {'mode': _readable_busmodes.get(voicemeeter.bus[index].mode.get(), 'Unknown')}
|
||||
|
||||
|
||||
@router.put('/{index}')
|
||||
async def set_bus_mode(
|
||||
index: int,
|
||||
mode: str = Body(..., embed=True),
|
||||
voicemeeter=Depends(get_voicemeeter_client),
|
||||
):
|
||||
"""Set the bus mode for the specified bus index."""
|
||||
if mode not in _reversed_busmodes:
|
||||
raise HTTPException(
|
||||
status_code=400, detail=f'Invalid mode. Valid modes are: {", ".join(_reversed_busmodes.keys())}'
|
||||
)
|
||||
|
||||
setattr(voicemeeter.bus[index].mode, _reversed_busmodes[mode], True)
|
||||
return {'mode': _readable_busmodes[_reversed_busmodes[mode]]}
|
||||
Reference in New Issue
Block a user