annotate Demo/scripts/morse.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 2bc66f1df7cc
children 6194fd754323
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # DAH should be three DOTs.
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 # Space between DOTs and DAHs should be one DOT.
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Space between two letters should be one DAH.
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # Space between two words should be DOT DAH DAH.
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 import sys, math, audiodev
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 DOT = 30
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 DAH = 3 * DOT
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
10 OCTAVE = 2 # 1 == 441 Hz, 2 == 882 Hz, ...
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 morsetab = {
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
13 'A': '.-', 'a': '.-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
14 'B': '-...', 'b': '-...',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
15 'C': '-.-.', 'c': '-.-.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
16 'D': '-..', 'd': '-..',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
17 'E': '.', 'e': '.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
18 'F': '..-.', 'f': '..-.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
19 'G': '--.', 'g': '--.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
20 'H': '....', 'h': '....',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
21 'I': '..', 'i': '..',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
22 'J': '.---', 'j': '.---',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
23 'K': '-.-', 'k': '-.-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
24 'L': '.-..', 'l': '.-..',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
25 'M': '--', 'm': '--',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
26 'N': '-.', 'n': '-.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
27 'O': '---', 'o': '---',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
28 'P': '.--.', 'p': '.--.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
29 'Q': '--.-', 'q': '--.-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
30 'R': '.-.', 'r': '.-.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
31 'S': '...', 's': '...',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
32 'T': '-', 't': '-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
33 'U': '..-', 'u': '..-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
34 'V': '...-', 'v': '...-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
35 'W': '.--', 'w': '.--',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
36 'X': '-..-', 'x': '-..-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
37 'Y': '-.--', 'y': '-.--',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
38 'Z': '--..', 'z': '--..',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
39 '0': '-----',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
40 '1': '.----',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
41 '2': '..---',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
42 '3': '...--',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
43 '4': '....-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
44 '5': '.....',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
45 '6': '-....',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
46 '7': '--...',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
47 '8': '---..',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
48 '9': '----.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
49 ',': '--..--',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
50 '.': '.-.-.-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
51 '?': '..--..',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
52 ';': '-.-.-.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
53 ':': '---...',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
54 "'": '.----.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
55 '-': '-....-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
56 '/': '-..-.',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
57 '(': '-.--.-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
58 ')': '-.--.-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
59 '_': '..--.-',
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
60 ' ': ' '
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 }
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 # If we play at 44.1 kHz (which we do), then if we produce one sine
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 # wave in 100 samples, we get a tone of 441 Hz. If we produce two
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 # sine waves in these 100 samples, we get a tone of 882 Hz. 882 Hz
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 # appears to be a nice one for playing morse code.
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 def mkwave(octave):
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
68 global sinewave, nowave
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
69 sinewave = ''
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
70 for i in range(100):
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
71 val = int(math.sin(math.pi * float(i) * octave / 50.0) * 30000)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
72 sinewave = sinewave + chr((val >> 8) & 255) + chr(val & 255)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
73 nowave = '\0' * 200
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 mkwave(OCTAVE)
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 def main():
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
78 import getopt, string
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
79 try:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
80 opts, args = getopt.getopt(sys.argv[1:], 'o:p:')
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
81 except getopt.error:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
82 sys.stderr.write('Usage ' + sys.argv[0] +
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
83 ' [ -o outfile ] [ args ] ...\n')
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
84 sys.exit(1)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
85 dev = None
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
86 for o, a in opts:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
87 if o == '-o':
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
88 import aifc
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
89 dev = aifc.open(a, 'w')
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
90 dev.setframerate(44100)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
91 dev.setsampwidth(2)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
92 dev.setnchannels(1)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
93 if o == '-p':
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
94 mkwave(string.atoi(a))
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
95 if not dev:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
96 import audiodev
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
97 dev = audiodev.AudioDev()
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
98 dev.setoutrate(44100)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
99 dev.setsampwidth(2)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
100 dev.setnchannels(1)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
101 dev.close = dev.stop
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
102 dev.writeframesraw = dev.writeframes
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
103 if args:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
104 line = string.join(args)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
105 else:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
106 line = sys.stdin.readline()
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
107 while line:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
108 mline = morse(line)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
109 play(mline, dev)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
110 if hasattr(dev, 'wait'):
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
111 dev.wait()
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
112 if not args:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
113 line = sys.stdin.readline()
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
114 else:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
115 line = ''
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
116 dev.close()
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 # Convert a string to morse code with \001 between the characters in
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 # the string.
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 def morse(line):
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
121 res = ''
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
122 for c in line:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
123 try:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
124 res = res + morsetab[c] + '\001'
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
125 except KeyError:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
126 pass
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
127 return res
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 # Play a line of morse code.
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 def play(line, dev):
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
131 for c in line:
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
132 if c == '.':
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
133 sine(dev, DOT)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
134 elif c == '-':
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
135 sine(dev, DAH)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
136 else: # space
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
137 pause(dev, DAH + DOT)
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
138 pause(dev, DOT)
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
139
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 def sine(dev, length):
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
141 for i in range(length):
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
142 dev.writeframesraw(sinewave)
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
143
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 def pause(dev, length):
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
145 for i in range(length):
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
146 dev.writeframesraw(nowave)
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
147
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 if __name__ == '__main__' or sys.argv[0] == __name__:
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 1928
diff changeset
149 main()