diff --git a/pyproject.toml b/pyproject.toml index d8a7f0e..1bbee58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "vmr-http" -version = "0.3.3" +version = "0.4.0" description = "HTTP API for controlling Voicemeeter" readme = "README.md" authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }] diff --git a/src/vmr_http/models/eq.py b/src/vmr_http/models/eq.py new file mode 100644 index 0000000..1b5a3bb --- /dev/null +++ b/src/vmr_http/models/eq.py @@ -0,0 +1,15 @@ +"""Models for the parameters of an equalizer.""" + +from typing import Optional + +from pydantic import BaseModel + + +class EQChannelCellParams(BaseModel): + """Parameters for an equalizer channel.""" + + on: Optional[bool] = None + type: Optional[int] = None + f: Optional[float] = None + gain: Optional[float] = None + q: Optional[float] = None diff --git a/src/vmr_http/web/bus.py b/src/vmr_http/web/bus.py index afed0f4..2774ac2 100644 --- a/src/vmr_http/web/bus.py +++ b/src/vmr_http/web/bus.py @@ -5,10 +5,11 @@ from fastapi import APIRouter, Depends from vmr_http.dependencies import get_voicemeeter_client from vmr_http.models.bus import BusParams -from . import busmode +from . import busmode, eq router = APIRouter() router.include_router(busmode.router, tags=['bus mode']) +router.include_router(eq.router, tags=['bus eq']) @router.patch('/{index}', tags=['bus']) diff --git a/src/vmr_http/web/eq.py b/src/vmr_http/web/eq.py new file mode 100644 index 0000000..594d59e --- /dev/null +++ b/src/vmr_http/web/eq.py @@ -0,0 +1,87 @@ +"""module for equalizer related endpoints.""" + +from fastapi import APIRouter, Body, Depends + +from vmr_http.dependencies import get_voicemeeter_client +from vmr_http.models.eq import EQChannelCellParams + +cell_router = APIRouter() + + +@cell_router.patch('/{cell_index}') +@cell_router.put('/{cell_index}') +async def update_strip_eq_channel_cell_params( + index: int, + channel_index: int, + cell_index: int, + params: EQChannelCellParams, + voicemeeter=Depends(get_voicemeeter_client), +): + """Update one or more parameters for the specified strip eq channel cell.""" + cell = voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index] + updated = {} + for key, value in params.model_dump(exclude_unset=True).items(): + setattr(cell, key, value) + updated[key] = getattr(cell, key) + return updated + + +@cell_router.get('/{cell_index}/on') +async def get_strip_eq_channel_cell_on( + index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) +): + """Get the current on status for the specified strip eq channel cell.""" + return {'on': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].on} + + +@cell_router.get('/{cell_index}/type') +async def get_strip_eq_channel_cell_type( + index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) +): + """Get the current type for the specified strip eq channel cell.""" + return {'type': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].type} + + +@cell_router.get('/{cell_index}/f') +async def get_strip_eq_channel_cell_f( + index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) +): + """Get the current f value for the specified strip eq channel cell.""" + return {'f': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].f} + + +@cell_router.get('/{cell_index}/gain') +async def get_strip_eq_channel_cell_gain( + index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) +): + """Get the current gain value for the specified strip eq channel cell.""" + return {'gain': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].gain} + + +@cell_router.get('/{cell_index}/q') +async def get_strip_eq_channel_cell_q( + index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) +): + """Get the current q value for the specified strip eq channel cell.""" + return {'q': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].q} + + +router = APIRouter() +router.include_router(cell_router, prefix='/{index}/eq/channel/{channel_index}/cell') + + +@router.patch('/{index}/eq') +@router.put('/{index}/eq') +async def update_strip_eq_params( + index: int, on: bool = Body(..., embed=True), voicemeeter=Depends(get_voicemeeter_client) +): + """Update one or more equalizer parameters for the specified strip index.""" + strip_eq = voicemeeter.strip[index].eq + strip_eq.on = on + return {'on': strip_eq.on} + + +@router.get('/{index}/eq/on') +async def get_strip_eq_on(index: int, voicemeeter=Depends(get_voicemeeter_client)): + """Get the current equalizer on status for the specified strip index.""" + return {'on': voicemeeter.strip[index].eq.on} diff --git a/src/vmr_http/web/strip.py b/src/vmr_http/web/strip.py index 73cc539..394df33 100644 --- a/src/vmr_http/web/strip.py +++ b/src/vmr_http/web/strip.py @@ -5,12 +5,13 @@ from fastapi import APIRouter, Depends from vmr_http.dependencies import get_voicemeeter_client from vmr_http.models.strip import StripParams -from . import stripcomp, stripdenoiser, stripgate +from . import eq, stripcomp, stripdenoiser, stripgate router = APIRouter() -router.include_router(stripcomp.router, prefix='/comp', tags=['strip comp']) -router.include_router(stripgate.router, prefix='/gate', tags=['strip gate']) -router.include_router(stripdenoiser.router, prefix='/denoiser', tags=['strip denoiser']) +router.include_router(stripcomp.router, tags=['strip comp']) +router.include_router(stripgate.router, tags=['strip gate']) +router.include_router(stripdenoiser.router, tags=['strip denoiser']) +router.include_router(eq.router, tags=['strip eq']) @router.patch('/{index}', tags=['strip']) diff --git a/uv.lock b/uv.lock index 0fa69ed..11e947f 100644 --- a/uv.lock +++ b/uv.lock @@ -1151,7 +1151,7 @@ wheels = [ [[package]] name = "vmr-http" -version = "0.3.3" +version = "0.4.0" source = { editable = "." } dependencies = [ { name = "fastapi" },