Advertisement
xMicroNinjax

MusicPlayer

Jan 26th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. noteBlocks = {
  2.     {noteName="1F#",side="front",colour=colors.white},
  3.     {noteName="1G",side="front",colour=colors.orange},
  4.     {noteName="1G#",side="front",colour=colors.magenta},
  5.     {noteName="1A",side="front",colour=colors.lightBlue},
  6.     {noteName="1A#",side="front",colour=colors.yellow},
  7.     {noteName="1B",side="front",colour=colors.lime},
  8.     {noteName="1C",side="front",colour=colors.pink},
  9.     {noteName="1C#",side="front",colour=colors.gray},
  10.     {noteName="1D",side="front",colour=colors.lightGray},
  11.     {noteName="1D#",side="front",colour=colors.cyan},
  12.     {noteName="1E",side="front",colour=colors.purple},
  13.     {noteName="1F",side="front",colour=colors.blue},
  14.     {noteName="2F#",side="front",colour=colors.brown},
  15.     {noteName="2G",side="back",colour=colors.white},
  16.     {noteName="2G#",side="back",colour=colors.orange},
  17.     {noteName="2A",side="back",colour=colors.magenta},
  18.     {noteName="2A#",side="back",colour=colors.lightBlue},
  19.     {noteName="2B",side="back",colour=colors.yellow},
  20.     {noteName="2C",side="back",colour=colors.lime},
  21.     {noteName="2C#",side="back",colour=colors.pink},
  22.     {noteName="2D",side="back",colour=colors.gray},
  23.     {noteName="2D#",side="back",colour=colors.lightGray},
  24.     {noteName="2E",side="back",colour=colors.cyan},
  25.     {noteName="2F",side="back",colour=colors.purple},
  26.     {noteName="3F#",side="back",colour=colors.blue}
  27. }                                      
  28.  
  29. song1 = {songTitle="Zelda Secret song",songNotes={
  30.     {noteName="2G", length=0.2},
  31.     {noteName="2F#",length=0.2},
  32.     {noteName="1D#",length=0.2},
  33.     {noteName="1A",length=0.2},
  34.     {noteName="1G#",length=0.2},
  35.     {noteName="1E",length=0.2},
  36.     {noteName="2G#",length=0.2},
  37.     {noteName="2C",length=0.2}}
  38. }
  39.  
  40.  
  41. songList = {
  42.     {songID = 1,songName=song1}
  43. }
  44.  
  45. function playSong(songToPlay)
  46.     side = ""
  47.     for x, note in ipairs(songToPlay.songNotes) do
  48.         for y, noteMaster in ipairs(noteBlocks) do
  49.             if note.noteName == noteMaster.noteName then
  50.                 side = noteMaster.side
  51.                 redstone.setBundledOutput(side, noteMaster.colour)
  52.             end
  53.         end
  54.         os.sleep(note.length)
  55.         redstone.setBundledOutput(side, 0)
  56.     end
  57. end
  58.  
  59. while true do
  60.     term.clear()
  61.     term.setCursorPos(1,1)
  62.     term.setCursorBlink(true)
  63.    
  64.     print("Please choose a song!")
  65.     for x, song in ipairs(songList) do
  66.         print("Song ID:",x, " | Song name:",song.songName.songTitle)       
  67.     end
  68.    
  69.     for x, song in ipairs(songList) do     
  70.         local input = read()
  71.         if input == tostring(song.songID) then
  72.             print("Chose song",song.songName.songTitle)
  73.             playSong(song.songName)
  74.         end
  75.     end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement