mirror of
https://github.com/onyx-and-iris/vmr-http.git
synced 2026-04-18 07:33:31 +00:00
Compare commits
2 Commits
6476be53c5
...
v0.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d6d91c20a | |||
| cbdfddba09 |
83
README.md
83
README.md
@@ -17,77 +17,20 @@ pip install vmr-http
|
||||
uvicorn vmr_http:app
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
*Set multiple Strip 0 parameters at once*
|
||||
|
||||
```bash
|
||||
curl -X 'PATCH' \
|
||||
'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 1 mute*
|
||||
|
||||
```bash
|
||||
curl -X 'PATCH' \
|
||||
'http://127.0.0.1:8000/strip/1' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"mute": true,
|
||||
}'
|
||||
```
|
||||
|
||||
*Get Bus 3 gain*
|
||||
|
||||
```bash
|
||||
curl -X 'GET' \
|
||||
'http://127.0.0.1:8000/bus/3/gain' \
|
||||
-H 'accept: application/json'
|
||||
```
|
||||
|
||||
*Get Bus 4 Mode*
|
||||
|
||||
```bash
|
||||
curl -X 'GET' \
|
||||
'http://127.0.0.1:8000/bus/4/mode' \
|
||||
-H 'accept: application/json'
|
||||
```
|
||||
|
||||
*Set Bus 2 Mode*
|
||||
|
||||
```bash
|
||||
curl -X 'PATCH' \
|
||||
'http://127.0.0.1:8000/bus/2/mode' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"mode": "Composite"
|
||||
}'
|
||||
```
|
||||
|
||||
*Healthcheck*
|
||||
|
||||
```bash
|
||||
curl -X 'GET' \
|
||||
'http://127.0.0.1:8000/health' \
|
||||
-H 'accept: application/json'
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
FastAPI [generates automatic docs][auto-docs], visit the link in the startup message when you launch the server.
|
||||
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
|
||||
|
||||
`vban-cli` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
||||
|
||||
[auto-docs]: https://fastapi.tiangolo.com/features/#automatic-docs
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "vmr-http"
|
||||
version = "0.4.1"
|
||||
version = "0.5.0"
|
||||
description = "HTTP API for controlling Voicemeeter"
|
||||
readme = "README.md"
|
||||
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
|
||||
|
||||
@@ -11,4 +11,3 @@ class BusParams(BaseModel):
|
||||
gain: Optional[float] = None
|
||||
mute: Optional[bool] = None
|
||||
mono: Optional[int] = None
|
||||
eq: Optional[bool] = None
|
||||
|
||||
@@ -5,6 +5,13 @@ from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class EQParams(BaseModel):
|
||||
"""Parameters for an equalizer."""
|
||||
|
||||
on: Optional[bool] = None
|
||||
ab: Optional[bool] = None
|
||||
|
||||
|
||||
class EQChannelCellParams(BaseModel):
|
||||
"""Parameters for an equalizer channel."""
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from . import busmode, eq
|
||||
|
||||
router = APIRouter()
|
||||
router.include_router(busmode.router, prefix='/mode', tags=['bus mode'])
|
||||
router.include_router(eq.router, prefix='/eq', tags=['bus eq'])
|
||||
router.include_router(eq.create_router(parent_router_kind='bus'), prefix='/eq', tags=['bus eq'])
|
||||
|
||||
|
||||
@router.patch('', tags=['bus'])
|
||||
|
||||
@@ -1,87 +1,96 @@
|
||||
"""module for equalizer related endpoints."""
|
||||
"""Module for equalizer related endpoints, supporting both strip and bus parents via a factory function."""
|
||||
|
||||
from fastapi import APIRouter, Body, Depends
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from vmr_http.dependencies import get_voicemeeter_client
|
||||
from vmr_http.models.eq import EQChannelCellParams
|
||||
|
||||
cell_router = APIRouter()
|
||||
from vmr_http.models.eq import EQChannelCellParams, EQParams
|
||||
|
||||
|
||||
@cell_router.patch('')
|
||||
@cell_router.put('')
|
||||
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
|
||||
def create_router(parent_router_kind: str) -> APIRouter:
|
||||
"""Create an APIRouter for equalizer endpoints, with the specified parent kind ('strip' or 'bus')."""
|
||||
if parent_router_kind not in ('strip', 'bus'):
|
||||
raise ValueError(f'Invalid router kind: {parent_router_kind}')
|
||||
parent_attr = parent_router_kind
|
||||
|
||||
def get_parent(voicemeeter, index):
|
||||
return getattr(voicemeeter, parent_attr)[index]
|
||||
|
||||
@cell_router.get('/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 = APIRouter()
|
||||
|
||||
@cell_router.patch('')
|
||||
@cell_router.put('')
|
||||
async 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 = get_parent(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('/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('/on')
|
||||
async 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': get_parent(voicemeeter, index).eq.channel[channel_index].cell[cell_index].on}
|
||||
|
||||
@cell_router.get('/type')
|
||||
async 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': get_parent(voicemeeter, index).eq.channel[channel_index].cell[cell_index].type}
|
||||
|
||||
@cell_router.get('/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('/f')
|
||||
async 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': get_parent(voicemeeter, index).eq.channel[channel_index].cell[cell_index].f}
|
||||
|
||||
@cell_router.get('/gain')
|
||||
async 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': get_parent(voicemeeter, index).eq.channel[channel_index].cell[cell_index].gain}
|
||||
|
||||
@cell_router.get('/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('/q')
|
||||
async 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': get_parent(voicemeeter, index).eq.channel[channel_index].cell[cell_index].q}
|
||||
|
||||
router = APIRouter()
|
||||
router.include_router(cell_router, prefix='/channel/{channel_index}/cell/{cell_index}')
|
||||
|
||||
@cell_router.get('/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.patch('')
|
||||
@router.put('')
|
||||
async def update_eq_params(index: int, params: EQParams, voicemeeter=Depends(get_voicemeeter_client)):
|
||||
"""Update one or more equalizer parameters for the specified index."""
|
||||
eq = get_parent(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')
|
||||
async def get_eq_on(index: int, voicemeeter=Depends(get_voicemeeter_client)):
|
||||
"""Get the current equalizer on status for the specified index."""
|
||||
return {'on': get_parent(voicemeeter, index).eq.on}
|
||||
|
||||
router = APIRouter()
|
||||
router.include_router(cell_router, prefix='/channel/{channel_index}/cell/{cell_index}')
|
||||
@router.get('/ab')
|
||||
async def get_eq_ab(index: int, voicemeeter=Depends(get_voicemeeter_client)):
|
||||
"""Get the current equalizer A/B status for the specified index."""
|
||||
return {'ab': get_parent(voicemeeter, index).eq.ab}
|
||||
|
||||
|
||||
@router.patch('')
|
||||
@router.put('')
|
||||
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('/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}
|
||||
return router
|
||||
|
||||
@@ -11,7 +11,7 @@ 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(eq.router, prefix='/eq', tags=['strip eq'])
|
||||
router.include_router(eq.create_router(parent_router_kind='strip'), prefix='/eq', tags=['strip eq'])
|
||||
|
||||
|
||||
@router.patch('', tags=['strip'])
|
||||
|
||||
Reference in New Issue
Block a user