From be9b3e4b3530b1a56ee9e4107da6b3f79a4befd6 Mon Sep 17 00:00:00 2001 From: Shawn Date: Sun, 14 Jun 2026 12:44:59 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20add=20POST=20/api/settings=20=E2=80=94?= =?UTF-8?q?=20generic=20settings=20persistence=20to=20config.yaml=20for=20?= =?UTF-8?q?input=5Fpad,=20input=5Fimpedance,=20audio=20interface,=20MIDI,?= =?UTF-8?q?=20display,=20tempo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/server.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/web/server.py b/src/web/server.py index 361f1d6..2b380d4 100644 --- a/src/web/server.py +++ b/src/web/server.py @@ -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}")