Mercurial > ~darius > hgwebdir.cgi > musiccutter
changeset 21:c710c4c3f44f
Add pitch offset (number of midi notes to move up/down)
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 29 Apr 2016 15:57:32 +0930 |
parents | 9bb72ae63651 |
children | 65e8298f5800 |
files | musiccutter.py |
diffstat | 1 files changed, 9 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/musiccutter.py Tue Apr 26 21:35:54 2016 +0930 +++ b/musiccutter.py Fri Apr 29 15:57:32 2016 +0930 @@ -18,13 +18,13 @@ 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, 10, 'Helvetica', 12) + m = Midi2PDF('notes', 120, 155, 5.5, 3.0, 6.0, 50, False, False, False, False, 12, 10, 'Helvetica', 12) base, ext = os.path.splitext(filename) m.processMidi(filename, base + '-%02d.pdf') class Midi2PDF(object): - def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, offset, leadin, timemarks, drawrect, notenames, notelines, timescale, fontname, fontsize): - self.midi2note, self.note2midi = Midi2PDF.genmidi2note() + def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, offset, 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 @@ -75,7 +75,7 @@ print 'note_off with no corresponding note_on for channel %d note %d' % (ev.channel, ev.note) else: if note not in self.note2slot: - print 'Skipping unplayable note %s' % (note) + print 'Skipping unplayable note %d (%s)' % (ev.note, note) unplayablecount += 1 else: start = channels[ev.channel][ev.note] @@ -135,8 +135,9 @@ # http://newt.phys.unsw.edu.au/jw/notes.html @staticmethod - def genmidi2note(): - '''Create forward & reverse tables for midi number to note name (assuming 69 = A4 = A440)''' + def genmidi2note(offset): + '''Create forward & reverse tables for midi number to note name (assuming 69 = A4 = A440) +offset is amount to shift notes (+12 = +1 octave)''' 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'] midi2note = {} note2midi = {} @@ -144,8 +145,8 @@ octave = midi / len(names) - 1 index = midi % len(names) name = names[index] % (octave) - midi2note[midi] = name - note2midi[name] = midi + midi2note[midi - offset] = name + note2midi[name] = midi - offset return midi2note, note2midi