9551

PlayH MUSIC PLAYER 1.0

Jul 18th, 2021 (edited)
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.18 KB | None | 0 0
  1. -------PlayH music player program by 9551 Dev-------
  2. -----------configuration------------
  3. local infoscreens = {
  4.     --example: ["top"] = true,
  5.     -----------["monitor_62"] = true,
  6. }
  7. local exclude_screens = {
  8.     --do not touch this unless you know what does this do and how to use it
  9. }
  10. local autostartPlay = false
  11. local defVol = 70
  12. local chesttype = "minecraft:chest" --the type of chest used by the system. useful setting for modded chests (system can max handle 27 slots)
  13. local updaterate = 1 --rate to update screen/click lower = smoother sytem but worse click detection high = good click detection but less smooth screen
  14. local readspeed = 5 --speed to read contets of chest (min 5) if this is below 5 system and timers are go break
  15. local breaktimerafterPlay = false --if this is true then playlist wont get updated while tape is inserted
  16. ------------------------------------
  17.  
  18. print("if you have multiple monitors dont forget to select info screens!")
  19. local arg = ...
  20. if not fs.exists("./musicdata") then
  21.     fs.makeDir("./musicdata")
  22. end
  23. if arg then
  24.     shell.run("rm ./musicdata/*")
  25.     return
  26. end
  27. if not fs.exists("button") then
  28.     shell.run("pastebin get LTDZZZEJ ./button") --API by 9551 Dev
  29. end
  30. if not fs.exists("bigfont") then
  31.     shell.run("pastebin get 3LfWxRWh ./bigfont") --API by Wojbie
  32. end
  33. -----vars-----
  34. local filter = function(name, wrap)
  35.     return not infoscreens[name]
  36. end
  37. if readspeed < 5 then
  38.     readspeed = 5
  39. end
  40. local shortspeed = 0.1
  41. local b = require("./button").monitor
  42. local bf = require("./bigfont")
  43. local periphs = peripheral.getNames()
  44. local m = peripheral.find("monitor", filter)
  45. local s = peripheral.find("tape_drive")
  46. local c = peripheral.find(chesttype)
  47. local start = false
  48. local maxname = "00000000000"
  49. ---periph check---
  50. if not m then
  51.     error("you are missing a monitor", 0)
  52. end
  53. if not s then
  54.     error("you are missing a tape drive", 0)
  55. end
  56. if not c then
  57.     error("you are missing a chest", 0)
  58. end
  59. local mname = peripheral.getName(m)
  60. ---periph check*---
  61.  
  62. -----vars*-----
  63. m.setBackgroundColor(colors.black)
  64. m.clear()
  65. m.setTextColor(colors.white)
  66. m.setTextScale(0.5)
  67. b.frame(mname, 5, 17, 71, 10, "white", "blue")
  68. m.setBackgroundColor(colors.blue)
  69. bf.writeOn(m, 2, "PlayH", nil, 10)
  70. m.setTextColor(colors.black)
  71. bf.writeOn(m, 1, "Music player program", 10, 19)
  72. bf.writeOn(m, 1, "by 9551 DEV", nil, 22)
  73. bf.writeOn(m, 1, "loading", 1, 2)
  74. ----------base functions----------
  75. local funcs = {}
  76. local function setup()
  77.     m.setCursorPos(1, 37)
  78.     m.write(string.rep("\140", 100))
  79.     m.setCursorPos(1, 38)
  80.     m.write("\169" .. " PlayH | copyright 2021/2022   9551 DEV")
  81.     b.frame(mname, 3, 19, 75, 17, "white", "black")
  82.     b.frame(mname, 6, 20, 20, 15, "white", "blue")
  83.     b.frame(mname, 30, 20, 45, 15, "white", "blue")
  84.     m.setCursorPos(6, 6)
  85.     m.blit("play list", "fffffffff", "000000000")
  86.     m.setBackgroundColor(colors.blue)
  87.     b.frame(mname, 32, 13, 41, 2, "black", "blue")
  88.     m.setCursorPos(32, 11)
  89.     m.blit("VOLUME", "000000", "ffffff")
  90.     m.setBackgroundColor(colors.black)
  91. end
  92. local function basemain()
  93.     m.clear()
  94.     setup()
  95.     if click then
  96.         if b.switch(mname, 1, click, 7, 4, "red", "green", "white", "loop song") then
  97.             if s.isEnd() then
  98.                 s.seek(-s.getSize())
  99.             end
  100.         end
  101.         if b.switch(mname, 2, click, 17, 4, "red", "green", "white", "shuffle") then
  102.             if s.isEnd() then
  103.                 s.seek(-s.getSize())
  104.                 moveOut()
  105.                 moveIn(1)
  106.                 s.seek(-s.getSize())
  107.                 b.sliderHor("setdb",2,32)
  108.                 sortchest(c)
  109.             end
  110.             moveIn(1)
  111.         end
  112.         b.switch(mname, 3, click, 68, 8, "red", "green", "white", "PLAY")
  113.         if b.switch("db", 3) then
  114.             b.switch("setdb", 3, s.play())
  115.         else
  116.             s.stop()
  117.         end
  118.         if b.switch("db", 1) and b.switch("db", 2) then
  119.             b.switch("setdb", 2, false)
  120.         end
  121.         b.frame(mname, 6, 20, 20, 15, "white", "blue")
  122.         m.setCursorPos(6, 6)
  123.         m.blit("play list", "fffffffff", "000000000")
  124.         m.setBackgroundColor(colors.green)
  125.         m.setTextColor(colors.black)
  126.         for k, v in pairs(objects) do
  127.             if b.button(mname, click, 7, 7 + k, v) then
  128.                 actions(v, k)
  129.             end
  130.         end
  131.         m.setTextColor(colors.white)
  132.         m.setBackgroundColor(colors.orange)
  133.         if b.button(mname, click, 63, 7, "EJECT TAPE") then
  134.             s.seek(-s.getSize())
  135.             moveOut()
  136.             short = os.startTimer(shortspeed)
  137.             long = os.startTimer(readspeed)
  138.         end
  139.         m.setBackgroundColor(colors.black)
  140.         if b.button(mname, click, 67, 38, "reset timers") then
  141.             short = os.startTimer(shortspeed)
  142.             long = os.startTimer(readspeed)
  143.         end
  144.         b.sliderHor(mname, click, 1, 33, 13, 38, "blue", "white")
  145.     end
  146.     m.setCursorPos(50, 38)
  147.     m.write("clocks:" .. timers1 .. "|" .. timers2)
  148.     local label = s.getLabel()
  149.     m.setCursorPos(33, 8)
  150.     m.setBackgroundColor(colors.blue)
  151.     m.setTextColor(colors.black)
  152.     if label ~= nil then
  153.         if label ~= "" then
  154.             bf.writeOn(m, 1, label, 30, 7)
  155.         else
  156.             bf.writeOn(m, 1, "UnTitled", 30, 7)
  157.         end
  158.         local maxpos = s.getSize()
  159.         local curpos = s.getPosition()
  160.         local timemax = math.floor(maxpos / 6000)
  161.         local curtime = math.floor(curpos / 6000)
  162.         b.bar(mname, 32, 27, 41, 6, curtime + 1, timemax, "gray", "cyan", "black", false, false, "", false, true, false)
  163.         local curfstr = ("%02d:%02d"):format(curtime / 60, curtime % 60)
  164.         local maxfstr = ("%02d:%02d"):format(timemax / 60, timemax % 60)
  165.         m.setCursorPos(32, 22)
  166.         m.blit(
  167.             curfstr .. " / " .. maxfstr,
  168.             string.rep("0", #curfstr + #maxfstr + 3),
  169.             string.rep("f", #curfstr + #maxfstr + 3)
  170.         )
  171.         local oc = m.getBackgroundColor()
  172.         m.setBackgroundColor(colors.blue)
  173.         b.frame(mname, 32, 18, 41, 2, "black", "blue")
  174.         m.setCursorPos(32, 16)
  175.         m.blit("TIMELINE", "00000000", "ffffffff")
  176.         if click then
  177.             b.sliderHor(mname, click, 2, 33, 18, 38, "blue", "white")
  178.             b.switch(mname, 4, click, 68, 17, "red", "green", "white", "SAVE")
  179.         end
  180.         local TIMELINE = b.sliderHor("db", 2)
  181.         if not b.switch("db", 4) then
  182.             b.sliderHor("setdb", 2, math.floor(curtime / timemax * 38) + 32)
  183.             short = os.startTimer(shortspeed)
  184.             long = os.startTimer(readspeed)
  185.         else
  186.             s.seek(-s.getSize())
  187.             local time = (b.sliderHor("db", 2) - 32) / 38 * timemax
  188.             s.seek(time * 6000)
  189.             short = os.startTimer(shortspeed)
  190.             long = os.startTimer(readspeed)
  191.         end
  192.         m.setBackgroundColor(oc)
  193.     else
  194.         m.setCursorPos(33, 8)
  195.         m.write("waiting for tape....")
  196.     end
  197.     m.setTextColor(colors.white)
  198.     m.setCursorPos(30, 10)
  199.     m.write(string.rep("\131", 44))
  200.     m.setBackgroundColor(colors.black)
  201.     local vol = b.sliderHor("db", 1)
  202.     if vol == nil then
  203.         vol = 0
  204.     end
  205.     if vol > 0 then
  206.         vol = vol - 32
  207.     end
  208.     s.setVolume(0.0263157894736842 * vol)
  209.     for mname, bool in pairs(infoscreens) do
  210.         if not exclude_screens[mname] then
  211.             local m = peripheral.wrap(mname)
  212.             m.setBackgroundColor(colors.blue)
  213.             m.clear()
  214.             m.setTextScale(0.5)
  215.             m.setCursorPos(1, 2)
  216.             m.write(string.rep("\131", 15), m.getSize())
  217.             m.setCursorPos(1, 1)
  218.             m.setBackgroundColor(colors.blue)
  219.             local label = s.getLabel()
  220.             if label == "" then
  221.                 label = "UnTitled"
  222.             end
  223.             m.write(label or "no tape....")
  224.             m.setCursorPos(1, 3)
  225.             m.write("state: " .. s.getState())
  226.             m.setCursorPos(1, 4)
  227.             m.write("volume: " .. math.floor((vol / 38) * 100) .. "%")
  228.             local maxpos = s.getSize()
  229.             local curpos = s.getPosition()
  230.             local timemax = math.floor(maxpos / 6000)
  231.             local curtime = math.floor(curpos / 6000)
  232.             local curfstr = ("%01d:%02d"):format(curtime / 60, curtime % 60)
  233.             local maxfstr = ("%01d:%02d"):format(timemax / 60, timemax % 60)
  234.             if label then
  235.                 b.bar(
  236.                     mname,
  237.                     3,
  238.                     8,
  239.                     12,
  240.                     2.5,
  241.                     curtime + 1,
  242.                     timemax,
  243.                     "gray",
  244.                     "cyan",
  245.                     "black",
  246.                     false,
  247.                     false,
  248.                     "",
  249.                     false,
  250.                     true,
  251.                     true
  252.                 )
  253.                 m.setCursorPos(3, 5)
  254.                 m.blit(
  255.                     curfstr .. "/" .. maxfstr,
  256.                     string.rep("0", #curfstr + #maxfstr + 1),
  257.                     string.rep("f", #curfstr + #maxfstr + 1)
  258.                 )
  259.             end
  260.         end
  261.     end
  262. end
  263. local function loadbar(ins, max)
  264.     m.setBackgroundColor(colors.blue)
  265.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  266.     b.bar(mname, 5, 22, 71, 13, ins, max, "gray", "cyan", "white", false, false, "", false, true, false)
  267. end
  268. function actions(disk, position)
  269.     m.setBackgroundColor(colors.black)
  270.     m.setTextColor(colors.white)
  271.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  272.     m.setCursorPos(20, 10)
  273.     m.setBackgroundColor(colors.green)
  274.     m.write("what action do you want to perform with")
  275.     m.setBackgroundColor(colors.lightBlue)
  276.     bf.writeOn(m, 1, disk, nil, 12)
  277.     while true do
  278.         local click = b.timetouch(1, mname)
  279.         m.setBackgroundColor(colors.red)
  280.         if b.button(mname, click, 26, 18, "EXIT") then
  281.             setup()
  282.             break
  283.         end
  284.         m.setBackgroundColor(colors.orange)
  285.         if b.button(mname, click, 34, 17, "WIPE TAPE") then
  286.             cleartape(disk, position)
  287.             setup()
  288.             break
  289.         end
  290.         m.setBackgroundColor(colors.orange)
  291.         if b.button(mname, click, 32, 18, "DOWNLOAD SONG") then
  292.             downloadtape(disk, position)
  293.             setup()
  294.             short = os.startTimer(shortspeed)
  295.             long = os.startTimer(readspeed)
  296.             break
  297.         end
  298.         m.setBackgroundColor(colors.green)
  299.         if b.button(mname, click, 49, 17, "PLAY") then
  300.             playtape(disk, position)
  301.             setup()
  302.             break
  303.         end
  304.         m.setBackgroundColor(colors.green)
  305.         if b.button(mname, click, 47, 18, "NAME TAPE") then
  306.             setTape(disk, position)
  307.             setup()
  308.             break
  309.         end
  310.         m.setBackgroundColor(colors.orange)
  311.         if b.button(mname, click, 34, 19, "LOAD FILE") then
  312.             loadtape(disk, position)
  313.             setup()
  314.             break
  315.         end
  316.     end
  317.     short = os.startTimer(shortspeed)
  318.     long = os.startTimer(readspeed)
  319. end
  320. actionlist = {}
  321. function moveIn(num)
  322.     s.pullItems(peripheral.getName(c), num, 64, 1)
  323. end
  324. function moveOut()
  325.     s.pushItems(peripheral.getName(c), 1, 64)
  326. end
  327. function cleartape(disk, position)
  328.     moveOut()
  329.     moveIn(position)
  330.     local tsize = s.getSize()
  331.     local counter1 = 0
  332.     local counter2 = 0
  333.     s.stop()
  334.     s.seek(-tsize)
  335.     s.stop()
  336.     s.seek(-90000)
  337.     local str = string.rep("\xAA", 8192)
  338.     for i = 1, tsize + 8191, 8192 do
  339.         s.write(str)
  340.         counter1 = counter1 + 1
  341.         counter2 = counter2 + 1
  342.         if counter1 > 10 then
  343.             counter1 = 0
  344.             b.frame(mname, 1000, 1000, 100, 20, "white", "blue") --*this is here to slow it down so monitor doesnt glitch
  345.         end
  346.         if counter2 > 300 then
  347.             counter2 = 0
  348.             loadbar(i, tsize)
  349.         end
  350.         local per = tsize / 100
  351.         local percent = math.floor(i / per)
  352.         bf.writeOn(
  353.             m,
  354.             1,
  355.             math.floor(i / 1024) .. "Kb/" .. math.floor(tsize / 1024) .. "Kb" .. " " .. percent .. "%",
  356.             5,
  357.             6
  358.         )
  359.     end
  360.     s.seek(-tsize)
  361.     s.seek(-90000)
  362.     moveOut()
  363. end
  364.  
  365. function downloadtape(disk, position)
  366.     moveOut()
  367.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  368.     bf.writeOn(m, 1, "continue in terminal")
  369.     term.clear()
  370.     term.setCursorPos(1, 1)
  371.     print("please enter direct download link to your dfpwm file.")
  372.     local ins = read()
  373.     print("please enter how you wanna name the file")
  374.     local name = read()
  375.     local rand = math.random(1, 999)
  376.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  377.     bf.writeOn(m, 1, "downloading from web")
  378.     local web, err = http.get(ins, nil, true)
  379.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  380.     bf.writeOn(m, 1, "DONE")
  381.     if not err then
  382.         local webdata = web.readAll()
  383.         local path = "./musicdata/" .. name .. "_" .. tostring(rand) .. ".dfpwm"
  384.         local file = fs.open(path, "wb")
  385.         moveIn(position)
  386.         --------------------------
  387.         local tsize = s.getSize()
  388.         local counter1 = 0
  389.         local counter2 = 0
  390.         s.stop()
  391.         s.seek(-tsize)
  392.         s.stop()
  393.         s.seek(-90000)
  394.         local str = string.rep("\xAA", 8192)
  395.         for i = 1, tsize + 8191, 8192 do
  396.             s.write(str)
  397.             counter1 = counter1 + 1
  398.             counter2 = counter2 + 1
  399.             if counter1 > 10 then
  400.                 counter1 = 0
  401.                 b.frame(mname, 1000, 1000, 100, 20, "white", "blue") --*this is here to slow it down so monitor doesnt glitch
  402.             end
  403.             if counter2 > 300 then
  404.                 counter2 = 0
  405.                 loadbar(i, tsize)
  406.             end
  407.             local per = tsize / 100
  408.             local percent = math.floor(i / per)
  409.             bf.writeOn(
  410.                 m,
  411.                 1,
  412.                 math.floor(i / 1024) .. "Kb/" .. math.floor(tsize / 1024) .. "Kb" .. " " .. percent .. "%",
  413.                 5,
  414.                 6
  415.             )
  416.         end
  417.         s.seek(-tsize)
  418.         s.seek(-90000)
  419.         --------------------------
  420.         file.write(webdata)
  421.         file.flush()
  422.         file.close()
  423.         file = fs.open(path, "rb")
  424.         local block = 8192
  425.         s.stop()
  426.         s.seek(-s.getSize())
  427.         s.stop()
  428.         local bytery = 0
  429.         local filesize = fs.getSize(path)
  430.         if filesize > s.getSize() then
  431.             filesize = s.getSize()
  432.         end
  433.         repeat
  434.             local bytes = {}
  435.             for i = 1, block do
  436.                 local byte = file.read()
  437.                 if not byte then
  438.                     break
  439.                 end
  440.                 bytes[#bytes + 1] = byte
  441.             end
  442.             if #bytes > 0 then
  443.                 bytery = bytery + #bytes
  444.                 loadbar(math.min(bytery, filesize), filesize)
  445.                 bf.writeOn(
  446.                     m,
  447.                     1,
  448.                     math.floor(math.min(bytery, filesize) / 1024) .. "Kb/" .. math.floor(filesize / 1024) .. "Kb",
  449.                     5,
  450.                     6
  451.                 )
  452.                 for i = 1, #bytes do
  453.                     s.write(bytes[i])
  454.                 end
  455.                 sleep(0)
  456.             end
  457.         until not bytes or #bytes <= 0 or bytery > filesize
  458.         file.close()
  459.         s.stop()
  460.         s.seek(-s.getSize())
  461.         s.stop()
  462.         if disk == "UnTitled" then
  463.             s.setLabel(name)
  464.         end
  465.         moveOut()
  466.     else
  467.         print("not able to get file. reason:\n" .. err)
  468.     end
  469. end
  470.  
  471. function playtape(disk, position)
  472.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  473.     if s.isReady() then
  474.         s.seek(-s.getSize())
  475.     end
  476.     moveOut()
  477.     moveIn(position)
  478.     sortchest(c)
  479. end
  480.  
  481. function setTape(disk, position)
  482.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  483.     bf.writeOn(m, 1, "continue in terminal")
  484.     moveOut()
  485.     moveIn(position)
  486.     term.clear()
  487.     term.setCursorPos(1, 1)
  488.     local ins = "placeHolderInHereIsPlaceholder!"
  489.     print("Enter name to asign to tape: " .. disk)
  490.     while #ins > #maxname do
  491.         ins = read()
  492.         if #ins > #maxname then
  493.             print("too long (max " .. #maxname .. " chars)")
  494.             sleep(2)
  495.             term.clear()
  496.             term.setCursorPos(1, 1)
  497.         end
  498.     end
  499.     s.setLabel(ins)
  500.     moveOut()
  501.     term.clear()
  502.     term.setCursorPos(1, 1)
  503. end
  504.  
  505. function loadtape(disk, position)
  506.     moveOut()
  507.     b.frame(mname, 3, 19, 75, 17, "white", "blue")
  508.     bf.writeOn(m, 1, "continue in terminal")
  509.     term.clear()
  510.     term.setCursorPos(1, 1)
  511.     shell.run("dir ./musicdata/")
  512.     print("\nplease enter what file you want to flash onto the tape")
  513.     local ins = read()
  514.     if fs.exists("./musicdata/" .. ins) then
  515.         print("please enter how you wanna name the tape (if unnamed)")
  516.         local name = read()
  517.         local rand = math.random(1, 1000)
  518.  
  519.         --
  520.         moveIn(position)
  521.         --------------------------
  522.         local tsize = s.getSize()
  523.         local counter1 = 0
  524.         local counter2 = 0
  525.         s.stop()
  526.         s.seek(-tsize)
  527.         s.stop()
  528.         s.seek(-90000)
  529.         local str = string.rep("\xAA", 8192)
  530.         for i = 1, tsize + 8191, 8192 do
  531.             s.write(str)
  532.             counter1 = counter1 + 1
  533.             counter2 = counter2 + 1
  534.             if counter1 > 10 then
  535.                 counter1 = 0
  536.                 b.frame(mname, 1000, 1000, 100, 20, "white", "blue") --*this is here to slow it down so monitor doesnt glitch
  537.             end
  538.             if counter2 > 300 then
  539.                 counter2 = 0
  540.                 loadbar(i, tsize)
  541.             end
  542.             local per = tsize / 100
  543.             local percent = math.floor(i / per)
  544.             bf.writeOn(
  545.                 m,
  546.                 1,
  547.                 math.floor(i / 1024) .. "Kb/" .. math.floor(tsize / 1024) .. "Kb" .. " " .. percent .. "%",
  548.                 5,
  549.                 6
  550.             )
  551.         end
  552.         s.seek(-tsize)
  553.         s.seek(-90000)
  554.         --------------------------
  555.         local file = fs.open("./musicdata/" .. ins, "rb")
  556.         file = fs.open("./musicdata/" .. ins, "rb")
  557.         local block = 8192
  558.         s.stop()
  559.         s.seek(-s.getSize())
  560.         s.stop()
  561.         local bytery = 0
  562.         local filesize = fs.getSize("./musicdata/" .. ins)
  563.         if filesize > s.getSize() then
  564.             filesize = s.getSize()
  565.         end
  566.         repeat
  567.             local bytes = {}
  568.             for i = 1, block do
  569.                 local byte = file.read()
  570.                 if not byte then
  571.                     break
  572.                 end
  573.                 bytes[#bytes + 1] = byte
  574.             end
  575.             if #bytes > 0 then
  576.                 bytery = bytery + #bytes
  577.                 loadbar(math.min(bytery, filesize), filesize)
  578.                 bf.writeOn(
  579.                     m,
  580.                     1,
  581.                     math.floor(math.min(bytery, filesize) / 1024) .. "Kb/" .. math.floor(filesize / 1024) .. "Kb",
  582.                     5,
  583.                     6
  584.                 )
  585.                 for i = 1, #bytes do
  586.                     s.write(bytes[i])
  587.                 end
  588.                 sleep(0)
  589.             end
  590.         until not bytes or #bytes <= 0 or bytery > filesize
  591.         file.close()
  592.         s.stop()
  593.         s.seek(-s.getSize())
  594.         s.stop()
  595.         if disk == "UnTitled" then
  596.             s.setLabel(name)
  597.         end
  598.     else
  599.         print("no such file")
  600.     end
  601.     moveOut()
  602. end
  603.  
  604. local function updateplaylist()
  605.     funcs = {}
  606.     objects = {}
  607.     local list = c.list()
  608.     for i = 1, c.size() do
  609.         if list[i] then
  610.             funcs[i] = function()
  611.                 local meta = c.getItemMeta(i)
  612.                 if meta then
  613.                     objects[i] = meta.media.label
  614.                     if objects[i] == "" then
  615.                         objects[i] = "UnTitled"
  616.                     end
  617.                 end
  618.             end
  619.         else
  620.             break
  621.         end
  622.     end
  623.     if #funcs > 0 then
  624.         parallel.waitForAll(table.unpack(funcs))
  625.     end
  626. end
  627. local function empty_end_slots(c)
  628.     local list = c.list()
  629.     local csize = c.size()
  630.     local count = 0
  631.     for i = 0, csize - 1 do
  632.         local num = csize - i
  633.         if not list[num] then
  634.             count = count + 1
  635.         end
  636.     end
  637.     return count
  638. end
  639. function sortchest(c)
  640.     sorting_stage = 0
  641.     local list = c.list()
  642.     if next(list) then
  643.         for i = 1, c.size() - empty_end_slots(c) do
  644.             sorting_stage = sorting_stage + 1
  645.             while not list[i] do
  646.                 for j = i + 1, 27 do
  647.                     c.pullItems(peripheral.getName(c), j, 64, j - 1)
  648.                 end
  649.                 list = c.list()
  650.             end
  651.             bf.writeOn(m, 1, "sorting: " .. i .. "/" .. c.size() - empty_end_slots(c), 5, 6)
  652.             loadbar(i, c.size() - empty_end_slots(c))
  653.         end
  654.     end
  655. end
  656. local firsst = true
  657. local function getClick()
  658.     click = b.timetouch(updaterate, mname)
  659.     if firsst then
  660.         firsst = false
  661.         b.switch(mname, 3, click, 68, 8, "red", "green", "white", "PLAY")
  662.         b.switch(mname, 2, click, 17, 4, "red", "green", "white", "shuffle")
  663.         b.sliderHor(mname, click, 1, 33, 13, 38, "blue", "white")
  664.         if autostartPlay then b.switch("setdb",3,true) end
  665.         if autostartPlay then b.switch("setdb",2,true) end
  666.         if autostartPlay then b.sliderHor("setdb",1,defVol) end
  667.     end
  668. end
  669.  
  670. local function checkforevent()
  671.     _, event = os.pullEvent("timer")
  672. end
  673. timers1 = 0
  674. timers2 = 0
  675. counts = 0
  676. local function timers()
  677.     if event == long then
  678.         updateplaylist()
  679.         timers1 = timers1 + 1
  680.         if not start then
  681.             start = not start
  682.             m.setTextColor(colors.white)
  683.             m.setBackgroundColor(colors.black)
  684.             m.clear()
  685.             setup()
  686.         end
  687.         long = os.startTimer(readspeed)
  688.         short = os.startTimer(shortspeed)
  689.     elseif event == short then
  690.         if not breaktimerafterPlay then
  691.             counts = counts + 1
  692.             if counts > readspeed then
  693.                 counts = 0
  694.                 updateplaylist()
  695.             end
  696.         end
  697.         parallel.waitForAll(basemain, getClick)
  698.         timers2 = timers2 + 1
  699.         short = os.startTimer(shortspeed)
  700.     end
  701. end
  702. ----------base functions*----------
  703. local function main()
  704.     short = os.startTimer(.1)
  705.     long = os.startTimer(2)
  706.     updateplaylist()
  707.     while true do
  708.         parallel.waitForAll(checkforevent, timers)
  709.     end
  710. end
  711.  
  712. local ok, err = pcall(main)
  713. if not ok then
  714.     local names = peripheral.getNames()
  715.     for i = 1, #names do
  716.         if peripheral.getType(names[i]) == "monitor" then
  717.             if not exclude_screens[peripheral.getType(names[i])] then
  718.                 peripheral.call(names[i], "setBackgroundColor", colors.black)
  719.                 peripheral.call(names[i], "setTextColor", colors.white)
  720.                 peripheral.call(names[i], "clear")
  721.             end
  722.         end
  723.     end
  724.     moveOut()
  725.     print("playH crashed reason:\n" .. err)
  726. end
  727.  
Add Comment
Please, Sign In to add comment