Guest User

music_player

a guest
Aug 11th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.28 KB | None | 0 0
  1. --this is the BlueTunes program
  2. --copyright of BlueTide Programs.inc, Benedict Allen, all members of BlueTide Programs.inc and all members of programcraft.inc
  3. --if you wish to use this program please contact Benedict Allen(awsumben13 on cc forums) and make sure you give the credit to BlueTide Programs
  4.  
  5. --usability functions
  6.  
  7. local function clear()
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. end
  11.  
  12. local function clearPos(x,y)
  13. term.clear()
  14. term.setCursorPos(x,y)
  15. end
  16.  
  17. local function printLine(x,y,text)
  18. term.setCursorPos(x,y)
  19. print(text)
  20. end
  21.  
  22. function clearPrint(x,y,text)
  23. term.clear()
  24. term.setCursorPos(x,y)
  25. print(text)
  26. end
  27.  
  28. function reset(file, x, y)
  29. if fs.exists(file) then
  30. h = fs.open(file, "w")
  31. h.write("")
  32. h.close()
  33. term.setCursorPos(x,y)
  34. print("File reset")
  35. sleep(2)
  36. else
  37. term.setCursorPos(x,y)
  38. print("file not found")
  39. sleep(2)
  40. end
  41. end
  42.  
  43. function tip(help)
  44. while true do
  45. clear()
  46. print(help)
  47. printLine(1,17,"press enter to exit")
  48. event, key = os.pullEvent()
  49. if key == 28 then break
  50. end
  51. end
  52. end
  53.  
  54. function drawloading()
  55. print("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
  56. print("O                                               O")
  57.  
  58. print("O                                               O")
  59.  
  60. print("O   OOO  O    O   O OOOO OOOO OOOO OOO  OOOO    O")
  61.  
  62. print("O   O  O O    O   O O     OO   OO  O  O O       O")
  63.  
  64. print("O   OOOO O    O   O OOOO  OO   OO  O  O OOOO    O")
  65.  
  66. print("O   O  O O    O   O O     OO   OO  O  O O       O")
  67.  
  68. print("O   OOO  OOOO  OOO  OOOO  OO  OOOO OOO  OOOO    O")
  69.  
  70. print("O                                               O")
  71.  
  72. print("O                  systems.inc                  O")
  73.  
  74. print("O                                               O")
  75.  
  76. print("O                 loading[    ]                 O")
  77.  
  78. print("O                                               O")
  79.  
  80. print("O                                               O")
  81.  
  82. print("O                                               O")
  83.  
  84. print("O            Made by: Benedict Allen            O")
  85.  
  86. print("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
  87. end
  88.  
  89. function startup()
  90.  
  91. term.clear()
  92.  
  93. term.setCursorPos(1,1)
  94. drawloading()
  95. printLine(27,12,"O   ")
  96.  
  97. sleep(0.3)
  98.  
  99. printLine(27,12," O  ")
  100.  
  101. sleep(0.3)
  102.  
  103. printLine(27,12,"  O ")
  104.  
  105. sleep(0.3)
  106.  
  107. printLine(27,12,"O  O")
  108.  
  109. sleep(0.3)
  110. printLine(27,12," O  ")
  111. sleep(0.5)
  112.  
  113. end
  114.  
  115.  
  116. function drawScreen()
  117. w, h = term.getSize()
  118. printLine(1,1,"+-----------------------------------------------+")
  119. printLine(1,2,"|                                               |")
  120. printLine(1,3,"|                                               |")
  121. printLine(1,4,"|                                               |")
  122. printLine(1,5,"|                                               |")
  123. printLine(1,6,"|                                               |")
  124. printLine(1,7,"|                                               |")
  125. printLine(1,8,"|                                               |")
  126. printLine(1,9,"|                                               |")
  127. printLine(1,10,"|                                               |")
  128. printLine(1,11,"|                                               |")
  129. printLine(1,12,"|                                               |")
  130. printLine(1,13,"|                                               |")
  131. printLine(1,14,"|                                               |")
  132. printLine(1,15,"|                                               |")
  133. printLine(1,16,"|                                               |")
  134. printLine(1,17,"+-----------------------------------------------+")
  135. printLine(3,2,"BlueTunes version "..version)
  136. printLine(w-(string.len(copyrightText)+2),16,copyrightText)
  137. end
  138.  
  139. --end
  140.  
  141. --programs functions
  142.  
  143. function menu()
  144. while true do
  145. clear()
  146. drawScreen()
  147. menuOptions = {
  148. "";
  149. "";
  150. "";
  151. "|  1.Run Music Player";
  152. "|  2.Settings";
  153. "|  3.Shutdown";
  154. "|  4.Exit";
  155. }
  156. for i = 1,#menuOptions do
  157. printLine(1,0+i,menuOptions[i])
  158. end
  159. printLine(3,menuSelected+3,">")
  160. event, key = os.pullEvent()
  161. if key == 200 and menuSelected > 1 then
  162.     menuSelected = menuSelected-1
  163. elseif key == 208 and menuSelected < 4 then
  164.     menuSelected = menuSelected+1
  165. elseif key == 14 then
  166.     clear()
  167.     break
  168. elseif key == 28 and menuSelected == 1 then
  169.     music_player()
  170. elseif key == 28 and menuSelected == 2 then
  171.     music_settings()
  172. elseif key == 28 and menuSelected == 3 then
  173.     os.shutdown()
  174. elseif key == 28 and menuSelected == 4 then
  175.     clear()
  176.     break
  177. end
  178. end
  179. end
  180.  
  181. function music_player()
  182. while true do
  183. clear()
  184. drawScreen()
  185. printLine(2,2,"                              ")
  186. printLine(25,16,"                       ")
  187. printLine(1,11,"+-----------------------------------------------+")
  188. printLine(1,3,"|   OOO  O    O   O OOOO OOOO OOOO OOO  OOOO    |")
  189.  
  190. printLine(1,4,"|   O  O O    O   O O     OO   OO  O  O O       |")
  191.  
  192. printLine(1,5,"|   OOOO O    O   O OOOO  OO   OO  O  O OOOO    |")
  193.  
  194. printLine(1,6,"|   O  O O    O   O O     OO   OO  O  O O       |")
  195.  
  196. printLine(1,7,"|   OOO  OOOO  OOO  OOOO  OO  OOOO OOO  OOOO    |")
  197. printLine((w/2)-(14/2),9,"music player")
  198. if musicPlaying == false then
  199. printLine(1,13,"|    \\/\\/   +--+     |\\      +---+    ----      |")
  200. printLine(1,14,"|    <()>   |  |     | >     |-->|    EXIT      |")
  201. printLine(1,15,"|    /\\/\\   +--+     |/      +---+    ----      |")
  202. elseif musicPlaying == true then
  203. printLine(1,13,"|    \\/\\/   +--+    || ||    +---+    ----      |")
  204. printLine(1,14,"|    <()>   |  |    || ||    |-->|    EXIT      |")
  205. printLine(1,15,"|    /\\/\\   +--+    || ||    +---+    ----      |")
  206. end
  207. if musicSelected == 1 then
  208. printLine(4,16,"settings")
  209. printLine(5,13,"[") printLine(10,13,"]")
  210. printLine(5,14,"[") printLine(10,14,"]")
  211. printLine(5,15,"[") printLine(10,15,"]")
  212. elseif musicSelected == 2 then
  213. printLine(13,16,"stop")
  214. printLine(12,13,"[") printLine(17,13,"]")
  215. printLine(12,14,"[") printLine(17,14,"]")
  216. printLine(12,15,"[") printLine(17,15,"]")
  217. elseif musicSelected == 3 then
  218. if musicPlaying == true then
  219. printLine(21,16,"pause")
  220. else
  221. printLine(21,16,"play")
  222. end
  223. printLine(20,13,"[") printLine(26,13,"]")
  224. printLine(20,14,"[") printLine(26,14,"]")
  225. printLine(20,15,"[") printLine(26,15,"]")
  226. elseif musicSelected == 4 then
  227. printLine(30,16,"eject")
  228. printLine(29,13,"[") printLine(35,13,"]")
  229. printLine(29,14,"[") printLine(35,14,"]")
  230. printLine(29,15,"[") printLine(35,15,"]")
  231. elseif musicSelected == 5 then
  232. printLine(39,16,"exit")
  233. printLine(38,13,"[") printLine(43,13,"]")
  234. printLine(38,14,"[") printLine(43,14,"]")
  235. printLine(38,15,"[") printLine(43,15,"]")
  236. end
  237. event, key = os.pullEvent()
  238. if key == 203 and musicSelected > 1 then
  239.     musicSelected = musicSelected-1
  240. elseif key == 205 and musicSelected < 5 then
  241.     musicSelected = musicSelected+1
  242. elseif key == 14 then
  243.     disk.stopAudio(mountPath)
  244.     musicPlaying = false
  245.     musicDiskIn = false
  246.     break
  247. elseif key == 28 and musicSelected == 1 then
  248.     music_settings()
  249. elseif key == 28 and musicSelected == 2 and musicPlaying == true then
  250.     disk.stopAudio()
  251.     musicPlaying = false
  252. elseif key == 28 and musicSelected == 3 and musicPlaying == true then
  253.     disk.stopAudio(mountPath)
  254.     musicPlaying = false
  255. elseif key == 28 and musicSelected == 3 and musicPlaying == false and musicDiskIn == true then
  256.     disk.playAudio(mountPath)
  257.     musicPlaying = true
  258. elseif key == 28 and musicSelected == 3 and musicPlaying == false and musicDiskIn == false then
  259.     printLine(2,10,"No Disk Mounted! Go to settings to mount a disk")
  260.     sleep(2)
  261. elseif key == 28 and musicSelected == 4 then
  262.     disk.eject("left") disk.eject("right") disk.eject("top") disk.eject("bottom") disk.eject("back") disk.eject("front")
  263.     musicPlaying = false
  264.     musicDiskIn = false
  265. elseif key == 28 and musicSelected == 5 then
  266.     musicPlaying = false
  267.     disk.stopAudio(mountPath)
  268.     musicDiskIn = false
  269.     break
  270. end
  271. end
  272. end
  273.  
  274. function music_settings()
  275. while true do
  276. clear()
  277. drawScreen()
  278. settingOptions = {
  279. "|  1.Insert/Mount Disk";
  280. "|  2.Change Mount Path-currently set to "..mountPath;
  281. "|  3.Go Back"
  282. }
  283. for i = 1,#settingOptions do
  284. printLine(1,3+i,settingOptions[i])
  285. end
  286. printLine(3,settingSelected+3,">")
  287. printLine(3,16,settingSelected)
  288. event, key = os.pullEvent()
  289. if key == 200 and settingSelected > 1 then
  290.     settingSelected = settingSelected-1
  291. elseif key == 208 and settingSelected < 3 then
  292.     settingSelected = settingSelected+1
  293. elseif key == 14 then
  294.     break
  295. elseif key == 28 and settingSelected == 1 then
  296.     if disk.hasAudio(mountPath) == true then
  297.     musicDiskIn = true
  298.     printLine(3,8,"disk mounted...you can now play the disk")
  299.     sleep(1)
  300.     else
  301.     printLine(3,8,"no audio found in "..mountPath)
  302.     sleep(1)
  303.     end
  304. elseif key == 28 and settingSelected == 2 then
  305.     printLine(3,8,"Change mount path to?")
  306.     term.setCursorPos(3,9)
  307.     mountPathNew = read()
  308.     if mountPathNew == "top" or mountPathNew == "bottom" or mountPathNew == "left" or mountPathNew == "right" or mountPathNew == "back" or mountPathNew == "front" then
  309.         printLine(3,10,"New mount path accepted")
  310.         mountPath = mountPathNew
  311.         sleep(1)
  312.         musicDiskIn = false
  313.     else
  314.         printLine(3,10,"Invalid side")
  315.         sleep(1)
  316.     end
  317. elseif key == 28 and settingSelected == 3 then
  318.     break
  319. end
  320. end
  321. end
  322.  
  323. --end
  324.  
  325. --variables
  326.  
  327. copyrightText = "[C] Bluetide Programs"
  328. version = "1.0.0"
  329. menuSelected = 1
  330. musicPlaying = false
  331. musicSelected = 3
  332. musicDiskIn = false
  333. settingSelected = 1
  334. mountPath = "bottom"
  335.  
  336. --end
  337.  
  338. --code
  339.  
  340. --startup()
  341. menu()
  342.  
  343. --end
Advertisement
Add Comment
Please, Sign In to add comment