Advertisement
TheRockettek

playSong

Apr 16th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. tArgs = {...}
  2. function px(x,y,c)
  3. paintutils.drawFilledBox(x,y,x,y,c)
  4. end
  5. speed = 1 -- Dont change this
  6. if not fs.exists(tArgs[1]) then error("Doesnt exist") end
  7. if peripheral.find("monitor") then term.redirect(peripheral.find("monitor")) end
  8. colour = {colours.blue,colours.orange,colours.cyan,colours.lightGrey,colours.green,colours.purple}
  9. title = tArgs[2] or tArgs[1]
  10. offsets = {0, -2, -1, -3, -4}
  11. size = {term.getSize()}
  12. nb = peripheral.find("Music") or peripheral.find("minecraft:noteblock") or peripheral.find("speaker")
  13. if not nb then
  14. if peripheral.find("neuralInterface") then
  15. if peripheral.find("neuralInterface").playNote then
  16. nb = peripheral.find("neuralInterface")
  17. end
  18. end
  19. end
  20. if ( not nb ) or ( not nb.playNote ) then error("Noteblock with playNote method required or neuralInterface with noteblock as module") end
  21. term.setCursorPos(1,size[2]/2)
  22. term.setTextColor(colours.cyan)
  23. term.setBackgroundColor(colours.black)
  24. term.clear()
  25. print(string.rep("-",size[1]))
  26. print()
  27. print(string.rep("-",size[1]))
  28. term.setCursorPos(2,(size[2]/2)+1)
  29. term.write(title)
  30. sleep(2)
  31. exec = true
  32. parallel.waitForAll(function()
  33. for line in io.lines(tArgs[1]) do
  34. --print(line)
  35. syntx = line:gmatch("([^|]*)")
  36. syntax = {}
  37. for l in syntx do
  38. table.insert(syntax,l)
  39. end
  40. if syntax[1] == "P" then
  41. arg1 = syntax[3] or 0
  42. arg2 = syntax[5] or 0
  43. px(tonumber(arg2) + offsets[tonumber(arg1)+1],size[2]-1,colour[tonumber(arg1)+1])
  44. term.setBackgroundColor(colours.black)
  45. --term.setBackgroundColour(colour[tonumber(arg1)+1])
  46. nb.playNote(tonumber(arg1),tonumber(arg2))
  47. elseif syntax[1] == "S" then
  48. arg1 = syntax[3] or 0
  49. sleep(tonumber(arg1)/speed)
  50. end
  51. end
  52. exec = false
  53. return
  54. end,
  55. function()
  56. while exec == true do
  57. os.sleep(0.1)
  58. term.scroll(1)
  59. end
  60. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement