démarrage du support de plusieurs wiimotes.
[minwii.git] / src / mxmMidi / experimental / EventDispatcherBase.py
1 class EventDispatcherBase:
2
3
4 def __init__(self, outstream):
5 """
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
9 the Midi Parser.
10 """
11 # internal values, don't mess with 'em directly
12 self.outstream = outstream
13
14
15 def eof(self):
16 "End of file!"
17 self.outstream.eof()
18
19
20 def update_time(self, new_time=0, relative=1):
21 "Updates relative/absolute time."
22 self.outstream.update_time(new_time, relative)
23
24 # 'official' midi events
25
26 def header(self, format, nTracks, division):
27 "Triggers the header event"
28 self.outstream.header(format, nTracks, division)
29
30
31 def start_of_track(self, current_track):
32 "Triggers the start of track event"
33
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)
39
40 # Event dispatchers for midi events
41
42 def channel_messages(self, hi_nible, channel, data):
43 "Dispatches channel messages"
44 self.outstream.channel_message(hi_nible, channel, data)
45
46
47 def continuous_controllers(self, channel, controller, value):
48 "Dispatches channel messages"
49 self.outstream.continuous_controller(channel, controller, value)
50
51
52 def system_commons(self, common_type, common_data):
53 "Dispatches system common messages"
54 self.outstream.system_common(common_type, common_data)
55
56
57 def meta_event(self, meta_type, data):
58 "Dispatches meta events"
59 self.outstream.meta_event(meta_type, data)
60
61
62 def sysex_events(self, data):
63 "Dispatcher for sysex events"
64 self.outstream.sysex_event(data)
65
66
67
68 if __name__ == '__main__':
69
70
71 from MidiToText import MidiToText
72 from constants import NOTE_ON
73
74 outstream = MidiToText()
75 dispatcher = EventDispatcherBase(outstream)
76 dispatcher.channel_messages(NOTE_ON, 0x00, '\x40\x40')