# Docs inputs for the AHX / HVL / MIDI-variant section of docs/guide/music.md (tools/fixtures.py; tools/docs_check.py # reads them): the demo songs of tools/fixtures/_hively.py, small MUS / XMI / HMP files from tools/fixtures/_midivar.py # and a .kar karaoke file written here. # tests/gen/docs_chip.luau { files = { [name] = bytes }, vars = { ahxBytes = "demo.ahx", ... } } import importlib.util, os, random, struct INPUTS = ["tools/docs_check.py", "tools/fixtures/_hively.py", "tools/fixtures/_midivar.py"] def load(ctx, name): spec = importlib.util.spec_from_file_location("docs_chip_" + name.replace("/", "_"), os.path.join(ctx.root, "tools", name + ".py")) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m def kar(V): """SMF 1 with a melody track and a "Words" track: @ headers, then syllables with \\ / line markers""" def trk(events): body = b"".join(V.vlq(dt) + data for dt, data in events) + b"\x00\xff\x2f\x00" return b"MTrk" + struct.pack(">I", len(body)) + body def text(s, kind=1): s = s.encode() return bytes([0xFF, kind]) + V.vlq(len(s)) + s melody = [(0, b"\xff\x51\x03\x07\xa1\x20"), (0, b"\xc0\x00")] for n in (60, 62, 64, 65): melody += [(0, bytes([0x90, n, 100])), (480, bytes([0x80, n, 0]))] words = [(0, text("Words", 3)), (0, text("@KMIDI KARAOKE FILE")), (0, text("@TLittle Song")), (0, text("@TThe Docs")), (0, text("\\Hel")), (480, text("lo ")), (480, text("/kar")), (480, text("aoke"))] return b"MThd" + struct.pack(">IHHh", 6, 1, 2, 480) + trk(melody) + trk(words) def generate(ctx): dc = load(ctx, "docs_check") H = load(ctx, "fixtures/_hively") V = load(ctx, "fixtures/_midivar") rng = random.Random(5) files = { "demo.ahx": H.write_ahx(H.demo_song(False)), "demo.hvl": H.write_hvl(H.demo_song(True)), "e1m1.mus": V.random_mus(rng, n=40), "song.xmi": V.write_xmi([V.random_xmi_song(rng, n=30, tempo=500000), V.random_xmi_song(rng, n=10, tempo=500000)]), "song.hmp": V.write_hmp(V.random_hmp_tracks(rng, ntracks=3, n=20, running=False)), "song.kar": kar(V), } dc.emit_inputs(ctx, files, {"ahxBytes": "demo.ahx", "hvlBytes": "demo.hvl", "musBytes": "e1m1.mus", "xmiBytes": "song.xmi", "hmpBytes": "song.hmp", "karBytes": "song.kar"})