diff musiccutter.py @ 30:f46cc9401e79

Make transposition optional and add note scale parameter (to get rearticulation)
author Daniel O'Connor <darius@dons.net.au>
date Tue, 03 May 2016 09:10:33 +0930
parents 767ba8ec90e6
children ea98c9507f47 f053dd6e9e68
line wrap: on
line diff
--- a/musiccutter.py	Tue May 03 09:09:27 2016 +0930
+++ b/musiccutter.py	Tue May 03 09:10:33 2016 +0930
@@ -19,13 +19,13 @@
     # Card layout from http://www.orgues-de-barbarie.com/wp-content/uploads/2014/09/format-cartons.pdf
     # Notes are read from right to left
     # Highest note is at the bottom (closest to the crank)
-    m = Midi2PDF('notes', 120, 155, 5.5, 3.3, 6.0, 50, False, False, False, False, 0, 10, 'Helvetica', 12)
+    m = Midi2PDF('notes', 120, 155, 5.5, 3.3, 6.0, 50, False, False, False, False, False, 0, 30, 0.9, 'Helvetica', 12)
     base, ext = os.path.splitext(filename)
     base = os.path.basename(base)
     m.processMidi(filename, base + '-%02d.pdf')
 
 class Midi2PDF(object):
-    def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, heel, leadin, timemarks, drawrect, notenames, notelines, noteoffset, timescale, fontname, fontsize):
+    def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, heel, leadin, timemarks, trytranspose, drawrect, notenames, notelines, noteoffset, timescale, notescale, fontname, fontsize):
         self.midi2note, self.note2midi = Midi2PDF.genmidi2note()
         self.note2slot, self.slot2note = Midi2PDF.loadnote2slot(notefile, self.note2midi)
         self.pagewidth = pagewidth # Dimensions are in millimetres
@@ -35,11 +35,13 @@
         self.heel = heel # Bottom margin (from bottom of page to centre of slot)
         self.leadin = leadin # Extra at the start
         self.timemarks = timemarks # Draw vertical time lines
+        self.trytranspose = trytranspose # Attempt to tranpose unplayable notes
         self.drawrect = drawrect # Draw rectangle around each page
         self.notenames = notenames # Draw note names on the right edge
         self.notelines = notelines # Draw line rulers
         self.noteoffset = noteoffset # Amount to adjust note pitches by (+12 = 1 octave)
         self.timescale = timescale # Width per second
+        self.notescale = notescale # Multiply all note lengths by this (to get rearticulation)
         self.fontname = fontname
         self.fontsize = fontsize # Points
 
@@ -94,11 +96,11 @@
 
                         if note in self.note2slot:
                             slot = self.note2slot[note]
-                        elif ev.note - 12 in self.midi2note and self.note2slot[self.midi2note[ev.note - 12]]:
+                        elif self.trytranspose and (ev.note - 12 in self.midi2note and self.note2slot[self.midi2note[ev.note - 12]]):
                             print 'Transposing note %d (%s) down' % (ev.note, note)
                             slot = self.note2slot[self.midi2note[ev.note - 12]]
                             transposedowncount += 1
-                        elif ev.note + 12 in self.midi2note and self.note2slot[self.midi2note[ev.note + 12]]:
+                        elif self.trytranspose and (ev.note + 12 in self.midi2note and self.note2slot[self.midi2note[ev.note + 12]]):
                             print 'Transposing note %d (%s) up' % (ev.note, note)
                             slot = self.note2slot[self.midi2note[ev.note + 12]]
                             transposeupcount += 1
@@ -108,7 +110,7 @@
 
                         if playable:
                             #print 'Note %s (%d) at %.2f length %.2f' % (note, slot, start, notelen)
-                            self.emitnote(pdfs, slot, start, notelen)
+                            self.emitnote(pdfs, slot, start, notelen * self.notescale)
                             playablecount += 1
 
                         del channels[ev.channel][ev.note]
@@ -120,8 +122,9 @@
 
         print 'Playable count:', playablecount
         print 'Unplayable count:', unplayablecount
-        print 'Transpose down:', transposedowncount
-        print 'Transpose up:', transposeupcount
+        if self.trytranspose:
+            print 'Transpose down:', transposedowncount
+            print 'Transpose up:', transposeupcount
 
         for pindx in range(len(pdfs)):
             pdf = pdfs[pindx]