Advertisement
Guest User

music

a guest
Feb 2nd, 2013
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. a=peripheral.wrap("top")
  2. b=peripheral.wrap("bottom")
  3. c=peripheral.wrap("front")
  4. d=peripheral.wrap("back")
  5. e=peripheral.wrap("left")
  6. f=peripheral.wrap("right")
  7. if a then
  8.   g=a
  9. elseif b then
  10.   g=b
  11. elseif c then
  12.   g=c
  13. elseif d then
  14.   g=d
  15. elseif e then
  16.   g=e
  17. elseif f then
  18.   g=f
  19. else
  20.   print("Iron Note Block not present. API 'music' will not be used.")
  21.   function noteblock()
  22.     return nil
  23.   end
  24.   function bpm(num)
  25.     return 1/num*60
  26.   end
  27.   function note()
  28.     return nil
  29.   end
  30.   function piano()
  31.     return nil
  32.   end
  33.   function bassdrum()
  34.     return nil
  35.   end
  36.   function snare()
  37.     return nil
  38.   end
  39.   function click()
  40.     return nil
  41.   end
  42.   function bass()
  43.     return nil
  44.   end
  45.   return
  46. end
  47. function noteblock()
  48.   return g
  49. end
  50. function bpm(num)
  51.   return 1/num*60
  52. end
  53. function note(name)
  54.   if name=="F#3" or name=="Gb3" then
  55.     return 0
  56.   elseif name=="G3" then
  57.     return 1
  58.   elseif name=="G#3" or name=="Ab3" then
  59.     return 2
  60.   elseif name=="A3" then
  61.     return 3
  62.   elseif name=="A#3" or name=="Bb3" then
  63.     return 4
  64.   elseif name=="B3" then
  65.     return 5
  66.   elseif name=="C4" then
  67.     return 6
  68.   elseif name=="C#4" or name=="Db4" then
  69.     return 7
  70.   elseif name=="D4" then
  71.     return 8
  72.   elseif name=="D#4" or name=="Eb4" then
  73.     return 9
  74.   elseif name=="E4" then
  75.     return 10
  76.   --elseif name=="E#4" or name=="Fb4" then
  77.     --return 10
  78.   elseif name=="F4" then
  79.     return 11
  80.   elseif name=="F#4" or name=="Gb4" then
  81.     return 12
  82.   elseif name=="G4" then
  83.     return 13
  84.   elseif name=="G#4" or name=="Ab4" then
  85.     return 14
  86.   elseif name=="A4" then
  87.     return 15
  88.   elseif name=="A#4" or name=="Bb4" then
  89.     return 16
  90.   elseif name=="B4" then
  91.     return 17
  92.   elseif name=="C5" then
  93.     return 18
  94.   elseif name=="C#5" or name=="Db5" then
  95.     return 19
  96.   elseif name=="D5" then
  97.     return 20
  98.   elseif name=="D#5" or name=="Eb5" then
  99.     return 21
  100.   elseif name=="E5" then
  101.     return 22
  102.   elseif name=="F5" then
  103.     return 23
  104.   elseif name=="F#5" or name=="Ab5" then
  105.     return 24
  106.   else
  107.     error("Not a valid note name.")
  108.   end
  109. end
  110. function piano(no)
  111.   if tonumber(no) then
  112.     noteblock().playNote(0,no)
  113.   else
  114.     noteblock().playNote(0,note(no))
  115.   end
  116. end
  117. function bassdrum(no)
  118.   if tonumber(no) then
  119.     noteblock().playNote(1,no)
  120.   else
  121.     noteblock().playNote(1,note(no))
  122.   end
  123. end
  124. function snare(no)
  125.   if tonumber(no) then
  126.     noteblock().playNote(2,no)
  127.   else
  128.     noteblock().playNote(2,note(no))
  129.   end
  130. end
  131. function click(no)
  132.   if tonumber(no) then
  133.     noteblock().playNote(3,no)
  134.   else
  135.     noteblock().playNote(3,note(no))
  136.   end
  137. end
  138. function bass(no)
  139.   if tonumber(no) then
  140.     noteblock().playNote(4,no)
  141.   else
  142.     noteblock().playNote(4,note(no))
  143.   end
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement