1
2
3 from MidiOutStream import MidiOutStream
4 -class MidiToText(MidiOutStream):
5
6
7 """
8 This class renders a midi file as text. It is mostly used for debugging
9 """
10
11
12
13
14
15 - def channel_message(self, message_type, channel, data):
16 """The default event handler for channel messages"""
17 print 'message_type:%X, channel:%X, data size:%X' % (message_type, channel, len(data))
18
19
20 - def note_on(self, channel=0, note=0x40, velocity=0x40):
21 print 'note_on - ch:%02X, note:%02X, vel:%02X time:%s' % (channel, note, velocity, self.rel_time())
22
23 - def note_off(self, channel=0, note=0x40, velocity=0x40):
24 print 'note_off - ch:%02X, note:%02X, vel:%02X time:%s' % (channel, note, velocity, self.rel_time())
25
26 - def aftertouch(self, channel=0, note=0x40, velocity=0x40):
27 print 'aftertouch', channel, note, velocity
28
29
30 - def continuous_controller(self, channel, controller, value):
31 print 'controller - ch: %02X, cont: #%02X, value: %02X' % (channel, controller, value)
32
33
34 - def patch_change(self, channel, patch):
35 print 'patch_change - ch:%02X, patch:%02X' % (channel, patch)
36
37
38 - def channel_pressure(self, channel, pressure):
39 print 'channel_pressure', channel, pressure
40
41
42 - def pitch_bend(self, channel, value):
43 print 'pitch_bend ch:%s, value:%s' % (channel, value)
44
45
46
47
48
49
50
51 - def system_exclusive(self, data):
52 print 'system_exclusive - data size: %s' % len(date)
53
54
55 - def song_position_pointer(self, value):
56 print 'song_position_pointer: %s' % value
57
58
59 - def song_select(self, songNumber):
60 print 'song_select: %s' % songNumber
61
62
63 - def tuning_request(self):
64 print 'tuning_request'
65
66
67 - def midi_time_code(self, msg_type, values):
68 print 'midi_time_code - msg_type: %s, values: %s' % (msg_type, values)
69
70
71
72
73
74
76 print 'format: %s, nTracks: %s, division: %s' % (format, nTracks, division)
77 print '----------------------------------'
78 print ''
79
82
83
84 - def start_of_track(self, n_track=0):
85 print 'Start - track #%s' % n_track
86
87
88 - def end_of_track(self):
89 print 'End of track'
90 print ''
91
92
93
94
95
96
97 - def sysex_event(self, data):
98 print 'sysex_event - datasize: %X' % len(data)
99
100
101
102
103
105 print 'undefined_meta_event:', meta_type, len(data)
106
107
108 - def sequence_number(self, value):
109 print 'sequence_number', number
110
111
112 - def text(self, text):
114
115
116 - def copyright(self, text):
117 print 'copyright', text
118
119
120 - def sequence_name(self, text):
121 print 'sequence_name:', text
122
123
124 - def instrument_name(self, text):
125 print 'instrument_name:', text
126
127
128 - def lyric(self, text):
130
131
132 - def marker(self, text):
134
135
136 - def cuepoint(self, text):
137 print 'cuepoint', text
138
139
140 - def midi_ch_prefix(self, channel):
141 print 'midi_ch_prefix', channel
142
143
144 - def midi_port(self, value):
145 print 'midi_port:', value
146
147
148 - def tempo(self, value):
149 print 'tempo:', value
150
151
152 - def smtp_offset(self, hour, minute, second, frame, framePart):
153 print 'smtp_offset', hour, minute, second, frame, framePart
154
155
156 - def time_signature(self, nn, dd, cc, bb):
157 print 'time_signature:', nn, dd, cc, bb
158
159
160 - def key_signature(self, sf, mi):
161 print 'key_signature', sf, mi
162
163
164 - def sequencer_specific(self, data):
165 print 'sequencer_specific', len(data)
166
167
168
169 if __name__ == '__main__':
170
171
172 test_file = 'test/midifiles/minimal.mid'
173 f = open(test_file, 'rb')
174
175
176 from MidiInFile import MidiInFile
177 midiIn = MidiInFile(MidiToText(), f)
178 midiIn.read()
179 f.close()
180