Advertisement
Guest User

tracker

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