开发者

Reading and Parsing a .MID file with Lua?

I am trying to read a .MID file with Lua and then parsing it into a table with all of the notes (ie {"A", "B#", "Cb", etc.}) but I cannot manage to read the file correctly. I use io.open and file:lines() but writing those same lines into another midi file results in a non-working midi file.

Is there any easie开发者_如何转开发r way to read and parse a .MID file with Lua?


The Standard MIDI File format is binary, not text. So you cannot expect to read it as "lines" at all. Instead, you'll need to use the read function to get bytes and inspect them. You might be better off finding a C library for MIDI files and binding it to Lua.


.MID files (presumably Standard MIDI format) are binary, not text. Reading them with file:lines() will not work. You need to read the entire thing into a "string" (Lua strings can hold arbitrary bytes of data) with file:read("*a") instead; this will read the entire file into a single string. You also need to make sure that you open the file in binary mode (for platforms where this makes a difference).


There seems to be a framework called MIDI.lua for parsing MIDI data. Not sure how well it handles MIDI files, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