MeiDaGay

Untitled

Sep 9th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 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.     print("= List of songs To Be Added!")
  83.    
  84.     write("Song name: ")
  85.     if not arepeat then
  86.         userInput = read()
  87.     end
  88.    
  89.     listC = gcapi.split((userInput .. ' '), ' ')
  90.    
  91.     if table.contains(listC , '-r' ) then
  92.         arepeat = true
  93.     end
  94.    
  95.     if userInput then
  96.         filePath = "/songs/" .. string.split(userInput .. " ", " ")[1]
  97.         print()
  98.        
  99.         if filePath and fs.exists(filePath) then
  100.             file = fs.open(filePath, "r")
  101.             song = textutils.unserialize(file.readAll())
  102.             file.close()
  103.             if existsMonitor then
  104.                 nMon.setSong(song)
  105.             end
  106.             startSong()
  107.         else
  108.             print("Song not found")
  109.             sleep(2)
  110.         end
  111.     end
  112. end
Add Comment
Please, Sign In to add comment