Some Music

Scripting is easier for me, my music theory is more limited. Perhaps an interactive player piano script be fun?


** ROUTEROS PLAYER PIANO **
Type a key to play a note… The note will play for 00:00:00.125. Keep holding to continue playing.
A 466 Hz
C 277 Hz
D 311 Hz
F 370 Hz
G 415 Hz
a 440 Hz
b 493 Hz
c 262 Hz
d 294 Hz
e 330 Hz
f 349 Hz
g 392 Hz
Notes are in the 4th octive of the scientific scale.
Sharp # notes are denoted by using a CAPTIAL letter of the note.
Bonus: To play a longer note, type a number
e.g. 2 will play all future notes twice as long so 00:00:00.250. Hit 1 to reset to 00:00:00.125
To QUIT, hit “q”


{
:local nms 125ms
:local scale {"c"=262; "C"=277;"d"=294; "D"=311; "e"=330; "f"=349; "F"=370; "g"=392; "G"=415; "a"=440; "A"=466; "b"=493}
:local "ascii-map" {"";"NUL";"SOH";"STX";"ETX";"EOT";"ENQ";"ACK";"back";"back";"tab";"VT";"FF";"enter";"return";"SI";"DLE";"DC1";"DC2";"DC3";"DC4";"NAK";"SYN";"ETB";"CAN";"EM";"SUB";"ESC";"FS";"GS";"RS";"US";"space";"!";"\"";"comment";"\$";"%";"&";"";"(";")";"*";"+";",";"-";".";"/";"0";"1";"2";"3";"4";"5";"6";"7";"8";"9";":";";";"<";"=";">";"\?";"@";"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";"P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z";"[";"\\";"]";"^";"_";"`";"a";"b";"c";"d";"e";"f";"g";"h";"i";"j";"k";"l";"m";"n";"o";"p";"q";"r";"s";"t";"u";"v";"w";"x";"y";"z";"{";"|";"}";"~";"delete"}
:local lastkey 65535
:put "** ROUTEROS PLAYER PIANO **"
:put "Type a key to play a note...  The note will play for $nms.  Keep holding to continue playing."
:foreach nltr,nfreq in=$scale do={:put "\t$nltr  \t  $nfreq Hz"}
:put "Notes are in the 4th octive of the scientific scale."
:put "Sharp # notes are denoted by using a CAPTIAL letter of the note."
:put "Bonus: To play a longer note, type a number"
:put "   e.g. 2 will play all future notes twice as long so $($nms*2).  Hit 1 to reset to $(nms)"
:put "To QUIT, hit \"q\""
:local lnms $nms
:while (lastkey != 113) do={
    :set lastkey [/terminal inkey]
    :if ($lastkey = 65535) do={:delay $nms} else={
        :if ($lastkey > 48 && $lastkey < 58) do={:set $lnms ($nms*($lastkey - 48))}
        :local lastascii ($"ascii-map"->$lastkey)
        :local freq ($scale->$lastascii)
        :if ([:typeof $freq]="num") do={
            :beep frequency=$freq length=$lnms
        }
        :delay $lnms
        /terminal cuu 
    }
}
}