Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7aa87cc5
Kaydet (Commit)
7aa87cc5
authored
Mar 10, 1995
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
added morse library (not finished yet)
üst
b7a38354
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
188 additions
and
0 deletions
+188
-0
morselib.py
Mac/Demo/sound/morselib.py
+188
-0
No files found.
Mac/Demo/sound/morselib.py
0 → 100644
Dosyayı görüntüle @
7aa87cc5
"""Translate text strings to Morse code"""
FRAMERATE
=
22050
SAMPWIDTH
=
2
BASEFREQ
=
441
OCTAVE
=
2
DOT
=
30
DAH
=
80
morsetab
=
{
'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'
:
'----.'
,
','
:
'--..--'
,
'.'
:
'.-.-.-'
,
'?'
:
'..--..'
,
';'
:
'-.-.-.'
,
':'
:
'---...'
,
"'"
:
'.----.'
,
'-'
:
'-....-'
,
'/'
:
'-..-.'
,
'('
:
'-.--.-'
,
')'
:
'-.--.-'
,
# XXX same as code for '(' ???
'_'
:
'..--.-'
,
' '
:
' '
}
def
morsecode
(
s
):
from
string
import
lower
m
=
''
for
c
in
s
:
c
=
lower
(
c
)
if
morsetab
.
has_key
(
c
):
c
=
morsetab
[
c
]
+
' '
else
:
c
=
'? '
m
=
m
+
c
return
m
class
BaseMorse
:
"base class for morse transmissions"
def
__init__
(
self
):
"constructor"
self
.
dots
=
DOT
self
.
dahs
=
DAH
def
noise
(
self
,
duration
):
"beep for given duration"
pass
def
pause
(
self
,
duration
):
"pause for given duration"
pass
def
dot
(
self
):
"short beep"
self
.
noise
(
self
.
dots
)
def
dah
(
self
):
"long beep"
self
.
noise
(
self
.
dahs
)
def
pdot
(
self
):
"pause as long as a dot"
self
.
pause
(
self
.
dots
)
def
pdah
(
self
):
"pause as long as a dah"
self
.
pause
(
self
.
dahs
)
def
sendmorse
(
self
,
s
):
for
c
in
s
:
if
c
==
'.'
:
self
.
dot
()
elif
c
==
'-'
:
self
.
dah
()
else
:
self
.
pdah
()
self
.
pdot
()
def
sendascii
(
self
,
s
):
self
.
sendmorse
(
morsecode
(
s
))
def
send
(
self
,
s
):
self
.
sendascii
(
s
)
import
Audio_mac
class
MyAudio
(
Audio_mac
.
Play_Audio_mac
):
def
_callback
(
self
,
*
args
):
if
hasattr
(
self
,
'usercallback'
):
self
.
usercallback
()
apply
(
Audio_mac
.
Play_Audio_mac
.
_callback
,
(
self
,)
+
args
)
class
MacMorse
(
BaseMorse
):
"Mac specific class to play Morse code"
def
__init__
(
self
):
BaseMorse
.
__init__
(
self
)
self
.
dev
=
MyAudio
()
self
.
dev
.
setoutrate
(
FRAMERATE
)
self
.
dev
.
setsampwidth
(
SAMPWIDTH
)
self
.
dev
.
setnchannels
(
1
)
self
.
dev
.
usercallback
=
self
.
usercallback
sinewave
=
''
n
=
int
(
FRAMERATE
/
BASEFREQ
)
octave
=
OCTAVE
from
math
import
sin
,
pi
for
i
in
range
(
n
):
val
=
int
(
sin
(
2
*
pi
*
i
*
octave
/
n
)
*
0x7fff
)
sample
=
chr
((
val
>>
8
)
&
255
)
+
chr
(
val
&
255
)
sinewave
=
sinewave
+
sample
[:
SAMPWIDTH
]
self
.
sinewave
=
sinewave
self
.
silence
=
'
\0
'
*
(
n
*
SAMPWIDTH
)
self
.
morsequeue
=
''
def
__del__
(
self
):
self
.
close
()
def
close
(
self
):
self
.
dev
=
None
def
pause
(
self
,
duration
):
self
.
dev
.
writeframes
(
self
.
silence
*
duration
)
def
noise
(
self
,
duration
):
self
.
dev
.
writeframes
(
self
.
sinewave
*
duration
)
def
sendmorse
(
self
,
s
):
self
.
morsequeue
=
self
.
morsequeue
+
s
self
.
dev
.
usercallback
()
self
.
dev
.
usercallback
()
self
.
dev
.
usercallback
()
def
usercallback
(
self
):
if
self
.
morsequeue
:
c
,
self
.
morsequeue
=
self
.
morsequeue
[
0
],
self
.
morsequeue
[
1
:]
if
c
==
'.'
:
self
.
dot
()
elif
c
==
'-'
:
self
.
dah
()
else
:
self
.
pdah
()
self
.
pdot
()
def
test
():
m
=
MacMorse
()
while
1
:
try
:
line
=
raw_input
(
'Morse line: '
)
except
(
EOFError
,
KeyboardInterrupt
):
break
m
.
send
(
line
)
while
m
.
morsequeue
:
pass
test
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment