Sectly_Playz

CC Speaker

Apr 7th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local speaker = peripheral.wrap("left")
  2.  
  3. local notes = {
  4.     ["F#1"]=0,    ["F#2"]=12,
  5.     ["Gb1"]=0,    ["Gb2"]=12,
  6.     ["G1"]=1,     ["G2"]=13,
  7.     ["G#1"]=2,    ["G#2"]=14,
  8.     ["Ab1"]=2,    ["Ab2"]=14,
  9.     ["A1"]=3,     ["A2"]=15,
  10.     ["A#1"]=4,    ["A#2"]=16,
  11.     ["Bb1"]=4,    ["Bb2"]=16,
  12.     ["B1"]=5,     ["B2"]=17,
  13.     ["C1"]=6,     ["C2"]=18,
  14.     ["C#1"]=7,    ["C#2"]=19,
  15.     ["Db1"]=7,    ["Db2"]=19,
  16.     ["D1"]=8,     ["D2"]=20,
  17.     ["D#1"]=9,    ["D#2"]=21,
  18.     ["Eb1"]=9,    ["Eb2"]=21,
  19.     ["E1"]=10,    ["E2"]=22,
  20.     ["F1"]=11,    ["F2"]=23,
  21.                   ["F#3"]=24,
  22.                   ["Gb3"]=24,
  23. }
  24.  
  25. local function playNote(instrument,note,volume)
  26.     volume = volume or 1
  27.     speaker.playNote(instrument,volume,notes[note])
  28. end
  29.  
  30. local function harp(note,volume)
  31.     playNote("harp",note,volume)
  32. end
  33.  
  34. --test
  35. local function a1()
  36.     harp "E1"
  37.     harp "G2"
  38.     harp "B2"
  39. end
  40.  
  41. local function a2()
  42.     harp "G2"
  43.     harp "C2"
  44.     harp "E2"
  45. end
  46.  
  47. local function a3()
  48.     harp "G2"
  49.     harp "B2"
  50.     harp "D2"
  51. end
  52.  
  53. local function a4()
  54.     harp "D1"
  55.     harp "F#2"
  56.     harp "A2"
  57. end
  58.  
  59. --[[
  60. --local bpm = 136
  61. --local bps = bpm / 60
  62. --local spb = 1 / bps
  63. --local quarter = spb / 4
  64. --]]
  65.  
  66. local function a(f,...)
  67.     local t={...}
  68.     for _,s in ipairs(t) do
  69.         if s > 0 then
  70.             f()
  71.             sleep(0.15 * s)
  72.         else
  73.             sleep(-0.15 * s)
  74.         end
  75.     end
  76. end
  77.  
  78. local function song()
  79.  
  80.     a(a1, 2,2,1,2,2)
  81.     a(a2, 1,2,2)
  82.     a(a3, 1,2,2)
  83.     a(a4, 1)
  84.  
  85.     a(a1, 2,2,1,2,2)
  86.     a(a2, 1)
  87.     a(a1, 2,2,1,2,2)
  88.     a(a2, 1)
  89.     a(a1, 2,2,1,2,2)
  90.  
  91.     a(a2, 1,2,2)
  92.     a(a3, 1,2,2)
  93.     a(a4, 1)
  94.  
  95.     a(a1, 2,2,1,2,2)
  96.     a(a2, 1)
  97.     a(a1, 2,2,1,2,2)
  98.     a(a2, 1)
  99.  
  100.     local t1 = 1/3
  101.     local t2 = 2/3
  102.     parallel.waitForAll(
  103.         function() a(a1, 2,2,1,2,2) end,
  104.         function() a(function()harp "B2" end, -t1,t1,t2,t2) end
  105.     )
  106.  
  107.     a(a2, 1,2,2)
  108.     a(a3, 1,2,2)
  109.     a(a4, 1)
  110.  
  111.     parallel.waitForAll(
  112.         function() a(a1, 2,2,1,2,2) end,
  113.         function() a(function()harp "B2" end, -t1,t1,t2,t2) end
  114.     )
  115.  
  116.     a(a2, 1)
  117.     a(a1, 2,2,1,2,2)
  118.     a(a2, 1)
  119.  
  120.     for i=1,4 do
  121.         parallel.waitForAll(
  122.             function() a(a1, 2,2,1) end,
  123.             function() a(function()harp "B2" end, -t1,t1,t2,t2) end
  124.         )
  125.     end
  126.  
  127.     for i=1,3 do
  128.         parallel.waitForAll(
  129.             function() a(a1, 2,2,1) end,
  130.             function() a(function()harp "B2" end, -t1,t1,t2,t1,t1) end
  131.         )
  132.     end
  133.  
  134.     parallel.waitForAll(
  135.         function() a(a1, 2,2,1) end,
  136.         function() a(function()harp "B2" end, -t1,t1,t2) end
  137.     )
  138.  
  139.     for j=1,3 do
  140.         a(a1, .5,.5,.5,.5,1)
  141.         a(a1, .5,.5,.5,.5,.5,.5,1)
  142.         a(a2, .5,.5,.5,.5,.5,.5,1)
  143.         a(a3, .5,.5,.5,.5,.5,.5,1)
  144.         a(a4, .5,.5)
  145.        
  146.         for i=1,3 do
  147.             a(a1, .5,.5,.5,.5,1)
  148.             a(a1, .5,.5,.5,.5,.5,.5,1)
  149.             a(a2, .5,.5)
  150.         end
  151.        
  152.         a(a2, .5,.5,.5,.5,1)
  153.         a(a3, .5,.5,.5,.5,.5,.5,1)
  154.         a(a4, .5,.5)
  155.     end
  156.  
  157. end
  158.  
  159. local function scrollWrite(text)
  160.     local w,h = term.getSize()
  161.    
  162.     text = string.rep(" ", w) .. text
  163.     term.clear()
  164.    
  165.     while #text > 0 do
  166.         sleep(0.5,text)
  167.         term.setCursorPos(1,h)
  168.         term.clearLine()
  169.         term.write(text)
  170.        
  171.         text = text:sub(2)
  172.     end
  173.     term.clear()
  174. end
  175.  
  176. local monitor = peripheral.wrap("bottom")
  177. term.redirect(monitor)
  178.  
  179. parallel.waitForAll(
  180.     function() scrollWrite("TEC_NO's Sound Thing Lol") end,
  181.     song
  182. )
  183.  
  184. term.redirect(term.native())
Advertisement
Add Comment
Please, Sign In to add comment