-
Notifications
You must be signed in to change notification settings - Fork 0
/
musica.py
executable file
·97 lines (84 loc) · 1.76 KB
/
musica.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import os, time
firstOctaveLa = 440
noteNames = ['do', 'dos', 're', 'res', 'mi', 'fa', 'fas', 'sol', 'sols', 'la', 'las', 'si']
laPos = 9
noteFreqs = {}
def location (elt, list):
return [i for i,x in enumerate(list) if x == elt][0]
for i, n in enumerate (noteNames):
noteFreqs[n] = firstOctaveLa * pow(2, (i - laPos)/12.0)
def freq (note, octave=1):
return octave * noteFreqs[note]
def beep (note, octave=1, l=1000):
os.system ('beep -f ' + str(freq(note, octave)) + ' -l ' + str(l))
def pause (l=1000):
time.sleep(l/1000.0)
def accelerate (song, ratio):
return map (lambda x:
[x[0], x[1]*ratio],
song)
hendrix = []
smokeOnTheWater = [
['mi', 500],
['sol', 500],
['la', 750],
['s',250],
#
['mi', 500],
['sol', 500],
['las', 250],
['la', 750],
['s',250],
#
['mi', 500],
['sol', 500],
['la', 750],
['s', 125],
#
['sol', 625],
['mi', 1000],
]
lalo = [
['si', 250],
['si', 250],
['do', 250],
['re', 250],
['re', 250],
['do', 250],
['si', 250],
['la', 250],
['sol', 250],
['sol', 250],
['la', 250],
['si', 250],
['si', 250],
['la', 250],
['la', 500],
#
['si', 250],
['si', 250],
['do', 250],
['re', 250],
['re', 250],
['do', 250],
['si', 250],
['la', 250],
['sol', 250],
['sol', 250],
['la', 250],
['si', 250],
['la', 250],
['sol', 250],
['sol', 500],
]
for note, length in accelerate (smokeOnTheWater, 0.8):
if note == 's':
pause(length)
else:
beep (note, l=length)
for note, length in accelerate (lalo, 0.8):
if note == 's':
pause(length)
else:
beep (note, l=length)