Files
4DBug 60544a3a77 ws-audio2: music/ptm (PolyTracker): it family, MOD letters with S3M fine slides, note slides, delta 8 / 16-bit samples; engine flags.panLaw = ft2 (square-root panning)
ops/MusicOps: accept modules of the other tracker formats by their engine family (Tracker.family), a one-line
backward-compatible change.
2026-10-31 14:29:01 -05:00

90 lines
3.9 KiB
Python

# PTM fixtures (tools/fixtures.py): generated PolyTracker modules exercising the effects, rendered by openmpt123.
# tests/gen/ptm_cases.luau { name, data (the module), ref (features of openmpt's render, tools/fixtures/_tracker.py),
# duration (openmpt's song length) }
import os, sys
# the shared tracker module, loaded by path (tools/fixtures/ must not go on sys.path: xml.py there would shadow xml)
T = sys.modules.get("_tracker")
if T is None:
import importlib.util
_spec = importlib.util.spec_from_file_location("_tracker", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_tracker.py"))
T = importlib.util.module_from_spec(_spec)
sys.modules["_tracker"] = T
_spec.loader.exec_module(T)
INPUTS = ["tools/fixtures/_tracker.py"]
def empty(ch):
return [[(0, 0, None, None, 0) for _ in range(ch)] for _ in range(64)]
def put(p, row, ch, note=0, ins=0, vol=None, cmd=None, param=0):
p[row][ch] = (note, ins, vol, cmd, param)
def samples():
return [
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 64, "c4spd": 8363, "loop": (0, 64)},
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 40, "c4spd": 16726, "loop": (0, 64)},
{"name": "saw16", "data": T.s16(T.synth("saw", 200, 100, 0.6)), "bits": 16, "volume": 64, "c4spd": 13000, "loop": (0, 200), "pingpong": True},
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 60, "c4spd": 8363},
{"name": "tri", "data": T.s8(T.synth("tri", 50, 50, 0.8)), "volume": 50, "c4spd": 10000, "loop": (0, 50)},
]
def song_effects(keep=None):
a, b = empty(6), empty(6)
mel = [61, 65, 68, 73, 68, 65, 63, 61]
for i in range(16):
put(a, i * 4, 0, mel[i % 8], 1, None, 0x0 if i % 4 == 1 else None, 0x37)
put(a, 0, 1, 49, 2, 48)
put(a, 4, 1, 0, 0, None, 0xA, 0x04)
put(a, 8, 1, 0, 0, None, 0xA, 0x20)
put(a, 12, 1, 0, 0, None, 0xA, 0xF2) # S3M-style fine slide
put(a, 16, 1, 51, 2, None, 0x2, 0x03)
put(a, 20, 1, 0, 0, None, 0x1, 0x06)
put(a, 24, 1, 0, 0, None, 0x1, 0xF4) # fine porta
put(a, 28, 1, 56, 2, None, 0x4, 0x46)
put(a, 36, 1, 0, 0, None, 0x6, 0x02)
put(a, 40, 1, 49, 2)
put(a, 41, 1, 61, 0, None, 0x3, 0x10)
put(a, 44, 1, 0, 0, None, 0x5, 0x01)
put(a, 48, 1, 54, 2, None, 0x7, 0x58)
put(a, 56, 1, 0, 0, None, 0xC, 0x20)
for r in range(0, 64, 8):
put(a, r, 3, 61, 4, 64 - r // 2)
put(a, 20, 3, 61, 4, None, 0x9, 0x08)
put(a, 32, 3, 61, 4, None, 0xE, 0xC3)
put(a, 40, 3, 61, 4, None, 0xE, 0xD2)
put(a, 48, 3, 61, 4, None, 0x11, 0x03) # retrigger
put(a, 4, 2, 37, 3, 50)
put(a, 2, 4, 73, 5, None, 0x8, 0x30) # panning
put(a, 18, 4, 0, 0, None, 0x8, 0xD0)
put(a, 10, 5, 56, 1, None, 0x12, 0x46) # fine vibrato
put(a, 24, 5, 0, 0, None, 0x13, 0x22) # note slide up: every 2 ticks by 2
put(a, 30, 5, 0, 0, None, 0x14, 0x31) # note slide down
put(a, 36, 5, 60, 1, None, 0x15, 0x21) # with retrigger
put(b, 0, 0, 49, 1, None, 0xF, 0x04)
put(b, 4, 0, 0, 0, None, 0xF, 0x90)
put(b, 8, 0, 61, 1, None, 0x10, 0x20) # global volume
put(b, 24, 0, 0, 0, None, 0x10, 0x40)
put(b, 0, 2, 37, 3)
put(b, 16, 2, 0, 0, None, 0xE, 0x92)
put(b, 32, 4, 68, 5, None, 0xD, 0x00)
if keep is not None:
for p in (a, b):
for row in p:
for ch in range(6):
if ch not in keep and row[ch][3] not in (0xD, 0xF, 0x10):
row[ch] = (0, 0, None, None, 0)
return T.write_ptm("effects", samples(), [0, 1], [a, b], 6, pans=[3, 12, 7, 0, 15, 9])
def generate(ctx):
cases = []
for nm, data in (("effects", song_effects()),):
ref = T.reference(ctx, data, "ptm")
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
ctx.emit("ptm_cases", cases)