Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- List of all known tracks, and their lengths.
- local tTracks = {
- {TrackName = "C418 - 13", Length = 2 * 60 + 58},
- {TrackName = "C418 - cat", Length = 3 * 60 + 05},
- {TrackName = "C418 - blocks", Length = 5 * 60 + 45},
- {TrackName = "C418 - chirp", Length = 3 * 60 + 05},
- {TrackName = "C418 - far", Length = 2 * 60 + 54},
- {TrackName = "C418 - mall", Length = 3 * 60 + 17},
- {TrackName = "C418 - mellohi", Length = 1 * 60 + 36},
- {TrackName = "C418 - stal", Length = 2 * 60 + 30},
- {TrackName = "C418 - strad", Length = 3 * 60 + 08},
- {TrackName = "C418 - ward", Length = 4 * 60 + 11},
- {TrackName = "C418 - 11", Length = 1 * 60 + 11},
- {TrackName = "C418 - wait", Length = 3 * 60 + 58}
- }
- local tJukeBoxes = {}
- -- tJukeBoxes format: Array of objects.
- -- DeviceName: (String) Name of peripheral
- -- TrackName: (String) Name of the loaded disc
- -- TrackLength: (Number) Length of the loaded disc
- -- Finds all Auto-Jukeboxes attached to the network, and saves them, with their loaded disc, to the tJukeBoxes table.
- local function BuildJukeBoxList()
- local tPeripherals
- local nIndex
- local tStack
- local nTrackIndex
- tJukeBoxes = {}
- tPeripherals = peripheral.getNames()
- for nIndex = 1, #tPeripherals do
- if peripheral.getType(tPeripherals[nIndex]) == "auto_jukebox" then
- tStack = peripheral.call(tPeripherals[nIndex], "getStackInSlot", 1)
- if tStack.disk ~= nil then
- -- Find the length of the track.
- for nTrackIndex = 1, #tTracks do
- if tTracks[nTrackIndex].TrackName == tStack.disk.label then
- tJukeBoxes[#tJukeBoxes + 1] = {DeviceName = tPeripherals[nIndex], TrackName = tStack.disk.label, TrackLength = tTracks[nTrackIndex].Length}
- break
- end
- end
- end
- end
- end
- end
- -- Plays the disc loaded in the given jukebox.
- local function PlayTrack(tJukeBox)
- peripheral.call(tJukeBox.DeviceName, "play")
- end
- -- Stops all playing tracks.
- local function StopAll()
- local nIndex
- for nIndex = 1, #tJukeBoxes do
- peripheral.call(tJukeBoxes[nIndex].DeviceName, "stop")
- end
- end
- -- Takes a number of seconds and returns a formatted string in m:ss format.
- local function FormatTime(nSeconds)
- local nMinutesOut
- local nSecondsOut
- local sSeconds
- nMinutesOut = math.floor(nSeconds / 60)
- nSecondsOut = nSeconds - (nMinutesOut * 60)
- sSeconds = tostring(nSecondsOut)
- if #sSeconds < 2 then
- sSeconds = "0" .. sSeconds
- end
- return tostring(nMinutesOut) .. ":" .. sSeconds
- end
- local nTrack
- BuildJukeBoxList()
- print("Track list:")
- for nTrack = 1, #tJukeBoxes do
- print(" " .. tJukeBoxes[nTrack].TrackName .. " (" .. FormatTime(tJukeBoxes[nTrack].TrackLength) .. ")")
- end
- print()
- while true do
- for nTrack = 1, #tJukeBoxes do
- StopAll()
- PlayTrack(tJukeBoxes[nTrack])
- print("Playing \"" .. tJukeBoxes[nTrack].TrackName .. "\" (" .. FormatTime(tJukeBoxes[nTrack].TrackLength) .. ")")
- os.sleep(tJukeBoxes[nTrack].TrackLength)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement