Advertisement
Guest User

sound

a guest
Apr 6th, 2020
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. --//funcs
  2. function playNote(pitch, side)
  3.     if not(pitch == -1) then
  4.       peripheral.call(side,"setPitch",pitch)
  5.       peripheral.call(side,"triggerNote")
  6.     end
  7. end
  8.  
  9. function pause(beatlength, length)
  10.         os.sleep(beatlength/length)
  11. end
  12.  
  13. function getSongInfo(file)
  14.         local dataH = fs.open(file, "r")
  15.         local data = textutils.unserialise(dataH.readAll())
  16.         dataH.close()
  17.  
  18.         local song = {}
  19.         song.beatlength = data[1]
  20.         song.notes = data[#data]
  21.         return song
  22. end
  23. --//
  24.  
  25. local args = {...}
  26. local file = args[1]
  27. local loop = args[2] == "loop"
  28. local debug = args[3] == "debug"
  29.  
  30. local song = getSongInfo(file)
  31. local notes = song.notes
  32. local beatlength = song.beatlength
  33.  
  34. repeat
  35.   for _, accord in pairs(notes) do
  36.         for _,note in pairs(accord[1])do
  37.                 playNote(note[1], note[2])
  38.         end
  39.         pause(beatlength, accord[2])
  40.   end
  41. until not loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement