Advertisement
Guest User

tracker

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