Quipex

Player

Apr 29th, 2012
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. --------------------------
  2. -- Minecraft Music Player with BuildCraft
  3. -- By: Negeator, 2012
  4. --------------------------
  5. -- When set up correcty, this program can automatically play and switch music discs without the player touching the disk drive.
  6. --------------------------
  7. --Variables--
  8. --DO NOT MODIFY THESE--
  9. local side, title, time
  10. local state = "none" --What the media player is currently doing
  11. local stateView = "" --What to display
  12. local quit = false --Whether to exit the program or not
  13. local timing = false --Whether the program is timing (Autoplay0
  14. local currTime = 0 --Current Time
  15. local visual = 0 --Visualization state variable
  16. --MODIFY THESE IF YOU WANT--
  17. local timeAmount = 300 --How long (in seconds) until we switch disks for Autoplay
  18. --Check for a disk in
  19. function checkSide()
  20. if disk.isPresent("top") == true and disk.hasAudio("top") == true then
  21. side = "top"
  22. elseif disk.isPresent("bottom") == true and disk.hasAudio("bottom") == true then
  23. side = "bottom"
  24. elseif disk.isPresent("left") == true and disk.hasAudio("left") == true then
  25. side = "left"
  26. elseif disk.isPresent("right") == true and disk.hasAudio("right") == true then
  27. side = "right"
  28. elseif disk.isPresent("front") == true and disk.hasAudio("front") == true then
  29. side = "front"
  30. elseif disk.isPresent("back") == true and disk.hasAudio("back") == true then
  31. side = "back"
  32. else
  33. side = "No Disc Found"
  34. end
  35. end
  36. --Clears the Screen
  37. function clear()
  38. term.clear()
  39. term.setCursorPos(1,1)
  40. end
  41. --Display
  42. function printInfo()
  43. term.write("Minecraft Music Player")
  44. term.setCursorPos(1,2)
  45. term.write(stateView)
  46. term.setCursorPos(1,3)
  47. term.write("Side: " .. side)
  48. if side ~= "No Disc Found" and state ~= "play" then
  49. if disk.hasAudio(side) then
  50. term.setCursorPos(1,4)
  51. term.write("Disk Inserted: "..disk.getAudioTitle(side))
  52. end
  53. end
  54. term.setCursorPos(1,5)
  55. if timing == true then
  56. term.write("Autoplay Turned ON "..timeAmount - currTime.." Seconds Remaining.")
  57. else
  58. term.write("Autoplay Turned OFF")
  59. end
  60. term.setCursorPos(1,6)
  61. term.write("-------------------------------------------------")
  62. term.setCursorPos(1,7)
  63. term.write("1 - Play | 2 - Stop | 3 - Switch Disk")
  64. term.setCursorPos(1,8)
  65. term.write("4 - Autoplay | 0 - Quit ")
  66. term.setCursorPos(1,9)
  67. term.write("-------------------------------------------------")
  68. term.setCursorPos(1,10)
  69. end
  70. --Does stuff based on the state variable
  71. function musicControl()
  72. --Play the disk automatically if in Autoplay mode
  73. if timing == true and state ~= "stop" then
  74. if state ~= "play" then
  75. state = "play"
  76. end
  77. end
  78.  
  79. if state == "play" then
  80. if side ~= "No Disc Found" then
  81. if stateView ~= "<Playing>" then
  82. disk.playAudio(side)
  83. stateView = "<Playing>"
  84. end
  85. end
  86. elseif state == "stop" then
  87. if side ~= "No Disc Found" then
  88. timing = false
  89. disk.stopAudio(side)
  90. stateView = "<Stopped>"
  91. end
  92. end
  93.  
  94. --If no disc is present, change the display
  95. if side == "No Disc Found" then
  96. stateView = "<INSERT DISC>"
  97. end
  98.  
  99. --Make sure it displays as stopped when a new disc is just inserted
  100. if stateView == "<INSERT DISC" and side ~= "No Disc Found" then
  101. stateView = "<Stopped>"
  102. end
  103. state = ""
  104.  
  105. end
  106. --Switch Disks
  107. function cycleDisk()
  108. clear()
  109. term.write("Switching Disk")
  110. rs.setOutput("bottom",true)
  111. sleep(1)
  112. rs.setOutput("bottom",false)
  113. if timing == true then
  114. os.startTimer(9) --Wait for new Disc
  115. currTime = 0
  116. end
  117. end
  118. --Updates the timer
  119. function updateTimer()
  120. if timing == true then
  121. currTime = currTime + 1
  122. if currTime >= timeAmount then
  123. currTime = 0
  124. cycleDisk()
  125. os.startTimer(9) --Wait for new Disc
  126. else
  127. os.startTimer(1)
  128. end
  129. end
  130. end
  131. --Main Function
  132. function main()
  133. while quit == false do
  134. clear()
  135. checkSide()
  136. musicControl()
  137. printInfo()
  138. event, p1, p2 = os.pullEvent()
  139. if event == "key" then
  140. if p1 == 2 then
  141. state = "play"
  142. elseif p1 == 3 then
  143. state = "stop"
  144. elseif p1 == 4 then
  145. cycleDisk()
  146. elseif p1 == 5 then
  147. if timing == true then
  148. timing = false
  149. else
  150. timing = true
  151. currTime = 0
  152. os.startTimer(1)
  153. end
  154. sleep(.25)
  155. elseif p1 == 11 then
  156. clear()
  157. quit = true
  158. end
  159. elseif event == "timer" then
  160. updateTimer()
  161. end
  162.  
  163. end
  164. end
  165. --START PROGRAM--
  166. main()
  167. --END PROGRAM--
Add Comment
Please, Sign In to add comment