comparison musiccutter.py @ 12:6e46ceee57a7

Use correct MIDI note generation, previous version did not agree with MUP (hmmmm).
author Daniel O'Connor <darius@dons.net.au>
date Sun, 10 Apr 2016 22:24:56 +0930
parents 9faad813e39e
children 5f4c21bb5140
comparison
equal deleted inserted replaced
11:9faad813e39e 12:6e46ceee57a7
4 import itertools 4 import itertools
5 import math 5 import math
6 import mido 6 import mido
7 import os 7 import os
8 import reportlab.lib.colors 8 import reportlab.lib.colors
9 import reportlab.pdfgen.canvas
9 from reportlab.lib.units import mm 10 from reportlab.lib.units import mm
10 import sys 11 import sys
11 12
12 CUT_COLOUR = reportlab.lib.colors.red 13 CUT_COLOUR = reportlab.lib.colors.red
13 ENGRAVE_COLOUR = reportlab.lib.colors.black 14 ENGRAVE_COLOUR = reportlab.lib.colors.black
97 tobj.setStrokeColor(ENGRAVE_COLOUR) 98 tobj.setStrokeColor(ENGRAVE_COLOUR)
98 tobj.textLine('%s (%d / %d)' % (title, i + 1, npages)) 99 tobj.textLine('%s (%d / %d)' % (title, i + 1, npages))
99 pdf.drawText(tobj) 100 pdf.drawText(tobj)
100 pdf.save() 101 pdf.save()
101 102
102 # http://www.electronics.dit.ie/staff/tscarff/Music_technology/midi/midi_note_numbers_for_octaves.htm 103 # http://newt.phys.unsw.edu.au/jw/notes.html
103 @staticmethod 104 @staticmethod
104 def genmidi2note(): 105 def genmidi2note():
105 '''Create forward & reverse tables for midi number to note name (assuming 69 == A440)''' 106 '''Create forward & reverse tables for midi number to note name (assuming 69 = A4 = A440)'''
106 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'] 107 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']
107 midi2note = {} 108 midi2note = {}
108 note2midi = {} 109 note2midi = {}
109 for midi in range(128): 110 for midi in range(128):
110 octave = midi / len(names) 111 octave = midi / len(names) - 1
111 index = midi % len(names) 112 index = midi % len(names)
112 name = names[index] % (octave) 113 name = names[index] % (octave)
113 midi2note[midi] = name 114 midi2note[midi] = name
114 note2midi[name] = midi 115 note2midi[name] = midi
115 116