Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configure these
- discSide = "front"
- -- 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 - Strad"}
- discs["C418 - wait"] = {duration=235, title="C418 - Wait"}
- 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"}
- currentSlot = turtle.getSelectedSlot()
- currentTimer = nil
- startTime = 0
- jbRunTime = 0
- discInfo = nil
- state = "startup"
- monitor = peripheral.find("monitor")
- activeslots = 0
- for i=1,16 do
- if turtle.getItemCount(i) == 1 then
- activeslots = activeslots + 1
- end
- end
- function incSlot(amount)
- currentSlot = currentSlot + amount
- if currentSlot > activeslots then
- currentSlot = currentSlot - activeslots
- elseif currentSlot == 0 then
- currentSlot = activeslots
- end
- return currentSlot
- end
- function changeDisk(dir)
- if dir == nil then
- dir = 1
- elseif dir == 99 then
- dir = math.random(activeslots - 1)
- end
- haveDisk = disk.isPresent(discSide)
- if haveDisk then
- turtle.suck()
- end
- slot = incSlot(dir)
- while turtle.getItemCount(slot) < 1 do
- slot = incSlot(dir)
- end
- turtle.select(currentSlot)
- turtle.drop()
- end
- function stopPlayback(quiet)
- if disk.isPresent(discSide) and disk.hasAudio(discSide) then
- disk.stopAudio(discSide)
- currentTimer = nil
- startTime = 0
- print("Stopped")
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.setTextColor(colors.gray)
- monitor.write("Stopped...")
- state="stopped"
- renderFooter(state)
- 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
- term.clear()
- term.setCursorPos(1,2)
- print("Playing " .. discInfo["title"] .. " for " .. discInfo["duration"] .. " seconds")
- if not(state == "playing") then
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.setTextColor(colors.gray)
- monitor.write("Now Playing:")
- state="playing"
- renderFooter(state)
- end
- monitor.setCursorPos(2,2)
- monitor.clearLine()
- monitor.setTextColor(colors.white)
- monitor.write(discInfo["title"])
- jbRunTime = discInfo["duration"]
- disk.playAudio(discSide)
- currentTimer = os.startTimer(discInfo["duration"])
- startTime = os.clock()
- renderDuration()
- print("[P]lay, [F]orward, [B]ack, [S]top")
- end
- function renderButton(text, active, state)
- if state == active then
- monitor.setTextColor(colors.green)
- monitor.write(text)
- else
- monitor.setTextColor(colors.gray)
- monitor.write(text)
- end
- end
- function renderFooter(state)
- monitor.setCursorPos(1,5)
- monitor.clearLine()
- renderButton("[]", "stopped", state)
- renderButton("<<", "rewind", state)
- renderButton("[?]", "random", state)
- renderButton(">>", "forward", state)
- renderButton("[>", "playing", state)
- end
- function checkButton(x, y)
- if y == 5 then
- if x == 1 or x == 2 then
- stopPlayback()
- elseif x == 3 or x == 4 then
- stopPlayback(true)
- changeDisk(-1)
- playCurrentDisc()
- elseif x == 5 or x == 6 or x == 7 then
- stopPlayback(true)
- changeDisk(99)
- playCurrentDisc()
- elseif x == 8 or x == 9 then
- stopPlayback(true)
- changeDisk(1)
- playCurrentDisc()
- elseif x == 10 or x == 11 then
- if currentTimer == nil then
- startPlayback()
- else
- print("Already playing")
- end
- end
- renderFooter(state)
- end
- end
- function renderDuration()
- monitor.setCursorPos(2,3)
- monitor.clearLine()
- local timeLeft = math.floor(os.clock() - startTime)
- if timeLeft > discInfo["duration"] then
- timeLeft = discInfo["duration"]
- end
- monitor.setTextColor(colors.white)
- monitor.write(time(timeLeft) .. "/" .. time(discInfo["duration"]))
- end
- function startPlayback()
- if disk.isPresent(discSide) and disk.hasAudio(discSide) then
- playCurrentDisc()
- else
- changeDisk(1)
- playCurrentDisc()
- end
- end
- function time(sec)
- min = math.floor((sec/60))
- secs = sec - (min * 60)
- if secs < 10 then
- secs = "0" .. secs
- end
- form = min .. ":" .. secs
- return form
- end
- countDownTimer = os.startTimer(1)
- startPlayback()
- while true do
- ev,p1,p2,p3 = os.pullEvent()
- if state == "playing" then
- -- Placed outside of timer loop to fix issues with timer in multiplayer
- tempTimer = os.startTimer(1)
- renderDuration()
- end
- if ev == "timer" then
- if currentTimer == p1 and disk.isPresent(discSide) and disk.hasAudio(discSide) then
- stopPlayback(true)
- changeDisk(1)
- playCurrentDisc()
- end
- 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()
- elseif p1 == 'r' then
- stopPlayback(true)
- changeDisk(99)
- playCurrentDisc()
- end
- elseif ev == "monitor_touch" then
- checkButton(p2, p3)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment