SHOW:
|
|
- or go back to the newest paste.
1 | - | -- Configure these |
1 | + | disksInfo = { |
2 | - | discSide = "front" |
2 | + | ["C418 - 11"] = {duration=75, title="C418 - 11"}, |
3 | - | |
3 | + | ["C418 - 13"] = {duration=178, title="C418 - 13"}, |
4 | - | -- Don't touch these |
4 | + | ["C418 - blocks"] = {duration=355, title="C418 - Blocks"}, |
5 | - | discs = {} |
5 | + | ["C418 - cat"] = {duration=188, title="C418 - Cat"}, |
6 | - | discs["C418 - 11"] = {duration=75, title="C418 - 11"} |
6 | + | ["C418 - chirp"] = {duration=186, title="C418 - Chirp"}, |
7 | - | discs["C418 - 13"] = {duration=178, title="C418 - 13"} |
7 | + | ["C418 - far"] = {duration=172, title="C418 - Far"}, |
8 | - | discs["C418 - blocks"] = {duration=355, title="C418 - Blocks"} |
8 | + | ["C418 - mall"] = {duration=200, title="C418 - Mall"}, |
9 | - | discs["C418 - cat"] = {duration=188, title="C418 - Cat"} |
9 | + | ["C418 - mellohi"] = {duration=99, title="C418 - Mellohi"}, |
10 | - | discs["C418 - chirp"] = {duration=186, title="C418 - Chirp"} |
10 | + | ["C418 - stal"] = {duration=156, title="C418 - Stal"}, |
11 | - | discs["C418 - far"] = {duration=172, title="C418 - Far"} |
11 | + | ["C418 - strad"] = {duration=193, title="C418 - Strad"}, |
12 | - | discs["C418 - mall"] = {duration=200, title="C418 - Mall"} |
12 | + | ["C418 - wait"] = {duration=235, title="C418 - Wait"}, |
13 | - | discs["C418 - mellohi"] = {duration=99, title="C418 - Mellohi"} |
13 | + | ["C418 - ward"] = {duration=251, title="C418 - Ward"}, |
14 | - | discs["C418 - stal"] = {duration=156, title="C418 - Stal"} |
14 | + | ["pg.radioloop"] = {duration=25, title="Valve - Radio Loop"}, |
15 | - | discs["C418 - strad"] = {duration=193, title="C418 - Strad"} |
15 | + | ["pg.stillalive"] = {duration=175, title="Valve - Still Alive"}, |
16 | - | discs["C418 - wait"] = {duration=235, title="C418 - Wait"} |
16 | + | ["pg.wantyougone"] = {duration=135, title="Valve - Want You Gone"}, |
17 | - | discs["C418 - ward"] = {duration=251, title="C418 - Ward"} |
17 | + | } |
18 | - | discs["pg.radioloop"] = {duration=25, title="Valve - Radio Loop"} |
18 | + | |
19 | - | discs["pg.stillalive"] = {duration=175, title="Valve - Still Alive"} |
19 | + | math.randomseed(os.time()) |
20 | - | discs["pg.wantyougone"] = {duration=135, title="Valve - Want You Gone"} |
20 | + | |
21 | finishTimer = nil | |
22 | - | currentSlot = turtle.getSelectedSlot() |
22 | + | startTime = 0 |
23 | - | currentTimer = nil |
23 | + | diskInfo = nil |
24 | - | startTime = 0 |
24 | + | state = "startup" |
25 | - | jbRunTime = 0 |
25 | + | |
26 | - | discInfo = nil |
26 | + | drive = nil |
27 | - | state = "startup" |
27 | + | |
28 | - | monitor = peripheral.find("monitor") |
28 | + | -- Face turtle towards Disk Drive |
29 | - | activeslots = 0 |
29 | + | for i = 1, 4 do |
30 | if peripheral.getType("front") == "drive" then | |
31 | drive = peripheral.wrap("front") | |
32 | - | for i=1,16 do |
32 | + | break |
33 | - | if turtle.getItemCount(i) == 1 then |
33 | + | end |
34 | - | activeslots = activeslots + 1 |
34 | + | |
35 | turtle.turnLeft() | |
36 | end | |
37 | ||
38 | if drive == nil then | |
39 | error("Disk Drive not found") | |
40 | - | function incSlot(amount) |
40 | + | |
41 | - | currentSlot = currentSlot + amount |
41 | + | |
42 | - | if currentSlot > activeslots then |
42 | + | monitor = peripheral.find("monitor") |
43 | - | currentSlot = currentSlot - activeslots |
43 | + | |
44 | - | elseif currentSlot == 0 then |
44 | + | function changeDisk(direction) |
45 | - | currentSlot = activeslots |
45 | + | turtle.suck() |
46 | ||
47 | - | return currentSlot |
47 | + | local disks = {} |
48 | ||
49 | - | |
49 | + | for i = 1, 16 do |
50 | - | function changeDisk(dir) |
50 | + | if turtle.getItemCount(i) ~= 0 then |
51 | - | if dir == nil then |
51 | + | table.insert(disks, i) |
52 | - | dir = 1 |
52 | + | |
53 | - | elseif dir == 99 then |
53 | + | end |
54 | - | dir = math.random(activeslots - 1) |
54 | + | |
55 | if #disks == 0 then | |
56 | - | haveDisk = disk.isPresent(discSide) |
56 | + | error("No disks found") |
57 | - | |
57 | + | end |
58 | - | if haveDisk then |
58 | + | |
59 | - | turtle.suck() |
59 | + | local slot = 1 |
60 | ||
61 | - | |
61 | + | if direction == nil then |
62 | - | slot = incSlot(dir) |
62 | + | slot = disks[math.random(#disks)] |
63 | - | while turtle.getItemCount(slot) < 1 do |
63 | + | else |
64 | - | slot = incSlot(dir) |
64 | + | current_slot = turtle.getSelectedSlot() |
65 | ||
66 | - | |
66 | + | for k, v in pairs(disks) do |
67 | - | turtle.select(currentSlot) |
67 | + | if v >= current_slot then |
68 | - | turtle.drop() |
68 | + | slot = disks[((k + direction - 1) % #disks) + 1] |
69 | - | |
69 | + | break |
70 | end | |
71 | - | |
71 | + | |
72 | - | function stopPlayback(quiet) |
72 | + | end |
73 | - | if disk.isPresent(discSide) and disk.hasAudio(discSide) then |
73 | + | |
74 | - | disk.stopAudio(discSide) |
74 | + | if turtle.getItemCount(slot) ~= 1 then |
75 | - | currentTimer = nil |
75 | + | error("No disk Found") |
76 | - | startTime = 0 |
76 | + | end |
77 | - | print("Stopped") |
77 | + | |
78 | - | monitor.clear() |
78 | + | turtle.select(slot) |
79 | - | monitor.setCursorPos(1,1) |
79 | + | turtle.drop() |
80 | - | monitor.setTextColor(colors.gray) |
80 | + | |
81 | - | monitor.write("Stopped...") |
81 | + | if not drive.hasAudio() then |
82 | - | state="stopped" |
82 | + | error("Item is not a disk") |
83 | - | renderFooter(state) |
83 | + | end |
84 | end | |
85 | ||
86 | - | |
86 | + | function renderButton(text, active, color) |
87 | - | function playCurrentDisc() |
87 | + | local old_color = monitor.getTextColor() |
88 | - | title = disk.getAudioTitle(discSide) |
88 | + | |
89 | - | discInfo = discs[title] |
89 | + | if (active == nil) or (active == state) then |
90 | - | if not discInfo then |
90 | + | monitor.setTextColor(color) |
91 | - | print("No disc info found for " .. title) |
91 | + | else |
92 | - | changeDisk(1) |
92 | + | monitor.setTextColor(colors.gray) |
93 | end | |
94 | - | term.clear() |
94 | + | |
95 | - | term.setCursorPos(1,2) |
95 | + | monitor.write(text) |
96 | - | print("Playing " .. discInfo["title"] .. " for " .. discInfo["duration"] .. " seconds") |
96 | + | monitor.setTextColor(old_color) |
97 | - | if not(state == "playing") then |
97 | + | |
98 | - | monitor.clear() |
98 | + | |
99 | - | monitor.setCursorPos(1,1) |
99 | + | function renderFooter() |
100 | - | monitor.setTextColor(colors.gray) |
100 | + | if (monitor ~= nil) and monitor.isColor() then |
101 | - | monitor.write("Now Playing:") |
101 | + | |
102 | - | state="playing" |
102 | + | |
103 | - | renderFooter(state) |
103 | + | |
104 | renderButton("[]", "stopped", colors.red) | |
105 | renderButton("<<", nil, colors.blue) | |
106 | renderButton("[?]", nil, colors.yellow) | |
107 | renderButton(">>", nil, colors.blue) | |
108 | - | monitor.write(discInfo["title"]) |
108 | + | renderButton("[>", "playing", colors.green) |
109 | - | jbRunTime = discInfo["duration"] |
109 | + | end |
110 | - | |
110 | + | |
111 | - | disk.playAudio(discSide) |
111 | + | |
112 | - | currentTimer = os.startTimer(discInfo["duration"]) |
112 | + | |
113 | - | startTime = os.clock() |
113 | + | if finishTimer ~= nil then |
114 | print("Already playing") | |
115 | - | print("[P]lay, [F]orward, [B]ack, [S]top") |
115 | + | |
116 | return | |
117 | end | |
118 | - | |
118 | + | |
119 | - | function renderButton(text, active, state) |
119 | + | if not drive.hasAudio() then |
120 | - | if state == active then |
120 | + | changeDisk(1) |
121 | - | monitor.setTextColor(colors.green) |
121 | + | end |
122 | - | monitor.write(text) |
122 | + | |
123 | - | else |
123 | + | local title = drive.getAudioTitle() |
124 | - | monitor.setTextColor(colors.gray) |
124 | + | |
125 | - | monitor.write(text) |
125 | + | if title == nil then |
126 | print("No disk found") | |
127 | changeDisk(1) | |
128 | - | |
128 | + | end |
129 | - | function renderFooter(state) |
129 | + | |
130 | diskInfo = disksInfo[title] | |
131 | ||
132 | - | |
132 | + | if diskInfo == nil then |
133 | - | renderButton("[]", "stopped", state) |
133 | + | print("No disk info found for " .. title) |
134 | - | renderButton("<<", "rewind", state) |
134 | + | changeDisk(1) |
135 | - | renderButton("[?]", "random", state) |
135 | + | end |
136 | - | renderButton(">>", "forward", state) |
136 | + | |
137 | - | renderButton("[>", "playing", state) |
137 | + | term.clear() |
138 | - | |
138 | + | term.setCursorPos(1,2) |
139 | ||
140 | - | |
140 | + | print("Playing " .. diskInfo["title"] .. " for " .. diskInfo["duration"] .. " seconds") |
141 | - | function checkButton(x, y) |
141 | + | |
142 | state = "playing" | |
143 | - | if x == 1 or x == 2 then |
143 | + | |
144 | - | stopPlayback() |
144 | + | if monitor ~= nil then |
145 | - | elseif x == 3 or x == 4 then |
145 | + | monitor.clear() |
146 | - | stopPlayback(true) |
146 | + | |
147 | - | changeDisk(-1) |
147 | + | monitor.setCursorPos(1,1) |
148 | - | playCurrentDisc() |
148 | + | monitor.setTextColor(colors.gray) |
149 | - | elseif x == 5 or x == 6 or x == 7 then |
149 | + | monitor.write("Now Playing:") |
150 | - | stopPlayback(true) |
150 | + | |
151 | - | changeDisk(99) |
151 | + | |
152 | - | playCurrentDisc() |
152 | + | |
153 | - | elseif x == 8 or x == 9 then |
153 | + | monitor.write(diskInfo["title"]) |
154 | - | stopPlayback(true) |
154 | + | |
155 | - | changeDisk(1) |
155 | + | renderFooter() |
156 | - | playCurrentDisc() |
156 | + | end |
157 | - | elseif x == 10 or x == 11 then |
157 | + | |
158 | - | if currentTimer == nil then |
158 | + | drive.playAudio() |
159 | - | startPlayback() |
159 | + | finishTimer = os.startTimer(diskInfo["duration"]) |
160 | - | else |
160 | + | startTime = os.clock() |
161 | - | print("Already playing") |
161 | + | renderDuration() |
162 | - | end |
162 | + | print("[P]lay, [F]orward, [B]ack, [S]top") |
163 | - | end |
163 | + | |
164 | - | renderFooter(state) |
164 | + | |
165 | function stopPlayback() | |
166 | drive.stopAudio() | |
167 | - | |
167 | + | finishTimer = nil |
168 | startTime = 0 | |
169 | ||
170 | state = "stopped" | |
171 | ||
172 | - | if timeLeft > discInfo["duration"] then |
172 | + | if monitor ~= nil then |
173 | - | timeLeft = discInfo["duration"] |
173 | + | monitor.clear() |
174 | monitor.setCursorPos(1,1) | |
175 | monitor.setTextColor(colors.gray) | |
176 | - | monitor.write(time(timeLeft) .. "/" .. time(discInfo["duration"])) |
176 | + | monitor.write("Stopped...") |
177 | renderFooter() | |
178 | - | |
178 | + | end |
179 | ||
180 | - | if disk.isPresent(discSide) and disk.hasAudio(discSide) then |
180 | + | print("Stopped") |
181 | - | playCurrentDisc() |
181 | + | |
182 | - | else |
182 | + | |
183 | - | changeDisk(1) |
183 | + | function playDisk(direction) |
184 | - | playCurrentDisc() |
184 | + | stopPlayback() |
185 | changeDisk(direction) | |
186 | startPlayback() | |
187 | end | |
188 | - | function time(sec) |
188 | + | |
189 | - | min = math.floor((sec/60)) |
189 | + | |
190 | - | secs = sec - (min * 60) |
190 | + | if monitor ~= nil then |
191 | - | if secs < 10 then |
191 | + | |
192 | - | secs = "0" .. secs |
192 | + | |
193 | ||
194 | - | form = min .. ":" .. secs |
194 | + | |
195 | - | return form |
195 | + | if timeLeft > diskInfo["duration"] then |
196 | timeLeft = diskInfo["duration"] | |
197 | end | |
198 | - | countDownTimer = os.startTimer(1) |
198 | + | |
199 | monitor.setTextColor(colors.white) | |
200 | monitor.write(time_string(timeLeft) .. "/" .. time_string(diskInfo["duration"])) | |
201 | end | |
202 | end | |
203 | - | ev,p1,p2,p3 = os.pullEvent() |
203 | + | |
204 | - | if state == "playing" then |
204 | + | function time_string(sec) |
205 | - | -- Placed outside of timer loop to fix issues with timer in multiplayer |
205 | + | local min = math.floor((sec/60)) |
206 | - | tempTimer = os.startTimer(1) |
206 | + | local secs = sec - (min * 60) |
207 | - | renderDuration() |
207 | + | if secs < 10 then |
208 | - | end |
208 | + | secs = "0" .. secs |
209 | - | if ev == "timer" then |
209 | + | end |
210 | - | |
210 | + | return min .. ":" .. secs |
211 | - | |
211 | + | |
212 | - | if currentTimer == p1 and disk.isPresent(discSide) and disk.hasAudio(discSide) then |
212 | + | |
213 | - | stopPlayback(true) |
213 | + | |
214 | - | changeDisk(1) |
214 | + | |
215 | - | playCurrentDisc() |
215 | + | |
216 | - | end |
216 | + | local ev, p1, p2, p3 = os.pullEvent() |
217 | - | elseif ev == "char" then |
217 | + | |
218 | - | if p1 == 'p' then |
218 | + | if state == "playing" then |
219 | - | if currentTimer == nil then |
219 | + | -- Placed outside of timer loop to fix issues with timer in multiplayer |
220 | - | startPlayback() |
220 | + | os.startTimer(1) |
221 | - | else |
221 | + | |
222 | - | print("Already playing") |
222 | + | end |
223 | - | end |
223 | + | |
224 | - | elseif p1 == 'f' then |
224 | + | if ev == "timer" then |
225 | - | stopPlayback(true) |
225 | + | if finishTimer == p1 and drive.hasAudio() then |
226 | - | changeDisk(1) |
226 | + | playDisk(1) |
227 | - | playCurrentDisc() |
227 | + | |
228 | - | elseif p1 == 'b' then |
228 | + | elseif ev == "char" then |
229 | - | stopPlayback(true) |
229 | + | if p1 == 'p' then |
230 | - | changeDisk(-1) |
230 | + | startPlayback() |
231 | - | playCurrentDisc() |
231 | + | elseif p1 == 'f' then |
232 | - | elseif p1 == 's' then |
232 | + | playDisk(1) |
233 | - | stopPlayback() |
233 | + | elseif p1 == 'b' then |
234 | - | elseif p1 == 'r' then |
234 | + | playDisk(-1) |
235 | - | stopPlayback(true) |
235 | + | elseif p1 == 's' then |
236 | - | changeDisk(99) |
236 | + | stopPlayback() |
237 | - | playCurrentDisc() |
237 | + | elseif p1 == 'r' then |
238 | - | end |
238 | + | playDisk(nil) |
239 | - | elseif ev == "monitor_touch" then |
239 | + | |
240 | - | checkButton(p2, p3) |
240 | + | elseif ev == "monitor_touch" then |
241 | - | end |
241 | + | local x = p2 |
242 | local y = p3 | |
243 | ||
244 | if y == 5 then | |
245 | if x == 1 or x == 2 then | |
246 | stopPlayback() | |
247 | elseif x == 3 or x == 4 then | |
248 | playDisk(-1) | |
249 | elseif x == 5 or x == 6 or x == 7 then | |
250 | playDisk(nil) | |
251 | elseif x == 8 or x == 9 then | |
252 | playDisk(1) | |
253 | elseif x == 10 or x == 11 then | |
254 | startPlayback() | |
255 | end | |
256 | ||
257 | renderFooter() | |
258 | end | |
259 | end | |
260 | end |