LEFT | RIGHT |
(no file at all) | |
1 #!@TARGET_PYTHON@ | 1 #!@TARGET_PYTHON@ |
2 | 2 |
3 # Copyright (C) 2006--2020 Brailcom, o.p.s. | 3 # Copyright (C) 2006--2020 Brailcom, o.p.s. |
4 # | 4 # |
5 # Author: Milan Zamazal <pdm@brailcom.org> | 5 # Author: Milan Zamazal <pdm@brailcom.org> |
6 # | 6 # |
7 # This file is part of LilyPond, the GNU music typesetter. | 7 # This file is part of LilyPond, the GNU music typesetter. |
8 # | 8 # |
9 # LilyPond is free software: you can redistribute it and/or modify | 9 # LilyPond is free software: you can redistribute it and/or modify |
10 # it under the terms of the GNU General Public License as published by | 10 # it under the terms of the GNU General Public License as published by |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 f = control_mode_formatter ("Control mode change: ", ch) | 163 f = control_mode_formatter ("Control mode change: ", ch) |
164 elif (func == 0xC0): | 164 elif (func == 0xC0): |
165 f = channel_formatter ("Program Change: ", ch) | 165 f = channel_formatter ("Program Change: ", ch) |
166 elif (func == 0xD0): | 166 elif (func == 0xD0): |
167 f = channel_formatter ("Channel aftertouch: ", ch) | 167 f = channel_formatter ("Channel aftertouch: ", ch) |
168 elif (ev[0] in [0xF0, 0xF7]): | 168 elif (ev[0] in [0xF0, 0xF7]): |
169 f = meta_formatter ("System-exclusive event: ") | 169 f = meta_formatter ("System-exclusive event: ") |
170 | 170 |
171 if f: | 171 if f: |
172 if len (ev) > 2: | 172 if len (ev) > 2: |
173 print padding + f.format (ev[1], ev[2]) | 173 print(padding + f.format (ev[1], ev[2])) |
174 elif len (ev) > 1: | 174 elif len (ev) > 1: |
175 print padding + f.format (ev[1]) | 175 print(padding + f.format (ev[1])) |
176 else: | 176 else: |
177 print padding + f.format () | 177 print(padding + f.format ()) |
178 else: | 178 else: |
179 print padding + "Unrecognized MIDI event: " + str (ev); | 179 print(padding + "Unrecognized MIDI event: " + str (ev)); |
180 | 180 |
181 def dump_midi (data, midi_file, options): | 181 def dump_midi (data, midi_file, options): |
182 if not options.pretty: | 182 if not options.pretty: |
183 print data | 183 print(data) |
184 return | 184 return |
185 # First, dump general info, #tracks, etc. | 185 # First, dump general info, #tracks, etc. |
186 print "Filename: " + midi_file; | 186 print("Filename: " + midi_file); |
187 i = data[0]; | 187 i = data[0]; |
188 m_formats = {0: 'single multi-channel track', | 188 m_formats = {0: 'single multi-channel track', |
189 1: "one or more simultaneous tracks", | 189 1: "one or more simultaneous tracks", |
190 2: "one or more sequentially independent single-track patterns"
} | 190 2: "one or more sequentially independent single-track patterns"
} |
191 print "MIDI format: " + str (i[0]) + " (" + m_formats.get (i[0], "") + ")"; | 191 print("MIDI format: " + str (i[0]) + " (" + m_formats.get (i[0], "") + ")")
; |
192 print "Divisions: " + str (i[1]) + " per whole note"; | 192 print("Divisions: " + str (i[1]) + " per whole note"); |
193 print "#Tracks: " + str ( len (data[1])) | 193 print("#Tracks: " + str ( len (data[1]))) |
194 n = 0; | 194 n = 0; |
195 for tr in data[1]: | 195 for tr in data[1]: |
196 time = 0; | 196 time = 0; |
197 n += 1; | 197 n += 1; |
198 print | 198 print() |
199 print "Track " + str(n) + ":" | 199 print("Track " + str(n) + ":") |
200 print " Time 0:" | 200 print(" Time 0:") |
201 for ev in tr: | 201 for ev in tr: |
202 if ev[0]>time: | 202 if ev[0]>time: |
203 time = ev[0] | 203 time = ev[0] |
204 print " Time " + str(time) + ": " | 204 print(" Time " + str(time) + ": ") |
205 dump_event (ev[1], time, " "); | 205 dump_event (ev[1], time, " "); |
206 | 206 |
207 | 207 |
208 | 208 |
209 def go (): | 209 def go (): |
210 options, args = process_options (sys.argv[1:]) | 210 options, args = process_options (sys.argv[1:]) |
211 midi_file = args[0] | 211 midi_file = args[0] |
212 midi_data = read_midi (midi_file) | 212 midi_data = read_midi (midi_file) |
213 info = track_info (midi_data) | 213 info = track_info (midi_data) |
214 if (options.dump or options.pretty): | 214 if (options.dump or options.pretty): |
215 dump_midi (midi_data, midi_file, options); | 215 dump_midi (midi_data, midi_file, options); |
216 elif options.regexp: | 216 elif options.regexp: |
217 import re | 217 import re |
218 regexp = re.compile (options.regexp) | 218 regexp = re.compile (options.regexp) |
219 numbers = [str(n+1) for n, name in info if regexp.search (name)] | 219 numbers = [str(n+1) for n, name in info if regexp.search (name)] |
220 if numbers: | 220 if numbers: |
221 if options.prefix: | 221 if options.prefix: |
222 sys.stdout.write ('%s ' % (options.prefix,)) | 222 sys.stdout.write ('%s ' % (options.prefix,)) |
223 sys.stdout.write (','.join (numbers)) | 223 sys.stdout.write (','.join (numbers)) |
224 sys.stdout.write ('\n') | 224 sys.stdout.write ('\n') |
225 else: | 225 else: |
226 for n, name in info: | 226 for n, name in info: |
227 sys.stdout.write ('%d %s\n' % (n+1, name,)) | 227 sys.stdout.write ('%d %s\n' % (n+1, name,)) |
228 | 228 |
229 if __name__ == '__main__': | 229 if __name__ == '__main__': |
230 go () | 230 go () |
LEFT | RIGHT |