Morse code: Difference between revisions
m
→{{header|EasyLang}}
(Added solution for Action!) |
|||
(17 intermediate revisions by 11 users not shown) | |||
Line 22:
from standard input until EOF is reached.
<
bits 16
;;; I/O ports
Line 213:
section .bss
buf: resb 1024 ; 1K buffer
.size: equ $-buf</
=={{header|ABAP}}==
<
TYPES: BEGIN OF y_morse_code,
letter TYPE string,
Line 287:
ELSE LET prev = index - 1 IN to_upper( word+prev(1) ) ) ]-code OPTIONAL )
IN NEXT word_coded = |{ word_coded } { _morse_code }| ) ) ) )
)->display( ).</
=={{header|Action!}}==
<
DEFINE COUNT="$60"
Line 413:
Process("Atari Action!")
Process("www.rosettacode.org")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Morse_code.png Screenshot from Atari 8-bit computer]
Line 432:
Specification of the package :
<
type Symbols is (Nul, '-', '.', ' ');
Line 471:
others => (1, " ")); -- Dummy => Other characters do not need code.
end Morse;</
<
use Ada, Ada.Strings, Ada.Strings.Maps, Interfaces;
Line 543:
Dit_ms := C.unsigned (Integer (Dit * 1000));
Dah_ms := C.unsigned (Integer (Dah * 1000));
end Morse;</
Main program :
<
procedure Morse_Tx is
begin
Morsebeep (Convert ("Science sans Conscience"));
end Morse_Tx;</
=={{header|AppleScript}}==
Line 555:
This caters for non-diacritical English letters, numerals, and the punctuation found on the Wikipedia page and makes a burping noise for anything else. The morse sounds brisker and smoother if the script's run as an application or from Script Menu rather than in Script Editor or Script Debugger.
<
use framework "Foundation"
use framework "AppKit"
Line 623:
-- Test code:
morseCode("Coded in AppleScrip†.")</
=={{header|Arturo}}==
<
code: #[
Line 660:
]
print out</
{{out}}
Line 670:
The frequency and element length are stored near the bottom of the script.
It uses the short form of if else that is implemented, to not have such a long script
<
MorseBeep(teststring) ;Beeps our string after conversion
return ;End Auto-Execute Section
Line 691:
} ;Spaces are extended. Sleep pauses the script
return morse ;Returns the text in morse code
} ; ---End Function Morse---</
=={{header|AWK}}==
AWK cannot play sounds by itself,
so here we just translate text to dits and dots:
<
BEGIN { FS="";
m="A.-B-...C-.-.D-..E.F..-.G--.H....I..J.---K-.-L.-..M--N-.";
Line 716:
printf("\n");
}
</syntaxhighlight>
{{Out}} with input "sos sos titanic"
Line 727:
{{works with|GNU bash, version 4 + sox (optional)}}
<
#!/bin/bash
# michaeltd 2019-11-29 https://github.com/michaeltd/dots/blob/master/dot.files/.bashrc.d/.var/morse.sh
Line 778:
fi
</syntaxhighlight>
{{out}} (input: sos titanic sos):
<pre>
Line 805:
Note that this will ''only'' work as-is under [[DOS]] (and [[Windows]] 9x); under NT systems, the <code>player</code> routine must be changed to use the <code>Beep</code> API call. ([http://www.freebasic.net/forum/viewtopic.php?p=20441#20441 This forum post] details how to use the speaker under Linux, DOS, and Windows in FreeBASIC; the Linux & DOS code differs further from the below by require inline assembly.)
<
'this determines the length of the notes
Line 864:
PLAY "p" + LTRIM$(STR$(noteLen))
NEXT i%
END SUB</
{{out}} (2 runs):
Line 876:
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<
DIM morse$(63)
FOR char% = 0 TO 63 : READ morse$(char%) : NEXT char%
Line 901:
DATA 33333,13333,11333,11133,11113,11111,31111,33111,33311,33331,333111,313131,6,31113,6,113311
DATA 133131,13,3111,3131,311,1,1131,331,1111,11,1333,313,1311,33,31,333
DATA 1331,3313,131,111,3,113,1113,133,3113,3133,3311,6,6,6,6,113313</
==={{header|Chipmunk Basic}}===
{{trans|Yabasic}}
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 rem Morse code
20 dim c$(54)
30 for f = 1 to 54
40 read l$ : read m$
50 d$ = d$+l$ : c$(f) = m$
60 next f
100 line input "Message? ";t$
105 t$ = ucase$(t$)
110 for f = 1 to len(t$)
120 p = instr(d$,mid$(t$,f,1))
130 if p > 0 then print c$(p); else print "?";
140 next f
150 print
160 goto 100
1000 data "A","._","B","_...","C","_._.","D","_..","E",".","F",".._."
1010 data "G","__.","H","....","I","..","J",".___","K","_._","L","._.."
1020 data "M","__","N","_.","O","___","P",".__.","Q","__._","R","._."
1030 data "S","...","T","_","U",".._","V","..._","W",".__","X","_.._"
1040 data "Y","_.__","Z","__..","1",".____","2","..___","3","...__"
1050 data "4","...._","5",".....","6","_....","7","__...","8","___.."
1060 data "9","____.","0","_____",".","._._._",",","__..__","?","..__.."
1070 data "'",".____.","!","_._.__","/","_.._.","(","_.__.",")","_.__._"
1080 data "&","._...",":","___...",";","_._._.","=","_..._","+","._._.","-","_...._"
1090 data "_","..__._","\","._.._.","$","..._.._","@",".__._."</syntaxhighlight>
==={{header|IS-BASIC}}===
<
110 STRING TONE$(48 TO 90)*5,ST$*254
120 SET CHARACTER 46,0,0,0,0,24,24,0,0,0:SET CHARACTER 47,0,0,0,0,126,126,0,0,0
Line 931 ⟶ 959:
350 CLEAR FONT
360 DATA .////,..///,...//,..../,.....,/....,//...,///..,////.,/////,"","","","","","",""
370 DATA ./,/...,/./.,/..,.,../.,//.,....,..,.///,/./,./..,//,/.,///,.//.,//./,./.,...,/,../,.../,.//,/../,/.//,//..</
==={{header|Commodore BASIC}}===
{{works with|Commodore BASIC|7.0}}
Line 937 ⟶ 965:
some of its structured programming features, such as DO...LOOP and BEGIN...BEND.</p>
<
110 DA$="Q.A": REM DA = DOTTED QUARTER NOTE
120 IS$="IR" : REM SPACE BETWEEN SYMS=1xDOT
Line 989 ⟶ 1,017:
620 DATA ".",".-.-.-", ",","--..--"
630 DATA "?","..--.."
640 DATA ""</
=={{header|Befunge}}==
Since Befunge doesn't have a way to output sound, this implementation just generates a text representation of the morse. The string to convert is read from stdin.
<
^v('_')v!:-*57g+3/"!"\%"!":+1\-*<
^$$,*84_\#!:#:2#-%#15#\9#/*#2+#,<
Line 1,002 ⟶ 1,030:
'(&*&#$&&*'$&)'%'/'########6)##$%
1'-')&$$.''&2'&%$'%&0'#%%%#&,'''(
&*&#$&&*'$&)'%'/'################</
{{out}}
Line 1,012 ⟶ 1,040:
One could substitute another program for ubuntu beep command.
<syntaxhighlight lang="c">
/*
Line 1,091 ⟶ 1,119:
return 0;
}
</syntaxhighlight>
=={{header|C sharp|C#}}==
<
using System.Collections.Generic;
Line 1,132 ⟶ 1,160:
}
}
</syntaxhighlight>
=={{header|C++}}==
<syntaxhighlight lang="c++">
/*
Michal Sikorski
Line 1,205 ⟶ 1,233:
}
</syntaxhighlight>
=={{header|Clojure}}==
<
(defn play [sample-rate bs]
Line 1,262 ⟶ 1,290:
(apply concat ,)
byte-array
(play sample-rate ,)))</
=={{header|CoffeeScript}}==
<
constructor : (@unit=0.05, @freq=700) ->
Line 1,315 ⟶ 1,343:
morse = new Morse()
morse.send 'hello world 0123456789'</
=={{header|D}}==
<syntaxhighlight lang="d">
import std.conv;
import std.stdio;
Line 1,377 ⟶ 1,405:
}
}
</syntaxhighlight>
=={{header|Delphi}}==
<syntaxhighlight lang="delphi">
program Morse;
Line 1,454 ⟶ 1,482:
Dictionary.Free;
end;
end.</
=={{header|EasyLang}}==
<syntaxhighlight>
txt$ = "sos sos"
#
chars$
code$[] = [ ".-" "-..." "-.-." "-.." "." "..-." "--." "...." ".." ".---" "-.-" ".-.." "--" "-." "---" ".--." "--.-" ".-." "..." "-" "..-" "...-" ".--" "-..-" "-.--" "--.." " " ]
#
if ind
write ch$ & " "
sleep 0.8
.
.
.
for ch$ in
.
</syntaxhighlight>
=={{header|EchoLisp}}==
<
(require 'json)
(require 'hash)
Line 1,515 ⟶ 1,543:
(else (writeln) (blink)))
(set! EMIT (rest EMIT))))
</syntaxhighlight>
{{out}}
<pre>
Line 1,528 ⟶ 1,556:
=={{header|Elixir}}==
<
@morse %{"!" => "---.", "\"" => ".-..-.", "$" => "...-..-", "'" => ".----.",
"(" => "-.--.", ")" => "-.--.-", "+" => ".-.-.", "," => "--..--",
Line 1,552 ⟶ 1,580:
end
IO.puts Morse.code("Hello, World!")</
{{out}}
Line 1,559 ⟶ 1,587:
</pre>
=={{header|F_Sharp|F#}}==
<
open System
open System.Threading
Line 1,595 ⟶ 1,623:
send "Rosetta Code"
</syntaxhighlight>
{{out}}
<pre>._. ___ ... . _ _ ._ _._. ___ _.. .</pre>
=={{header|Factor}}==
<
"Hello world!" play-as-morse</
=={{header|Forth}}==
Line 1,607 ⟶ 1,635:
The Morse code generator could have taken the form of a look-up array with bit patterns cross referencing dits and dahs, but we instead used the Forth dictionary, which is functionally like a big case statement. By making each letter an executable routine in Forth we get a very succinct way to code our Morse. Proper sounding morse code requires precise time delays between the dits, dahs, letters and words. The program uses the Forth word "ms" which delays for n milliseconds and gives us real time control. This morse code sounds right.
There is a lot accomplished in 75 lines of code for a "low level" language.
<syntaxhighlight lang="text">
HEX
\ PC speaker hardware control (requires GIVEIO or DOSBOX for windows operation)
Line 1,691 ⟶ 1,719:
PREVIOUS DEFINITIONS \ go back to previous namespace
: TRANSMIT MORSE TRANSMIT PREVIOUS ;</
Test at the Forth console
Line 1,699 ⟶ 1,727:
=={{header|FreeBASIC}}==
<
' FB 1.05.0 Win64
Line 1,776 ⟶ 1,804:
DyLibFree(library)
End
</syntaxhighlight>
=={{header|FutureBasic}}==
When compiled with FB, this code produces a packaged, stand-alone 64-bit application that will run on either Intel or the newer M-series Macs. It translates a text string into Morse Code and plays back characters along with their respective sounds. The oscillator frequency and volume, along with letter and word spacing, can be adjusted with the definitions at the head of the file. While the code meets the Rosetta Code parameters, it's by no means exhaustive. For instance, it does not include translation of punctuation or prosigns, and the GUI is minimal. It's simply a proof of concept. It's been tested on Catalina (10.15.x) to Monterey (12.4.x) with Ventura still in beta at the time of this post. The free FB compiler is available on the
[http://www.brilorsoftware.com/fb/pages/home.html FutureBasic] home page.
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
include "Tlbx AVKit.incl"
#define VOLUME 0.2
#define HZ_FREQUENCY 440.0
_ditDelay = 100
_dahDelay = 200
_spcDelay = 300
void local fn PlayCodeDone( ref as AVAudioPlayerNodeRef, userData as ptr )
NSLog(@"%@\b",userData)
end fn
local fn PlayFrequency( frequency as float, amplitude as float, character as CFStringRef ) as AVAudioPlayerNodeRef
static AVAudioEngineRef audioEngine
audioEngine = fn AVAudioEngineInit
AVAudioPlayerNodeRef player = fn AVAudioPlayerNodeInit
AVAudioMixerNodeRef mixer = fn AVAudioEngineMainMixerNode( audioEngine )
float sampleRate = fn AVAudioFormatSampleRate( fn AVAudioNodeOutputFormatForBus( mixer, 0 ) )
AVAudioFrameCount frameBufferLength = fn floorf( sampleRate / frequency ) * 1
AVAudioPCMBufferRef buffer = fn AVAudioPCMBufferWithFormat( fn AVAudioNodeOutputFormatForBus( player, 0 ), frameBufferLength )
AVAudioPCMBufferSetFrameLength( buffer, frameBufferLength )
NSInteger channelCount = fn AVAudioFormatChannelCount( fn AVAudioNodeOutputFormatForBus( mixer, 0 ) )
AVAudioFrameCount frameLength = fn AVAudioPCMBufferFrameLength( buffer )
ptr p = (ptr)fn AVAudioPCMBufferFloatChannelData(buffer)
xref floatChannelData(100) as ^float
floatChannelData = p
long i, channelNumber
float theta, value
^float channelBuffer
for i = 0 to frameLength - 1
theta = frequency * i * 2.0 * M_PI / sampleRate
value = fn sinf(theta)
for channelNumber = 0 to channelCount - 1
channelBuffer = floatChannelData(channelNumber)
cln channelBuffer[i] = value * amplitude;
next
next
AVAudioEngineAttachNode( audioEngine, player )
AVAudioEngineConnect( audioEngine, player, mixer, fn AVAudioNodeOutputFormatForBus( player, 0 ) )
fn AVAudioEngineStart( audioEngine, NULL )
AVAudioPlayerNodePlay( player )
AVAudioPlayerNodeScheduleBufferAtTime( player, buffer, NULL, AVAudioPlayerNodeBufferLoops, @fn PlayCodeDone, (ptr)character )
end fn = player
void local fn PlayMorseCode( play as BOOL, character as CFStringRef )
static AVAudioPlayerNodeRef player
select ( play )
case YES : player = fn PlayFrequency( HZ_FREQUENCY, VOLUME, character )
case NO : AVAudioPlayerNodeStop( player ) // : AppRemoveAllProperties
end select
end fn
local fn ParseCodeAndPlay( character as CFStringRef )
dispatchmain
if fn StringIsEqual( character, @"." ) then timerbegin : fn PlayMorseCode( YES, character ) : delay _ditDelay : fn PlayMorseCode( NO, NULL ) : timerend
if fn StringIsEqual( character, @"-" ) then timerbegin : fn PlayMorseCode( YES, character ) : delay _dahDelay : fn PlayMorseCode( NO, NULL ) : timerend
if fn StringIsEqual( character, @" " ) then timerbegin : NSLog(@" \b") : delay _spcDelay : timerend
if fn StringIsEqual( character, @"\n" ) then timerbegin : NSLog(@"") : timerend
dispatchend
end fn
local fn MorseCharacter( letter as CFStringRef ) as CFStringRef
CFDictionaryRef morseDict = @{
@"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":@"--..", @"0":@"-----",
@"1":@".----", @"2":@"..---", @"3":@"...--",
@"4":@"....-", @"5":@".....", @"6":@"-....",
@"7":@"--...", @"8":@"---..", @"9":@"----."}
end fn = morseDict[letter]
local fn BuildMorseString( asciiStr as CFStringRef ) as CFStringRef
NSInteger i
CFStringRef processStr = fn StringLowerCaseString( asciiStr )
CFMutableStringRef mutStr = fn MutableStringWithCapacity(0)
NSInteger length = len( processStr )
for i = 0 to length - 1
CFStringRef temp = mid( processStr, i, 1 )
select ( temp )
case @"\n", @"\r"
MutableStringAppendString( mutStr, @"\n" )
case else
CFStringRef code = fn MorseCharacter( temp )
if ( code != NULL )
MutableStringAppendString( mutStr, fn StringByAppendingString( code, @" " ) )
else
MutableStringAppendString( mutStr, @" " )
end if
end select
next
end fn = fn StringWithString( mutStr )
local fn MorseCodeAudio( morseStr as CFStringRef )
NSInteger i
NSInteger length = len( morseStr )
for i = 0 to length - 1
CFStringRef temp = mid( morseStr, i, 1 )
fn ParseCodeAndPlay( temp )
next
end fn
local fn OutputMorseCode( morseStr as CFStringRef )
NSLog( @"\nSample ham radio Morse Code transmission:\n\n%@", morseStr )
CFStringRef codeStr = fn BuildMorseString( morseStr )
NSLog( @"\n\nMorse Code:\n\n%@", codeStr )
NSLog( @"\n\nAudio playing...\n" )
dispatchglobal
fn MorseCodeAudio( codeStr )
dispatchend
end fn
CFStringRef morseStr = @"CQ CQ CQ DE K1XYZ K1XYZ K TRANSMIT K1XYZ DE W1ZZZ TKS FOR CALL UR RST 479 479 NAME KEN KEN QTH NR KENTUCKY KENTUCKY G3ZZY DE W1ZZZ K"
fn OutputMorseCode( morseStr )
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Sample ham radio Morse Code transmission:
CQ CQ CQ DE K1XYZ K1XYZ K TRANSMIT K1XYZ DE W1ZZZ TKS FOR CALL UR RST 479 479 NAME KEN KEN QTH NR KENTUCKY KENTUCKY K1XYZ DE W1ZZZ K
Morse Code:
-.-. --.- -.-. --.- -.-. --.- -.. . -.- .---- -..- -.-- --.. -.- .---- -..- -.-- --.. -.- - .-. .- -. ... -- .. - -.- .---- -..- -.-- --.. -.. . .-- .---- --.. --.. --.. - -.- ... ..-. --- .-. -.-. .- .-.. .-.. ..- .-. .-. ... - ....- --... ----. ....- --... ----. -. .- -- . -.- . -. -.- . -. --.- - .... -. .-. -.- . -. - ..- -.-. -.- -.-- -.- . -. - ..- -.-. -.- -.-- --. ...-- --.. --.. -.-- -.. . .-- .---- --.. --.. --.. -.-
Audio playing...
-.-. --.- -.-. --.- -.-. --.- -.. . -.- .---- -..- -.
</pre>
=={{header|Gambas}}==
<
Public Sub Main()
Line 1,830 ⟶ 2,026:
Next
End</
Output (plus sound):
<pre>
Line 1,838 ⟶ 2,034:
=={{header|Go}}==
<
// showing the output on the console, and playing it as sound.
// Only works on ubuntu.
Line 1,991 ⟶ 2,187:
}
</syntaxhighlight>
=={{header|Haskell}}==
Line 2,000 ⟶ 2,196:
The main program.
<syntaxhighlight lang="haskell">
import System.IO
import MorseCode
Line 2,011 ⟶ 2,207:
text <- getContents
play $ toMorse text
</syntaxhighlight>
The module to convert text to Morse code symbols.
<syntaxhighlight lang="haskell">
module MorseCode (Morse, MSym(..), toMorse) where
Line 2,051 ⟶ 2,247:
fromChar = fromJust . flip M.lookup dict
weed = filter (\c -> c == ' ' || M.member c dict)
</syntaxhighlight>
The module to interpret Morse code symbols as sound.
<syntaxhighlight lang="haskell">
module MorsePlaySox (play) where
Line 2,094 ⟶ 2,290:
play :: Morse -> IO ExitCode
play = simple put none rate . concatMap toSamples
</syntaxhighlight>
=={{header|J}}==
<
morse=:[:; [:(' ',~' .-' {~ 3&#.inv)&.> (_96{.".0 :0-.LF) {~ a.&i.@toupper
79 448 0 1121 0 0 484 214 644 0 151 692 608 455 205 242 161 134 125 122
Line 2,106 ⟶ 2,302:
onoffdur=: 0.01*100<.@*(1.2%[)*(4 4#:2 5 13){~' .-'i.]
playmorse=: 30&$: :((wavnote&, 63 __"1)@(onoffdur morse))</
Example use:
<syntaxhighlight lang="text"> morse'this is an example'
- .... .. ... .. ... .- -. . -..- .- -- .--. .-.. .
playmorse'this is an example'
1
12 playmorse'as is this'
1</
morse converts from text to dot dash notation
Line 2,135 ⟶ 2,331:
=={{header|Java}}==
{{works with|java|7}}
<
public class MorseCode {
Line 2,178 ⟶ 2,374:
System.out.println("\n");
}
}</
<pre>sos
Line 2,193 ⟶ 2,389:
This implementation utilises the fairly new Web Audio API in the browser for generating tones, as such it only uses one vendor implementation (WebKit). It is split into three modules; 1. translating the characters into morse code. 2. creating timings for the morse code. 3. creating tones with the timings.
<syntaxhighlight lang="javascript">
var globalAudioContext = new webkitAudioContext();
Line 2,277 ⟶ 2,473:
return cont;
}
</syntaxhighlight>
Usage:
<syntaxhighlight lang="javascript">
morsecode('Hello World');
</syntaxhighlight>
{{out}}
Line 2,291 ⟶ 2,487:
=={{header|Julia}}==
Requires a sound card and the PortAudio libraries.
<
const pstream = PortAudioStream(0, 2)
Line 2,322 ⟶ 2,518:
sendmorse("sos sos sos")
sendmorse("The case of letters in Morse coding is ignored."
</syntaxhighlight>
=={{header|Kotlin}}==
Line 2,328 ⟶ 2,524:
Java does not have easy access to the beep method, so we need to create one using the Audio API it provides.
<
import javax.sound.sampled.AudioSystem
Line 2,389 ⟶ 2,585:
playMorseCode(toMorseCode(it.toLowerCase()))
}
}</
=={{header|Liberty BASIC}}==
<
Input "Input the text to translate to Morse Code... "; string$
Print PlayMorse$(string$)
Line 2,446 ⟶ 2,642:
Data "@", ".--.-.", "(", "-.--.", ")", "-.--.-", "_", "..--.-", "$", "...-..-", "&", ".-..."
Data "=", "-...-", "!", "..--.", " ", " ", "End", ""
End Function </
=={{header|Lua}}==
The following code is actual eLua code used to beep the speaker in Morse code n the Shenzhou III STM32F103ZET6 evaluation board. eLua is a Lua 5.1.4 implementation paired with libraries for low-level hardware access in embedded systems. The below code could easily be converted to any other Lua 5.n environment (including games), provided some kind of sound library has been installed. Only the functions buzz and pause would have to be modified.
<
-- module-local variables
Line 2,543 ⟶ 2,739:
init(50000)
return M</
Using this module is as simple as:
<
morse.beep "I am the very model of a modern major-general."</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Line 2,557 ⟶ 2,753:
The function, sonicMorse[s_String], plays the Morse code audio translation of a string.
<
mark = 0.1; gap = 0.125; (* gap should be equal to mark. But longer gap makes audio code easier to decode *)
shortgap = 3*gap; medgap = 7*gap;
Line 2,589 ⟶ 2,785:
morseCode[s_String] := StringReplace[ToLowerCase@s, codeRules~Join~{x_ /; FreeQ[Flatten@{Dictionary, " "}, x] -> "? "}]
morseDecode[s_String] := StringReplace[s, decodeRules]
sonicMorse[s_String] := EmitSound@Sound@Flatten[Characters@morseCode@s /. soundRules]</
{{out|Text example}}
Line 2,605 ⟶ 2,801:
This function will remove any characters not defined in the morse code.
<
%% Translate AlphaNumeric Text to Morse Text
Line 2,675 ⟶ 2,871:
end
end %text2morse</
{{out}} This will play the audio automatically, because the playSound argument is "true".
<
ans =
-.-.|.-|.-..|.-..| |--|.| |..|...|....|--|.-|.|.-..|</
=={{header|Modula-2}}==
<
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
Line 2,746 ⟶ 2,942:
ReadChar;
END MorseCode.</
=={{header|Nim}}==
Text mode only. The text to translate is provided in the command line.
<
const Morse = {'A': ".-", 'B': "-...", 'C': "-.-.", 'D': "-..", 'E': ".",
Line 2,774 ⟶ 2,970:
for arg in commandLineParams():
m.add morse(arg)
echo m.join(" ")</
{{out}}
Line 2,783 ⟶ 2,979:
Using <code>/dev/dsp</code>:
<
'a', ".-"; 'b', "-..."; 'c', "-.-.";
'd', "-.."; 'e', "."; 'f', "..-.";
Line 2,828 ⟶ 3,024:
| _ -> prerr_endline "unknown char")
let () = morse "rosettacode morse"</
=={{header|Ol}}==
Line 2,834 ⟶ 3,030:
To simplify the example will be used only lower letter case.
<syntaxhighlight lang="ol">
(display "Please, enter the string in lower case bounded by \" sign: ")
(lfor
Line 2,860 ⟶ 3,056:
; <== "hello world"
; ==> ......-...-..--- .-----.-..-..-..
</syntaxhighlight>
=={{header|PARI/GP}}==
<
while((ms-=gettime()) > 0,);
};
Line 2,877 ⟶ 3,073:
};
Morse("...---...")</
=={{header|Pascal}}==
Line 2,884 ⟶ 3,080:
This program uses OpenAL for cross-platform PCM audio.
<syntaxhighlight lang="pascal">
{$mode delphi}
PROGRAM cw;
Line 3,006 ⟶ 3,202:
AlutExit();
END.
</syntaxhighlight>
=={{header|Perl}}==
<
SetMorseVals(20,30,400);
SendMorseMsg('Hello World! abcdefg @\;'); # note, caps are ingnored in Morse Code
exit;</
The above code requires:
Line 3,025 ⟶ 3,221:
=={{header|Phix}}==
With Baden-Powell menemonics.
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Morse_code.htm here].
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Morse_code.exw
-- ===========================
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #7060A8;">beep</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">input</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">output</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">vbox</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dlg</span>
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">title</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Morse code"</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">help_text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Enter a message to
Press Return to listen to the result.
Characters A-Z are shown with Baden-Powell menemonics.
(Note said are a memory aid, not perfectly readable.)
Obviously deliberately looking away and listening
would be the best way to use this as a learning aid.
"""</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">show_help</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupMessage</span><span style="color: #0000FF;">(</span><span style="color: #000000;">title</span><span style="color: #0000FF;">,</span><span style="color: #000000;">help_text</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bWrap</span><span style="color: #0000FF;">:=</span><span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetFocus</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span> <span style="color: #000080;font-style:italic;">-- (don't open the browser help!)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">morse_data</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
!-.-.--#".-..-.#$...-..-#&.-...#'.----.#(-.--.#)-.--.-#+.-.-.#,--..--#--....-#..-.-.-#/-..-.#=-...-#
0-----#1.----#2..---#3...--#4....-#5.....#6-....#7--...#8---..#9----.#:---...#;-.-.-.#?..--..#@.--.-.#
A.-51517525#B-...7177414144444747#C-.-.7121121277271616#D-..717741414747#E.7474#F..-.7171111174247777#
G--.712177271818#H....2121717127277777#I..51515757#J.---2121222558269668#K-.-742184854428#(-.--.#
L.-..7171727677771717#M--45118155#N-.71362727#O---712182861216#P.--.8181612164247777#)-.--.-#
Q--.-8286121677775818#R.-.717144261717#S...515154545757#T-7121#U..-818111117727#V...-8181111156567727#
W.--818187534317#X-..-8154333365654518#Y-.--8163545433115558#Z--..7121762277771717#_..--.-# #"""</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">morse</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">``</span><span style="color: #0000FF;">,</span><span style="color: #000000;">255</span><span style="color: #0000FF;">),</span> <span style="color: #000080;font-style:italic;">-- the eg "..."'s</span>
<span style="color: #000000;">bdnpwl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">({},</span><span style="color: #000000;">255</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- Baden-Powell mnemonics</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">setMorse</span><span style="color: #0000FF;">()</span>
<span style="color: #000080;font-style:italic;">-- I trust the characters and morse codes are all pretty evident in morse_data.
-- Baden-Powell mnemonics are encoded as 4 points on a 9wx7h grid per dot/dash,
-- counting (it just turned out that way) right to left and top to bottom, such
-- that "9711" (=1197) is(/looks like) a forwardslash and "9117" a backslash.
-- Each quite fiddly to set up - rather relieved there were only 26 of them!</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">data</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">morse_data</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">),</span><span style="color: #008000;">'#'</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">di</span> <span style="color: #008080;">in</span> <span style="color: #000000;">data</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">key</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">di</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">bpm</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">trim_head</span><span style="color: #0000FF;">(</span><span style="color: #000000;">di</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$],</span><span style="color: #008000;">".- "</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">code</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">di</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..-</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">4</span><span style="color: #0000FF;">*</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">code</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #000000;">key</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">code</span> <span style="color: #000080;font-style:italic;">-- eg morse['S'] = "..."</span>
<span style="color: #000000;">bdnpwl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">key</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sq_sub</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'5'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #008000;">'['</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #008000;">'('</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #008000;">']'</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #008000;">')'</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">setMorse</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">text</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">upper</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)),</span>
<span style="color: #000000;">outstr</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">dw</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dh</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">),</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">tw</span><span style="color: #0000FF;">,</span><span style="color: #000000;">th</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCanvasGetTextSize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span><span style="color: #000000;">text</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">tw</span><span style="color: #0000FF;">></span><span style="color: #000000;">dw</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">outstr</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">outstr</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">" "</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">outstr</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #000000;">text</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]]</span>
<span style="color: #000000;">text</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">text</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">tw</span><span style="color: #0000FF;">,</span><span style="color: #000000;">th</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCanvasGetTextSize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span><span style="color: #000000;">text</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">cw</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tw</span><span style="color: #0000FF;">/</span><span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">text</span><span style="color: #0000FF;">),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">cx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dw</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">cy</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dh</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span>
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetBackground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_LIGHT_PARCHMENT</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasClear</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">#BBADA0</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasText</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">text</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cx</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">cw</span><span style="color: #0000FF;">*(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">text</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">0.5</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_BLUE</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetLineWidth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCanvasMarkSize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">gw</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cw</span><span style="color: #0000FF;">*</span><span style="color: #000000;">0.75</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">gh</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">th</span><span style="color: #0000FF;">*</span><span style="color: #000000;">0.285</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">ch</span> <span style="color: #008080;">in</span> <span style="color: #000000;">text</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">bpm</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">bdnpwl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">by</span> <span style="color: #000000;">4</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">x1</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">gw</span><span style="color: #0000FF;">*</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">+</span><span style="color: #000000;">0</span><span style="color: #0000FF;">]/</span><span style="color: #000000;">8</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">y1</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">gh</span><span style="color: #0000FF;">*</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">-</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">x2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">gw</span><span style="color: #0000FF;">*</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]/</span><span style="color: #000000;">8</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">y2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">gh</span><span style="color: #0000FF;">*</span><span style="color: #000000;">bpm</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">+</span><span style="color: #000000;">3</span><span style="color: #0000FF;">]/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">-</span><span style="color: #000000;">3</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">x1</span><span style="color: #0000FF;">=</span><span style="color: #000000;">x2</span> <span style="color: #008080;">and</span> <span style="color: #000000;">y1</span><span style="color: #0000FF;">=</span><span style="color: #000000;">y2</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">cdCanvasMark</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y1</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">else</span>
<span style="color: #7060A8;">cdCanvasLine</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y2</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">cx</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">cw</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">outstr</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">outstr</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">" "</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">outstr</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">output</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">outstr</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">map_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cdcanvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cddbuffer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_DBUFFER</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">-- cdCanvasFont(cddbuffer,"Courier",CD_PLAIN,24)</span>
<span style="color: #7060A8;">cdCanvasFont</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Courier"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">CD_PLAIN</span><span style="color: #0000FF;">,</span><span style="color: #000000;">48</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetTextAlignment</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_CENTER</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">frequency</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1280</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- in Hz, 37..32767</span>
<span style="color: #000000;">wpm</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- words per minute</span>
<span style="color: #000000;">dit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1200</span><span style="color: #0000FF;">/</span><span style="color: #000000;">wpm</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- in milliseconds</span>
<span style="color: #000000;">dah</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">*</span><span style="color: #000000;">dit</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">lettergap</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">*</span><span style="color: #000000;">dit</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">wordgap</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">*</span><span style="color: #000000;">dit</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">key_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*dlg*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #004600;">K_ESC</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CLOSE</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> <span style="color: #000080;font-style:italic;">-- (standard practice for me)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #004600;">K_F5</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> <span style="color: #000080;font-style:italic;">-- (let browser reload work)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #004600;">K_F1</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #000000;">show_help</span><span style="color: #0000FF;">()</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #004600;">K_CR</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">text</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">trim</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">upper</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)))</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">durations</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">ch</span> <span style="color: #008080;">in</span> <span style="color: #000000;">text</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #008000;">' '</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">durations</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">wordgap</span>
<span style="color: #008080;">else</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">durations</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">durations</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">lettergap</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">morse</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #000000;">durations</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">dit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">durations</span> <span style="color: #0000FF;">&=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]=</span><span style="color: #008000;">'.'</span><span style="color: #0000FF;">?</span><span style="color: #000000;">dit</span><span style="color: #0000FF;">:</span><span style="color: #000000;">dah</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">beep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frequency</span><span style="color: #0000FF;">,</span><span style="color: #000000;">durations</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.5</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"SELECTION"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ALL"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"#"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">beep</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span>
<span style="color: #008080;">else</span>
<span style="color: #7060A8;">IupUpdate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CONTINUE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">input</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"EXPAND=HORIZONTAL"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupCanvas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"RASTERSIZE=520x40"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">output</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"EXPAND=HORIZONTAL"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">vbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">input</span><span style="color: #0000FF;">,</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">output</span><span style="color: #0000FF;">},</span> <span style="color: #008000;">"MARGIN=10x5, GAP=5"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">vbox</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`TITLE="%s",MINSIZE=440x140`</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">title</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"KEY_CB"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"key_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">IupSetCallbacks</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"MAP_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"map_cb"</span><span style="color: #0000FF;">),</span>
<span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">)})</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"RASTERSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttributeHandle</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"PARENTDIALOG"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
=={{header|PicoLisp}}==
The following simply uses the 'beep' pc-speaker beeper utility.
<
(balance '*Morse
Line 3,168 ⟶ 3,447:
(wait (- *Dah *Dit)) ) )
(morse "Hello world!")</
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
/* Sound Morse code via the PC buzzer. June 2011 */
MORSE: procedure options (main);
Line 3,222 ⟶ 3,501:
end send_morse;
END MORSE;</
=={{header|PowerShell}}==
This function is case insensitive, ignores all non-Morse characters and optionally displays the Morse code.
<syntaxhighlight lang="powershell">
function Send-MorseCode
{
Line 3,286 ⟶ 3,565:
}
}
</syntaxhighlight>
<syntaxhighlight lang="powershell">
Send-MorseCode -Message "S.O.S" -ShowCode
</syntaxhighlight>
{{Out}}
<pre>
... --- ...
</pre>
<syntaxhighlight lang="powershell">
"S.O.S", "Goodbye, cruel world!" | Send-MorseCode -ShowCode
</syntaxhighlight>
{{Out}}
<pre>
Line 3,304 ⟶ 3,583:
-.-. .-. ..- . .-..
.-- --- .-. .-.. -..
</pre>
=={{header|Prolog}}==
Runs in SWI Prolog, Edinburgh syntax
<syntaxhighlight lang="prolog">
% convert text to morse
% query text2morse(Text, Morse)
% where
% Text is string to convert
% Morse is Morse representation
% There is a space between chars and double space between words
%
text2morse(Text, Morse) :-
string_lower(Text, TextLower), % rules are in lower case
string_chars(TextLower, Chars), % convert string into list of chars
chars2morse(Chars, MorseChars), % convert each char into morse
string_chars(MorsePlusSpace, MorseChars), % append returned string list into single string
string_concat(Morse, ' ', MorsePlusSpace). % Remove trailing space
chars2morse([], "").
chars2morse([H|CharTail], Morse) :-
morse(H, M),
chars2morse(CharTail, MorseTail),
string_concat(M,' ', MorseSpace),
string_concat(MorseSpace, MorseTail, Morse).
% space
morse(' ', " ").
% letters
morse('a', ".-").
morse('b', "-...").
morse('c', "-.-.").
morse('d', "-..").
morse('e', ".").
morse('f', "..-.").
morse('g', "--.").
morse('h', "....").
morse('i', "..").
morse('j', ".---").
morse('k', "-.-").
morse('l', ".-..").
morse('m', "--").
morse('n', "-.").
morse('o', "---").
morse('p', ".--.").
morse('q', "--.-").
morse('r', ".-.").
morse('s', "...").
morse('t', "-").
morse('u', "..-").
morse('v', "...-").
morse('w', ".--").
morse('x', "-..-").
morse('y', "-.--").
morse('z', "--..").
% numbers
morse('1', ".----").
morse('2', "..---").
morse('3', "...--").
morse('4', "....-").
morse('5', ".....").
morse('6', "-....").
morse('7', "--...").
morse('8', "---..").
morse('9', "----.").
morse('0', "-----").
% common punctuation
morse('.', ".-.-.-").
morse(',', "--..--").
morse('/', "-..-.").
morse('?', "..--..").
morse('=', "-...-").
morse('+', ".-.-.").
morse('-', "-....-").
morse('@', ".--.-.").
</syntaxhighlight>
<syntaxhighlight lang="prolog">
text2morse("Hello World", Morse).
</syntaxhighlight>
{{Out}}
<pre>
Morse = ".... . .-.. .-.. --- .-- --- .-. .-.. -.."
</pre>
=={{header|PureBasic}}==
<
#Frequence=1250
#Short = #BaseTime
Line 3,435 ⟶ 3,796:
Data.s "Done",""
EndOfMorseCode:
EndDataSection</
=={{header|Python}}==
<
char2morse = {
Line 3,499 ⟶ 3,860:
while True:
windowsmorse(input('A string to change into morse: '))
</syntaxhighlight>
=={{header|Quackery}}==
Mac specific as Quackery sits on top of Python, which is not strong with cross-platform audio.
<syntaxhighlight lang="Quackery"> [ $ /
import subprocess
subprocess.run(["say",
string_from_stack()])
/ python ] is speak ( $ --> )
[ 3 times [ $ " " speak ] ] is pause ( --> )
[ [] swap witheach
[ char - = iff
[ $ "dash " join ]
else [ $ "dot " join ] ]
space join ] is dotdash ( $ --> $ )
[ table ] is letter ( n --> $ )
$ ".- -... -.-. -.. . ..-.
--. .... .. .--- -.-
.-.. -- -. --- .--.
--.- .-. ... - ..- ...-
.-- -..- -.-- --.."
nest$ witheach
[ dotdash ' letter put ]
[ table ] is number ( n --> $ )
$ "----- .---- ..--- ...--
....- ..... -.... --...
---.. ----."
nest$ witheach
[ dotdash ' number put ]
[ witheach
[ dup space = iff
[ drop pause ] done
dup char 0 char 9 1+
within iff
[ char 0 -
number speak ] done
upper
dup char A char Z 1+
within iff
[ char A -
letter speak ] done
drop ] ] is morse ( $ --> )</syntaxhighlight>
=={{header|Racket}}==
Using MIDI on Windows for the beeps.
<
#lang racket
(require ffi/unsafe ffi/unsafe/define)
Line 3,544 ⟶ 3,954:
(morse "Say something here")
</syntaxhighlight>
=={{header|Raku}}==
Line 3,552 ⟶ 3,962:
Just read the output, leaving extra pauses where indicated
by either whitespace or underscore.
<syntaxhighlight lang="raku"
|<
! ---.
Line 3,615 ⟶ 4,025:
}
say prompt("Gimme a string: ").uc.comb.map: { %m{$_} // "<scratch> " }</
Sample run:
<p>Gimme a string: <b>Howdy, World!</b>
Line 3,625 ⟶ 4,035:
or "red.exe -r morse.red " to compile to single .exe file <br>
each character will be printed with its corresponding code before played
<
file: %morse.red ;; filename, could be ommited
]
Line 3,685 ⟶ 4,095:
morse-text "rosetta code"
morse-text "hello world"
</syntaxhighlight>
<
file: %api.reds ;; filename, could be ommited
]
Line 3,711 ⟶ 4,121:
] [ wsleep duration ]
;;----------------------------------------------
</syntaxhighlight>
=={{header|REXX}}==
Line 3,740 ⟶ 4,150:
=={{header|Ring}}==
<
Line 3,798 ⟶ 4,208:
strmorse = left(strmorse,len(strmorse)-1)
see strmorse + nl
</syntaxhighlight>
Output:
<pre>
-|....|..|...| ..|...| .-| -|.|...|-| -|.|-..-|-
</pre>
=={{header|RPL}}==
We use here AWK's elegant way to store the Morse code.
≪ <span style="color:red">"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--."
440 0.1</span>
→ morse freq beat
≪ <span style="color:red">-56</span> CF <span style="color:grey">@ to be replaced by 51 SF on HP-28s</span>
<span style="color:red">1</span> OVER SIZE '''FOR''' j
morse OVER j DUP SUB
'''IF''' POS '''THEN'''
LAST
'''WHILE''' <span style="color:red">1</span> + ".-" morse 3 PICK DUP SUB POS '''REPEAT'''
LAST beat * freq SWAP BEEP
beat WAIT
'''END'''
DROP <span style="color:red">3</span>
'''ELSE''' <span style="color:red">5</span> '''END'''
beat * WAIT
'''NEXT'''
≫ ≫ '<span style="color:blue">EMIT</span>' STO
"SOS" <span style="color:blue">EMIT</span>
=={{header|Ruby}}==
{{works with|Ruby|1.8.7+}} (uses <code>each_char</code>)
{{libheader|win32-utils}}
<
class MorseCode
Line 3,871 ⟶ 4,304:
MorseCode.new('sos').send
MorseCode.new('this is a test.').send</
{{out}}
Line 3,888 ⟶ 4,321:
morse_code/src/main.rs file:
<
//!
//! morse_code/src/main.rs
Line 3,918 ⟶ 4,351:
}
}
</syntaxhighlight>
morse_code/src/lib.rs file:
<
//!
//! morse_code/src/lib.rs
Line 4,039 ⟶ 4,472:
morse_map
}
</syntaxhighlight>
=={{header|Scala}}==
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/9Dsd74J/1 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/68KAarvEQQafYevTkWaCWg Scastie (remote JVM)].
<
private val code = Map(
Line 4,070 ⟶ 4,503:
printMorse("Rosetta Code")
}</
=={{header|sed}}==
Translation of AWK:
<
# Convert to uppercase
s/.*/\U&/
Line 4,084 ⟶ 4,517:
ta
# Remove lookup table
s/\n.*//</
Example:
<
$ echo hello world! | ./morse.sed
.... . .-.. .-.. --- .-- --- .-. .-.. -.. !</
=={{header|Tcl}}==
{{libheader|Snack}}
<
package require sound
Line 4,153 ⟶ 4,586:
set frequency 700
morse "Morse code with Tcl and Snack." 20</
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
MODE DATA
Line 4,190 ⟶ 4,623:
mc=EXCHANGE (mc,space2split)
BEEP $mc
</syntaxhighlight>
{{out}}
<pre>
Line 4,208 ⟶ 4,641:
=={{header|Ursa}}==
{{trans|Python}}
<
decl string<> chars
decl string<> morse
Line 4,304 ⟶ 4,737:
out "A string to change into morse: " console
encode_morse (in string console)
end while</
=={{header|VBA}}==
<
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Line 4,367 ⟶ 4,800:
Sleep DELAY
Next i
End Sub</
{{out}}
Play the sound's morse and display :
Line 4,378 ⟶ 4,811:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
Sub Main()
Line 4,407 ⟶ 4,840:
End Sub
End Module</
=={{header|Wren}}==
Line 4,415 ⟶ 4,848:
Any characters which do not appear in the Morse alphabet are simply ignored.
<
import "./sound" for Wav
var charToMorse = {
Line 4,471 ⟶ 4,904:
}
}
Wav.create("morse_code.wav", data, sampleRate)</
{{out}}
Line 4,480 ⟶ 4,913:
It's also possible to play .wav files which (preferably) have a sample rate of 44.1 kHz using DOME:
{{libheader|DOME}}
<
class Main {
Line 4,495 ⟶ 4,928:
}
var Game = Main.new()</
=={{header|XPL0}}==
Line 4,504 ⟶ 4,937:
when its volume parameter is set to zero.
<
string 0; \use zero-terminated strings
Line 4,545 ⟶ 4,978:
CrLf(0);
Morse("Hello, world!");
]</
{{out}}
<pre>
Line 4,554 ⟶ 4,987:
=={{header|Yabasic}}==
Mixin classic/modern style. In Yabasic, line number is not mandatory.
<
20 DIM c$(54)
30 FOR f = 1 TO 54
Line 4,584 ⟶ 5,017:
1070 DATA "'",".____.","!","_._.__","/","_.._.","(","_.__.",")","_.__._"
1080 DATA "&","._...",":","___...",";","_._._.","=","_..._","+","._._.","-","_...._"
1090 DATA "_","..__._","\"","._.._.","$","..._.._","@",".__._."</
|