Advertisement
MeiDaGay

Untitled

Sep 9th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. os.loadAPI("gcapi")
  2.  
  3. existsMonitor = false
  4. if peripheral.find("monitor") then
  5. os.loadAPI("nMon")
  6. existsMonitor = true
  7. end
  8.  
  9. --peripheral.find() in Tekkit
  10. function findPeripheral(pType)
  11. pList = {}
  12. for _,pName in pairs(peripheral.getNames()) do
  13. if peripheral.getType(pName) == pType then
  14. table.insert(pList, peripheral.wrap(pName))
  15. end
  16. end
  17. return unpack(pList)
  18. end
  19. peripheral.find = findPeripheral
  20.  
  21. --Split string
  22. function split(self, delimiter)
  23. result = {};
  24. for match in (self..delimiter):gmatch("(.-)"..delimiter) do
  25. table.insert(result, match);
  26. end
  27. return result;
  28. end
  29. string.split = split
  30. --------------------------------------------------------
  31. --> MUSIC <--
  32. --------------------------------------------------------
  33. local pitchs = {[0]=0, [1]=0.53, [2]=0.56, [3]=0.6, [4]=0.63, [5]=0.67, [6]=0.7, [7]=0.75,
  34. [8]=0.8,[9]=0.85,[10]=0.9,[11]=0.95,[12]=1,[13]=1.05,[14]=1.1,[15]=1.2,[16]=1.25,[17]=1.32,[18]=1.4,
  35. [19]=1.5,[20]=1.6,[21]=1.7,[22]=1.8,[23]=1.9,[24]=2}
  36.  
  37. local instruments = {[1]="note.harp",[2]="note.bassattack",[3]="note.bd",[4]="note.snare",[5]="note.hat"}
  38.  
  39. local song = nil
  40.  
  41. local noteblocks = {peripheral.find("music")}
  42.  
  43. function playNote(instrument, pitch, vol)
  44. if instrument and pitch and vol then
  45. for _,noteblock in pairs(noteblocks) do
  46. noteblock.playSound(instrument, pitch, vol)
  47. end
  48. end
  49. end
  50.  
  51. --------------------------------------------------------
  52. --> Main programs <--
  53. --------------------------------------------------------
  54.  
  55. function startSong()
  56. local delay = song["delay"]
  57. for i,tick in ipairs(song) do
  58. if existsMonitor then
  59. nMon.updateMonitor(i)
  60. end
  61. for instrumentID, notePitchs in pairs(tick) do
  62. for _,pitchID in pairs(notePitchs) do
  63. playNote(instruments[instrumentID], pitchs[pitchID], 0.7)
  64. end
  65. end
  66. sleep(delay)
  67. end
  68. end
  69.  
  70. function clearTerminal()
  71. term.setCursorPos(1,1)
  72. term.clear()
  73. end
  74.  
  75. if existsMonitor then
  76. nMon.setupMonitor()
  77. end
  78.  
  79. userInput = ''
  80. while true do
  81. clearTerminal()
  82.  
  83. print("= List of songs =")
  84. print(" - portal")
  85. print(" - nyancat")
  86. print(" - zelda")
  87. print(" - sas")
  88. print(" - tetris")
  89. print(" - banjo")
  90. print(" - evilmorty")
  91. print(" - jinglebells")
  92. print(" - Johnny_B_Goode")
  93. print(" - Nothing_Else_Matters")
  94. print(" - Pokemon_Center_Theme")
  95. print(" - Popcorn")
  96. print(" - Positive_Force")
  97. print(" - Pushing_Onwards")
  98. print(" - Remedy")
  99. print(" - Smells_Like_Teen_Spirit")
  100. print(" - Song_of_Storms")
  101. print(" - Super_Mario_Bros_3_Athletic")
  102. print(" - Sweden")
  103. print(" - Terraria_Theme")
  104. print(" - Tetris_A_Theme")
  105. print(" - Tetris_B_Theme")
  106. print(" - The_Edge_of_Glory")
  107. print(" - Turkish_March")
  108. print(" - Vanilla_Twilight")
  109. print(" - What_is_Love")
  110. print(" - What_Ive_Done")
  111. print(" - A_Kind_of_Magic")
  112. print(" - Bohemian_Rhapsody")
  113. print(" - Call_Me_Maybe")
  114. print(" - Cara_Mia")
  115. print(" - revenge")
  116. print(" - Dont_Stop_Me_Now")
  117. print(" - Every_Little_Earthquake")
  118. print(" - Friday")
  119. print(" - Gangnam_Style")
  120. print(" - Get_Ready_For_This")
  121. print(" - Hammer_To_Fall")
  122. print(" - Hes_A_Pirate")
  123. print(" - Hold_The_Line")
  124. print(" - Indiana_Jones_Theme")
  125. print(" - Its_My_Life")
  126.  
  127. write("Song name: ")
  128. if not arepeat then
  129. userInput = read()
  130. end
  131.  
  132. listC = gcapi.split((userInput .. ' '), ' ')
  133.  
  134. if table.contains(listC , '-r' ) then
  135. arepeat = true
  136. end
  137.  
  138. if userInput then
  139. filePath = "/songs/" .. string.split(userInput .. " ", " ")[1]
  140. print()
  141.  
  142. if filePath and fs.exists(filePath) then
  143. file = fs.open(filePath, "r")
  144. song = textutils.unserialize(file.readAll())
  145. file.close()
  146. if existsMonitor then
  147. nMon.setSong(song)
  148. end
  149. startSong()
  150. else
  151. print("Song not found")
  152. sleep(2)
  153. end
  154. end
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement