Compare commits

..

No commits in common. "main" and "v0.2.0" have entirely different histories.
main ... v0.2.0

27 changed files with 520 additions and 739 deletions

6
.gitignore vendored
View File

@ -88,7 +88,7 @@ ipython_config.py
# pyenv # pyenv
# For a library or package, you might want to ignore these files since the code is # For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in: # intended to run in multiple environments; otherwise, check them in:
.python-version # .python-version
# pipenv # pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@ -185,9 +185,9 @@ cython_debug/
.abstra/ .abstra/
# Visual Studio Code # Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer, # and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder # you could uncomment the following to ignore the entire vscode folder
# .vscode/ # .vscode/

1
.python-version Normal file
View File

@ -0,0 +1 @@
3.13

View File

@ -1,175 +0,0 @@
# API Usage
## Prerequisites
- The FastAPI server must be running (default: http://localhost:8000)
---
## App Router
### */health*
```console
curl -X 'GET' \
'http://127.0.0.1:8000/health' \
-H 'accept: application/json'
```
---
## Strip Router
### */strip/{index}*
> Get single parameter
```console
curl -X 'GET' \
'http://127.0.0.1:8000/strip/0/gain' \
-H 'accept: application/json'
```
> Set single parameter
```console
curl -X 'PATCH' \
'http://127.0.0.1:8000/strip/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"mute": true,
}'
```
> Set multiple parameters
```console
curl -X 'PATCH' \
'http://127.0.0.1:8000/strip/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"gain": -36.8,
"mute": true,
"mono": false,
"solo": true,
"A1": true,
"A2": false,
"A3": true,
"B1": false,
"B2": true,
}'
```
## Strip Gate Router
### */strip/{index}/gate*
> Get single parameter
```console
curl -X 'GET' \
'http://127.0.0.1:8000/strip/0/gate/knob' \
-H 'accept: application/json'
```
> Set multiple parameters
```console
curl -X 'PATCH' \
'http://127.0.0.1:8000/strip/0/gate' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"threshold": -28.7,
"damping": -60,
"attack": 2
}'
```
---
## Bus Router
### */bus/{index}*
> Get single parameter
```console
curl -X 'GET' \
'http://127.0.0.1:8000/bus/0/mono' \
-H 'accept: application/json'
```
> Set single parameter
```console
curl -X 'PATCH' \
'http://127.0.0.1:8000/bus/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"gain": -32.8,
}'
```
> Set multiple parameters
```console
curl -X 'PATCH' \
'http://127.0.0.1:8000/bus/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"gain": -18.7,
"mute": false,
"mono": 1
}'
```
## Bus EQ Channel Cell Router
### */bus/{index}/eq/channel/{channel_index}/cell/{cell_index}*
> Get single parameter
```console
curl -X 'GET' \
'http://127.0.0.1:8000/bus/0/eq/channel/0/cell/0/type' \
-H 'accept: application/json'
```
> Set single parameter
```console
curl -X 'PATCH' \
'http://127.0.0.1:8000/bus/0/eq/channel/0/cell/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"q": 9.5
}'
```
> Set multiple parameters
```console
curl -X 'PATCH' \
'http://127.0.0.1:8000/bus/0/eq/channel/0/cell/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"on": true,
"type": 4,
"f": 538.2,
"gain": -0.6,
"q": 9.5
}'
```
---
## More
For a full list of endpoints and schemas, see the [Swagger UI](http://localhost:8000/docs) or [ReDoc](http://localhost:8000/redoc).

View File

@ -14,25 +14,60 @@ pip install vmr-http
## Run ## Run
```console ```console
uvicorn vmr_http:app uvicorn vmr_http.app:app
```
## Use
*Set multiple Strip parameters at once*
```console
curl -X 'PUT' \
'http://127.0.0.1:8000/strip/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"gain": -38.7,
"mute": true,
"mono": true,
"A1": true,
"A2": false,
"A5": true,
"B1": true,
"B3": true
}'
```
*Set Strip mute*
```console
curl -X 'PUT' \
'http://127.0.0.1:8000/strip/1/mute' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"mute": true
}'
```
*Get Bus gain*
```console
curl -X 'GET' \
'http://127.0.0.1:8000/bus/3/gain' \
-H 'accept: application/json'
```
*Get Bus Mode*
```console
curl -X 'GET' \
'http://127.0.0.1:8000/bus/mode/4/mode' \
-H 'accept: application/json'
``` ```
## Documentation ## Documentation
For a few examples see [API_EXAMPLES](./API_EXAMPLES.md). FastAPI [generates automatic docs][auto-docs], visit the link in the startup message when you launch the server.
For an exhaustive list of the endpoints FastAPI generates [automatic docs][auto-docs], simply launch the server and then visit:
*Swagger UI*
- http://localhost:8000/docs
*ReDoc*
- http://localhost:8000/redoc
---
## License
`vmr-http` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
[auto-docs]: https://fastapi.tiangolo.com/features/#automatic-docs [auto-docs]: https://fastapi.tiangolo.com/features/#automatic-docs

