Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local thread = require("threads")
- local c = true;
- j = com.list("note_block")
- jk = {}
- jkt = {}
- for k,v in pairs(j) do
- table.insert(jk,k)
- end
- -- 1 - piano
- -- 2 - Double Bass
- -- 3 - Bass Drum
- -- 4 - Snare Drum
- -- 5 - Click
- print("в какой последовательность проигрываются нотные блоки?")
- function posl()
- for i=1,5 do
- com.invoke(jk[i],"trigger")
- os.sleep(1)
- end
- end
- for o=1,5 do
- posl()
- io.write("на каком месте "..o.." блок: ")
- vbr=io.read()
- table.insert(jkt,jk[tonumber(vbr)])
- end
- thread.init()
- her="/Night.lua"
- local tbl = {
- [0] = 1,
- [1] = 3,
- [2] = 4,
- [3] = 5,
- [4] = 2,
- }
- function countnotes(test)
- for i = 1,1000 do
- local subs = string.sub(test,1,3*i)
- local lens = string.len(subs)
- local subs2 = string.sub(test,1,3*i+1)
- local lens2 = string.len(subs2)
- if lens==lens2 then
- return i
- end
- end
- end
- local function thirding(linen,mi)
- local n1 = (3*mi)-2
- local n2 = 3*mi
- local subs = string.sub(linen,n1,n2)
- return subs
- end
- function parse(i)
- local file = io.open(her)
- for line in file:lines() do
- local line = thirding(line,i)
- if line ~= "" and line ~= " " and line ~= nil then
- local instrum = tonumber(string.sub(line,1,1))
- local Notes = tonumber(string.sub(line,2,3))
- com.invoke(jkt[tbl[instrum]],"setPitch",Notes)
- com.invoke(jkt[tbl[instrum]],"trigger")
- end
- os.sleep(0.05)
- end
- file:close()
- end
- function check()
- local file = io.open(her)
- local line3 = file:read("*l")
- local cln3 = countnotes(line3)
- if line3 ~= nil then
- for hg = 1, cln3 do
- thread.create(parse, hg)
- end
- end
- file:close()
- end
- thread.create(check)
- thread.waitForAll()
Add Comment
Please, Sign In to add comment