Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MML Tick checker
- local timebase = 24 -- ticks per quarter note
- if #arg == 0 then
- print("No MML Given")
- return
- end
- local mmlpath = arg[1]
- local mmlfile = io.open(mmlpath, "r")
- if mmlfile == nil then
- print("Unable to open MML file")
- return
- end
- local c = mmlfile:read(1)
- local tick = 0
- while c do
- local fetchNext = true
- c = c:lower()
- if c == "@" then
- -- somehow skip advanced commands
- c = mmlfile:read(1)
- while c and c ~= " " and c ~= "\t" and c ~= "\n" do
- c = mmlfile:read(1)
- end
- elseif c == "l" then
- defaultLen = mmlfile:read("*n")
- elseif c == "r" or c == "c" or c == "d" or c == "e" or c == "f" or c == "g" or c == "a" or c == "b" then
- local n = 0
- c = mmlfile:read(1)
- while c == "+" or c == "-" or c == "0" or c == "1" or c == "2" or c == "3" or c == "4" or c == "5" or c == "6" or c == "7" or c == "8" or c == "9" do
- if c ~= "+" and c ~= "-" then
- n = n * 10 + tonumber(c)
- end
- c = mmlfile:read(1)
- end
- local thisTick = ((timebase * 4) / n)
- local baseTick = thisTick
- while c == "." do
- baseTick = baseTick / 2
- thisTick = thisTick + baseTick
- c = mmlfile:read(1)
- end
- tick = tick + thisTick
- else
- c = mmlfile:read(1)
- end
- end
- print(tick .. " ticks")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement