/music.lua Secret
Created
February 2, 2013 17:15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
print("Iron Note Block not present. API 'music' will not be used.") | |
end | |
-- put all the notes in a table | |
local notes = { | |
["F#3"] = 0, ["Gb3"] = 0, | |
["G3"] = 1, | |
["G#3"] = 2, ["Ab3"] = 2, | |
["A3"] = 3, | |
["A#3"] = 4, ["Bb3"] = 4, | |
["B3"] = 5, | |
["C4"] = 6, | |
["C#4"] = 7, ["Db4"] = 7, | |
["D4"] = 8, | |
["D#4"] = 9, ["Eb4"] = 9, | |
["E4"] = 10, | |
["F4"] = 11, | |
["F#4"] = 12, ["Gb4"] = 12, | |
["G4"] = 13, | |
["G#4"] = 14, ["Ab4"] = 14, | |
["A4"] = 15, | |
["A#4"] = 16, ["Bb4"] = 16, | |
["B4"] = 17, | |
["C5"] = 18, | |
["C#5"] = 19, ["Db5"] = 19, | |
["D5"] = 20, | |
["D#5"] = 21, ["Eb5"] = 21, | |
["E5"] = 22, | |
["F5"] = 23, | |
["F#5"] = 24, ["Ab5"] = 24 | |
} | |
-- return either the noteblock, or an empty table that doesn't error | |
function noteblock() | |
return g or {playNote = function() end} | |
end | |
-- try and convert the argument into a note | |
function note(name) | |
if type(name) == 'number' then | |
return name | |
else | |
return notes[name] | |
or error("Not a valid note name.") | |
end | |
end | |
-- shorthands | |
function piano(no) | |
noteblock().playNote(0, note(no)) | |
end | |
function bassdrum(no) | |
noteblock().playNote(1, note(no)) | |
end | |
function snare(no) | |
noteblock().playNote(2, note(no)) | |
end | |
function click(no) | |
noteblock().playNote(3, note(no)) | |
end | |
function bass(no) | |
noteblock().playNote(4, note(no)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment