Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local speak = peripheral.find("speaker")
- local lib = io.open("musiclib.txt")
- local sizeX, sizeY = term.getSize()
- local lines = lib:lines()
- function noUS (s)
- return s:gsub("%_", " ")
- end
- function visual (det, offs)
- term.clear()
- term.setCursorPos((sizeX/2)-3,(sizeY/2)-1)
- print("playing")
- term.setCursorPos(((sizeX/2)-(string.len(det[1])/2))+1,(sizeY/2))
- local swatch = {"1","2","3","4","5","6","9","a","b","c","d","e"}
- local front = ""
- local back = ""
- for it = 1,string.len(det[1]) do
- front = front .. "" .. swatch[(it-offs)%12+1]
- back = back .. "f"
- end
- term.blit((noUS(det[1])),front,back)
- term.setTextColor(colors.red)
- term.setCursorPos(((sizeX/2)-(string.len(det[2])/2)-1),(sizeY/2)+1)
- print("by " .. (noUS(det[2])))
- term.setTextColor(colors.white)
- end
- if(#tArgs == 1) then
- song = tArgs[1]
- for line in lines do
- deets = {}
- i=0
- for sub in line:gmatch("%S+") do
- deets[i] = sub
- i=i+1
- end
- if(deets[0] == song) then
- speak.playSound(deets[3])
- ofs = 0
- visual(deets, ofs)
- sleep(1)
- while true do
- timerID = os.startTimer(0.25)
- local evdat = {os.pullEvent()}
- local ev = evdat[1]
- if ev == "key_up" then
- speak.stop()
- term.clear()
- term.setCursorPos(1,1)
- term.write("song ended")
- return
- elseif ev == "timer" and evdat[2] == timerID then
- ofs = ofs+1
- visual(deets,ofs)
- end
- end
- end
- end
- print("song not found")
- end
- if(#tArgs == 0) then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.green)
- term.write("Music Selection")
- term.setTextColor(colors.white)
- for line in lines do
- _, pos = term.getCursorPos()
- if (pos > sizeY-2) then
- os.pullEvent("key_up")
- end
- print()
- deets = {}
- i=0
- for sub in line:gmatch("%S+") do
- deets[i] = sub
- i=i+1
- end
- term.setTextColor(colors.yellow)
- term.write((deets[0]) .. " ")
- term.setTextColor(colors.orange)
- term.write((noUS(deets[1])))
- term.setTextColor(colors.blue)
- term.write(" -" .. (noUS(deets[2])))
- end
- os.pullEvent("key_up")
- print()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement