# MED fixtures (tools/fixtures.py): generated MED / OctaMED modules (MMD0, MMD1 with instrument extras, MMD2 with a play # sequence) exercising the effects, rendered by openmpt123. # tests/gen/med_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, rows=64): return [[(0, 0, 0, 0) for _ in range(ch)] for _ in range(rows)] def put(p, row, ch, note=0, ins=0, cmd=0, param=0): p[row][ch] = (note, ins, cmd, param) def samples(extras=False): s = [ {"data": T.s8(T.synth("sine", 64, 64)), "volume": 64, "loop": (0, 64)}, {"data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 44, "loop": (0, 64)}, {"data": T.s8(T.synth("saw", 128, 64, 0.6)), "volume": 64, "loop": (64, 64), "transpose": -12}, {"data": T.s8(T.synth("noise", 4000, 1, 0.7, decay=1200)), "volume": 60}, {"data": T.s8(T.synth("tri", 32, 32, 0.8)), "volume": 52, "loop": (0, 32)}, ] if extras: s[0]["hold"], s[0]["decay"] = 6, 4 # hold / decay: a volume envelope s[1]["finetune"] = 3 s[4]["hold"], s[4]["decay"] = 2, 0 return s def song_basic(keep=None, version=0): a, b = empty(4), empty(4, 32) mel = [13, 17, 20, 25, 20, 17, 15, 13] for i in range(16): put(a, i * 4, 0, mel[i % 8], 1) put(a, 2, 0, 0, 0, 0x0, 0x37) # arpeggio put(a, 0, 1, 1, 2) put(a, 4, 1, 0, 0, 0x1, 0x02) put(a, 12, 1, 0, 0, 0x2, 0x03) put(a, 20, 1, 13, 2, 0xC, 0x32) # volume (decimal: 32) put(a, 24, 1, 0, 0, 0xD, 0x03) # volume slide down (every tick) put(a, 28, 1, 0, 0, 0xD, 0x20) put(a, 32, 1, 8, 2, 0x4, 0x34) # vibrato (twice as deep) put(a, 40, 1, 13, 2) put(a, 41, 1, 20, 0, 0x3, 0x10) # tone portamento put(a, 48, 1, 0, 0, 0x5, 0x01) for r in range(0, 64, 8): put(a, r, 3, 13, 4, 0xC, 0x64 - r) put(a, 2, 2, 25, 3) put(a, 36, 2, 1, 5, 0xF, 0xF2) # delay note put(a, 44, 2, 1, 5, 0xF, 0xF1) # play twice put(a, 34, 3, 0, 0, 0x9, 0x04) # secondary speed put(a, 50, 3, 0, 0, 0xF, 0x90) # tempo 0x90 (BPM 144 / 0.264...) put(b, 0, 0, 13, 1) put(b, 8, 1, 20, 2) put(b, 16, 2, 13, 3, 0x8, 0x40) # panning (8xx) put(b, 24, 3, 25, 5, 0xF, 0x00) # pattern break if keep is not None: for p in (a, b): for row in p: for ch in range(4): if ch not in keep and row[ch][2] not in (0x9, 0xF): row[ch] = (0, 0, 0, 0) return T.write_med(version, samples(version > 0), [a, b], [0, 1, 0], tempo=0x21 if version == 0 else 125, tempo2=6, flags=0x10 if version > 0 else 0, flags2=0x23 if version > 0 else 0, title="med test" if version > 0 else None) def song_mmd2(): """MMD2: 6 tracks, a play sequence with a section, ProTracker-style slides, BPM tempo, track volumes""" a = empty(6, 48) for r in range(0, 48, 4): put(a, r, r // 4 % 6, 13 + (r // 4) % 12, 1 + r // 4 % 5) put(a, 6, 1, 0, 0, 0x1, 0x04) put(a, 10, 2, 0, 0, 0xD, 0x02) put(a, 20, 4, 0, 0, 0x16, 0x00) # loop start put(a, 23, 4, 0, 0, 0x16, 0x01) # loop once put(a, 30, 5, 0, 0, 0x1F, 0x20) # note delay 2 put(a, 44, 0, 0, 0, 0x1D, 0x08) # break to row 8 (hex) b = empty(6, 16) put(b, 0, 0, 25, 2, 0x0C, 0x20) put(b, 8, 3, 30, 4) return T.write_med(2, samples(), [a, b], [0, 1], tempo=120, tempo2=5, flags=0x20 | 0x10, flags2=0x20 | 3, trackvols=[64, 48, 64, 32, 64, 64]) def song_octaves(): """MMD1 with an IFF 3-octave sample (three copies of a waveform, each twice as long as the last): a keymap""" w = T.s8(T.synth("saw", 32, 32, 0.7)) + T.s8(T.synth("saw", 64, 64, 0.7)) + T.s8(T.synth("saw", 128, 128, 0.7)) smp = [{"data": w, "volume": 64, "octaves": 3, "loop": (0, 32)}, samples()[0]] a = empty(2, 48) for i, n in enumerate([1, 8, 13, 20, 25, 32, 37, 30, 18, 6, 13, 25]): put(a, i * 4, 0, n, 1) put(a, i * 4 + 2, 1, n, 2, 0xC, 0x20) return T.write_med(1, smp, [a], [0], tempo=125, tempo2=6, flags=0x10, flags2=0x23) def generate(ctx): cases = [] for nm, data in (("mmd0", song_basic()), ("mmd1", song_basic(version=1)), ("mmd2", song_mmd2()), ("octaves", song_octaves())): ref = T.reference(ctx, data, "med") cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]}) ctx.emit("med_cases", cases)