Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local thread = require("threads")
- local fs = require("filesystem")
- local NBlocks = com.list("note_block")
- local NBlockList = {}
- _G.CalibrationNBlocks = {}
- print("Введите путь к файлу (*.nbp)")
- local nepath=io.read()
- if fs.exists(nepath) then
- local path=nepath
- else
- print("Такого файла нет")
- os.exit()
- end
- if _G.da==nil then
- for k,v in pairs(NoteBlock) do
- table.insert(NoteBlockList,k)
- end
- -- 1 - piano
- -- 2 - Double Bass
- -- 3 - Bass Drum
- -- 4 - Snare Drum
- -- 5 - Click
- print("в какой последовательность проигрываются нотные блоки?")
- local function posl()
- for i=1,5 do
- com.invoke(NoteBlockList[i],"trigger")
- os.sleep(1)
- end
- end
- for o=1,5 do
- posl()
- io.write("на каком месте "..o.." блок: ")
- table.insert(_G.CalibrationNBlocks,NoteBlockList[tonumber(io.read())])
- end
- _G.da=true
- end
- thread.init()
- local tbl = {
- [0] = 1,
- [1] = 3,
- [2] = 4,
- [3] = 5,
- [4] = 2,
- }
- local function countnotes(test)
- for i = 1, math.huge 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)
- return string.sub(linen, 3*mi - 2, 3*mi)
- end
- local function max()
- local fil = io.open(path)
- local maxn=0
- for line in fil:lines() do
- local v=countnotes(line)
- if v>maxn then
- maxn=v
- end
- end
- fil:close()
- return maxn
- end
- local function parse(i)
- local file = io.open(path)
- 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(_G.CalibrationNBlocks[tbl[instrum]],"setPitch",Notes)
- com.invoke(_G.CalibrationNBlocks[tbl[instrum]],"trigger")
- end
- os.sleep(0.05)
- end
- file:close()
- end
- local function check()
- local file = io.open(path)
- local line3 = file:read("*l")
- local maxn=max()
- if line3 ~= nil then
- for hg = 1, maxn do
- thread.create(parse, hg)
- end
- end
- file:close()
- end
- thread.create(check)
- thread.waitForAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement