Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local note = com.iron_noteblock
- local fs = require("filesystem")
- local maxn = 0
- if not fs.exists("/usr/lib/threads.lua") then
- os.execute("mkdir /usr/lib")
- os.execute("pastebin get TVJq1WTe /usr/lib/threads.lua -f")
- end
- local thread = require("threads")
- print("Введите путь к файлу (*.nbp)")
- local her=io.read()
- if not fs.exists(her) then
- print("Такого файла нет")
- os.exit()
- end
- thread.init()
- 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
- local function max()
- local fil = io.open(her)
- for line in fil:lines() do
- local v=countnotes(line)
- if v>maxn then
- maxn=v
- end
- end
- fil:close()
- 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))
- note.playNote(instrum, Notes, 1)
- elseif line = "" or line = " " or line = nil then
- os.sleep(0.1)
- end
- end
- file:close()
- end
- function check()
- max()
- for hg = 1, maxn do
- thread.create(parse, hg)
- end
- end
- thread.create(check)
- thread.waitForAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement