Files
rosetta/tools/fixtures/ult.py
T

96 lines
4.8 KiB
Python

# ULT fixtures (tools/fixtures.py): generated UltraTracker modules exercising the effects (two per cell), rendered by
# openmpt123.
# tests/gen/ult_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, 0, 0, 0, 0) for _ in range(ch)] for _ in range(64)]
def put(p, row, ch, note=0, ins=0, e1=0, p1=0, e2=0, p2=0):
p[row][ch] = (note, ins, e1, p1, e2, p2)
def samples():
return [
{"name": "sine", "data": T.s8(T.synth("sine", 64, 64)), "volume": 255, "loop": (0, 64)},
{"name": "square", "data": T.s8(T.synth("square", 64, 64, 0.5)), "volume": 180, "speed": 16726, "loop": (0, 64)},
{"name": "saw16", "data": T.s16(T.synth("saw", 200, 100, 0.6)), "bits": 16, "volume": 240, "loop": (0, 200), "pingpong": True},
{"name": "noise", "data": T.s8(T.synth("noise", 6000, 1, 0.7, decay=1500)), "volume": 230},
{"name": "tri", "data": T.s8(T.synth("tri", 50, 50, 0.8)), "volume": 200, "speed": 10000, "finetune": 3000, "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, 0xC, 0x80 + i * 8) # note + set volume (volume column)
put(a, 0, 1, 49, 2)
put(a, 4, 1, 0, 0, 0xA, 0x04) # volume slide down
put(a, 8, 1, 0, 0, 0xA, 0x20, 0x4, 0x46) # slide + vibrato: two columns
put(a, 16, 1, 51, 2, 0x2, 0x03)
put(a, 20, 1, 0, 0, 0x1, 0x06, 0xB, 0x0C) # porta up + panning
put(a, 24, 1, 0, 0, 0xE, 0x14) # fine porta up
put(a, 28, 1, 56, 2, 0x4, 0x46)
put(a, 40, 1, 49, 2)
put(a, 41, 1, 61, 0, 0x3, 0x10) # tone portamento (keeps going)
put(a, 48, 1, 54, 2, 0x7, 0x58) # tremolo (v4)
put(a, 56, 1, 0, 0, 0xE, 0xA4)
put(a, 58, 1, 0, 0, 0xE, 0xB8)
for r in range(0, 64, 8):
put(a, r, 3, 61, 4, 0xC, 255 - r * 3)
put(a, 20, 3, 61, 4, 0x9, 0x20) # offset (x 4)
put(a, 32, 3, 61, 4, 0xE, 0xC3) # note cut
put(a, 40, 3, 61, 4, 0xE, 0xD2) # note delay
put(a, 4, 2, 37, 3)
put(a, 30, 2, 0, 0, 0x5, 0x0C) # key off: the sustain loop ends
put(a, 36, 2, 44, 3, 0x0, 0x47) # arpeggio
put(a, 2, 4, 73, 5, 0xB, 0x03)
put(a, 44, 4, 0, 0, 0xE, 0x93) # retrigger
put(a, 10, 5, 56, 1, 0xF, 0x04) # speed
put(a, 34, 5, 0, 0, 0xF, 0x90) # tempo
put(b, 0, 0, 49, 1, 0xC, 0xFF, 0xF, 0x05) # volume + speed in one cell
put(b, 8, 0, 61, 1, 0x1, 0x04, 0xA, 0x03) # porta up -> volume column
put(b, 16, 0, 56, 1, 0x3, 0x08, 0x4, 0x05) # tone porta + vibrato depth
put(b, 24, 2, 49, 3, 0xE, 0x84) # fine pattern delay
put(b, 0, 5, 37, 2, 0xA, 0xF0, 0x3, 0x00)
put(b, 32, 4, 68, 5, 0xD, 0x00, 0xC, 0x60) # break + volume
if keep is not None: # debugging: only some channels (their speed / tempo / break effects stay)
for p in (a, b):
for row in p:
for ch in range(6):
if ch not in keep and row[ch][2] not in (0xD, 0xF) and row[ch][4] not in (0xD, 0xF):
row[ch] = (0, 0, 0, 0, 0, 0)
return T.write_ult("effects", samples(), [0, 1], [a, b], 6, pans=[3, 12, 7, 0, 15, 9])
def song_old():
"""a v1.3 file: no tremolo, no sample speed; arpeggio"""
a = empty(4)
for r in range(0, 64, 4):
put(a, r, r // 4 % 4, 49 + (r // 4) % 12, 1 + r // 4 % 3, 0x0, 0x37)
put(a, 32, 0, 0, 0, 0xF, 0x03)
return T.write_ult("old", samples(), [0, 0], [a], 4, version=3)
def generate(ctx):
cases = []
for nm, data in (("effects", song_effects()), ("old", song_old())):
ref = T.reference(ctx, data, "ult")
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
ctx.emit("ult_cases", cases)