prise en charge des indications de tempo des fichiers musicxml. Si absent, le tempo...
[minwii.git] / src / mxmMidi / MidiInFile.py
1 # -*- coding: ISO-8859-1 -*-
2
3 from RawInstreamFile import RawInstreamFile
4 from MidiFileParser import MidiFileParser
5
6
7 class MidiInFile:
8
9 """
10
11 Parses a midi file, and triggers the midi events on the outStream
12 object.
13
14 Get example data from a minimal midi file, generated with cubase.
15 >>> test_file = 'C:/Documents and Settings/maxm/Desktop/temp/midi/src/midi/tests/midifiles/minimal-cubase-type0.mid'
16
17 Do parsing, and generate events with MidiToText,
18 so we can see what a minimal midi file contains
19 >>> from MidiToText import MidiToText
20 >>> midi_in = MidiInFile(MidiToText(), test_file)
21 >>> midi_in.read()
22 format: 0, nTracks: 1, division: 480
23 ----------------------------------
24 <BLANKLINE>
25 Start - track #0
26 sequence_name: Type 0
27 tempo: 500000
28 time_signature: 4 2 24 8
29 note_on - ch:00, note:48, vel:64 time:0
30 note_off - ch:00, note:48, vel:40 time:480
31 End of track
32 <BLANKLINE>
33 End of file
34
35
36 """
37
38 def __init__(self, outStream, infile):
39 # these could also have been mixins, would that be better? Nah!
40 self.raw_in = RawInstreamFile(infile)
41 self.parser = MidiFileParser(self.raw_in, outStream)
42
43
44 def read(self):
45 "Start parsing the file"
46 p = self.parser
47 p.parseMThdChunk()
48 p.parseMTrkChunks()
49
50
51 def setData(self, data=''):
52 "Sets the data from a plain string"
53 self.raw_in.setData(data)
54
55