SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local com = require("component") |
| 1 | + | local com = require("component")
|
| 2 | - | local thread = require("threads") |
| 2 | + | local thread = require("threads")
|
| 3 | - | local c = true; |
| 3 | + | local fs = require("filesystem")
|
| 4 | - | j = com.list("note_block") |
| 4 | + | local NBlocks = com.list("note_block")
|
| 5 | - | jk = {} |
| 5 | + | local NBlockList = {}
|
| 6 | - | jkt = {} |
| 6 | + | _G.CalibrationNBlocks = {}
|
| 7 | - | |
| 7 | + | |
| 8 | - | for k,v in pairs(j) do |
| 8 | + | print("Введите путь к файлу (*.nbp)")
|
| 9 | - | table.insert(jk,k) |
| 9 | + | local nepath=io.read() |
| 10 | - | end |
| 10 | + | |
| 11 | - | |
| 11 | + | if fs.exists(nepath) then |
| 12 | - | -- 1 - piano |
| 12 | + | local path=nepath |
| 13 | - | -- 2 - Double Bass |
| 13 | + | else |
| 14 | - | -- 3 - Bass Drum |
| 14 | + | print("Такого файла нет")
|
| 15 | - | -- 4 - Snare Drum |
| 15 | + | os.exit() |
| 16 | - | -- 5 - Click |
| 16 | + | end |
| 17 | - | |
| 17 | + | |
| 18 | - | print("в какой последовательность проигрываются нотные блоки?") |
| 18 | + | if _G.da==nil then |
| 19 | - | |
| 19 | + | |
| 20 | - | function posl() |
| 20 | + | for k,v in pairs(NoteBlock) do |
| 21 | - | for i=1,5 do |
| 21 | + | table.insert(NoteBlockList,k) |
| 22 | - | com.invoke(jk[i],"trigger") |
| 22 | + | end |
| 23 | - | os.sleep(1) |
| 23 | + | |
| 24 | - | end |
| 24 | + | -- 1 - piano |
| 25 | - | end |
| 25 | + | -- 2 - Double Bass |
| 26 | - | |
| 26 | + | -- 3 - Bass Drum |
| 27 | - | |
| 27 | + | -- 4 - Snare Drum |
| 28 | - | for o=1,5 do |
| 28 | + | -- 5 - Click |
| 29 | - | posl() |
| 29 | + | |
| 30 | - | io.write("на каком месте "..o.." блок: ") |
| 30 | + | print("в какой последовательность проигрываются нотные блоки?")
|
| 31 | - | vbr=io.read() |
| 31 | + | |
| 32 | - | table.insert(jkt,jk[tonumber(vbr)]) |
| 32 | + | |
| 33 | - | end |
| 33 | + | local function posl() |
| 34 | - | |
| 34 | + | for i=1,5 do |
| 35 | - | thread.init() |
| 35 | + | com.invoke(NoteBlockList[i],"trigger") |
| 36 | - | |
| 36 | + | os.sleep(1) |
| 37 | - | her="/Night.lua" |
| 37 | + | end |
| 38 | - | |
| 38 | + | end |
| 39 | - | local tbl = { |
| 39 | + | |
| 40 | - | [0] = 1, |
| 40 | + | |
| 41 | - | [1] = 3, |
| 41 | + | for o=1,5 do |
| 42 | - | [2] = 4, |
| 42 | + | posl() |
| 43 | - | [3] = 5, |
| 43 | + | io.write("на каком месте "..o.." блок: ")
|
| 44 | - | [4] = 2, |
| 44 | + | table.insert(_G.CalibrationNBlocks,NoteBlockList[tonumber(io.read())]) |
| 45 | - | } |
| 45 | + | end |
| 46 | - | |
| 46 | + | _G.da=true |
| 47 | - | function countnotes(test) |
| 47 | + | end |
| 48 | - | for i = 1,1000 do |
| 48 | + | |
| 49 | - | local subs = string.sub(test,1,3*i) |
| 49 | + | thread.init() |
| 50 | - | local lens = string.len(subs) |
| 50 | + | |
| 51 | - | local subs2 = string.sub(test,1,3*i+1) |
| 51 | + | local tbl = {
|
| 52 | - | local lens2 = string.len(subs2) |
| 52 | + | [0] = 1, |
| 53 | - | if lens==lens2 then |
| 53 | + | [1] = 3, |
| 54 | - | return i |
| 54 | + | [2] = 4, |
| 55 | - | end |
| 55 | + | [3] = 5, |
| 56 | - | end |
| 56 | + | [4] = 2, |
| 57 | - | end |
| 57 | + | } |
| 58 | - | |
| 58 | + | |
| 59 | - | local function thirding(linen,mi) |
| 59 | + | local function countnotes(test) |
| 60 | - | local n1 = (3*mi)-2 |
| 60 | + | for i = 1, math.huge do |
| 61 | - | local n2 = 3*mi |
| 61 | + | local subs = string.sub(test, 1, 3*i) |
| 62 | - | local subs = string.sub(linen,n1,n2) |
| 62 | + | local lens = string.len(subs) |
| 63 | - | return subs |
| 63 | + | local subs2 = string.sub(test, 1, 3*i+1) |
| 64 | - | end |
| 64 | + | local lens2 = string.len(subs2) |
| 65 | - | |
| 65 | + | if lens==lens2 then |
| 66 | - | function parse(i) |
| 66 | + | return i |
| 67 | - | local file = io.open(her) |
| 67 | + | end |
| 68 | - | for line in file:lines() do |
| 68 | + | end |
| 69 | - | local line = thirding(line,i) |
| 69 | + | end |
| 70 | - | if line ~= "" and line ~= " " and line ~= nil then |
| 70 | + | |
| 71 | - | local instrum = tonumber(string.sub(line,1,1)) |
| 71 | + | local function thirding(linen,mi) |
| 72 | - | local Notes = tonumber(string.sub(line,2,3)) |
| 72 | + | return string.sub(linen, 3*mi - 2, 3*mi) |
| 73 | - | com.invoke(jkt[tbl[instrum]],"setPitch",Notes) |
| 73 | + | end |
| 74 | - | com.invoke(jkt[tbl[instrum]],"trigger") |
| 74 | + | |
| 75 | - | end |
| 75 | + | local function max() |
| 76 | - | os.sleep(0.05) |
| 76 | + | local fil = io.open(path) |
| 77 | - | end |
| 77 | + | local maxn=0 |
| 78 | - | file:close() |
| 78 | + | for line in fil:lines() do |
| 79 | - | end |
| 79 | + | local v=countnotes(line) |
| 80 | - | |
| 80 | + | if v>maxn then |
| 81 | - | function check() |
| 81 | + | maxn=v |
| 82 | - | local file = io.open(her) |
| 82 | + | end |
| 83 | - | local line3 = file:read("*l") |
| 83 | + | end |
| 84 | - | local cln3 = countnotes(line3) |
| 84 | + | fil:close() |
| 85 | - | if line3 ~= nil then |
| 85 | + | return maxn |
| 86 | - | for hg = 1, cln3 do |
| 86 | + | end |
| 87 | - | thread.create(parse, hg) |
| 87 | + | |
| 88 | - | end |
| 88 | + | local function parse(i) |
| 89 | - | end |
| 89 | + | local file = io.open(path) |
| 90 | - | file:close() |
| 90 | + | for line in file:lines() do |
| 91 | - | end |
| 91 | + | local line = thirding(line,i) |
| 92 | - | |
| 92 | + | if line ~= "" and line ~= " " and line ~= nil then |
| 93 | - | thread.create(check) |
| 93 | + | local instrum = tonumber(string.sub(line,1,1)) |
| 94 | local Notes = tonumber(string.sub(line,2,3)) | |
| 95 | com.invoke(_G.CalibrationNBlocks[tbl[instrum]],"setPitch",Notes) | |
| 96 | com.invoke(_G.CalibrationNBlocks[tbl[instrum]],"trigger") | |
| 97 | end | |
| 98 | os.sleep(0.05) | |
| 99 | end | |
| 100 | file:close() | |
| 101 | end | |
| 102 | ||
| 103 | local function check() | |
| 104 | local file = io.open(path) | |
| 105 | local line3 = file:read("*l")
| |
| 106 | local maxn=max() | |
| 107 | if line3 ~= nil then | |
| 108 | for hg = 1, maxn do | |
| 109 | thread.create(parse, hg) | |
| 110 | end | |
| 111 | end | |
| 112 | file:close() | |
| 113 | end | |
| 114 | ||
| 115 | thread.create(check) | |
| 116 | thread.waitForAll() |