View File

@ -1,11 +1,15 @@
[project] [project]
name = "vmr-http" name = "vmr-http"
version = "0.7.2" version = "0.2.0"
description = "HTTP API for controlling Voicemeeter" description = "HTTP API for controlling Voicemeeter"
readme = "README.md" readme = "README.md"
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }] authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
requires-python = ">=3.10" requires-python = ">=3.10"
dependencies = ["fastapi>=0.135.3", "uvicorn>=0.43.0", "voicemeeter-api>=2.7.2"] dependencies = [
"fastapi>=0.135.3",
"uvicorn>=0.43.0",
"voicemeeter-api>=2.7.2",
]
classifiers = [ classifiers = [
"Development Status :: 4 - Beta", "Development Status :: 4 - Beta",
"Programming Language :: Python", "Programming Language :: Python",
@ -22,10 +26,14 @@ requires = ["uv_build>=0.11.3,<0.12.0"]
build-backend = "uv_build" build-backend = "uv_build"
[dependency-groups] [dependency-groups]
dev = ["fastapi[standard]>=0.135.3", "poethepoet>=0.43.0", "ruff>=0.15.9"] dev = [
"fastapi[standard]>=0.135.3",
"poethepoet>=0.43.0",
"ruff>=0.15.9",
]
[tool.fastapi] [tool.fastapi]
entrypoint = "vmr_http:app" entrypoint = "vmr_http.app:app"
[tool.uv.sources] [tool.uv.sources]
voicemeeter-api = { path = "../voicemeeter-api-python", editable = true } voicemeeter-api = { path = "../voicemeeter-api-python", editable = true }

View File

@ -1,5 +0,0 @@
"""Voicemeeter HTTP API."""
from .app import app
__all__ = ['app']

View File

@ -27,15 +27,15 @@ app = FastAPI(
{'name': 'bus', 'description': 'Endpoints for controlling bus parameters.'}, {'name': 'bus', 'description': 'Endpoints for controlling bus parameters.'},
], ],
) )
app.include_router(strip.router, prefix='/strip/{index}') app.include_router(strip.router, prefix='/strip')
app.include_router(bus.router, prefix='/bus/{index}') app.include_router(bus.router, prefix='/bus')
@app.get('/health') @app.get('/health')
def health_check(voicemeeter=Depends(get_voicemeeter_client)): def health_check(voicemeeter=Depends(get_voicemeeter_client)):
"""Health check endpoint to verify the service is running.""" """Health check endpoint to verify the service is running."""
try: try:
version = voicemeeter.version version = voicemeeter.version # Check if we can communicate with Voicemeeter
type_ = voicemeeter.type type_ = voicemeeter.type
except CAPIError as e: except CAPIError as e:
raise HTTPException(status_code=503, detail=f'Voicemeeter API error: {str(e)}') raise HTTPException(status_code=503, detail=f'Voicemeeter API error: {str(e)}')

View File

@ -2,12 +2,13 @@
from typing import Optional from typing import Optional
from pydantic import BaseModel, Field from pydantic import BaseModel
class BusParams(BaseModel): class BusParams(BaseModel):
"""Parameters for a single bus.""" """Parameters for a single bus."""
gain: Optional[float] = Field(None, ge=-60.0, le=12.0, description='Gain value for the bus') gain: Optional[float] = None
mute: Optional[bool] = Field(None, description='Mute status for the bus') mute: Optional[bool] = None
mono: Optional[int] = Field(None, description='Mono status for the bus') mono: Optional[int] = None
eq: Optional[bool] = None

View File

@ -1,22 +0,0 @@
"""Models for the parameters of an equalizer."""
from typing import Optional
from pydantic import BaseModel, Field
class EQParams(BaseModel):
"""Parameters for an equalizer."""
on: Optional[bool] = Field(None, description='Whether the equalizer is enabled or not.')
ab: Optional[bool] = Field(None, description='Whether the equalizer is in mode A/B.')
class EQChannelCellParams(BaseModel):
"""Parameters for an equalizer channel."""
on: Optional[bool] = Field(None, description='Whether the equalizer channel is enabled or not.')
type: Optional[int] = Field(None, ge=0, le=6, description='Type of the equalizer channel.')
f: Optional[float] = Field(None, ge=20.0, le=20000.0, description='Frequency of the equalizer channel.')
gain: Optional[float] = Field(None, ge=-36.0, le=18.0, description='Gain of the equalizer channel.')
q: Optional[float] = Field(None, ge=0.3, le=100.0, description='Q factor of the equalizer channel.')

