Mercurial > ~darius > hgwebdir.cgi > musiccutter
annotate musiccutter.py @ 18:cf93a76eda92
The laser cutter software barfs on these lines and stops processing
the PDF (but doesn't emit any errors!) so just if them out for now.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 20 Apr 2016 08:38:38 +0930 |
parents | c50427f1da2d |
children | ffaf97818ce3 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
3 import exceptions | |
4
9f4fa5f231e6
Rework to use mido iterator and paginate.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
4 import itertools |
7 | 5 import math |
0 | 6 import mido |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
7 import os |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
8 import reportlab.lib.colors |
12
6e46ceee57a7
Use correct MIDI note generation, previous version did not agree with
Daniel O'Connor <darius@dons.net.au>
parents:
11
diff
changeset
|
9 import reportlab.pdfgen.canvas |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
10 from reportlab.lib.units import mm |
0 | 11 import sys |
12 | |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
13 CUT_COLOUR = reportlab.lib.colors.red |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
14 ENGRAVE_COLOUR = reportlab.lib.colors.black |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
15 |
3
49a33c431b45
Accept filename for test function
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
16 def test(filename = None): |
49a33c431b45
Accept filename for test function
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
17 if filename == None: |
49a33c431b45
Accept filename for test function
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
18 filename = 'test.midi' |
7 | 19 # Card layout from http://www.orgues-de-barbarie.com/wp-content/uploads/2014/09/format-cartons.pdf |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
20 m = Midi2PDF('notes', 200, 155, 5.5, 3.0, 6.0, 20, 10, 'Helvetica', 12) |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
21 base, ext = os.path.splitext(filename) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
22 m.processMidi(filename, base + '-%02d.pdf') |
0 | 23 |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
24 class Midi2PDF(object): |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
25 def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, offset, lmargin, timescale, fontname, fontsize): |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
26 self.midi2note, self.note2midi = Midi2PDF.genmidi2note() |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
27 self.note2slot, self.slot2note = Midi2PDF.loadnote2slot(notefile, self.note2midi) |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
28 self.pagewidth = pagewidth # Dimensions are in millimetres |
7 | 29 self.pageheight = pageheight |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
30 self.pitch = pitch # Distance between each slot |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
31 self.slotsize = slotsize # Size of each slot cut out |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
32 self.offset = offset # Bottom margin |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
33 self.lmargin = lmargin # Left margin |
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
34 self.timescale = timescale # Width per second |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
35 self.fontname = fontname |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
36 self.fontsize = fontsize # Points |
0 | 37 |
7 | 38 def processMidi(self, midifile, outpat): |
39 playablecount = 0 | |
40 unplayablecount = 0 | |
41 midi = mido.MidiFile(midifile) | |
42 ctime = 0 | |
43 channels = [] | |
44 for i in range(16): | |
45 channels.append({}) | |
0 | 46 |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
47 npages = int(math.ceil(((midi.length * self.timescale) + self.lmargin) / self.pagewidth)) |
7 | 48 print 'npages', npages |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
49 pdfs = [] |
7 | 50 for i in range(npages): |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
51 pdf = reportlab.pdfgen.canvas.Canvas(file(outpat % (i + 1), 'w'), pagesize = (self.pagewidth * mm, self.pageheight * mm)) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
52 pdfs.append(pdf) |
0 | 53 |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
54 title = midifile |
7 | 55 for ev in midi: |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
56 if ev.type == 'text' and ctime == 0: |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
57 title = ev.text |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
58 |
7 | 59 ctime += ev.time |
60 if ev.type == 'note_on' or ev.type == 'note_off': | |
61 note = self.midi2note[ev.note] | |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
62 #print ctime, ev |
7 | 63 if ev.type == 'note_on' and ev.velocity > 0: |
64 if ev.note in channels[ev.channel]: | |
65 print 'Duplicate note_on message %d (%s)' % (ev.note, note) | |
0 | 66 else: |
7 | 67 channels[ev.channel][ev.note] = ctime |
68 elif ev.type == 'note_off' or (ev.type == 'note_on' and ev.velocity == 0): | |
69 if ev.note not in channels[ev.channel]: | |
70 print 'note_off with no corresponding note_on for channel %d note %d' % (ev.channel, ev.note) | |
0 | 71 else: |
7 | 72 if note not in self.note2slot: |
73 print 'Skipping unplayable note %s' % (note) | |
74 unplayablecount += 1 | |
75 else: | |
76 start = channels[ev.channel][ev.note] | |
77 notelen = ctime - start | |
78 slot = self.note2slot[note] | |
79 print 'Note %s (%d) at %.2f length %.2f' % (note, slot, start, notelen) | |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
80 self.emitnote(pdfs, slot, start, notelen) |
7 | 81 playablecount += 1 |
82 del channels[ev.channel][ev.note] | |
83 elif ev.type == 'end_of_track': | |
84 print 'EOT, not flushing, check for missed notes' | |
85 for chan in channels: | |
86 for ev in chan: | |
87 print ev | |
88 | |
89 print 'Playable count:', playablecount | |
90 print 'Unplayable count:', unplayablecount | |
91 | |
17
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
92 for pindx in range(len(pdfs)): |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
93 pdf = pdfs[pindx] |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
94 # Add title and page number |
17
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
95 Midi2PDF.textHelper(pdf, 25 * mm, 1 * mm, ENGRAVE_COLOUR, True, self.fontname, self.fontsize, '%s (%d / %d)' % (title, pindx + 1, npages)) |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
96 |
17
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
97 pdf.saveState() # Not really necessary since this is last thing we do |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
98 pdf.setLineWidth(0) |
17
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
99 |
18
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
100 # Draw time marks |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
101 if False: |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
102 tstart = 0 |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
103 tend = (self.pagewidth - self.lmargin) / self.timescale |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
104 if pindx > 0: |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
105 tsize = self.pagewidth / self.timescale |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
106 tstart = tend + tsize * pindx |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
107 tend = tend + tsize * (pindx + 1) |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
108 for s in range(tstart, tend, 5): |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
109 x = float(s * self.timescale + self.lmargin) % self.pagewidth |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
110 pdf.line(x * mm, self.offset, x * mm, self.pageheight * mm) |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
111 Midi2PDF.textHelper(pdf, x * mm, 1 * mm, ENGRAVE_COLOUR, False, self.fontname, self.fontsize, str(s) + 's') |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
112 |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
113 # Draw rectangle around page |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
114 if False: |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
115 pdf.rect(0, 0, self.pagewidth * mm, self.pageheight * mm, fill = False, stroke = True) |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
116 pdf.line(0, 0, 0, self.pagewidth * mm) |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
117 pdf.line(0, self.pagewidth * mm, self.pagewidth * mm, self.pageheight * mm) |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
118 pdf.line(self.pagewidth * mm, self.pageheight * mm, 0, self.pageheight * mm) |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
119 pdf.line(0, self.pageheight * mm, 0, 0) |
cf93a76eda92
The laser cutter software barfs on these lines and stops processing
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
120 |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
121 # Draw lines per note |
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
122 for slot in sorted(self.slot2note.keys()): |
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
123 ofs = (self.offset + slot * self.pitch) * mm |
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
124 pdf.line(0, ofs, self.pagewidth * mm, ofs) |
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
125 # Note name |
17
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
126 Midi2PDF.textHelper(pdf, 0 * mm, ofs + 1 * mm, ENGRAVE_COLOUR, False, self.fontname, self.fontsize, self.slot2note[slot]) |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
127 pdf.restoreState() |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
128 pdf.save() |
7 | 129 |
12
6e46ceee57a7
Use correct MIDI note generation, previous version did not agree with
Daniel O'Connor <darius@dons.net.au>
parents:
11
diff
changeset
|
130 # http://newt.phys.unsw.edu.au/jw/notes.html |
7 | 131 @staticmethod |
132 def genmidi2note(): | |
12
6e46ceee57a7
Use correct MIDI note generation, previous version did not agree with
Daniel O'Connor <darius@dons.net.au>
parents:
11
diff
changeset
|
133 '''Create forward & reverse tables for midi number to note name (assuming 69 = A4 = A440)''' |
7 | 134 names = ['C%d', 'C%d#', 'D%d', 'D%d#', 'E%d', 'F%d', 'F%d#', 'G%d', 'G%d#', 'A%d', 'A%d#', 'B%d'] |
135 midi2note = {} | |
136 note2midi = {} | |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
137 for midi in range(21, 128): |
12
6e46ceee57a7
Use correct MIDI note generation, previous version did not agree with
Daniel O'Connor <darius@dons.net.au>
parents:
11
diff
changeset
|
138 octave = midi / len(names) - 1 |
7 | 139 index = midi % len(names) |
140 name = names[index] % (octave) | |
141 midi2note[midi] = name | |
142 note2midi[name] = midi | |
4
9f4fa5f231e6
Rework to use mido iterator and paginate.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
143 |
7 | 144 return midi2note, note2midi |
145 | |
146 @staticmethod | |
147 def loadnote2slot(fname, note2midi): | |
148 note2slot = {} | |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
149 slot2note = {} |
7 | 150 index = 0 |
151 | |
152 for note in file(fname): | |
153 note = note.strip() | |
154 if note[0] == '#': | |
155 continue | |
156 if note not in note2midi: | |
157 raise exceptions.ValueError('Note \'%s\' not valid' % note) | |
158 note2slot[note] = index | |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
159 slot2note[index] = note |
7 | 160 index += 1 |
161 | |
13
5f4c21bb5140
Add lines and notes engraved on the paper.
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
162 return note2slot, slot2note |
4
9f4fa5f231e6
Rework to use mido iterator and paginate.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
163 |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
164 def emitnote(self, pdfs, slot, start, notelen): |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
165 x = start * self.timescale + self.lmargin |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
166 pageidx = int(x / self.pagewidth) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
167 x = x % self.pagewidth |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
168 y = self.offset + slot * self.pitch + (self.pitch - self.slotsize) / 2 |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
169 w = notelen * self.timescale |
16
20337b22977d
Add left margin and slot size support.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
170 h = self.slotsize |
7 | 171 |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
172 print 'page = %d x = %.3f y = %.3f w = %.3f h = %.3f' % (pageidx, x, y, w, h) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
173 w1 = w |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
174 # Check if the note crosses a page |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
175 if x + w > self.pagewidth: |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
176 w1 = x - self.pagewidth # Crop first note |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
177 w2 = w - w1 |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
178 assert w1 <= self.pagewidth, 'note extends for more than a page' |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
179 # Emit second half of note |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
180 print 'split note, page %d w2 = %.3f' % (pageidx + 1, w2) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
181 Midi2PDF._emitnote(pdfs[pageidx + 1], 0, y, w2, h) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
182 |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
183 Midi2PDF._emitnote(pdfs[pageidx], x, y, w1, h) |
7 | 184 |
185 @staticmethod | |
11
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
186 def _emitnote(pdf, x, y, w, h): |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
187 pdf.saveState() |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
188 pdf.setStrokeColor(CUT_COLOUR) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
189 pdf.setLineWidth(0) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
190 pdf.rect(x * mm, y * mm, w * mm, h * mm, fill = False, stroke = True) |
9faad813e39e
switch to PDF to avoid dealing with CorelDraw crashing
Daniel O'Connor <darius@dons.net.au>
parents:
9
diff
changeset
|
191 pdf.restoreState() |
0 | 192 |
17
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
193 @staticmethod |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
194 def textHelper(pdf, x, y, colour, fill, fontname, fontsize, text): |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
195 tobj = pdf.beginText() |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
196 tobj.setTextOrigin(x, y) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
197 tobj.setFont(fontname, fontsize) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
198 tobj.setStrokeColor(colour) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
199 tobj.setFillColor(colour) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
200 if fill: |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
201 tobj.setTextRenderMode(0) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
202 else: |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
203 tobj.setTextRenderMode(1) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
204 tobj.textLine(text) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
205 pdf.drawText(tobj) |
c50427f1da2d
- Draw vertical time lines.
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
206 |
0 | 207 if __name__ == '__main__': |
208 main() |