Advertisement
Microstar301

tracker / OC

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