Advertisement
Dakewlmoncoding

mcMidiJukebox

Jul 11th, 2023
1,263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. speaker = peripheral.wrap("bottom")
  2.  
  3.  
  4. function mysplit (inputstr, sep)
  5.     if sep == nil then
  6.             sep = "%s"
  7.     end
  8.     local t={}
  9.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  10.             table.insert(t, str)
  11.     end
  12.     return t
  13. end
  14.  
  15.  
  16.  
  17.  
  18. songName = read()
  19. Play = false --holdover from organ setup. could be more optimized for this
  20.  
  21. --main code
  22. print("Playing song!")
  23. for line in io.lines(songName) do
  24.     local msg = mysplit(line, ', ')
  25.     if msg[2] == 'off' then
  26.         Play = false
  27.     elseif msg[2] == 'on' then
  28.         Play = true
  29.     end
  30.  
  31.     sleep(tonumber(msg[1]))
  32.     speaker.playNote(msg[4],1,tonumber(msg[3]))
  33. end
  34. print("end of song!")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement