Guest User

playerblo.lua

a guest
Sep 3rd, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local com = require("component")
  2. local thread = require("threads")
  3. local c = true;
  4. j = com.list("note_block")
  5. jk = {}
  6. jkt = {}
  7.  
  8. for k,v in pairs(j) do
  9.   table.insert(jk,k)
  10. end
  11.  
  12. -- 1 - piano
  13. -- 2 - Double Bass
  14. -- 3 - Bass Drum
  15. -- 4 - Snare Drum
  16. -- 5 - Click
  17.  
  18. print("в какой последовательность проигрываются нотные блоки?")
  19.  
  20. function posl()
  21.     for i=1,5 do
  22.         com.invoke(jk[i],"trigger")
  23.         os.sleep(1)
  24.     end  
  25. end
  26.  
  27.  
  28. for o=1,5 do
  29.     posl()
  30.     io.write("на каком месте "..o.." блок: ")
  31.     vbr=io.read()
  32.     table.insert(jkt,jk[tonumber(vbr)])
  33. end
  34.  
  35. thread.init()
  36.  
  37. her="/Night.lua"
  38.  
  39. local tbl = {
  40.     [0] = 1,
  41.     [1] = 3,
  42.     [2] = 4,
  43.     [3] = 5,
  44.     [4] = 2,
  45. }
  46.  
  47. function countnotes(test)
  48.     for i = 1,1000 do
  49.         local subs = string.sub(test,1,3*i)
  50.         local lens = string.len(subs)
  51.         local subs2 = string.sub(test,1,3*i+1)
  52.         local lens2 = string.len(subs2)
  53.         if lens==lens2 then
  54.             return i
  55.         end
  56.     end
  57. end
  58.  
  59. local function thirding(linen,mi)
  60.     local n1 = (3*mi)-2
  61.     local n2 = 3*mi
  62.     local subs = string.sub(linen,n1,n2)
  63.     return subs
  64. end
  65.  
  66. function parse(i)
  67.     local file = io.open(her)
  68.     for line in file:lines() do
  69.         local line = thirding(line,i)
  70.         if line ~= "" and line ~= " " and line ~= nil then
  71.             local instrum = tonumber(string.sub(line,1,1))
  72.             local Notes = tonumber(string.sub(line,2,3))
  73.             com.invoke(jkt[tbl[instrum]],"setPitch",Notes)
  74.             com.invoke(jkt[tbl[instrum]],"trigger")
  75.         end
  76.         os.sleep(0.05)
  77.     end
  78.     file:close()
  79. end
  80.  
  81. function check()
  82.     local file = io.open(her)
  83.     local line3 = file:read("*l")
  84.     local cln3 = countnotes(line3)
  85.     if line3 ~= nil then
  86.         for hg = 1, cln3 do
  87.             thread.create(parse, hg)
  88.         end
  89.     end
  90.     file:close()
  91. end
  92.  
  93. thread.create(check)
  94. thread.waitForAll()
Add Comment
Please, Sign In to add comment