comparison musiccutter.py @ 1:123b42d95ab8

Use cm directly
author Daniel O'Connor <darius@dons.net.au>
date Sat, 05 Mar 2016 22:47:56 +1030
parents 0773354c7428
children b1aac55d2864
comparison
equal deleted inserted replaced
0:0773354c7428 1:123b42d95ab8
43 index += 1 43 index += 1
44 44
45 return note2slot 45 return note2slot
46 46
47 def emitnote(svg, slot, start, notelen): 47 def emitnote(svg, slot, start, notelen):
48 # Let us say 185 ticks for a quaver and that is 5mm long 48 # Let us say 185 ticks for a quaver and that is 0.5cm long
49 tickscale = 185.0 / 5.0 49 tickscale = 185.0 / 0.5
50 pitch = 5.5 50 pitch = 0.55
51 offset = 6 51 offset = 0.60
52 x = start / tickscale 52 x = start / tickscale
53 y = offset + slot * pitch 53 y = offset + slot * pitch
54 w = notelen / tickscale 54 w = notelen / tickscale
55 h = pitch 55 h = pitch / 10.0
56 print x, y, w, h 56 print 'x = %.3f y = %.3f w = %.3f h = %.3f' % (x, y, w, h)
57 svg.add(svgwrite.shapes.Rect(insert = ('%.3fcm' % (x / 10, '%.3fcm' % (y / 10)), size = (w, h), stroke = 'red', stroke_width = '1px', fill = 'red')) 57 svg.add(svgwrite.shapes.Rect(insert = ('%.3fcm' % (x), '%.3fcm' % (y)),
58 size = ('%.3fcm' % (w), '%.3fcm' % (h)),
59 stroke = 'red', stroke_width = '1px', fill = 'red'))
58 60
59 def midi2svg(inf, outpat, pitch, midi2note, note2midi, note2slot): 61 def midi2svg(inf, outpat, pitch, midi2note, note2midi, note2slot):
60 midi = mido.MidiFile(inf) 62 midi = mido.MidiFile(inf)
61 svg = svgwrite.Drawing(outpat % (0)) 63 svg = svgwrite.Drawing(outpat % (0), size = ('20.0cm', '15.5cm'))
62 tnum = 0 64 tnum = 0
63 for t in midi.tracks: 65 for t in midi.tracks:
64 print "Track", tnum 66 print "Track", tnum
65 tnum += 1 67 tnum += 1
66 channels = [] 68 channels = []