Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- CC TAPE PLAYER INTERFACE V1.2
- -- by Microstar301
- --
- -- made for CC Tweaked / Computercraft and Computronics
- --
- --
- term.clear()
- tape = peripheral.find("tape_drive")
- tape.setVolume(1)
- tape.setSpeed(1)
- --tape.seek(-tape.getSize())
- --tape.stop()
- speed=1.0
- vol=100
- status="STOPPED"
- if tape.isReady()==true then
- tapename=tape.getLabel()
- if (string.match(tapename,"HQ")~=nil or string.match(tapename,"2x")~=nil) then
- speed=2
- tape.setSpeed(speed)
- elseif (string.match(tapename,"LP")~=nil) then
- speed=0.5
- tape.setSpeed(speed)
- end
- else
- speed=1
- tape.setSpeed(speed)
- tapename="NO TAPE"
- end
- function inv()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- end
- function norm()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function ts(xpos,ypos)
- term.setCursorPos(tonumber(xpos),tonumber(ypos))
- end
- function anim()
- ax, ay = term.getSize()
- while true do
- term.setCursorPos(tonumber(ax)-1,tonumber(ay))
- write(" ")
- for t=1,1 do -- for break
- if tape.getState()=="PLAYING" then
- term.setCursorPos(tonumber(ax),tonumber(ay))
- write("/")
- sleep(0.2)
- term.setCursorPos(tonumber(ax),tonumber(ay))
- write("-")
- sleep(0.2)
- if tape.getState()~="PLAYING" then
- break
- end
- term.setCursorPos(tonumber(ax),tonumber(ay))
- write("\\")
- sleep(0.2)
- term.setCursorPos(tonumber(ax),tonumber(ay))
- write("|")
- sleep(0.2)
- elseif (tape.getState()=="STOPPED") then
- term.setCursorPos(tonumber(ax),tonumber(ay))
- write("#")
- sleep(1)
- elseif (tape.getState()=="REWINDING") then
- term.setCursorPos(tonumber(ax)-1,tonumber(ay))
- write("<<")
- sleep(1)
- elseif (tape.getState()=="FORWARDING") then
- term.setCursorPos(tonumber(ax)-1,tonumber(ay))
- write(">>")
- sleep(1)
- else
- sleep(1)
- end
- end
- end
- end
- function screen()
- term.setCursorPos(1,15)
- term.clearLine()
- term.setCursorPos(1,17)
- term.clearLine()
- term.setCursorPos(1,1)
- print("-TAPE PLAYER CONTROL-")
- print("")
- print("W - vol+ H - HQ speed")
- print("S - vol- N - normal speed")
- print("A - seek left L - LP speed")
- print("D - seek right")
- print("R - instant rewind")
- print("+ - speed up")
- print("- - slow down")
- print("SPACE - play/stop")
- print("P - power")
- print("")
- print("")
- print("Current Tape: ")
- inv()
- print(tapename)
- norm()
- print("")
- write("VOL: ")
- inv()
- write(vol)
- norm()
- write("\tStatus: ")
- inv()
- write(status)
- norm()
- write("\tSpeed: ")
- inv()
- write(speed)
- norm()
- end
- function keyinput()
- while true do
- e,k = os.pullEvent("char")
- if (k=="w" or k=="W") then
- if vol < 100 then
- vol=vol+10
- else
- vol=100
- end
- tape.setVolume(vol/100)
- elseif (k=="s" or k=="S") then
- if vol > 0 then
- vol=vol-10
- else
- vol=0
- end
- tape.setVolume(vol/100)
- elseif (k=="+") then
- if speed < 2 then
- speed=speed+0.1
- else
- speed=2
- end
- tape.setSpeed(speed)
- elseif (k=="-") then
- if speed > 0.3 then
- speed=speed-0.1
- else
- speed=0.3
- end
- tape.setSpeed(speed)
- elseif (k=="a" or k=="A") then
- tape.seek(-10000*speed)
- elseif (k=="d" or k=="D") then
- tape.seek(10000*speed)
- elseif (k=="r" or k=="R") then
- tape.stop()
- tape.seek(-tape.getSize())
- elseif (k==" ") then
- if tape.getState()~="PLAYING" then
- if(string.match(tapename,"HQ")~=nil or string.match(tapename,"2x")~=nil) then
- speed=2
- tape.setSpeed(speed)
- elseif (string.match(tapename,"LP")~=nil) then
- speed=0.5
- tape.setSpeed(speed)
- end
- tape.play()
- else
- tape.stop()
- end
- elseif (k=="p" or k=="P") then
- tape.stop()
- os.shutdown()
- elseif (k=="h" or k=="H") then
- speed=2
- tape.setSpeed(speed)
- elseif (k=="n" or k=="N") then
- speed=1
- tape.setSpeed(speed)
- elseif (k=="l" or k=="L") then
- speed=0.5
- tape.setSpeed(speed)
- else
- sleep(0.1)
- end
- screen()
- sleep(0.1)
- end
- end
- function update()
- tostop=0
- while true do
- status=tape.getState()
- if tape.isReady()==true then
- tapename=tape.getLabel()
- else
- tapename="NO TAPE"
- speed=1
- tape.setSpeed(speed)
- end
- screen()
- if tape.getState()=="PLAYING" or tape.getState()=="REWINDING" or tape.getState()=="FORWARDING" then
- --TAPE COUNT
- eqval=math.floor(tape.getPosition()/tape.getSize()*51)
- term.setCursorPos(1,18)
- term.clearLine()
- inv()
- for e=1,eqval do
- write(" ")
- end
- norm()
- if tape.read()==0 and tape.getState()=="PLAYING" then
- tostop=tostop+1
- else
- tostop=0
- end
- if tostop>2 then
- tostop=0
- if tape.getState()=="PLAYING" then
- tape.stop()
- end
- end
- else
- term.setCursorPos(1,18)
- term.clearLine()
- end
- sleep(1)
- end
- end
- parallel.waitForAny(update,keyinput,anim)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement