57dbbff57b01d2e4f4ea267467272df6d55332bd
1 from MidiOutFile
import MidiOutFile
2 from MidiInFile
import MidiInFile
5 This is an example of the smallest possible type 0 midi file, where
6 all the midi events are in the same track.
10 class Transposer(MidiOutFile
):
12 "Transposes all notes by 1 octave"
14 def _transp(self
, ch
, note
):
15 if ch
!= 9: # not the drums!
22 def note_on(self
, channel
=0, note
=0x40, velocity
=0x40):
23 note
= self
._transp
(channel
, note
)
24 MidiOutFile
.note_on(self
, channel
, note
, velocity
)
27 def note_off(self
, channel
=0, note
=0x40, velocity
=0x40):
28 note
= self
._transp
(channel
, note
)
29 MidiOutFile
.note_off(self
, channel
, note
, velocity
)
32 out_file
= 'midiout/transposed.mid'
33 midi_out
= Transposer(out_file
)
35 #in_file = 'midiout/minimal_type0.mid'
36 #in_file = 'test/midifiles/Lola.mid'
37 in_file
= 'test/midifiles/tennessee_waltz.mid'
38 midi_in
= MidiInFile(midi_out
, in_file
)