ws-audio2: music/ult (UltraTracker): it family, two effect columns folded into the IT volume column, sustain loops, auto tone portamento (also from the volume column)
This commit is contained in:
1 parent
80f5fd2c5b
commit
f3299bf70f
8 files changed
+489
-2
No files matched your search
@@ -616,3 +616,50 @@ def write_stm(title, samples, orders, patterns, tempo=0x60, gvol=64, minor=21):
|
||||
struct.pack_into("<HHHH", h, 14, 0, 0, 0, 0xFFFF)
|
||||
body[smp_at + 32 * i:smp_at + 32 * i + 32] = h
|
||||
return bytes(body)
|
||||
|
||||
|
||||
def write_ult(title, samples, orders, patterns, channels, version=4, pans=None, message=b""):
|
||||
"""samples: [{name, data (signed bytes; 16-bit little-endian), bits 8|16, volume 0..255, speed (c2spd / 2... the
|
||||
file's C-4 rate), finetune, loop: (start, end) in frames | None, pingpong}]; patterns: [[row: [(note, ins, e1, p1,
|
||||
e2, p2)] * channels] * 64] with note 0 = none else our note (25..120), e1 / e2 effect nibbles (low / high nibble of
|
||||
the effect byte); repeated identical events are run-length packed"""
|
||||
out = bytearray(b"MAS_UTrack_V00" + bytes([0x30 + version]) + name(title, 32).replace(b"\0", b" "))
|
||||
out.append(len(message) // 32)
|
||||
out += message
|
||||
out.append(len(samples))
|
||||
pos = 0
|
||||
for s in samples:
|
||||
bps = 2 if s.get("bits", 8) == 16 else 1
|
||||
n = len(s["data"]) // bps
|
||||
ls, le = s.get("loop") or (0, 0)
|
||||
fl = (4 if bps == 2 else 0) | (8 if s.get("loop") else 0) | (16 if s.get("pingpong") else 0)
|
||||
out += name(s.get("name", ""), 32) + name(s.get("name", "")[:8] + ".smp", 12)
|
||||
out += struct.pack("<IIIIBB", ls * bps, le * bps, pos, pos + n, s.get("volume", 255), fl)
|
||||
if version >= 4:
|
||||
out += struct.pack("<Hh", s.get("speed", 8363), s.get("finetune", 0))
|
||||
else:
|
||||
out += struct.pack("<h", s.get("finetune", 0))
|
||||
pos += n
|
||||
out += bytes(orders) + b"\xff" * (256 - len(orders))
|
||||
out += bytes([channels - 1, len(patterns) - 1])
|
||||
if version >= 3:
|
||||
out += bytes(pans or [(i % 2) * 15 for i in range(channels)])
|
||||
for ch in range(channels):
|
||||
for pat in patterns:
|
||||
evs = []
|
||||
for row in pat:
|
||||
note, ins, e1, p1, e2, p2 = row[ch]
|
||||
evs.append(bytes([note - 24 if note else 0, ins, (e2 << 4) | e1, p1, p2]))
|
||||
i = 0
|
||||
while i < len(evs):
|
||||
j = i
|
||||
while j + 1 < len(evs) and evs[j + 1] == evs[i] and j - i < 250:
|
||||
j += 1
|
||||
if j > i:
|
||||
out += bytes([0xFC, j - i + 1]) + evs[i]
|
||||
else:
|
||||
out += evs[i]
|
||||
i = j + 1
|
||||
for s in samples:
|
||||
out += s["data"]
|
||||
return bytes(out)
|
||||
Reference in new issue
Block a user