Jump to content




[API][MiscPeripherals] Music API (Iron Note Block)

media

1 reply to this topic

#1 mitterdoo

  • Members
  • 30 posts
  • LocationOregon, United States

Posted 02 February 2013 - 07:46 PM

Hello!
I have written an API that allows you to do better things with the Iron Note Block in MiscPeripherals addon. Remember, no command will work except music.bpm() if an Iron Note Block is not connected. You must restart the computer if you add or remove an Iron Note Block after the computer has started.Here are all of the commands:

music.noteblock()
Finds the iron note block connected to the computer. Returns nil if there is none.

music.bpm(float bpm)
Calculates and returns the distance between each beat in the given BPM in seconds.

music.note(string note)
Returns how many clicks it takes to reach the note given. Goes from F#3 to F#5. Also handles flats. Returns nil if no note block.

music.piano(int note)
Plays a piano sound to the Iron Note Block connected. Returns nil if no note block.

music.bassdrum(int note)
Same as above, but with a bass drum sound instead of a piano. Returns nil if no note block.

music.snare(int note)
Same as above, but with a snare drum. Returns nil if no note block.

music.click(int note)
Same as above, but with the click sound. Returns nil if no note block.

music.bass(int note)
Same as above, but with a bass guitar. Returns nil if no note block.


Download
pastebin get bFZRWJhA music

#2 Eric

  • Members
  • 92 posts
  • LocationUK

Posted 03 February 2013 - 06:01 AM

Pro-tip: instead of

a=peripheral.wrap("top")
b=peripheral.wrap("bottom")
c=peripheral.wrap("front")
d=peripheral.wrap("back")
e=peripheral.wrap("left")
f=peripheral.wrap("right")
if a then
  g=a
elseif b then
  g=b
elseif c then
  g=c
elseif d then
  g=d
elseif e then
  g=e
elseif f then
  g=f
else
  -- ...

consider using:

g = peripheral.wrap("top")
 or peripheral.wrap("bottom")
 or peripheral.wrap("front")
 or peripheral.wrap("back")
 or peripheral.wrap("left")
 or peripheral.wrap("right")

if not g then
   -- ...

Here's the same api, in half as many lines.

Edited by Eric, 03 February 2013 - 06:13 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users