1 class MidiOutStreamBase
:
6 MidiOutStreamBase is Basically an eventhandler. It is the most central
7 class in the Midi library. You use it both for writing events to
8 an output stream, and as an event handler for an input stream.
10 This makes it extremely easy to take input from one stream and
11 send it to another. Ie. if you want to read a Midi file, do some
12 processing, and send it to a midiport.
14 All time values are in absolute values from the opening of a
15 stream. To calculate time values, please use the MidiTime and
16 MidiDeltaTime classes.
22 # the time is rather global, so it needs to be stored
23 # here. Otherwise there would be no really simple way to
24 # calculate it. The alternative would be to have each event
25 # handler do it. That sucks even worse!
26 self
._absolute
_time
= 0
27 self
._relative
_time
= 0
28 self
._current
_track
= 0
30 # time handling event handlers. They should overwritten with care
32 def update_time(self
, new_time
=0, relative
=1):
34 Updates the time, if relative is true, new_time is relative,
38 self
._relative
_time
= new_time
39 self
._absolute
_time
+= new_time
41 self
._absolute
_time
= new_time
42 self
._relative
_time
= new_time
- self
._absolute
_time
45 "Returns the relative time"
46 return self
._relative
_time
49 "Returns the absolute time"
50 return self
._absolute
_time
52 # track handling event handlers
54 def set_current_track(self
, new_track
):
55 "Sets the current track number"
56 self
._current
_track
= new_track
58 def get_current_track(self
):
59 "Returns the current track number"
60 return self
._current
_track
67 def channel_message(self
, message_type
, channel
, data
):
68 """The default event handler for channel messages"""
75 def system_exclusive(self
, data
):
77 """The default event handler for system_exclusive messages"""
81 def system_common(self
, common_type
, common_data
):
83 """The default event handler for system common messages"""
87 #########################
88 # header does not really belong here. But anyhoo!!!
90 def header(self
, format
, nTracks
, division
):
93 format: type of midi file in [1,2]
94 nTracks: number of tracks
95 division: timing division
100 def start_of_track(self
, n_track
=0):
103 n_track: number of track
111 End of file. No more events to be processed.
116 #####################
120 def meta_event(self
, meta_type
, data
, time
):
122 """The default event handler for meta_events"""
128 if __name__
== '__main__':
130 midiOut
= MidiOutStreamBase()
131 midiOut
.update_time(0,0)
132 midiOut
.note_on(0, 63, 127)
133 midiOut
.note_off(0, 63, 127)