— Prise en charge des altérations ;
[minwii.git] / src / mxmMidi / MidiToText.py
1 # -*- coding: ISO-8859-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 # channel events
13
14 def channel_message(self, message_type, channel, data):
15 """The default event handler for channel messages"""
16 print 'message_type:%X, channel:%X, data size:%X' % (message_type, channel, len(data))
17
18
19 def note_on(self, channel=0, note=0x40, velocity=0x40):
20 print 'note_on - ch:%02X, note:%02X, vel:%02X time:%s' % (channel, note, velocity, self.timeInMs())
21
22 def note_off(self, channel=0, note=0x40, velocity=0x40):
23 print 'note_off - ch:%02X, note:%02X, vel:%02X time:%s' % (channel, note, velocity, self.abs_time())
24
25 def aftertouch(self, channel=0, note=0x40, velocity=0x40):
26 print 'aftertouch', channel, note, velocity
27
28
29 def continuous_controller(self, channel, controller, value):
30 print 'controller - ch: %02X, cont: #%02X, value: %02X' % (channel, controller, value)
31
32
33 def patch_change(self, channel, patch):
34 print 'patch_change - ch:%02X, patch:%02X' % (channel, patch)
35
36
37 def channel_pressure(self, channel, pressure):
38 print 'channel_pressure', channel, pressure
39
40
41 def pitch_bend(self, channel, value):
42 print 'pitch_bend ch:%s, value:%s' % (channel, value)
43
44
45
46 #####################
47 ## Common events
48
49
50 def system_exclusive(self, data):
51 print 'system_exclusive - data size: %s' % len(data)
52
53
54 def song_position_pointer(self, value):
55 print 'song_position_pointer: %s' % value
56
57
58 def song_select(self, songNumber):
59 print 'song_select: %s' % songNumber
60
61
62 def tuning_request(self):
63 print 'tuning_request'
64
65
66 def midi_time_code(self, msg_type, values):
67 print 'midi_time_code - msg_type: %s, values: %s' % (msg_type, values)
68
69
70
71 #########################
72 # header does not really belong here. But anyhoo!!!
73
74 def header(self, format=0, nTracks=1, division=96):
75 print 'format: %s, nTracks: %s, division: %s' % (format, nTracks, division)
76 print '----------------------------------'
77 print ''
78 print division
79 self.division = division
80
81 def eof(self):
82 print 'End of file'
83
84
85 def start_of_track(self, n_track=0):
86 print 'Start - track #%s' % n_track
87
88
89 def end_of_track(self):
90 print 'End of track'
91 print ''
92
93
94
95 ###############
96 # sysex event
97
98 def sysex_event(self, data):
99 print 'sysex_event - datasize: %X' % len(data)
100
101
102 #####################
103 ## meta events
104
105 def meta_event(self, meta_type, data):
106 print 'undefined_meta_event:', meta_type, len(data)
107
108
109 def sequence_number(self, value):
110 print 'sequence_number', value
111
112
113 def text(self, text):
114 print 'text', text
115
116
117 def copyright(self, text):
118 print 'copyright', text
119
120
121 def sequence_name(self, text):
122 print 'sequence_name:', text
123
124
125 def instrument_name(self, text):
126 print 'instrument_name:', text
127
128
129 def lyric(self, text):
130 print 'lyric', text
131
132
133 def marker(self, text):
134 print 'marker', text
135
136
137 def cuepoint(self, text):
138 print 'cuepoint', text
139
140
141 def midi_ch_prefix(self, channel):
142 print 'midi_ch_prefix', channel
143
144
145 def midi_port(self, value):
146 print 'midi_port:', value
147
148
149 def tempo(self, value):
150 print 'tempo:', value
151 self.tempo = value
152
153
154 def smtp_offset(self, hour, minute, second, frame, framePart):
155 print 'smtp_offset', hour, minute, second, frame, framePart
156
157
158 def time_signature(self, nn, dd, cc, bb):
159 print 'time_signature:', nn, dd, cc, bb
160
161
162 def key_signature(self, sf, mi):
163 print 'key_signature', sf, mi
164
165
166 def sequencer_specific(self, data):
167 print 'sequencer_specific', len(data)
168
169 def timeInMs(self):
170 return(long(self.abs_time())*1000000000/(long(self.tempo)*long(self.division)))
171
172
173
174 if __name__ == '__main__':
175
176 # get data
177 test_file = '../songs/midis/test.mid'
178 f = open(test_file, 'rb')
179
180 # do parsing
181 from MidiInFile import MidiInFile
182 midiIn = MidiInFile(MidiToText(), f)
183 midiIn.read()
184 f.close()