Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.startTimer(5)
- f = fs.open("setup","r")
- setup = textutils.unserialize(f.readAll())
- os.loadAPI("play")
- local radios = {}
- local function isRadio(msg)
- if type(msg) ~= "table" then
- return false
- end
- if msg.sType ~= "radio" then
- return false
- end
- return true
- end
- print("Scanning for online radio stations...")
- while true do
- local tEvent = {os.pullEvent()}
- if isRadio(tEvent[3]) then
- radios[tEvent[3].sChannel] = tEvent[3].sChannel
- end
- if tEvent[1] == "timer" then
- break
- end
- end
- i = 0
- for k,v in pairs(radios) do
- i = i + 1
- print(i..": "..v)
- end
- write("Connect to: ")
- local chan = read()
- function updateTime()
- if cont.cur ~= ocur then
- ges = cont.all
- cur = cont.cur
- allm = math.floor(ges/60)
- alls = ges%60
- curm = math.floor(cur/60)
- curs = cur%60
- text = string.format("%2i:%2i",curm,curs):gsub(" ","0").." / "..string.format("%2i:%2i",allm,alls):gsub(" ","0").." - "..cont.name
- x,y = term.getCursorPos()
- term.setCursorPos(1,y)
- term.clearLine()
- term.write(text)
- ocur = cur
- end
- end
- ocur = -1
- block = peripheral.find("iron_note")
- while true do
- e = {os.pullEvent("bitnet_message")}
- msg = e[3]
- if msg.sType == "radio" and msg.sChannel == chan then
- cont = msg.tMessage
- updateTime()
- for i,v in pairs(cont.notes) do
- if v and v.pitch then
- if (v.inst == 0 or v.inst == 2 or v.inst == 3) then
- play.play(1,1,v.inst,v.pitch,setup, true)
- elseif (v.inst == 1) then
- play.play(1,3,v.inst,v.pitch,setup, true)
- elseif (v.inst == 4) then
- play.play(1,7,v.inst,v.pitch,setup, true)
- else
- play.play(1,5,v.inst,v.pitch,setup, true)
- end
- end
- --pcall(function() block.playNote(v.inst,v.pitch) end)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement