Advertisement
FluttyProger

nbpPlayer

Sep 2nd, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local com = require("component")
  2. local note = com.iron_noteblock
  3. local fs = require("filesystem")
  4. local maxn = 0
  5.  
  6. if not fs.exists("/usr/lib/threads.lua") then
  7.     os.execute("mkdir /usr/lib")
  8.     os.execute("pastebin get TVJq1WTe /usr/lib/threads.lua -f")
  9. end
  10.  
  11. local thread = require("threads")
  12.  
  13. print("Введите путь к файлу (*.nbp)")
  14. local her=io.read()
  15.  
  16.  
  17. if not fs.exists(her)  then
  18.   print("Такого файла нет")
  19.   os.exit()
  20. end
  21.  
  22. thread.init()
  23.  
  24. function countnotes(test)
  25.     for i = 1,1000 do
  26.         local subs = string.sub(test,1,3*i)
  27.         local lens = string.len(subs)
  28.         local subs2 = string.sub(test,1,3*i+1)
  29.         local lens2 = string.len(subs2)
  30.         if lens==lens2 then
  31.             return i
  32.         end
  33.     end
  34. end
  35.  
  36. local function thirding(linen,mi)
  37.     local n1 = (3*mi)-2
  38.     local n2 = 3*mi
  39.     local subs = string.sub(linen,n1,n2)
  40.     return subs
  41. end
  42.  
  43. local function max()
  44.     local fil = io.open(her)
  45.     for line in fil:lines() do
  46.         local v=countnotes(line)
  47.         if v>maxn then
  48.             maxn=v
  49.         end
  50.     end
  51.     fil:close()
  52. end
  53.  
  54. function parse(i)
  55.     local file = io.open(her)
  56.     for line in file:lines() do
  57.         local line = thirding(line,i)
  58.         if line ~= "" and line ~= " " and line ~= nil then
  59.             local instrum = tonumber(string.sub(line,1,1))
  60.             local Notes = tonumber(string.sub(line,2,3))
  61.             note.playNote(instrum, Notes, 1)
  62.         elseif line = "" or line = " " or line = nil then
  63.             os.sleep(0.1)
  64.         end
  65.     end
  66.     file:close()
  67. end
  68.  
  69. function check()
  70.     max()
  71.     for hg = 1, maxn do
  72.         thread.create(parse, hg)
  73.     end
  74. end
  75.  
  76. thread.create(check)
  77. thread.waitForAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement