Sound Lab tab for REW, handbooks, settings note; VK-Audio only in the start animation and settings
Sound Lab takes filters from REW's API or a filter file onto a channel with a comparison curve, and sends a channel's curve or filters back. Only checked against a fake server built from REW's OpenAPI spec. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
14ca3aec4b
commit
a754021381
10 files changed
+455
-9
No files matched your search
@@ -17,11 +17,14 @@ import mimetypes
|
||||
import re
|
||||
import secrets
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import parse_qs, urlsplit
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
import sim
|
||||
from dsp import preset, usbhid
|
||||
@@ -144,6 +147,71 @@ def clean_soundfield(data) -> dict:
|
||||
}
|
||||
|
||||
|
||||
REW_URL = "http://127.0.0.1:4735" # REW's API only answers on its own computer
|
||||
|
||||
|
||||
def rew_call(method: str, path: str, body=None):
|
||||
"""One request to REW's API."""
|
||||
data = json.dumps(body).encode() if body is not None else None
|
||||
req = Request(REW_URL + path, data=data, method=method, headers={"Content-Type": "application/json"})
|
||||
try:
|
||||
with urlopen(req, timeout=8) as r:
|
||||
raw = r.read()
|
||||
except HTTPError as e:
|
||||
try:
|
||||
msg = json.loads(e.read()).get("message", "")
|
||||
except (ValueError, AttributeError):
|
||||
msg = ""
|
||||
raise RuntimeError(f"REW: {msg or e.code}") from None
|
||||
except (URLError, OSError):
|
||||
raise RuntimeError("REW can't be reached") from None
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def rew_id(body: dict) -> str:
|
||||
mid = str(body.get("id") or "")
|
||||
if not re.fullmatch(r"[\w-]{1,64}", mid):
|
||||
raise ValueError("No measurement chosen")
|
||||
return mid
|
||||
|
||||
|
||||
def rew_filters(mid: str) -> list:
|
||||
res = rew_call("GET", f"/measurements/{mid}/filters")
|
||||
return res.get("filters", []) if isinstance(res, dict) else res
|
||||
|
||||
|
||||
def rew_measurements() -> list:
|
||||
res = rew_call("GET", "/measurements")
|
||||
items = res.values() if isinstance(res, dict) else res
|
||||
return [{"id": m.get("uuid") or "", "title": m.get("title") or "?"} for m in items if isinstance(m, dict) and m.get("uuid")]
|
||||
|
||||
|
||||
def rew_send_filters(mid: str, filters: list):
|
||||
"""Put a channel's EQ on a measurement. The generic equaliser takes all filter types and enough filters."""
|
||||
rew_call("POST", f"/measurements/{mid}/equaliser", {"manufacturer": "Generic", "model": "Generic"})
|
||||
filters = [f for f in filters if isinstance(f, dict)][:9]
|
||||
for i, f in enumerate(filters):
|
||||
f["index"] = i + 1
|
||||
rest = [{"index": f.get("index"), "type": "None", "enabled": True, "isAuto": False}
|
||||
for f in rew_filters(mid) if isinstance(f, dict) and f.get("index", 0) > len(filters) and f.get("type") not in (None, "None")]
|
||||
rew_call("POST", f"/measurements/{mid}/filters", {"filters": filters + rest})
|
||||
|
||||
|
||||
def rew_floats(values) -> str:
|
||||
"""REW's data format: base64 of 32-bit floats, most significant byte first."""
|
||||
return base64.b64encode(struct.pack(f">{len(values)}f", *[float(v) for v in values])).decode()
|
||||
|
||||
|
||||
def rew_send_curve(body: dict):
|
||||
mag, phase = body.get("magnitude"), body.get("phase")
|
||||
if not isinstance(mag, list) or not isinstance(phase, list) or not 2 <= len(mag) <= 4000 or len(mag) != len(phase):
|
||||
raise ValueError("No curve to send")
|
||||
rew_call("POST", "/import/frequency-response-data", {
|
||||
"identifier": str(body.get("identifier") or "DSP Control")[:60], "isImpedance": False,
|
||||
"startFreq": _num(body.get("startFreq"), 1, 20000, 20), "ppo": int(_num(body.get("ppo"), 1, 192, 96)),
|
||||
"magnitude": rew_floats(mag), "phase": rew_floats(phase)})
|
||||
|
||||
|
||||
DASH_TYPES = ("status", "meters", "mixer", "curve", "channel", "limiter", "routing", "delays", "fir", "notes")
|
||||
|
||||
|
||||
@@ -847,6 +915,19 @@ class App:
|
||||
return await self.set_demo(body) if method == "PUT" else self.demo_info()
|
||||
if path == "/api/scan" and method == "POST":
|
||||
return await self.scan_network()
|
||||
if path == "/api/rew/status" and method == "GET":
|
||||
res = await asyncio.to_thread(rew_call, "GET", "/version")
|
||||
return {"version": res.get("message", "") if isinstance(res, dict) else str(res)}
|
||||
if path == "/api/rew/measurements" and method == "GET":
|
||||
return await asyncio.to_thread(rew_measurements)
|
||||
if path == "/api/rew/filters" and method == "POST":
|
||||
return await asyncio.to_thread(rew_filters, rew_id(body))
|
||||
if path == "/api/rew/send-filters" and method == "POST":
|
||||
await asyncio.to_thread(rew_send_filters, rew_id(body), body.get("filters") or [])
|
||||
return {"ok": True}
|
||||
if path == "/api/rew/send-curve" and method == "POST":
|
||||
await asyncio.to_thread(rew_send_curve, body)
|
||||
return {"ok": True}
|
||||
if path == "/api/usb" and method == "GET":
|
||||
return await asyncio.to_thread(usbhid.list_devices)
|
||||
if path == "/api/limiter" and method == "GET":
|
||||
|
||||
Reference in new issue
Block a user