Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NoteBlock Controller API
- -- by MysticT
- -- Config
- -- id of the players
- local tIds = {}
- -- number of notes per player
- local nNotes = 0
- -- Instruments
- piano = 1
- bass = 2
- bass_drum = 3
- snare_drum = 4
- click = 5
- local function send(id, t)
- rednet.send(id, "<PLAY> "..textutils.serialize(t))
- end
- --[[
- i: instrument (1-5)
- n: note (0-24)
- --]]
- function playNote(i, n)
- local t = {}
- t[i] = { n }
- local id = tIds[math.floor(n / nNotes) + 1]
- send(id, t)
- end
- --[[
- i: instrument (1-5)
- notes: { n1, n2, n3, ..., nN}
- n: note (0-24)
- --]]
- function playChord(i, notes)
- local ts = {}
- for _,n in ipairs(notes) do
- local id = tIds[math.floor(n / nNotes) + 1]
- if not ts[id] then
- ts[id] = {}
- end
- if not ts[id][i] then
- ts[id][i] = {}
- end
- table.insert(ts[id][i], n)
- end
- for id, v in pairs(ts) do
- send(id, v)
- end
- end
- --[[
- Table format:
- t = {
- [i1] = { n1, n2, n3, ..., nN },
- [i2] = { n1, n2, n3, ..., nN },
- ...
- [iN] = { n1, n2, n3, ..., nN }
- }
- i: instrument (1-5)
- n: note (0-24)
- --]]
- function play(t)
- local ts = {}
- for i, notes in pairs(t) do
- for _,n in ipairs(notes) do
- local id = tIds[math.floor(n / nNotes) + 1]
- if not ts[id] then
- ts[id] = {}
- end
- if not ts[id][i] then
- ts[id][i] = {}
- end
- table.insert(ts[id][i], n)
- end
- end
- for id, v in pairs(ts) do
- send(id, v)
- end
- end
- --[[
- Table format:
- t = {
- [1] = n,
- [2] = n,
- [3] = n,
- ...
- [N] = n,
- ["delay"] = d,
- }
- d: delay (in seconds), default 0.5
- n: instrument-notes table (play() format, see above)
- --]]
- function playSong(t)
- local nDelay = t.delay or 0.5
- for _,n in ipairs(t) do
- play(n)
- sleep(nDelay)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement