diff 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
line wrap: on
line diff
--- a/musiccutter.py	Sat Mar 05 21:59:44 2016 +1030
+++ b/musiccutter.py	Sat Mar 05 22:47:56 2016 +1030
@@ -45,20 +45,22 @@
     return note2slot
 
 def emitnote(svg, slot, start, notelen):
-    # Let us say 185 ticks for a quaver and that is 5mm long
-    tickscale = 185.0 / 5.0
-    pitch = 5.5
-    offset = 6
+    # Let us say 185 ticks for a quaver and that is 0.5cm long
+    tickscale = 185.0 / 0.5
+    pitch = 0.55
+    offset = 0.60
     x = start / tickscale
     y = offset + slot * pitch
     w = notelen / tickscale
-    h = pitch
-    print x, y, w, h
-    svg.add(svgwrite.shapes.Rect(insert = ('%.3fcm' % (x / 10, '%.3fcm' % (y / 10)), size = (w, h), stroke = 'red', stroke_width = '1px', fill = 'red'))
+    h = pitch / 10.0
+    print 'x = %.3f y = %.3f w = %.3f h = %.3f' % (x, y, w, h)
+    svg.add(svgwrite.shapes.Rect(insert = ('%.3fcm' % (x), '%.3fcm' % (y)),
+                                 size = ('%.3fcm' % (w), '%.3fcm' % (h)),
+                                stroke = 'red', stroke_width = '1px', fill = 'red'))
 
 def midi2svg(inf, outpat, pitch, midi2note, note2midi, note2slot):
     midi = mido.MidiFile(inf)
-    svg = svgwrite.Drawing(outpat % (0))
+    svg = svgwrite.Drawing(outpat % (0), size = ('20.0cm', '15.5cm'))
     tnum = 0
     for t in midi.tracks:
         print "Track", tnum