1 class EventDispatcherBase
:
4 def __init__(self
, outstream
):
6 The event dispatcher generates events on the outstream. This
7 is the base implementation. It is more like an interface for
8 how the EventDispatcher. It has the methods that are used by
11 # internal values, don't mess with 'em directly
12 self
.outstream
= outstream
20 def update_time(self
, new_time
=0, relative
=1):
21 "Updates relative/absolute time."
22 self
.outstream
.update_time(new_time
, relative
)
24 # 'official' midi events
26 def header(self
, format
, nTracks
, division
):
27 "Triggers the header event"
28 self
.outstream
.header(format
, nTracks
, division
)
31 def start_of_track(self
, current_track
):
32 "Triggers the start of track event"
34 # I do this twice so that users can overwrite the
35 # start_of_track event handler without worrying whether the
36 # track number is updated correctly.
37 self
.outstream
.set_current_track(current_track
)
38 self
.outstream
.start_of_track(current_track
)
40 # Event dispatchers for midi events
42 def channel_messages(self
, hi_nible
, channel
, data
):
43 "Dispatches channel messages"
44 self
.outstream
.channel_message(hi_nible
, channel
, data
)
47 def continuous_controllers(self
, channel
, controller
, value
):
48 "Dispatches channel messages"
49 self
.outstream
.continuous_controller(channel
, controller
, value
)
52 def system_commons(self
, common_type
, common_data
):
53 "Dispatches system common messages"
54 self
.outstream
.system_common(common_type
, common_data
)
57 def meta_event(self
, meta_type
, data
):
58 "Dispatches meta events"
59 self
.outstream
.meta_event(meta_type
, data
)
62 def sysex_events(self
, data
):
63 "Dispatcher for sysex events"
64 self
.outstream
.sysex_event(data
)
68 if __name__
== '__main__':
71 from MidiToText
import MidiToText
72 from constants
import NOTE_ON
74 outstream
= MidiToText()
75 dispatcher
= EventDispatcherBase(outstream
)
76 dispatcher
.channel_messages(NOTE_ON
, 0x00, '\x40\x40')