feat: add POST /api/settings — generic settings persistence to config.yaml for input_pad, input_impedance, audio interface, MIDI, display, tempo
This commit is contained in:
@@ -1533,6 +1533,59 @@ class WebServer:
|
||||
"restarted": True,
|
||||
}
|
||||
|
||||
# ── Generic settings persistence ──────────────────────────
|
||||
|
||||
KEY_MAP = {
|
||||
"input_device": ("audio", "input_device"),
|
||||
"output_device": ("audio", "output_device"),
|
||||
"channel_mode": ("audio", "mode"),
|
||||
"input_pad": ("audio", "input_pad"),
|
||||
"input_impedance": ("audio", "input_impedance"),
|
||||
"midi_channel": ("midi", "channel"),
|
||||
"midi_clock": ("midi", "clock"),
|
||||
"midi_thru": ("midi", "thru"),
|
||||
"auto_dim": ("display", "auto_dim"),
|
||||
"screen_saver": ("display", "screen_saver"),
|
||||
"tap_tempo": ("tempo", "tap_tempo"),
|
||||
"tempo_division": ("tempo", "division"),
|
||||
"tap_tempo_mute": ("tempo", "mute_on_tap"),
|
||||
}
|
||||
|
||||
@app.post("/api/settings")
|
||||
async def save_settings(data: dict):
|
||||
"""Save arbitrary settings to config.yaml.
|
||||
|
||||
Accepts a dict of key-value pairs. Each key is mapped to
|
||||
the correct ``section.key`` in ``~/.pedal/config.yaml`` and
|
||||
persisted immediately.
|
||||
|
||||
Special handling:
|
||||
``brightness`` — UI sends 1–10, stored as 0.1–1.0 float.
|
||||
"""
|
||||
if self.deps.config is None:
|
||||
raise HTTPException(status_code=503, detail="Config not available")
|
||||
|
||||
cfg = self.deps.config
|
||||
n_saved = 0
|
||||
|
||||
for key, val in data.items():
|
||||
if key == "brightness":
|
||||
leds = cfg.setdefault("leds", {})
|
||||
if isinstance(val, (int, float)) and val >= 1:
|
||||
leds["brightness"] = val / 10.0
|
||||
else:
|
||||
leds["brightness"] = val
|
||||
n_saved += 1
|
||||
elif key in KEY_MAP:
|
||||
section, skey = KEY_MAP[key]
|
||||
cfg.setdefault(section, {})[skey] = val
|
||||
n_saved += 1
|
||||
|
||||
save_config(cfg, self.deps.config_path)
|
||||
logger.info("Settings saved: %d keys from %s", n_saved, data)
|
||||
|
||||
return {"ok": True, "saved": n_saved}
|
||||
|
||||
# ── FX block param schemas ───────────────────────────────
|
||||
|
||||
@app.get("/api/block-params/{fx_type}")
|
||||
|
||||
Reference in New Issue
Block a user