The call is a line of text, and a table turns each letter into dits and dahs; loops key them with the code’s own spaces between, print each word as it goes out, and send the call twice with a silence to listen. It plays the same notes as the notes page, tone for tone.
1# CQ, a general call in International Morse code (ITU-R M.1677-1). No composer; the words are the arranger's. https://lab.glossema.dev/play/morse-cq/code2# It plays the notes of https://lab.glossema.dev/play/morse-cq, tone for tone.3# CQ calls all stations, DE means from, ROUTER is the station calling and K invites a reply.4# One tone, F5 at 698 Hz, keyed on and off at 20 words per minute: a unit of 60 ms.5# A dit sounds for one unit and a dah for three. The silence is one unit between the6# signals of a letter, three between letters and seven between words.7# The call goes out twice, with a pause between to listen for an answer.8{9:localcall"CQ CQ DE ROUTER ROUTER K"10# Each letter of the call in Morse code: a dot for a dit, a dash for a dah.11:localmorse{"C"="-.-.";"D"="-..";"E"=".";"K"="-.-";"O"="---";"Q"="--.-";"R"=".-.";"T"="-";"U"="..-"}12:localpitch 69813:localunit 60ms14:localdit$unit15:localdah($unit* 3)16:forpassfrom=1 to=2 do={17# Before the second call, listen for a reply: 34 units after the word space.18:if($pass= 2)do={:delay($unit* 34)}19:localstart 020:while($start<[:len$call])do={21# A word runs up to the next space; a space after the call ends the last one.22:localend[:find($call." ")" "$start]23:localword[:pick$call$start$end]24:put$word25:forifrom=0 to=([:len$word]- 1)do={26:localletter[:pick$word$i]27:localcode($morse->$letter)28:forjfrom=0 to=([:len$code]- 1)do={29:if([:pick$code$j]=".")do={30:beepfrequency=$pitchlength=$dit31:delay$dit32 }else={33:beepfrequency=$pitchlength=$dah34:delay$dah35 }36# One unit of silence after every signal,37:delay$unit38 }39# two more after a letter, to make three,40:delay($unit* 2)41 }42# and four more after a word, to make seven.43:delay($unit* 4)44:setstart($end+ 1)45 }46 }47}
One command sounds one tone: :beep frequency=<hertz> length=<time>; the beeper plays one note at a time.
:delay is the clock. A beep starts the tone and returns at once, so every note is a beep followed by a delay of the same length and a small gap.
Most tunes here are written out note by note, a beep and a delay each; some also come as code, with loops, tables and functions, that plays the very same notes. Download any of these and run it in a terminal.