View File

@ -2,53 +2,53 @@
from typing import Optional from typing import Optional
from pydantic import BaseModel, Field from pydantic import BaseModel
class StripParams(BaseModel): class StripParams(BaseModel):
"""Parameters for a single strip.""" """Parameters for a single strip."""
gain: Optional[float] = Field(None, ge=-60.0, le=12.0, description='Gain value for the strip') gain: Optional[float] = None
mute: Optional[bool] = Field(None, description='Mute status for the strip') mute: Optional[bool] = None
mono: Optional[bool] = Field(None, description='Mono status for the strip') mono: Optional[bool] = None
solo: Optional[bool] = Field(None, description='Solo status for the strip') solo: Optional[bool] = None
A1: Optional[bool] = Field(None, description='A1 output status for the strip') A1: Optional[bool] = None
A2: Optional[bool] = Field(None, description='A2 output status for the strip') A2: Optional[bool] = None
A3: Optional[bool] = Field(None, description='A3 output status for the strip') A3: Optional[bool] = None
A4: Optional[bool] = Field(None, description='A4 output status for the strip') A4: Optional[bool] = None
A5: Optional[bool] = Field(None, description='A5 output status for the strip') A5: Optional[bool] = None
B1: Optional[bool] = Field(None, description='B1 output status for the strip') B1: Optional[bool] = None
B2: Optional[bool] = Field(None, description='B2 output status for the strip') B2: Optional[bool] = None
B3: Optional[bool] = Field(None, description='B3 output status for the strip') B3: Optional[bool] = None
class StripCompParams(BaseModel): class StripCompParams(BaseModel):
"""Parameters for the compressor of a strip.""" """Parameters for the compressor of a strip."""
knob: Optional[float] = Field(None, ge=0.0, le=10.0, description='Compressor knob value for the strip') knob: Optional[float] = None
gainin: Optional[float] = Field(None, ge=-24.0, le=24.0, description='Compressor gain in value for the strip') gainin: Optional[float] = None
ratio: Optional[float] = Field(None, ge=1.0, le=8.0, description='Compressor ratio value for the strip') ratio: Optional[float] = None
threshold: Optional[float] = Field(None, ge=-40.0, le=-3.0, description='Compressor threshold value for the strip') threshold: Optional[float] = None
attack: Optional[float] = Field(None, ge=0.0, le=200.0, description='Compressor attack value for the strip') attack: Optional[float] = None
release: Optional[float] = Field(None, ge=0.0, le=5000.0, description='Compressor release value for the strip') release: Optional[float] = None
knee: Optional[float] = Field(None, ge=0.0, le=1.0, description='Compressor knee value for the strip') knee: Optional[float] = None
gainout: Optional[float] = Field(None, ge=-24.0, le=24.0, description='Compressor gain out value for the strip') gainout: Optional[float] = None
makeup: Optional[bool] = Field(None, description='Compressor makeup status for the strip') makeup: Optional[bool] = None
class StripGateParams(BaseModel): class StripGateParams(BaseModel):
"""Parameters for the gate of a strip.""" """Parameters for the gate of a strip."""
knob: Optional[float] = Field(None, ge=0.0, le=10.0, description='Gate knob value for the strip') knob: Optional[float] = None
threshold: Optional[float] = Field(None, ge=-60.0, le=-10.0, description='Gate threshold value for the strip') threshold: Optional[float] = None
damping: Optional[float] = Field(None, ge=-60.0, le=-10.0, description='Gate damping value for the strip') damping: Optional[float] = None
bpsidechain: Optional[float] = Field(None, ge=100.0, le=4000.0, description='Gate sidechain value for the strip') bpsidechain: Optional[float] = None
attack: Optional[float] = Field(None, ge=0.0, le=1000.0, description='Gate attack value for the strip') attack: Optional[float] = None
hold: Optional[float] = Field(None, ge=0.0, le=5000.0, description='Gate hold value for the strip') hold: Optional[float] = None
release: Optional[float] = Field(None, ge=0.0, le=5000.0, description='Gate release value for the strip') release: Optional[float] = None
class StripDenoiserParams(BaseModel): class StripDenoiserParams(BaseModel):
"""Parameters for the denoiser of a strip.""" """Parameters for the denoiser of a strip."""
knob: Optional[float] = Field(None, ge=0.0, le=10.0, description='Denoiser knob value for the strip') knob: Optional[float] = None

