Advertisement
Microstar301

CC / TAPE PLAYER

Aug 4th, 2019 (edited)
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.23 KB | None | 0 0
  1. --
  2. -- CC TAPE PLAYER INTERFACE V1.2
  3. -- by Microstar301
  4. --
  5. -- made for CC Tweaked / Computercraft and Computronics
  6. --
  7. --
  8. term.clear()
  9. tape = peripheral.find("tape_drive")
  10. tape.setVolume(1)
  11. tape.setSpeed(1)
  12. --tape.seek(-tape.getSize())
  13. --tape.stop()
  14.  
  15. speed=1.0
  16. vol=100
  17. status="STOPPED"
  18. if tape.isReady()==true then
  19.     tapename=tape.getLabel()
  20.     if (string.match(tapename,"HQ")~=nil or string.match(tapename,"2x")~=nil) then
  21.         speed=2
  22.         tape.setSpeed(speed)
  23.     elseif (string.match(tapename,"LP")~=nil) then
  24.         speed=0.5
  25.         tape.setSpeed(speed)
  26.     end
  27. else
  28.     speed=1
  29.     tape.setSpeed(speed)
  30.     tapename="NO TAPE"
  31. end
  32. function inv()
  33.     term.setBackgroundColor(colors.white)
  34.     term.setTextColor(colors.black)
  35. end
  36. function norm()
  37.     term.setBackgroundColor(colors.black)
  38.     term.setTextColor(colors.white)
  39. end
  40.  
  41. function ts(xpos,ypos)
  42.     term.setCursorPos(tonumber(xpos),tonumber(ypos))
  43. end
  44.  
  45. function anim()
  46.     ax, ay = term.getSize()
  47.     while true do
  48.         term.setCursorPos(tonumber(ax)-1,tonumber(ay))
  49.         write("  ")
  50.         for t=1,1 do -- for break
  51.         if tape.getState()=="PLAYING" then
  52.             term.setCursorPos(tonumber(ax),tonumber(ay))
  53.             write("/")
  54.             sleep(0.2)
  55.             term.setCursorPos(tonumber(ax),tonumber(ay))
  56.             write("-")
  57.             sleep(0.2)
  58.             if tape.getState()~="PLAYING" then
  59.                 break
  60.             end
  61.             term.setCursorPos(tonumber(ax),tonumber(ay))
  62.             write("\\")
  63.             sleep(0.2)
  64.             term.setCursorPos(tonumber(ax),tonumber(ay))
  65.             write("|")
  66.             sleep(0.2)
  67.         elseif (tape.getState()=="STOPPED") then
  68.             term.setCursorPos(tonumber(ax),tonumber(ay))
  69.             write("#")
  70.             sleep(1)
  71.         elseif (tape.getState()=="REWINDING") then
  72.             term.setCursorPos(tonumber(ax)-1,tonumber(ay))
  73.             write("<<")
  74.             sleep(1)
  75.         elseif (tape.getState()=="FORWARDING") then
  76.             term.setCursorPos(tonumber(ax)-1,tonumber(ay))
  77.             write(">>")
  78.             sleep(1)
  79.         else
  80.             sleep(1)
  81.         end
  82.         end      
  83.     end
  84. end            
  85.  
  86. function screen()
  87.     term.setCursorPos(1,15)
  88.     term.clearLine()
  89.     term.setCursorPos(1,17)
  90.     term.clearLine()
  91.     term.setCursorPos(1,1)
  92.     print("-TAPE PLAYER CONTROL-")
  93.     print("")
  94.     print("W - vol+                H - HQ speed")
  95.     print("S - vol-                N - normal speed")
  96.     print("A - seek left           L - LP speed")
  97.     print("D - seek right")
  98.     print("R - instant rewind")
  99.     print("+ - speed up")
  100.     print("- - slow down")
  101.     print("SPACE - play/stop")
  102.     print("P - power")
  103.     print("")
  104.     print("")
  105.     print("Current Tape: ")
  106.     inv()
  107.     print(tapename)
  108.     norm()
  109.     print("")
  110.     write("VOL: ")
  111.     inv()
  112.     write(vol)
  113.     norm()
  114.     write("\tStatus: ")
  115.     inv()
  116.     write(status)
  117.     norm()
  118.     write("\tSpeed: ")
  119.     inv()
  120.     write(speed)
  121.     norm()
  122. end
  123. function keyinput()
  124.     while true do
  125.         e,k = os.pullEvent("char")
  126.         if (k=="w" or k=="W") then
  127.             if vol < 100 then
  128.                 vol=vol+10
  129.             else
  130.                 vol=100
  131.             end
  132.             tape.setVolume(vol/100)
  133.         elseif (k=="s" or k=="S") then
  134.             if vol > 0 then
  135.                 vol=vol-10
  136.             else
  137.                 vol=0
  138.             end
  139.             tape.setVolume(vol/100)
  140.         elseif (k=="+") then
  141.             if speed < 2 then
  142.                 speed=speed+0.1
  143.             else
  144.                 speed=2
  145.             end
  146.             tape.setSpeed(speed)
  147.         elseif (k=="-") then
  148.             if speed > 0.3 then
  149.                 speed=speed-0.1
  150.             else
  151.                 speed=0.3
  152.             end
  153.             tape.setSpeed(speed)
  154.         elseif (k=="a" or k=="A") then
  155.             tape.seek(-10000*speed)
  156.         elseif (k=="d" or k=="D") then
  157.             tape.seek(10000*speed)
  158.         elseif (k=="r" or k=="R") then
  159.             tape.stop()
  160.             tape.seek(-tape.getSize())
  161.         elseif (k==" ") then
  162.             if tape.getState()~="PLAYING" then
  163.                 if(string.match(tapename,"HQ")~=nil or string.match(tapename,"2x")~=nil) then
  164.                     speed=2
  165.                     tape.setSpeed(speed)
  166.                 elseif (string.match(tapename,"LP")~=nil) then
  167.                     speed=0.5
  168.                     tape.setSpeed(speed)
  169.                 end
  170.                 tape.play()
  171.             else
  172.                 tape.stop()
  173.             end
  174.         elseif (k=="p" or k=="P") then
  175.             tape.stop()
  176.             os.shutdown()
  177.         elseif (k=="h" or k=="H") then
  178.             speed=2
  179.             tape.setSpeed(speed)
  180.         elseif (k=="n" or k=="N") then
  181.             speed=1
  182.             tape.setSpeed(speed)
  183.         elseif (k=="l" or k=="L") then
  184.             speed=0.5
  185.             tape.setSpeed(speed)
  186.         else
  187.             sleep(0.1)
  188.         end
  189.         screen()
  190.         sleep(0.1)
  191.     end
  192. end
  193.    
  194. function update()
  195.     tostop=0
  196.     while true do
  197.         status=tape.getState()
  198.         if tape.isReady()==true then
  199.             tapename=tape.getLabel()
  200.         else
  201.             tapename="NO TAPE"
  202.             speed=1
  203.             tape.setSpeed(speed)
  204.         end
  205.         screen()
  206.         if tape.getState()=="PLAYING" or tape.getState()=="REWINDING" or tape.getState()=="FORWARDING" then
  207.             --TAPE COUNT
  208.             eqval=math.floor(tape.getPosition()/tape.getSize()*51)
  209.             term.setCursorPos(1,18)
  210.             term.clearLine()
  211.             inv()
  212.             for e=1,eqval do
  213.                write(" ")
  214.             end
  215.             norm()
  216.         if tape.read()==0 and tape.getState()=="PLAYING" then
  217.                 tostop=tostop+1
  218.             else
  219.                 tostop=0
  220.             end
  221.             if tostop>2 then
  222.                 tostop=0
  223.                 if tape.getState()=="PLAYING" then
  224.                     tape.stop()
  225.                 end
  226.             end
  227.         else
  228.             term.setCursorPos(1,18)
  229.             term.clearLine()
  230.         end
  231.         sleep(1)
  232.     end
  233. end
  234.  
  235. parallel.waitForAny(update,keyinput,anim)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement