Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configure these
- discSide = "left"
- radioSide = "right"
- -- Don't touch these
- discs = {}
- discs["C418 - 11"] = {duration=75, title="C418 - 11"}
- discs["C418 - 13"] = {duration=178, title="C418 - 13"}
- discs["C418 - blocks"] = {duration=355, title="C418 - Blocks"}
- discs["C418 - cat"] = {duration=188, title="C418 - Cat"}
- discs["C418 - chirp"] = {duration=186, title="C418 - Chirp"}
- discs["C418 - far"] = {duration=172, title="C418 - Far"}
- discs["C418 - mall"] = {duration=200, title="C418 - Mall"}
- discs["C418 - mellohi"] = {duration=99, title="C418 - Mellohi"}
- discs["C418 - stal"] = {duration=156, title="C418 - Stal"}
- discs["C418 - strad"] = {duration=193, title="C418 - Strand"}
- discs["C418 - ward"] = {duration=251, title="C418 - Ward"}
- discs["pg.radioloop"] = {duration=25, title="Valve - Radio Loop"}
- discs["pg.stillalive"] = {duration=175, title="Valve - Still Alive"}
- discs["pg.wantyougone"] = {duration=135, title="Valve - Want You Gone"}
- discs["wait"] = {duration=235, title="C418 - Wait"}
- currentSlot = 0
- computerId = 0
- currentTimer = nil
- discInfo = nil
- startTime = 0
- function incSlot(amount)
- currentSlot = currentSlot + amount
- if currentSlot == 17 then
- currentSlot = 1
- elseif currentSlot == 0 then
- currentSlot = 16
- end
- return currentSlot
- end
- function changeDisk(dir)
- if dir == nil then
- dir = 1
- end
- haveDisk = disk.isPresent(discSide)
- -- Turn to face the disk drive
- if discSide == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- if haveDisk then
- turtle.suck()
- end
- slot = incSlot(dir)
- while turtle.getItemCount(slot) < 1 do
- slot = incSlot(dir)
- end
- turtle.select(currentSlot)
- turtle.drop()
- -- Turn away from the disk drive
- if discSize == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function stopPlayback(quiet)
- if disk.isPresent(discSide) and disk.hasAudio(discSide) then
- disk.stopAudio(discSide)
- currentTimer = nil
- startTime = 0
- if not quiet then
- if not(computerId == nil) then
- rednet.send(computerId, textutils.serialize({type="jukebox", action="stopped"}))
- end
- print("Stopped")
- end
- end
- end
- function playCurrentDisc()
- title = disk.getAudioTitle(discSide)
- discInfo = discs[title]
- if not discInfo then
- print("No disc info found for " .. title)
- changeDisk(1)
- end
- if computerId > 0 then
- rednet.send(computerId, textutils.serialize({type="jukebox", action="playing", discInfo=discInfo, runTime=0}))
- end
- print("Playing " .. discInfo["title"] .. " for " .. discInfo["duration"] .. " seconds")
- disk.playAudio(discSide)
- startTime = os.clock()
- currentTimer = os.startTimer(discInfo["duration"])
- end
- function startPlayback()
- if disk.isPresent(discSide) then
- if disk.hasAudio(discSide) then
- playCurrentDisc()
- end
- else
- changeDisk(1)
- playCurrentDisc()
- end
- end
- if peripheral.isPresent(radioSide) and peripheral.getType(radioSide) == "modem" then
- rednet.open(radioSide)
- rednet.broadcast(textutils.serialize({action="announce", type="jukebox", device="jukebox"}))
- end
- while true do
- ev,p1,p2,p3 = os.pullEvent()
- if ev == "rednet_message" then
- data = textutils.unserialize(p2)
- if data["type"] == "jukebox" then
- if data["action"] == "acknowledge" or (data["action"] == "announce" and data["device"] == "monitor") then
- print("Found a monitor!")
- computerId = p1
- if not(data["action"] == "acknowledge") then
- rednet.send(computerId, textutils.serialize({type="jukebox", action="acknowledge"}))
- end
- if currentTimer == nill then
- rednet.send(computerId, textutils.serialize({type="jukebox", action="stopped"}))
- else
- runTime = os.clock() - startTime
- rednet.send(computerId, textutils.serialize({type="jukebox", action="playing", discInfo=discInfo, runTime=runTime}))
- end
- elseif data["action"] == "stop" then
- stopPlayback()
- elseif data["action"] == "play" then
- startPlayback()
- elseif data["action"] == "next" then
- stopPlayback(true)
- changeDisk(1)
- playCurrentDisc()
- elseif data["action"] == "prev" then
- stopPlayback(true)
- changeDisk(-1)
- playCurrentDisc()
- end
- end
- elseif ev == "timer" and currentTimer == p1 then
- if disk.isPresent(discSide) and disk.hasAudio(discSide) then
- stopPlayback(true)
- end
- changeDisk(1)
- playCurrentDisc()
- elseif ev == "char" then
- if p1 == 'p' then
- if currentTimer == nil then
- startPlayback()
- else
- print("Already playing")
- end
- elseif p1 == 'f' then
- stopPlayback(true)
- changeDisk(1)
- playCurrentDisc()
- elseif p1 == 'b' then
- stopPlayback(true)
- changeDisk(-1)
- playCurrentDisc()
- elseif p1 == 's' then
- stopPlayback()
- else
- print("[P]lay, [F]orward, [B]ack, [S]top")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement