summaryrefslogtreecommitdiff
path: root/trunk/users/metalab/python/MakerTunes/daftcode.py
blob: 674e244017a7394a6f784403fdcb85eaa12fb29b (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python

frequencies = [
  32.70,  #C1    0
  65.41,  #C2    1
  69.31,  #C#2   2
  73.42,  #D2    3
  77.78,  #D#2   4
  82.41,  #E2    5
  87.31,  #F2    6
  92.50,  #F#2   7
  98.00,  #G2    8
  103.83, #G#2   9
  110.00, #A2    10
  116.54, #Bb2   11
  123.47, #B2    12
  130.81, #C3    13
  138.59, #C#3   14
  146.83, #D3    15
  155.56, #D#3   16
  164.81, #E3    17
  174.61, #F3    18
  185.00, #F#3   19
  196.00, #G3    20
  207.65, #G#3   11 
  220.00, #A3    22
  233.08, #Bb3   23
  246.94, #B3    24
  261.63, #C4    25
  277.18, #C#4   26
  293.66, #D4    27
  311.13, #D#4   28
  329.63, #E4    29
  349.23, #F4    30
  369.99, #F#4   31
  392.00, #G4    32
  415.30, #G#4   33
  440.00, #A4    34
  466.16, #Bb4   35
  493.88, #B4    36
  523.25, #C5    37
  554.37, #C#5   38
  587.33, #D5    39
  622.25, #D#5   40
  659.26, #E5    41
  698.46, #F5    42
  739.99, #F#5   43
  783.99, #G5    44
  830.61, #G#5   45
  880.00  #A5    46
]


notes = [
    0,-1,
    17,13,10,6,
    -1,5,0,
    -1,0,-1,
    0,-1,
    17,13,10,6,
    -1,3,1,
    -1,
]

lengths = [
    2,2,
    1,1,1,1,
    1,1,2,
    1,2,1,
    2,2,
    1,1,1,1,
    1,1,4,
    2
]

assert(len(lengths) == len(notes))

feedrates = [60.0*f/320 for f in frequencies]

print "G21"
print "G90"
print "G92 X0 Y0 Z0"
print "G28"

z = 0;
for i in range(4):
    for (note,length) in zip(notes, lengths):
        if note == -1:
            print "G4 P%(P)d" % {'P':length*136}
        else:
            if note > 0: note = note + 12
            z += 0.136 * length * feedrates[note] / 60
            print "G1 Z%(Z).2f F%(F).2f" % {'Z':z, 'F':feedrates[note]}