Mercurial > ~darius > hgwebdir.cgi > musiccutter
comparison musiccutter.py @ 20:9bb72ae63651
- Make various things optional.
- Fix card size typo.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 26 Apr 2016 21:35:54 +0930 |
parents | ffaf97818ce3 |
children | c710c4c3f44f |
comparison
equal
deleted
inserted
replaced
19:ffaf97818ce3 | 20:9bb72ae63651 |
---|---|
16 def test(filename = None): | 16 def test(filename = None): |
17 if filename == None: | 17 if filename == None: |
18 filename = 'test.midi' | 18 filename = 'test.midi' |
19 # Card layout from http://www.orgues-de-barbarie.com/wp-content/uploads/2014/09/format-cartons.pdf | 19 # Card layout from http://www.orgues-de-barbarie.com/wp-content/uploads/2014/09/format-cartons.pdf |
20 # Notes are read from right to left | 20 # Notes are read from right to left |
21 m = Midi2PDF('notes', 130, 155, 5.5, 3.0, 6.0, 0, False, False, 10, 'Helvetica', 12) | 21 m = Midi2PDF('notes', 120, 155, 5.5, 3.0, 6.0, 50, False, False, False, False, 10, 'Helvetica', 12) |
22 base, ext = os.path.splitext(filename) | 22 base, ext = os.path.splitext(filename) |
23 m.processMidi(filename, base + '-%02d.pdf') | 23 m.processMidi(filename, base + '-%02d.pdf') |
24 | 24 |
25 class Midi2PDF(object): | 25 class Midi2PDF(object): |
26 def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, offset, leadin, timemarks, drawrect, timescale, fontname, fontsize): | 26 def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, offset, leadin, timemarks, drawrect, notenames, notelines, timescale, fontname, fontsize): |
27 self.midi2note, self.note2midi = Midi2PDF.genmidi2note() | 27 self.midi2note, self.note2midi = Midi2PDF.genmidi2note() |
28 self.note2slot, self.slot2note = Midi2PDF.loadnote2slot(notefile, self.note2midi) | 28 self.note2slot, self.slot2note = Midi2PDF.loadnote2slot(notefile, self.note2midi) |
29 self.pagewidth = pagewidth # Dimensions are in millimetres | 29 self.pagewidth = pagewidth # Dimensions are in millimetres |
30 self.pageheight = pageheight | 30 self.pageheight = pageheight |
31 self.pitch = pitch # Distance between each slot | 31 self.pitch = pitch # Distance between each slot |
32 self.slotsize = slotsize # Size of each slot cut out | 32 self.slotsize = slotsize # Size of each slot cut out |
33 self.offset = offset # Bottom margin | 33 self.offset = offset # Bottom margin |
34 self.leadin = leadin # Extra at the start | 34 self.leadin = leadin # Extra at the start |
35 self.timemarks = timemarks # Draw vertical time lines | 35 self.timemarks = timemarks # Draw vertical time lines |
36 self.drawrect = drawrect # Draw rectangle around each page | 36 self.drawrect = drawrect # Draw rectangle around each page |
37 self.notenames = notenames # Draw note names on the right edge | |
38 self.notelines = notelines # Draw line rulers | |
37 self.timescale = timescale # Width per second | 39 self.timescale = timescale # Width per second |
38 self.fontname = fontname | 40 self.fontname = fontname |
39 self.fontsize = fontsize # Points | 41 self.fontsize = fontsize # Points |
40 | 42 |
41 def processMidi(self, midifile, outpat): | 43 def processMidi(self, midifile, outpat): |
122 pdf.line(0, self.pageheight * mm, 0, 0) | 124 pdf.line(0, self.pageheight * mm, 0, 0) |
123 | 125 |
124 # Draw lines per note | 126 # Draw lines per note |
125 for slot in sorted(self.slot2note.keys()): | 127 for slot in sorted(self.slot2note.keys()): |
126 ofs = (self.offset + slot * self.pitch) * mm | 128 ofs = (self.offset + slot * self.pitch) * mm |
127 pdf.line(0, ofs, self.pagewidth * mm, ofs) | 129 if self.notelines: |
130 pdf.line(0, ofs, self.pagewidth * mm, ofs) | |
128 # Note name | 131 # Note name |
129 Midi2PDF.textHelper(pdf, (self.pagewidth - 10) * mm, ofs + 1 * mm, ENGRAVE_COLOUR, False, self.fontname, self.fontsize, self.slot2note[slot]) | 132 if self.notenames: |
130 pdf.restoreState() | 133 Midi2PDF.textHelper(pdf, (self.pagewidth - 10) * mm, ofs + 1 * mm, ENGRAVE_COLOUR, False, self.fontname, self.fontsize, self.slot2note[slot]) |
131 pdf.save() | 134 pdf.save() |
132 | 135 |
133 # http://newt.phys.unsw.edu.au/jw/notes.html | 136 # http://newt.phys.unsw.edu.au/jw/notes.html |
134 @staticmethod | 137 @staticmethod |
135 def genmidi2note(): | 138 def genmidi2note(): |
136 '''Create forward & reverse tables for midi number to note name (assuming 69 = A4 = A440)''' | 139 '''Create forward & reverse tables for midi number to note name (assuming 69 = A4 = A440)''' |