summaryrefslogtreecommitdiffstats
path: root/doc/the_free_software_song.py
blob: 5ea095b38a48fb80a0d4f3f4f91d5c15ac04b677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3


notes = []

def note(name, value):
	nameMap = {
		"pause"	: 0,
		"c"	: 1,
		"d"	: 2,
		"e"	: 3,
		"f"	: 4,
		"g"	: 5,
		"a"	: 6,
		"b"	: 7,
		"c'"	: 8,
		"d'"	: 9,
		"e'"	: 10,
		"f'"	: 11,
		"g'"	: 12,
		"a'"	: 13,
		"b'"	: 14,
		None	: 15,
	}
	valueMap = {
		"1/1"	: 0,
		"1/2"	: 1,
		"1/4"	: 2,
		"1/8"	: 3,
		"1/16"	: 4,
		"1/32"	: 5,
		"1/64"	: 6,

		"sharp"	: 0,
		"dot"	: 1,
		"tie"	: 2,
		"up"	: 3,
		"down"	: 4,
	}
	notes.append(nameMap[name] | (valueMap[value] << 4))

n = note
tie = lambda: note(None, "tie")
dot = lambda: note(None, "dot")


# The Free Software Song
# Sadi moma bela loza (Bulgarian folk song)
# Words by Richard Stallman, the Free Software Foundation http://fsf.org/
# Richard Stallman and the Free Software Foundation claim no copyright on this song.
# The official homepage for this song is http://www.gnu.org/music/free-software-song.html

n("d'", "1/4"); n("c'", "1/8"); n("b", "1/4"); n("a", "1/4")
n("b", "1/4"); n("c'", "1/8"); n("b", "1/8"); tie(); n("a", "1/8"); n("g", "1/4")
n("g", "1/4"); dot(); n("a", "1/4"); dot(); tie(); n("b", "1/8")
n("c'", "1/4"); dot(); n("b", "1/4"); n("b", "1/8"); n("d'", "1/4")
n("a", "1/4"); dot(); n("a", "1/2")
n("d'", "1/4"); tie(); n("c'", "1/8"); tie(); n("b", "1/2")
n("d'", "1/4"); n("c'", "1/8"); n("b", "1/4"); n("a", "1/4")
n("b", "1/4"); n("c'", "1/8"); n("b", "1/8"); tie(); n("a", "1/8"); n("g", "1/4")
n("g", "1/4"); dot(); n("a", "1/4"); dot(); tie(); n("b", "1/8")
n("c'", "1/4"); dot(); n("b", "1/4"); n("b", "1/8"); n("d'", "1/4")
n("a", "1/4"); dot(); n("a", "1/2")
n("a", "1/4"); dot(); tie(); n("a", "1/2")


header="""DATA_BLOCK "DB_song"
	STRUCT
		SONG : ARRAY [0 .. %d] OF BYTE;
	END_STRUCT;
BEGIN
""" % (len(notes))

footer="END_DATA_BLOCK\n"

print(header, end='')
for i, n in enumerate(notes):
	print("\tSONG[%d] := B#16#%02X;\n" % (i, n), end='')
print("\tSONG[%d] := B#16#FF;\n" % (i + 1), end='')
print(footer, end='')
bues.ch cgit interface