# Super Mario Bros. ground theme (overworld), Koji Kondo, 1985 - remastered for one beeper - https://lab.glossema.dev/play/mario-remastered/code # It plays the notes of https://lab.glossema.dev/play/mario-remastered, tone for tone. # Each part is written once: its lead, note by note, and the bass voice's notes on beats 1 and 3. # The form line is the playlist: the intro call, the A strain twice, the B strain twice, the C strain # (closing on the intro call), the A strain twice more, the D strain twice (the second ending on the arrival). # One speaker sounds every voice: a bass stroke, a grace or an answer takes its time out of the slot # of the note or rest it sits in, never out of the bar. { # The pitch of each note the tune sounds, in Hz :local hz { "C3"=131; "D3"=147; "F3"=175; "G3"=196; "G#3"=208; "B3"=247; "C4"=262; "E4"=330; "G4"=392; "G#4"=415; "A4"=440; "A#4"=466; "B4"=494; "C5"=523; "D5"=587; "D#5"=622; "E5"=659; "F5"=698; "F#5"=740; "G5"=784; "A5"=880; "B5"=988; "C6"=1047; "F6"=1397 } # Note values: e eighth, q quarter, d dotted quarter, h half, t a triplet note (three to a half). # The slot each takes in ms, how long a note sounds in it, and how long when a rest comes next. :local slots {"e"=150; "q"=300; "d"=450; "h"=600; "t"=200} :local full {"e"=120; "q"=270; "d"=405; "h"=540; "t"=180} :local light {"e"=90; "d"=270; "h"=360} # One slot of the lead, shared by the voices: the bass stroke, then a grace or an answer, each # paid out of the slot; the note, or the rest, takes what is left of it. :local share do={ :local spent 0 :if ([:len $bass] > 0) do={ :beep frequency=($hz->$bass) length=30ms :delay 35ms :set spent ($spent + 35) } :if ([:len $grace] > 0) do={ :beep frequency=($hz->$grace) length=22ms :delay 22ms :set spent ($spent + 22) } :if ([:len $answer] > 0) do={ :beep frequency=($hz->$answer) length=50ms :delay 60ms :set spent ($spent + 60) } :if ($note != "-") do={ :beep frequency=($hz->$note) length=(($length - $spent) * 1ms) } :delay (($slot - $spent) * 1ms) } # The parts, each written once. The lead, a bar to a line: note and value, a dash for a rest, # and after a rest the second voice's note that answers in it. The bass: the bass voice's note # struck on beat 1 and on beat 3 of each bar, a dash where it does not strike there. :local parts { "intro"={ "lead"={ "E5:e"; "E5:q"; "E5:q"; "C5:e"; "E5:q"; "G5:h"; "G4:h" }; "bass"={"D3"; "-"; "G4"; "G3"} }; "A"={ "lead"={ "C5:d"; "G4:d"; "E4:d"; "A4:q"; "B4:q"; "A#4:e"; "A4:e"; "-:e"; "G4:t"; "E5:t"; "G5:t"; "A5:e"; "-:e"; "F5:e"; "G5:q"; "E5:q"; "C5:e"; "D5:e"; "B4:d" }; "bass"={"G3"; "-"; "-"; "-"; "E3"; "F4"; "-"; "B3"} }; "B-opening"={ "lead"={ "-:q"; "G5:e"; "F#5:e"; "F5:e"; "D#5:e"; "-:e"; "E5:e"; "-:e"; "G#4:e"; "A4:e"; "C5:e"; "-:e"; "A4:e"; "C5:e"; "D5:e" }; "bass"={"C3"; "-"; "F3"; "C4"} }; "B-high"={ "lead"={ "-:q"; "G5:e"; "F#5:e"; "F5:e"; "D#5:e"; "-:e"; "E5:e"; "-:e"; "C6:e"; "-:e"; "C6:e"; "C6:h" }; "bass"={"C3"; "-"; "-"; "G5"} }; "B-close"={ "lead"={ "-:q"; "D#5:d"; "D5:d"; "C5:h"; "-:h" }; "bass"={"C3"; "-"; "C4"; "G3"} }; "C-opening"={ "lead"={ "C5:e"; "C5:q"; "C5:q"; "C5:e"; "D5:e"; "-:e"; "E5:e"; "C5:e"; "-:e"; "A4:e"; "G4:h" }; "bass"={"G#2"; "-"; "G3"; "-"} }; "C-answer"={ "lead"={ "C5:e"; "C5:e"; "-:e"; "C5:e"; "-:e"; "C5:e"; "D5:e"; "E5:d"; "-:d"; "-:d" }; "bass"={"G#2"; "-"; "G3"; "-"} }; "D-opening"={ "lead"={ "E5:e"; "C5:q"; "G4:d"; "G#4:q"; "A4:e"; "F5:e"; "-:e"; "F5:e"; "A4:h" }; "bass"={"C3"; "G3"; "F3"; "C4"} }; "D-climb"={ "lead"={ "B4:t"; "A5:t"; "A5:t"; "A5:t"; "G5:t"; "F5:t"; "E5:e"; "C5:e"; "-:e"; "A4:e"; "G4:h" }; "bass"={"D3"; "G3"; "G3"; "C4"} }; "D-close"={ "lead"={ "B4:e"; "F5:e"; "-:e"; "F5:e"; "F5:t"; "E5:t"; "D5:t"; "C5:h"; "-:h:C4" }; "bass"={"G3"; "G3"; "C4"; "C3"} } } # Graces, 22ms, by part and pass: each in front of the first note of its name. # On its fourth pass the A strain puts the octave above in front of its first C5 and its first F5. :local graces { "intro 1"={"G5"="F#5"}; "B-opening 1"={"G5"="A5"}; "B-high 1"={"C6"="B5"}; "B-high 2"={"C6"="B5"}; "C-answer 1"={"E5"="D#5"}; "A 4"={"C5"="C6"; "F5"="F6"} } # The playlist: the form line, part by part :local form { "intro"; "A"; "A"; "B-opening"; "B-high"; "B-opening"; "B-close"; "B-opening"; "B-high"; "B-opening"; "B-close"; "C-opening"; "C-answer"; "C-opening"; "intro"; "A"; "A"; "D-opening"; "D-climb"; "D-opening"; "D-close"; "D-opening"; "D-climb"; "D-opening"; "D-close" } # The strains, by the part each one begins with, as the terminal names them :local strains { "intro"="Intro call"; "A"="A strain"; "B-opening"="B strain"; "C-opening"="C strain"; "D-opening"="D strain" } # Where a strain begins: at the first part, and after each part that closes one (the intro # call, an A, B-close, D-close). Count how many times each strain plays. :local titles [:toarray ""] :local plays [:toarray ""] :foreach title in=$strains do={ :set ($plays->$title) 0 } :local begins true :foreach part in=$form do={ :local title "" :if ($begins) do={ :set title ($strains->$part) :set ($plays->$title) (($plays->$title) + 1) } :set titles ($titles, $title) :set begins (($part = "intro") || ($part = "A") || ($part = "B-close") || ($part = "D-close")) } # Play the form, part by part :local heard [:toarray ""] :foreach title in=$strains do={ :set ($heard->$title) 0 } :local passes [:toarray ""] :foreach part in=$form do={ :set ($passes->$part) 0 } :local last ([:len $form] - 1) :for i from=0 to=$last do={ :local part ($form->$i) :local lead ($parts->$part->"lead") :local bass ($parts->$part->"bass") # The graces this pass of the part sounds :set ($passes->$part) (($passes->$part) + 1) :local pass ($part . " " . ($passes->$part)) :local pending [:toarray ""] :foreach which,notes in=$graces do={ :if ($which = $pass) do={ :set pending $notes } } # The last part ends on the arrival: its closing rest is not played :local end ([:len $lead] - 1) :if ($i = $last) do={ :set end ($end - 1) } # Each strain is announced as it begins, with its count when it plays more than once :local title ($titles->$i) :if ($title != "") do={ :set ($heard->$title) (($heard->$title) + 1) :if (($plays->$title) > 1) do={ :set title ($title . " " . ($heard->$title) . " of " . ($plays->$title)) } :put $title } :local onset 0 :for k from=0 to=$end do={ # One step of the lead: a note or a dash, its value, and the answer after a rest :local step ($lead->$k) :local colon [:find $step ":"] :local note [:pick $step 0 $colon] :local value [:pick $step ($colon + 1)] :local answer "" :if ([:len $step] > ($colon + 3)) do={ :set answer [:pick $step ($colon + 3) [:len $step]] } # A note sounds light when a rest comes next, in this part or at the start of the next :local next "" :if ($k < ([:len $lead] - 1)) do={ :set next ($lead->($k + 1)) } else={ :set next ($parts->($form->($i + 1))->"lead"->0) } :local length ($full->$value) :if ([:pick $next 0 1] = "-") do={ :set length ($light->$value) } :local slot ($slots->$value) # On beats 1 and 3, where a step begins, the bass strikes, moved into the third octave; # never in front of a triplet note :local stroke "" :if ((($onset % 600) = 0) && ($value != "t")) do={ :local struck ($bass->($onset / 600)) :if ($struck != "-") do={ :set stroke ([:pick $struck 0 ([:len $struck] - 1)] . "3") } } # A grace sounds once, in front of the first note of its name :local grace "" :foreach name,sound in=$pending do={ :if ($name = $note) do={ :set grace $sound } } :if ([:len $grace] > 0) do={ :set ($pending->$note) "" } # The arrival: the last C5 held 1500ms after the 35ms of its bass stroke :if (($i = $last) && ($k = $end)) do={ :set length (35 + 1500) :set slot (35 + 1500) } $share hz=$hz note=$note bass=$stroke grace=$grace answer=$answer length=$length slot=$slot :set onset ($onset + ($slots->$value)) } } }