Advertisement
Etsukazu_Aoi

temporaire

Dec 9th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. --get arguments
  2.  
  3. local tArgs = { ... }
  4. musicplaylist = false
  5. selectedsong = nil
  6. displaynotes = ""
  7. mute = {{ },{ },{ },{ },{ }}
  8. i = 1
  9. j = 1
  10. selectedi = 1
  11. selectedj = 1
  12. ptoggle = 0
  13. debug = false
  14. --attaching ironblocks
  15. ironblock1 = peripheral.wrap("left")
  16. ironblock2 = peripheral.wrap("right")
  17. ironblock3 = peripheral.wrap("back")
  18. ironblock4 = peripheral.wrap("top")
  19. ironblock5 = peripheral.wrap("bottom")
  20.  
  21. function round(num, idp)
  22. local mult = 10^(idp or 0)
  23. return math.floor(num * mult + 0.5) / mult
  24. end
  25.  
  26. input = function(evt, arg1, arg2)
  27. if debug and evt == "key" and arg1 == 41 then
  28. debug = false
  29. elseif evt == "key" and arg1 == 41 then
  30. debug = true
  31. end
  32.  
  33. if debug then
  34. if evt == "key" and arg1 == 17 and selectedi < 5 then
  35. selectedi = selectedi + 1
  36. elseif evt == "key" and arg1 == 31 and selectedi > 1 then
  37. selectedi = selectedi - 1
  38. elseif evt == "key" and arg1 == 32 and selectedj < 5 then
  39. selectedj = selectedj + 1
  40. elseif evt == "key" and arg1 == 30 and selectedj > 1 then
  41. selectedj = selectedj - 1
  42. end
  43.  
  44. if evt == "key" and arg1 == 57 and mute[selectedi][selectedj] ~= 0 then
  45. mute[selectedi][selectedj] = 0
  46. elseif evt == "key" and arg1 == 57 and mute[selectedi][selectedj] == 0 then
  47. mute[selectedi][selectedj] = 1
  48. end
  49. end
  50.  
  51. if evt == "key" and arg1 == 15 and ptoggle ~= 0 then
  52. ptoggle = 0
  53. elseif evt == "key" and arg1 == 15 and ptoggle == 0 then
  54. ptoggle = 1
  55. end
  56.  
  57. if evt == "key" and arg1 >= 2 and arg1 <= 12 then
  58. factor = allNotes / 10
  59. i = round(factor * (arg1 - 2), 0)
  60. end
  61. end
  62.  
  63. playnotes = function(noteblockside, channle, int)
  64. displaynotes = displaynotes .. "("
  65. if song[i][channle] then
  66.  
  67. if song[i][channle][1] and mute[channle][1] ~= 0 then
  68. note = song[i][channle][1]
  69. noteblockside.playNote(int,note)
  70. displaynotes = displaynotes .. note .. ","
  71. end
  72. if song[i][channle][2] and mute[channle][2] ~= 0 then
  73. note = song[i][channle][2]
  74. noteblockside.playNote(int,note)
  75. displaynotes = displaynotes .. note .. ","
  76. end
  77. if song[i][channle][3] and mute[channle][3] ~= 0 then
  78. note = song[i][channle][3]
  79. noteblockside.playNote(int,note)
  80. displaynotes = displaynotes .. note .. ","
  81. end
  82. if song[i][channle][4] and mute[channle][4] ~= 0 then
  83. note = song[i][channle][4]
  84. noteblockside.playNote(int,note)
  85. displaynotes = displaynotes .. note .. ","
  86. end
  87. if song[i][channle][5] and mute[channle][5] ~= 0 then
  88. note = song[i][channle][5]
  89. noteblockside.playNote(int,note)
  90. displaynotes = displaynotes .. note .. ","
  91. end
  92. end
  93. displaynotes = displaynotes .. ")"
  94. end
  95.  
  96. -- Song selection stuff
  97. if fs.exists("playlist") and #tArgs < 1 then
  98. local file = fs.open("playlist", "r")
  99. playlist = {}
  100. toltal = 0
  101. while true do
  102. local songque = file.readLine()
  103. if songque == nil then --if reached end of file
  104. break end
  105. table.insert(playlist, songque)
  106. toltal = toltal + 1
  107. musicplaylist = true
  108. end
  109. selectedsong = playlist[1]
  110. elseif #tArgs < 1 then
  111. shell.run("clear")
  112. print( "Use the arrows and enter to chose. " )
  113. songlist = fs.list("music")
  114. i = 0
  115. max = -1
  116. while true do
  117. i = i + 1
  118. max = max + 1
  119. if songlist[i] == nil then break end
  120. end
  121. pointer = 1
  122. term.setCursorPos(1, 10)
  123. term.clearLine(none)
  124. print( "->" .. pointer .. ": " .. songlist[pointer])
  125. while true do
  126.  
  127. list = 1
  128. while list < 9 do
  129. term.setCursorPos(1, 10 - list)
  130. term.clearLine(none)
  131. if songlist[pointer - (list)] then
  132. write( " " .. pointer - (list) .. ": " .. songlist[pointer - (list)])
  133. end
  134. list = list + 1
  135. end
  136. term.setCursorPos(1, 10)
  137. term.clearLine(none)
  138. print( "->" .. pointer .. ": " .. songlist[pointer])
  139. list = 1
  140. while list < 10 do
  141. term.setCursorPos(1, 10 + list)
  142. term.clearLine(none)
  143. if songlist[pointer + (list)] then
  144. write( " " .. pointer + (list) .. ": " .. songlist[pointer + (list)])
  145. end
  146. list = list + 1
  147. end
  148. local evt, arg1, arg2 = os.pullEvent()
  149. if arg1 == 28 then break end
  150. if arg1 == 200 and pointer > 1 then
  151. pointer = pointer - 1
  152. elseif arg1 == 208 and pointer < max then
  153. pointer = pointer + 1
  154. end
  155.  
  156. end
  157.  
  158. selectedsong = songlist[pointer]
  159. else
  160. selectedsong = tArgs[1]
  161. end
  162.  
  163. que = 0
  164. while true do
  165. if musicplaylist then
  166. if que >= toltal then
  167. que = 1
  168. else
  169. que = que + 1
  170. end
  171. selectedsong = playlist[que]
  172. end
  173.  
  174. -- Playing The Music
  175.  
  176. --opening file
  177. shell.run( "clear" )
  178. if fs.exists("Instrument/" .. selectedsong) then
  179. shell.run( "Instrument/" .. selectedsong )
  180. else
  181. int1 = 0
  182. int2 = 0
  183. int3 = 0
  184. int4 = 0
  185. int5 = 0
  186. end
  187. file = io.open( "music/" .. selectedsong )
  188. filedata = file:read()
  189. file:close()
  190. --converting file to table
  191. song = textutils.unserialize(filedata)
  192. allNotes = song["lenght"] / song["delay"]
  193. -- Song info
  194. term.setCursorPos(1,1)
  195. print("Song:" .. song["name"] )
  196. print("Author:" .. song["author"] )
  197. print("Original Author:" .. song["original_author"] )
  198. -- Start playing
  199. i = 0
  200. line1 = ""
  201. line2 = ""
  202. line3 = ""
  203. line4 = ""
  204. line5 = ""
  205. line6 = ""
  206. line7 = ""
  207. line8 = ""
  208. line9 = ""
  209. line10 = ""
  210. while i * song["delay"] < song["lenght"] + 1 do
  211. term.setCursorPos(1,4)
  212. if ptoggle ~= 1 then
  213. term.clearLine()
  214. print(i * song["delay"] .."/" .. song["lenght"] .. " Seconds" )
  215. else
  216. term.clearLine()
  217. print(i .."/" .. allNotes .. " Notes" )
  218. end
  219. if debug then
  220. print("[" .. selectedi .. "," .. selectedj .. "]")
  221. else
  222. term.clearLine()
  223. end
  224. --clear all notes
  225. displaynotes = "["
  226.  
  227. -- read notes for up to 5 parts
  228. i = i + 1
  229. if song[i] then
  230. if ironblock1 then playnotes(ironblock1, 1, int1) end
  231. if ironblock2 then playnotes(ironblock2, 2, int2) end
  232. if ironblock3 then playnotes(ironblock3, 3, int3) end
  233. if ironblock4 then playnotes(ironblock4, 4, int4) end
  234. if ironblock5 then playnotes(ironblock5, 5, int5) end
  235. end
  236. displaynotes = displaynotes .. "] "
  237. line1 = line2
  238. line2 = line3
  239. line3 = line4
  240. line4 = line5
  241. line5 = line6
  242. line6 = line7
  243. line7 = line8
  244. line8 = line9
  245. line9 = line10
  246. line10 = displaynotes
  247. term.setCursorPos(1,9)
  248. term.clearLine()
  249. print(line1)
  250. term.clearLine()
  251. print(line2)
  252. term.clearLine()
  253. print(line3)
  254. term.clearLine()
  255. print(line4)
  256. term.clearLine()
  257. print(line5)
  258. term.clearLine()
  259. print(line6)
  260. term.clearLine()
  261. print(line7)
  262. term.clearLine()
  263. print(line8)
  264. term.clearLine()
  265. print(line9)
  266. term.clearLine()
  267. print(line10)
  268.  
  269.  
  270.  
  271. os.startTimer(song["delay"])
  272. evt, arg1, arg2 = os.pullEvent()
  273. input(evt, arg1, arg2)
  274. if evt ~= "timer" then
  275. os.sleep(song["delay"])
  276. end
  277.  
  278. end
  279.  
  280. if musicplaylist == false then break end
  281. end
  282. -- End Playing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement