Advertisement
2222Jonathan

Music

Dec 13th, 2019
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local speaker = nil
  4. for k, v in pairs(peripheral.getNames()) do
  5.     local type = peripheral.getType(v)
  6.     if type == "speaker" then
  7.         speaker = peripheral.wrap(v)
  8.     end
  9. end
  10.  
  11. if speaker == nil then
  12.     print("Error: No speaker found!")
  13.     return
  14. end
  15.  
  16. local music = "Jurassic Park Theme"
  17.  
  18. if #tArgs > 1 then
  19.     print("Usage: <music>")
  20.     return
  21. end
  22.  
  23. if #tArgs ~= 1 then
  24.     print("Default to playing ", music)
  25. end
  26.  
  27. local N_L = {FS=0, G=1, GS=2, A=3, AS=4, B=5}
  28. local N_M = {C=6, CS=7, D=8, DS=9, E=10, F=11, FS=12, G=13, GS=14, A=15, AS=16, B=17}
  29. local N_H = {C=18, CS=19, D=20, DS=21, E=22, F=23, FS=24}
  30.  
  31.  
  32. if music == "Jurassic Park Theme" then
  33.     -- A number between 0 and 3, 3 is the volume of a normal note block.
  34.     local vol = 2
  35.     -- The instrument to play the song in
  36.     local inst = "harp"--"guitar"
  37.     local bpm = 100
  38.     local tempo = bpm/60
  39.     local a8 = tempo*(1/8)
  40.     local a4 = tempo*(1/4)
  41.     local a2 = tempo*(1/2)
  42.     local a1 = tempo
  43.  
  44.     function note(pitch, length)
  45.         speaker.playNote(inst, vol, pitch)
  46.         sleep(length)
  47.     end
  48.     -- pitch goes from (0) F# to (24) F# 2 octaves higher.
  49.     note(N_M.G, a2 + a4) -- G
  50.  
  51.     note(N_M.G, a8) -- G
  52.     note(N_M.FS, a8) -- F#
  53.     note(N_M.G, a2 + a4) -- G
  54.  
  55.     note(N_M.G, a8) -- G
  56.     note(N_M.FS, a8) -- F#
  57.     note(N_M.G, a4 + a8) -- G
  58.  
  59.     note(N_M.A, a8) -- A
  60.     note(N_M.A, a4 + a8) -- A
  61.  
  62.     note(N_H.C, a8) -- C
  63.     note(N_H.C, a2 + a4) -- C
  64.  
  65.     note(N_M.B, a8) -- B
  66.     note(N_M.G, a8) -- G
  67.     note(N_M.A, a4 + a8) -- A
  68.  
  69.     note(N_M.FS, a8) -- F#
  70.     note(N_M.D, a4) -- D
  71.  
  72.     note(N_M.B, a8) -- B
  73.     note(N_M.G, a8) -- G
  74.     note(N_M.A, a4 + a8) -- A
  75.  
  76.     note(N_H.D, a8) -- D (Third octav)
  77.     note(N_M.G, a8) -- G
  78.     vol = 3
  79.     note(N_H.C, a4 + a8) -- C (Third octav)
  80.     note(N_M.B, a8) -- B
  81.     note(N_M.B, a4 + a8) -- B
  82.  
  83.     note(N_M.A, a8) -- A
  84.     note(N_M.A, a2) -- A
  85.  
  86.     note(N_M.G, a8) -- G
  87.     note(N_M.FS, a8) -- F#
  88.     note(N_M.G, a4) -- G
  89.     note(N_M.D, a4) -- D
  90.     note(N_M.C, a4) -- C
  91.     note(N_M.G, a8) -- G
  92.     note(N_M.FS, a8) -- F#
  93.     note(N_M.G, a4) -- G
  94.     note(N_M.D, a4) -- D
  95.     note(N_M.C, a4) -- C
  96.     note(N_M.G, a8) -- G
  97.     note(N_M.FS, a8) -- F#
  98.     note(N_M.FS, a8) -- F#
  99.     note(N_M.G, a4 + a8) -- G
  100.  
  101.     note(N_M.D, a4) -- D
  102.     note(N_L.G, a4) -- G
  103.     note(N_M.F, a2) -- F
  104.  
  105.     note(N_M.G, a8) -- G
  106.     note(N_M.FS, a8) -- F#
  107.     note(N_M.G, a4) -- G
  108.     note(N_M.D, a4) -- D
  109.     note(N_M.C, a4) -- C
  110.     note(N_M.G, a8) -- G
  111.     note(N_M.FS, a8) -- F#
  112.     note(N_M.G, a4) -- G
  113.     note(N_M.D, a4) -- D
  114.     note(N_M.C, a4) -- C
  115.     note(N_M.G, a8) -- G
  116.     note(N_M.FS, a8) -- F#
  117.     note(N_M.FS, a8) -- F#
  118.     note(N_M.G, a4 + a8) -- G
  119.  
  120.     note(N_M.D, a4) -- D
  121.     note(N_L.G, a4) -- G
  122.  
  123.     note(N_M.G, a1) -- G
  124.  
  125.     note(N_M.FS, a1) -- F#
  126.  
  127.     note(N_M.G, a1) -- G
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement