# HG changeset patch # User Daniel O'Connor # Date 1462230279 -34200 # Node ID 657bc32a0dfdc71b16ba92b86a1ff5745a64168e # Parent 87cf66e04ef982ba2ca0484dca484012e78409e3 Try transposing unplayable notes down or up an octave (in that order). diff -r 87cf66e04ef9 -r 657bc32a0dfd musiccutter.py --- a/musiccutter.py Tue May 03 08:31:28 2016 +0930 +++ b/musiccutter.py Tue May 03 08:34:39 2016 +0930 @@ -46,6 +46,8 @@ def processMidi(self, midifile, outpat): playablecount = 0 unplayablecount = 0 + transposeupcount = 0 + transposedowncount = 0 midi = mido.MidiFile(midifile) ctime = 0 channels = [] @@ -81,16 +83,29 @@ if ev.note not in channels[ev.channel]: 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 %d (%s)' % (ev.note, note) - unplayablecount += 1 + start = channels[ev.channel][ev.note] + notelen = ctime - start + playable = True + + if note in self.note2slot: + slot = self.note2slot[note] + elif ev.note - 12 in self.midi2note and self.note2slot[self.midi2note[ev.note - 12]]: + print 'Transposing note %d (%s) down' % (ev.note, note) + slot = self.note2slot[self.midi2note[ev.note - 12]] + transposedowncount += 1 + elif ev.note + 12 in self.midi2note and self.note2slot[self.midi2note[ev.note + 12]]: + print 'Transposing note %d (%s) up' % (ev.note, note) + slot = self.note2slot[self.midi2note[ev.note + 12]] + transposeupcount += 1 else: - start = channels[ev.channel][ev.note] - notelen = ctime - start - slot = self.note2slot[note] - print 'Note %s (%d) at %.2f length %.2f' % (note, slot, start, notelen) + unplayablecount += 1 + playable = False + + if playable: + #print 'Note %s (%d) at %.2f length %.2f' % (note, slot, start, notelen) self.emitnote(pdfs, slot, start, notelen) playablecount += 1 + del channels[ev.channel][ev.note] elif ev.type == 'end_of_track': print 'EOT, not flushing, check for missed notes' @@ -100,6 +115,8 @@ print 'Playable count:', playablecount print 'Unplayable count:', unplayablecount + print 'Transpose down:', transposedowncount + print 'Transpose up:', transposeupcount for pindx in range(len(pdfs)): pdf = pdfs[pindx]