Mercurial > ~darius > hgwebdir.cgi > musiccutter
comparison musiccutter.py @ 22:65e8298f5800
Remove extension and path name from title.
Put destination file in CWD.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 29 Apr 2016 17:36:31 +0930 |
parents | c710c4c3f44f |
children | 63d13efa040f |
comparison
equal
deleted
inserted
replaced
21:c710c4c3f44f | 22:65e8298f5800 |
---|---|
2 | 2 |
3 import exceptions | 3 import exceptions |
4 import itertools | 4 import itertools |
5 import math | 5 import math |
6 import mido | 6 import mido |
7 import os | 7 import os.path |
8 import reportlab.lib.colors | 8 import reportlab.lib.colors |
9 import reportlab.pdfgen.canvas | 9 import reportlab.pdfgen.canvas |
10 from reportlab.lib.units import mm | 10 from reportlab.lib.units import mm |
11 import sys | 11 import sys |
12 | 12 |
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', 120, 155, 5.5, 3.0, 6.0, 50, False, False, False, False, 12, 10, 'Helvetica', 12) | 21 m = Midi2PDF('notes', 120, 155, 5.5, 3.0, 6.0, 50, False, False, False, False, 12, 10, 'Helvetica', 12) |
22 base, ext = os.path.splitext(filename) | 22 base, ext = os.path.splitext(filename) |
23 base = os.path.basename(base) | |
23 m.processMidi(filename, base + '-%02d.pdf') | 24 m.processMidi(filename, base + '-%02d.pdf') |
24 | 25 |
25 class Midi2PDF(object): | 26 class Midi2PDF(object): |
26 def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, offset, leadin, timemarks, drawrect, notenames, notelines, noteoffset, timescale, fontname, fontsize): | 27 def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, offset, leadin, timemarks, drawrect, notenames, notelines, noteoffset, timescale, fontname, fontsize): |
27 self.midi2note, self.note2midi = Midi2PDF.genmidi2note(noteoffset) | 28 self.midi2note, self.note2midi = Midi2PDF.genmidi2note(noteoffset) |
54 pdfs = [] | 55 pdfs = [] |
55 for i in range(npages): | 56 for i in range(npages): |
56 pdf = reportlab.pdfgen.canvas.Canvas(file(outpat % (i + 1), 'w'), pagesize = (self.pagewidth * mm, self.pageheight * mm)) | 57 pdf = reportlab.pdfgen.canvas.Canvas(file(outpat % (i + 1), 'w'), pagesize = (self.pagewidth * mm, self.pageheight * mm)) |
57 pdfs.append(pdf) | 58 pdfs.append(pdf) |
58 | 59 |
59 title = midifile | 60 title = os.path.basename(midifile) |
61 title, ext = os.path.splitext(title) | |
60 for ev in midi: | 62 for ev in midi: |
61 if ev.type == 'text' and ctime == 0: | 63 if ev.type == 'text' and ctime == 0: |
62 title = ev.text | 64 title = ev.text |
63 | 65 |
64 ctime += ev.time | 66 ctime += ev.time |