Advertisement
Guest User

tracker

a guest
Oct 14th, 2019
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. local note = require("note")
  2. local os = require("os")
  3. local fs = require("io")
  4.  
  5. -- WRITTEN FOR OPEN COMPUTERS BY Voxelat3d
  6. -- Version 0.3
  7. local sleepsecs = 0.5
  8.  
  9. local curtone = ""
  10. local curoct = 2
  11.  
  12. function translatenotes(t)
  13.   local curnote = note.name(note.ticks(t))
  14.   local oct = curnote:gsub("%a","")
  15.   oct = oct:gsub("#","")
  16.   local octave = tonumber(oct)+curoct
  17.   curtone = curnote:gsub("%d","")..octave
  18. end
  19.  
  20.  
  21. function n(t)
  22.     os.sleep(sleepsecs)
  23.     translatenotes(t)
  24.     note.play(curtone)
  25. end
  26.  
  27. function nn(t)
  28.     os.sleep(sleepsecs)
  29.     note.play(t)
  30. end
  31.  
  32. --TRACKER BEGIN
  33. local args = {...}
  34. local sheet = fs.open(args[1],"r")
  35. local validdata = true
  36. local lc = 1
  37.  
  38. while validdata do
  39.     data = sheet:read()
  40.     if data ~= nil then
  41.         if not string.match(data,"#") or string.match(data,"%a+#") then
  42.             if string.match(data,"s") then
  43.                 if string.match(data,"s%d+%.*%d*") then
  44.                     tosleep = string.match(data,"%d+%.*%d*")
  45.                     print("S ",tosleep)  
  46.                     sleepsecs = tonumber(tosleep)
  47.                 else
  48.                     error("NOPE SLEEP SYNTAX WRONG @ "..lc)
  49.                 end
  50.             elseif string.match(data,"o") then
  51.                 if string.match(data,"o%d+") then
  52.                     curoct = string.match(data,"%d+")
  53.                     print("O ",curoct)
  54.                 else
  55.                     error("NOPE OCTAVE SYNTAX WRONG @ "..lc)
  56.                 end
  57.             elseif string.match(data,"%a+#%d+") or string.match(data,"%a+%d+") then
  58.                 print("+ ",data)
  59.                 nn(data)
  60.             elseif string.match(data,"%d+") then
  61.                 print("* ",data)
  62.                 n(tonumber(data))
  63.             else
  64.                 error("NOPE @ "..lc)
  65.             end
  66.         else
  67.             print(data)
  68.         end
  69.         lc=lc+1
  70.     else
  71.         validdata = false
  72.     end
  73. end
  74. sheet:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement