Files
JIANT/web/studio/dev_server.py
T
Claude 62cde03949 JIANT Studio: install, edit, the screen, the emulator and recording in one page, for JIANT FM and JIANT BYTE
web/studio/ (published at /JIANT/studio/; .github/workflows/emulator.yml):
- One page in each firmware's look (JIANT FM: cream, violet and the heat gradient, Michroma, the horizon grid;
  JIANT BYTE: stars, synthwave stripes, pixel type), chosen by the firmware the FM-1 runs (INFO's engines: MATH is
  BYTE's) or by hand. Home in steps (connect, install, use it) after Melodee's installer, with the help that matters.
- A target for everything: the FM-1 over USB, or the emulator.
- Install / Editor / Emulator: the sites' own pages in frames (JIANT FM's from /JIANT/, BYTE's from /JIANT-BYTE/: one
  origin), dressed in the look, without their own headers. The editor connects by itself to the FM-1 Studio found.
- Screen: the FM-1's (78 SCREEN / 79 SCREEN_DATA) or the emulator's, straight to full screen; square, the width in
  portrait and the height in landscape, the controls beside; sharp or smooth pixels; the phone kept awake.
- Record: the FM-1's USB audio (stereo, or USB > STEMS's 8 channels: T1..T6, FX, the mix, as a ZIP) or the emulator's
  output, as WAV; what comes in over MIDI as a .mid; a song's offline stems through the emulator's panel.
- Install safety: on the jiant-midi channel like every MIDI page: lets the FM-1 go while an installer writes.
- dev_server.py: the published layout on this computer (local tools, the live site for the rest).
The emulator answers the whole editor (web/emu/editor-api.h: the firmware's editor.c, as the ports' core runs it; built
into felucca.wasm by web/emu/build.sh), so with target Emulator the editor edits the FM-1 in the browser; the emulator
lets Studio record its output and choose which MIDI input plays it.
editor.html: ?emu=1 inside Studio edits the emulator; the Screen button goes full screen at once.
Tests: web/studio/studio_test.mjs (screen frames as the editor's and the firmware's, WAV / ZIP / MIDI, the words),
web/studio/browser_test.mjs (Chromium: detection, the screen and full screen both ways, install safety, the editor on
the emulator, recording), in tests/run_tests.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVqsRnhKjiABTzc6Ety3dd
2026-11-23 17:21:49 +00:00

85 lines
4.1 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
"""JIANT Studio on this computer, laid out as the published sites are (one origin, so the frames, the screen, the recorder
and the install safety work as they will on juanjiant-bit.github.io):
/JIANT/studio/... web/studio/
/JIANT/webapp/editor/ web/editor.html (its brand style filled in as make_site.py does; fukiai.ttf beside it)
/JIANT/emu/... build/emu/ (web/emu/build.sh), else the live site's
/JIANT-BYTE/webapp/editor/ ../JIANT-BYTE/web/editor.html, when that checkout is beside this one (or BYTE_DIR)
/JIANT-BYTE/emu/... ../JIANT-BYTE/build/emu/, else the live site's
anything else fetched from https://juanjiant-bit.github.io (the installers and their packages, ...)
python3 web/studio/dev_server.py [PORT] then open http://localhost:PORT/JIANT/studio/ (?mock=1: no FM-1)
"""
import os
import sys
import urllib.request
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
HERE = Path(__file__).resolve().parent
FM = HERE.parent.parent
BYTE = Path(os.environ.get("BYTE_DIR") or next((p for p in (FM.parent / "JIANT-BYTE", FM.parent / "jiant-byte") if p.exists()), FM.parent / "JIANT-BYTE"))
LIVE = "https://juanjiant-bit.github.io"
TYPES = {".html": "text/html; charset=utf-8", ".js": "text/javascript", ".mjs": "text/javascript", ".css": "text/css",
".wasm": "application/wasm", ".json": "application/json", ".ttf": "font/ttf", ".woff": "font/woff", ".png": "image/png",
".svg": "image/svg+xml", ".fwsc": "application/octet-stream", ".txt": "text/plain"}
def editor(repo):
html = (repo / "web" / "editor.html").read_text(encoding="utf-8")
brand = repo / "web" / "jiant-ui.css"
return html.replace("/*JIANT_UI*/", brand.read_text(encoding="utf-8") if brand.exists() else "").encode()
def local(path):
"""the local file (bytes) for a site path, or None"""
for site, repo in (("/JIANT/", FM), ("/JIANT-BYTE/", BYTE)):
if not path.startswith(site):
continue
rest = path[len(site):]
if rest in ("webapp/editor/", "webapp/editor/index.html") and (repo / "web" / "editor.html").exists():
return editor(repo)
if rest.startswith("webapp/editor/"):
f = repo / "web" / rest[len("webapp/editor/"):]
return f.read_bytes() if f.is_file() else None
if site == "/JIANT/" and rest.startswith("studio/"):
f = HERE / (rest[len("studio/"):] or "index.html")
return f.read_bytes() if f.is_file() else None
if rest.startswith("emu/"):
f = repo / "build" / "emu" / (rest[len("emu/"):] or "index.html")
return f.read_bytes() if f.is_file() else None
return None
class Handler(SimpleHTTPRequestHandler):
def do_GET(self):
path = self.path.split("?")[0].split("#")[0]
if path in ("/", "/JIANT", "/JIANT/studio"):
self.send_response(302); self.send_header("Location", "/JIANT/studio/"); self.end_headers(); return
body = local(path)
kind = TYPES.get(Path(path).suffix or ".html", "application/octet-stream")
if body is None:
try:
with urllib.request.urlopen(LIVE + self.path, timeout=30) as r:
body, kind = r.read(), r.headers.get("Content-Type", kind)
except Exception as e: # noqa: BLE001 (a missing page: say so)
self.send_error(404, f"{path}: {e}"); return
self.send_response(200)
self.send_header("Content-Type", kind)
self.send_header("Content-Length", str(len(body)))
self.send_header("Cache-Control", "no-store")
self.end_headers()
self.wfile.write(body)
def log_message(self, *a):
pass
if __name__ == "__main__":
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8770
print(f"JIANT Studio: http://localhost:{port}/JIANT/studio/ (JIANT BYTE from {BYTE})")
ThreadingHTTPServer(("127.0.0.1", port), Handler).serve_forever()