Create: Computing AgesBrass Docs
Built-in programs

music

plays a tune through a speaker

Runs on Speaker Any computer a Speaker touches, and the Smartphone · 27 lines
Type this at the prompt of a computer to copy it onto the medium:
Terminal
> examples music
> edit music

The program

music
-- Plays "Frere Jacques" through a Speaker touching the computer (a
-- smartphone has its own). Another instrument: music bell
-- A note counts semitones from 0 to 24, like the clicks of a note
-- block: 6 is a C, 18 the C one octave higher.
if not sound then
  print("No sound: put a Speaker against the computer.")
  return
end
local instrument = arg[1] or "harp"  -- sound.instruments() lists them
local names = {[1] = "G", [6] = "C", [8] = "D", [10] = "E", [11] = "F", [13] = "G", [15] = "A"}
-- each note: its pitch, then how long it lasts in beats
local tune = {
  {6, 2}, {8, 2}, {10, 2}, {6, 2},
  {6, 2}, {8, 2}, {10, 2}, {6, 2},
  {10, 2}, {11, 2}, {13, 4},
  {10, 2}, {11, 2}, {13, 4},
  {13, 1}, {15, 1}, {13, 1}, {11, 1}, {10, 2}, {6, 2},
  {13, 1}, {15, 1}, {13, 1}, {11, 1}, {10, 2}, {6, 2},
  {6, 2}, {1, 2}, {6, 4},
  {6, 2}, {1, 2}, {6, 4},
}
for _, n in ipairs(tune) do
  sound.note(instrument, n[1])
  write(names[n[1]] .. " ")
  sleep(n[2] * 0.15)  -- a beat lasts 3 ticks
end
print()