Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. -- MML Tick checker
  2.  
  3. local timebase = 24 -- ticks per quarter note
  4.  
  5. if #arg == 0 then
  6.     print("No MML Given")
  7.     return
  8. end
  9.  
  10. local mmlpath = arg[1]
  11. local mmlfile = io.open(mmlpath, "r")
  12. if mmlfile == nil then
  13.     print("Unable to open MML file")
  14.     return
  15. end
  16.  
  17. local c = mmlfile:read(1)
  18. local tick = 0
  19. while c do
  20.     local fetchNext = true
  21.  
  22.     c = c:lower()
  23.     if c == "@" then
  24.         -- somehow skip advanced commands
  25.         c = mmlfile:read(1)
  26.         while c and c ~= " " and c ~= "\t" and c ~= "\n" do
  27.             c = mmlfile:read(1)
  28.         end
  29.     elseif c == "l" then
  30.         defaultLen = mmlfile:read("*n")
  31.     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
  32.         local n = 0
  33.         c = mmlfile:read(1)
  34.         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
  35.             if c ~= "+" and c ~= "-" then
  36.                 n = n * 10 + tonumber(c)
  37.             end
  38.             c = mmlfile:read(1)
  39.         end
  40.  
  41.         local thisTick = ((timebase * 4) / n)
  42.         local baseTick = thisTick
  43.         while c == "." do
  44.             baseTick = baseTick / 2
  45.             thisTick = thisTick + baseTick
  46.             c = mmlfile:read(1)
  47.         end
  48.         tick = tick + thisTick
  49.     else
  50.         c = mmlfile:read(1)
  51.     end
  52. end
  53. print(tick .. " ticks")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement