ws-apifix: music is audio (F.save / F.convert of a Module or Midi to an audio format renders it, render options from opts; F.audio.open / load render music bytes), F.music builder (ops/MusicOps: new, addPattern, setCell / getCell, addSample, addInstrument, note; also F.ops.music), MIDI writer writes track.name as a 0x03 event

api (init.luau): detectFor() falls back from audio to rendering music formats; encoderFor finds audio formats for
music values; renderMusic() through codecs/audio/Tracker or music/midi render.
This commit is contained in:
4DBug committed 2026-10-31 13:56:21 -05:00
1 parent 25d8e4ff25
commit 10bd6b021f
7 files changed
+692 -16

No files matched your search

+17 -1
View File
@@ -3,7 +3,8 @@
-- divisions; running status, also across meta / sysex events as most players accept), skips unknown chunks, unwraps
-- RIFF RMID. Writes MThd + MTrk with optional running status; with running status on (the default) the bytes are
-- those python mido writes for the same events (running status reset after meta / sysex, one end-of-track at the
-- end, mid-track end-of-track events dropped). Written from the SMF 1.0 specification (no third-party code).
-- end, mid-track end-of-track events dropped); a track's name is written as a 0x03 event at tick 0 when the track
-- has none. Written from the SMF 1.0 specification (no third-party code).
local Err = require("@formats/core/Err")
local Bytes = require("@formats/core/Bytes")
local Types = require("@formats/Types")
@@ -323,6 +324,21 @@ function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?)
return order[a] < order[c]
end)
end
-- track.name: written as a track-name meta event (0x03) at tick 0 when the track has none of its own
if type(track.name) == "string" and track.name ~= "" then
local named = false
for _, ev in list do
if ev.type == "meta" and ev.meta == 0x03 then
named = true
break
end
end
if not named then
local bytes = { string.byte(track.name, 1, math.min(#track.name, 4096)) }
list = table.clone(list)
table.insert(list, 1, { tick = 0, type = "meta", meta = 0x03, data = bytes })
end
end
w:string("MTrk")
local lenAt = w:tell()
w:u32be(0)