View File

@ -1,5 +0,0 @@
"""API endpoints for controlling various Voicemeeter components."""
from . import bus, strip
__all__ = ['bus', 'strip']

55
src/vmr_http/web/bus.py Normal file
View File

@ -0,0 +1,55 @@
"""module for bus-related endpoints."""
from fastapi import APIRouter, Body, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.bus import BusParams
from . import busmode
router = APIRouter()
router.include_router(busmode.router, prefix='/mode', tags=['bus mode'])
@router.put('/{index}', tags=['bus'])
async def set_bus_params(index: int, request: BusParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Set multiple parameters of a bus at once."""
bus = voicemeeter.bus[index]
for key, value in request.model_dump(exclude_unset=True).items():
setattr(bus, key, value)
return {key: getattr(bus, key) for key in request.model_dump(exclude_unset=True)}
@router.get('/{index}/gain', tags=['bus'])
async def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gain value for the specified bus index."""
return {'gain': voicemeeter.bus[index].gain}
@router.put('/{index}/gain', tags=['bus'])
async def set_gain(
index: int,
gain: float = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the gain value for the specified bus index."""
voicemeeter.bus[index].gain = gain
return {'gain': voicemeeter.bus[index].gain}
@router.get('/{index}/mute', tags=['bus'])
async def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mute status for the specified bus index."""
return {'mute': voicemeeter.bus[index].mute}
@router.put('/{index}/mute', tags=['bus'])
async def set_mute(
index: int,
mute: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the mute status for the specified bus index."""
voicemeeter.bus[index].mute = mute
return {'mute': voicemeeter.bus[index].mute}

View File

@ -1,5 +0,0 @@
"""module for bus-related endpoints, including the bus equalizer."""
from .bus import router
__all__ = ['router']

View File

@ -1,44 +0,0 @@
"""module for bus-related endpoints."""
from fastapi import APIRouter, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.bus import BusParams
from vmr_http.web import eq
from . import mode
router = APIRouter()
router.include_router(mode.router, prefix='/mode', tags=['bus mode'])
router.include_router(eq.create_router(eq_kind='bus'), prefix='/eq', tags=['bus eq'])
@router.patch('', tags=['bus'])
@router.put('', tags=['bus'])
def update_bus_params(index: int, params: BusParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more parameters for the specified bus index."""
bus = voicemeeter.bus[index]
updated = {}
for key, value in params.model_dump(exclude_unset=True).items():
setattr(bus, key, value)
updated[key] = getattr(bus, key)
return updated
@router.get('/gain', tags=['bus'])
def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gain value for the specified bus index."""
return {'gain': voicemeeter.bus[index].gain}
@router.get('/mute', tags=['bus'])
def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mute status for the specified bus index."""
return {'mute': voicemeeter.bus[index].mute}
@router.get('/mono', tags=['bus'])
def get_mono(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mono status for the specified bus index."""
opts = ['Off', 'On', 'Stereo Reverse']
return {'mono': opts[voicemeeter.bus[index].mono]}

View File

@ -23,19 +23,23 @@ _readable_busmodes = {
_reversed_busmodes = {v: k for k, v in _readable_busmodes.items()} _reversed_busmodes = {v: k for k, v in _readable_busmodes.items()}
@router.patch('') @router.get('/{index}')
@router.put('') async def get_bus_mode(index: int, voicemeeter=Depends(get_voicemeeter_client)):
def update_bus_mode(index: int, mode: str = Body(..., embed=True), voicemeeter=Depends(get_voicemeeter_client)): """Get the current bus mode for the specified bus index."""
"""Update the 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: if mode not in _reversed_busmodes:
raise HTTPException( raise HTTPException(
status_code=400, detail=f'Invalid mode. Valid modes are: {", ".join(_reversed_busmodes.keys())}' status_code=400, detail=f'Invalid mode. Valid modes are: {", ".join(_reversed_busmodes.keys())}'
) )
setattr(voicemeeter.bus[index].mode, _reversed_busmodes[mode], True) setattr(voicemeeter.bus[index].mode, _reversed_busmodes[mode], True)
return {'mode': _readable_busmodes[_reversed_busmodes[mode]]} return {'mode': _readable_busmodes[_reversed_busmodes[mode]]}
@router.get('')
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')}

View File

@ -1,98 +0,0 @@
"""Module for equalizer related endpoints, supporting both strip and bus parents via a factory function."""
from typing import Literal
from fastapi import APIRouter, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.eq import EQChannelCellParams, EQParams
def create_router(eq_kind: str) -> APIRouter:
"""Create an APIRouter for equalizer endpoints, with the specified kind ('strip' or 'bus')."""
if eq_kind not in ('strip', 'bus'):
raise ValueError(f'Invalid router kind: {eq_kind}')
parent_attr: Literal['strip', 'bus'] = eq_kind
def target_cls(voicemeeter, index):
return getattr(voicemeeter, parent_attr)[index]
cell_router = APIRouter()
@cell_router.patch('')
@cell_router.put('')
def update_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 eq channel cell."""
cell = target_cls(voicemeeter, 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('/on')
def get_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 eq channel cell."""
return {'on': target_cls(voicemeeter, index).eq.channel[channel_index].cell[cell_index].on}
@cell_router.get('/type')
def get_eq_channel_cell_type(
index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client)
):
"""Get the current type for the specified eq channel cell."""
return {'type': target_cls(voicemeeter, index).eq.channel[channel_index].cell[cell_index].type}
@cell_router.get('/f')
def get_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 eq channel cell."""
return {'f': target_cls(voicemeeter, index).eq.channel[channel_index].cell[cell_index].f}
@cell_router.get('/gain')
def get_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 eq channel cell."""
return {'gain': target_cls(voicemeeter, index).eq.channel[channel_index].cell[cell_index].gain}
@cell_router.get('/q')
def get_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 eq channel cell."""
return {'q': target_cls(voicemeeter, index).eq.channel[channel_index].cell[cell_index].q}
router = APIRouter()
router.include_router(cell_router, prefix='/channel/{channel_index}/cell/{cell_index}')
@router.patch('')
@router.put('')
def update_eq_params(index: int, params: EQParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more equalizer parameters for the specified index."""
eq = target_cls(voicemeeter, index).eq
updated = {}
for key, value in params.model_dump(exclude_unset=True).items():
setattr(eq, key, value)
updated[key] = getattr(eq, key)
return updated
@router.get('/on')
def get_eq_on(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current equalizer on status for the specified index."""
return {'on': target_cls(voicemeeter, index).eq.on}
@router.get('/ab')
def get_eq_ab(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current equalizer A/B status for the specified index."""
return {'ab': target_cls(voicemeeter, index).eq.ab}
return router

227
src/vmr_http/web/strip.py Normal file
View File

@ -0,0 +1,227 @@
"""module for strip-related endpoints."""
from fastapi import APIRouter, Body, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripParams
from . import 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.put('/{index}', tags=['strip'])
async def set_strip_params(index: int, request: StripParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Set the parameters for the specified strip index."""
strip = voicemeeter.strip[index]
for key, value in request.model_dump(exclude_unset=True).items():
setattr(strip, key, value)
return {key: getattr(strip, key) for key in request.model_dump(exclude_unset=True)}
@router.get('/{index}/gain', tags=['strip'])
async def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gain value for the specified strip index."""
return {'gain': voicemeeter.strip[index].gain}
@router.put('/{index}/gain', tags=['strip'])
async def set_gain(
index: int,
gain: float = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the gain value for the specified strip index."""
voicemeeter.strip[index].gain = gain
return {'gain': voicemeeter.strip[index].gain}
@router.get('/{index}/mute', tags=['strip'])
async def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mute status for the specified strip index."""
return {'mute': voicemeeter.strip[index].mute}
@router.put('/{index}/mute', tags=['strip'])
async def set_mute(
index: int,
mute: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the mute status for the specified strip index."""
voicemeeter.strip[index].mute = mute
return {'mute': voicemeeter.strip[index].mute}
@router.get('/{index}/mono', tags=['strip'])
async def get_mono(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mono status for the specified strip index."""
return {'mono': voicemeeter.strip[index].mono}
@router.put('/{index}/mono', tags=['strip'])
async def set_mono(
index: int,
mono: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the mono status for the specified strip index."""
voicemeeter.strip[index].mono = mono
return {'mono': voicemeeter.strip[index].mono}
@router.get('/{index}/solo', tags=['strip'])
async def get_solo(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current solo status for the specified strip index."""
return {'solo': voicemeeter.strip[index].solo}
@router.put('/{index}/solo', tags=['strip'])
async def set_solo(
index: int,
solo: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the solo status for the specified strip index."""
voicemeeter.strip[index].solo = solo
return {'solo': voicemeeter.strip[index].solo}
@router.get('/{index}/A1', tags=['strip'])
async def get_A1(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A1 output status for the specified strip index."""
return {'A1': voicemeeter.strip[index].A1}
@router.put('/{index}/A1', tags=['strip'])
async def set_A1(
index: int,
A1: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the A1 output status for the specified strip index."""
voicemeeter.strip[index].A1 = A1
return {'A1': voicemeeter.strip[index].A1}
@router.get('/{index}/A2', tags=['strip'])
async def get_A2(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A2 output status for the specified strip index."""
return {'A2': voicemeeter.strip[index].A2}
@router.put('/{index}/A2', tags=['strip'])
async def set_A2(
index: int,
A2: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the A2 output status for the specified strip index."""
voicemeeter.strip[index].A2 = A2
return {'A2': voicemeeter.strip[index].A2}
@router.get('/{index}/A3', tags=['strip'])
async def get_A3(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A3 output status for the specified strip index."""
return {'A3': voicemeeter.strip[index].A3}
@router.put('/{index}/A3', tags=['strip'])
async def set_A3(
index: int,
A3: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the A3 output status for the specified strip index."""
voicemeeter.strip[index].A3 = A3
return {'A3': voicemeeter.strip[index].A3}
@router.get('/{index}/A4', tags=['strip'])
async def get_A4(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A4 output status for the specified strip index."""
return {'A4': voicemeeter.strip[index].A4}
@router.put('/{index}/A4', tags=['strip'])
async def set_A4(
index: int,
A4: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the A4 output status for the specified strip index."""
voicemeeter.strip[index].A4 = A4
return {'A4': voicemeeter.strip[index].A4}
@router.get('/{index}/A5', tags=['strip'])
async def get_A5(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A5 output status for the specified strip index."""
return {'A5': voicemeeter.strip[index].A5}
@router.put('/{index}/A5', tags=['strip'])
async def set_A5(
index: int,
A5: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the A5 output status for the specified strip index."""
voicemeeter.strip[index].A5 = A5
return {'A5': voicemeeter.strip[index].A5}
@router.get('/{index}/B1', tags=['strip'])
async def get_B1(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B1 output status for the specified strip index."""
return {'B1': voicemeeter.strip[index].B1}
@router.put('/{index}/B1', tags=['strip'])
async def set_B1(
index: int,
B1: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the B1 output status for the specified strip index."""
voicemeeter.strip[index].B1 = B1
return {'B1': voicemeeter.strip[index].B1}
@router.get('/{index}/B2', tags=['strip'])
async def get_B2(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B2 output status for the specified strip index."""
return {'B2': voicemeeter.strip[index].B2}
@router.put('/{index}/B2', tags=['strip'])
async def set_B2(
index: int,
B2: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the B2 output status for the specified strip index."""
voicemeeter.strip[index].B2 = B2
return {'B2': voicemeeter.strip[index].B2}
@router.get('/{index}/B3', tags=['strip'])
async def get_B3(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B3 output status for the specified strip index."""
return {'B3': voicemeeter.strip[index].B3}
@router.put('/{index}/B3', tags=['strip'])
async def set_B3(
index: int,
B3: bool = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the B3 output status for the specified strip index."""
voicemeeter.strip[index].B3 = B3
return {'B3': voicemeeter.strip[index].B3}

View File

@ -1,5 +0,0 @@
"""module for strip-related endpoints, including the strip equalizer."""
from .strip import router
__all__ = ['router']

View File

@ -1,83 +0,0 @@
"""module for strip compressor related endpoints."""
from fastapi import APIRouter, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripCompParams
router = APIRouter()
@router.patch('')
@router.put('')
def update_strip_comp_params(index: int, params: StripCompParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more compressor parameters for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
updated = {}
for key, value in params.model_dump(exclude_unset=True).items():
setattr(strip_comp, key, value)
updated[key] = getattr(strip_comp, key)
return updated
@router.get('/knob')
def get_strip_comp_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor knob value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'knob': strip_comp.knob}
@router.get('/gainin')
def get_strip_comp_gainin(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor gain in value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'gainin': strip_comp.gainin}
@router.get('/ratio')
def get_strip_comp_ratio(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor ratio value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'ratio': strip_comp.ratio}
@router.get('/threshold')
def get_strip_comp_threshold(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor threshold value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'threshold': strip_comp.threshold}
@router.get('/attack')
def get_strip_comp_attack(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor attack value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'attack': strip_comp.attack}
@router.get('/release')
def get_strip_comp_release(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor release value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'release': strip_comp.release}
@router.get('/knee')
def get_strip_comp_knee(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor knee value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'knee': strip_comp.knee}
@router.get('/gainout')
def get_strip_comp_gainout(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor gain out value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'gainout': strip_comp.gainout}
@router.get('/makeup')
def get_strip_comp_makeup(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor makeup status for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'makeup': strip_comp.makeup}

View File

@ -1,30 +0,0 @@
"""module for strip denoiser related endpoints."""
from fastapi import APIRouter, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripDenoiserParams
router = APIRouter()
@router.patch('')
@router.put('')
def update_strip_denoiser_params(index: int, params: StripDenoiserParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more denoiser parameters for the specified strip index."""
strip_denoiser = voicemeeter.strip[index].denoiser
updated = {}
for key, value in params.model_dump(exclude_unset=True).items():
setattr(strip_denoiser, key, value)
updated[key] = getattr(strip_denoiser, key)
return updated
@router.get('/knob')
def get_strip_denoiser_knob(
index: int,
voicemeeter=Depends(get_voicemeeter_client),
):
"""Get the denoiser knob value for the specified strip index."""
strip_denoiser = voicemeeter.strip[index].denoiser
return {'knob': strip_denoiser.knob}

View File

@ -1,27 +0,0 @@
"""module for strip gain layer related endpoints."""
from fastapi import APIRouter, Body, Depends
from vmr_http.dependencies import get_voicemeeter_client
router = APIRouter()
@router.patch('')
@router.put('')
def update_strip_comp_params(
index: int,
gainlayer_index: int,
level: float = Body(..., ge=-60.0, le=12.0, embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Update one or more compressor parameters for the specified strip index."""
gainlayer = voicemeeter.strip[index].gainlayer[gainlayer_index]
gainlayer.gain = level
return {'gain_layer': {'level': gainlayer.gain}}
@router.get('/level')
def get_strip_gain_layer_level(index: int, gainlayer_index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gain layer level for the specified strip index."""
return {'gain_layer': {'level': voicemeeter.strip[index].gainlayer[gainlayer_index].gain}}

View File

@ -1,69 +0,0 @@
"""module for strip gate related endpoints."""
from fastapi import APIRouter, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripGateParams
router = APIRouter()
@router.patch('')
@router.put('')
def update_strip_gate_params(index: int, params: StripGateParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more gate parameters for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
updated = {}
for key, value in params.model_dump(exclude_unset=True).items():
setattr(strip_gate, key, value)
updated[key] = getattr(strip_gate, key)
return updated
@router.get('/knob')
def get_strip_gate_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate knob value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'knob': strip_gate.knob}
@router.get('/threshold')
def get_strip_gate_threshold(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate threshold value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'threshold': strip_gate.threshold}
@router.get('/damping')
def get_strip_gate_damping(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate damping value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'damping': strip_gate.damping}
@router.get('/bpsidechain')
def get_strip_gate_bpsidechain(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate sidechain value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'bpsidechain': strip_gate.bpsidechain}
@router.get('/attack')
def get_strip_gate_attack(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate attack value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'attack': strip_gate.attack}
@router.get('/hold')
def get_strip_gate_hold(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate hold value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'hold': strip_gate.hold}
@router.get('/release')
def get_strip_gate_release(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate release value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'release': strip_gate.release}

View File

@ -1,100 +0,0 @@
"""module for strip-related endpoints."""
from fastapi import APIRouter, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripParams
from vmr_http.web import eq
from . import comp, denoiser, gainlayer, gate
router = APIRouter()
router.include_router(gainlayer.router, prefix='/gainlayer/{gainlayer_index}', tags=['strip gainlayer'])
router.include_router(comp.router, prefix='/comp', tags=['strip comp'])
router.include_router(gate.router, prefix='/gate', tags=['strip gate'])
router.include_router(denoiser.router, prefix='/denoiser', tags=['strip denoiser'])
router.include_router(eq.create_router(eq_kind='strip'), prefix='/eq', tags=['strip eq'])
@router.patch('', tags=['strip'])
@router.put('', tags=['strip'])
def update_strip_params(index: int, params: StripParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more parameters for the specified strip index."""
strip = voicemeeter.strip[index]
updated = {}
for key, value in params.model_dump(exclude_unset=True).items():
setattr(strip, key, value)
updated[key] = getattr(strip, key)
return updated
@router.get('/gain', tags=['strip'])
def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gain value for the specified strip index."""
return {'gain': voicemeeter.strip[index].gain}
@router.get('/mute', tags=['strip'])
def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mute status for the specified strip index."""
return {'mute': voicemeeter.strip[index].mute}
@router.get('/mono', tags=['strip'])
def get_mono(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mono status for the specified strip index."""
return {'mono': voicemeeter.strip[index].mono}
@router.get('/solo', tags=['strip'])
def get_solo(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current solo status for the specified strip index."""
return {'solo': voicemeeter.strip[index].solo}
@router.get('/A1', tags=['strip'])
def get_A1(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A1 output status for the specified strip index."""
return {'A1': voicemeeter.strip[index].A1}
@router.get('/A2', tags=['strip'])
def get_A2(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A2 output status for the specified strip index."""
return {'A2': voicemeeter.strip[index].A2}
@router.get('/A3', tags=['strip'])
def get_A3(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A3 output status for the specified strip index."""
return {'A3': voicemeeter.strip[index].A3}
@router.get('/A4', tags=['strip'])
def get_A4(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A4 output status for the specified strip index."""
return {'A4': voicemeeter.strip[index].A4}
@router.get('/A5', tags=['strip'])
def get_A5(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A5 output status for the specified strip index."""
return {'A5': voicemeeter.strip[index].A5}
@router.get('/B1', tags=['strip'])
def get_B1(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B1 output status for the specified strip index."""
return {'B1': voicemeeter.strip[index].B1}
@router.get('/B2', tags=['strip'])
def get_B2(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B2 output status for the specified strip index."""
return {'B2': voicemeeter.strip[index].B2}
@router.get('/B3', tags=['strip'])
def get_B3(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B3 output status for the specified strip index."""
return {'B3': voicemeeter.strip[index].B3}

View File

@ -0,0 +1,37 @@
"""module for strip compressor related endpoints."""
from fastapi import APIRouter, Body, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripCompParams
router = APIRouter()
@router.put('/{index}/comp')
async def set_strip_comp_params(index: int, request: StripCompParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Set the compressor parameters for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
for key, value in request.model_dump(exclude_unset=True).items():
setattr(strip_comp, key, value)
return {key: getattr(strip_comp, key) for key in request.model_dump(exclude_unset=True)}
@router.get('/{index}/comp/knob')
async def get_strip_comp_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor knob value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
return {'knob': strip_comp.knob}
@router.put('/{index}/comp/knob')
async def set_strip_comp_knob(
index: int,
knob: float = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the compressor knob value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp
strip_comp.knob = knob
return {'knob': strip_comp.knob}

View File

@ -0,0 +1,44 @@
"""module for strip denoiser related endpoints."""
from fastapi import APIRouter, Body, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripDenoiserParams
router = APIRouter()
@router.put('/{index}/denoiser')
async def set_strip_denoiser_params(
index: int,
request: StripDenoiserParams,
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the denoiser parameters for the specified strip index."""
strip_denoiser = voicemeeter.strip[index].denoiser
for key, value in request.model_dump(exclude_unset=True).items():
setattr(strip_denoiser, key, value)
return {key: getattr(strip_denoiser, key) for key in request.model_dump(exclude_unset=True)}
@router.get('/{index}/denoiser/knob')
async def get_strip_denoiser_knob(
index: int,
voicemeeter=Depends(get_voicemeeter_client),
):
"""Get the denoiser knob value for the specified strip index."""
strip_denoiser = voicemeeter.strip[index].denoiser
return {'knob': strip_denoiser.knob}
@router.put('/{index}/denoiser/knob')
async def set_strip_denoiser_knob(
index: int,
knob: float = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the denoiser knob value for the specified strip index."""
strip_denoiser = voicemeeter.strip[index].denoiser
strip_denoiser.knob = knob
return {'knob': strip_denoiser.knob}

View File

@ -0,0 +1,37 @@
"""module for strip gate related endpoints."""
from fastapi import APIRouter, Body, Depends
from vmr_http.dependencies import get_voicemeeter_client
from vmr_http.models.strip import StripGateParams
router = APIRouter()
@router.put('/{index}/gate')
async def set_strip_gate_params(index: int, request: StripGateParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Set the gate parameters for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
for key, value in request.model_dump(exclude_unset=True).items():
setattr(strip_gate, key, value)
return {key: getattr(strip_gate, key) for key in request.model_dump(exclude_unset=True)}
@router.get('/{index}/gate/knob')
async def get_strip_gate_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate knob value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
return {'knob': strip_gate.knob}
@router.put('/{index}/gate/knob')
async def set_strip_gate_knob(
index: int,
knob: float = Body(..., embed=True),
voicemeeter=Depends(get_voicemeeter_client),
):
"""Set the gate knob value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate
strip_gate.knob = knob
return {'knob': strip_gate.knob}

2
uv.lock generated
View File

@ -1151,7 +1151,7 @@ wheels = [
[[package]] [[package]]
name = "vmr-http" name = "vmr-http"
version = "0.7.2" version = "0.2.0"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "fastapi" }, { name = "fastapi" },