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 playNote2(i, n)
- m = peripheral.wrap("left")
- local t = {}
- t[i] = { n }
- local id = tIds[math.floor(n / nNotes) + 1]
- m.playNote(i-1,n)
- end
- function playNote3(i, n)
- u = peripheral.wrap("right")
- local t = {}
- t[i] = { n }
- local id = tIds[math.floor(n / nNotes) + 1]
- u.playNote(i-1,n)
- end
- --[[
- i: instrument (1-5)
- notes: { n1, n2, n3, ..., nN}
- n: note (0-24)
- --]]
- function playChord(i, notes)
- local ts = {}
- m = peripheral.wrap("left")
- o = peripheral.wrap("right")
- for g, n in ipairs(notes) do
- if g/2 == 0 then
- m.playnote(i-1, n)
- else
- o.playnote(i-1,n)
- end
- 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 i,n in ipairs(notes) do
- if i/2 == 0 then
- playNote2(i, n)
- else
- playNote3(i, n)
- end
- end
- 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