# HG changeset patch # User Daniel O'Connor # Date 1462000034 -34200 # Node ID 71b78f06ff038ffba37ba545843d8bd172c35fc0 # Parent 63d13efa040f6bfc476a3b2ee06ccc6083973863 Highest notes are at the bottom not the top. Rename margin to heel to match the builders nomenclature. diff -r 63d13efa040f -r 71b78f06ff03 musiccutter.py --- a/musiccutter.py Fri Apr 29 17:36:46 2016 +0930 +++ b/musiccutter.py Sat Apr 30 16:37:14 2016 +0930 @@ -18,20 +18,21 @@ filename = 'test.midi' # Card layout from http://www.orgues-de-barbarie.com/wp-content/uploads/2014/09/format-cartons.pdf # Notes are read from right to left - m = Midi2PDF('notes', 120, 155, 5.5, 3.0, 6.0, 50, False, False, False, False, 12, 10, 'Helvetica', 12) + # 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) 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, offset, leadin, timemarks, drawrect, notenames, notelines, noteoffset, timescale, fontname, fontsize): + def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, heel, leadin, timemarks, drawrect, notenames, notelines, noteoffset, timescale, fontname, fontsize): self.midi2note, self.note2midi = Midi2PDF.genmidi2note(noteoffset) self.note2slot, self.slot2note = Midi2PDF.loadnote2slot(notefile, self.note2midi) self.pagewidth = pagewidth # Dimensions are in millimetres self.pageheight = pageheight self.pitch = pitch # Distance between each slot self.slotsize = slotsize # Size of each slot cut out - self.offset = offset # Bottom margin + 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.drawrect = drawrect # Draw rectangle around each page @@ -114,7 +115,7 @@ tend = tend + tsize * (pindx + 1) for s in range(tstart, tend, 5): x = self.pagewidth - (float(s * self.timescale + self.leadin) % self.pagewidth) - pdf.line(x * mm, self.offset, x * mm, self.pageheight * mm) + pdf.line(x * mm, self.heel, x * mm, self.pageheight * mm) Midi2PDF.textHelper(pdf, x * mm, 1 * mm, ENGRAVE_COLOUR, False, self.fontname, self.fontsize, str(s) + 's') # Draw rectangle around page @@ -123,7 +124,7 @@ # Draw lines per note for slot in sorted(self.slot2note.keys()): - ofs = (self.offset + slot * self.pitch) * mm + ofs = (self.heel - self.slotsize / 2 + slot * self.pitch) * mm if self.notelines: pdf.line(0, ofs, self.pagewidth * mm, ofs) # Note name @@ -171,7 +172,7 @@ pageidx = int(x / self.pagewidth) # Determine which page x = x % self.pagewidth # and where on that page h = self.slotsize - y = self.offset + slot * self.pitch + (self.pitch - h) / 2 + y = self.pageheight - (self.heel + slot * self.pitch - self.slotsize / 2) - self.slotsize w = notelen * self.timescale # Convert note length in time to distance print 'page = %d x = %.3f y = %.3f w = %.3f h = %.3f' % (pageidx, x, y, w, h)