c'est bof... on va essayer autre chose.
[minwii.git] / src / mxmMidi / experimental / MidiOutStreamBase.py
1 class MidiOutStreamBase:
2
3
4 """
5
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.
9
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.
13
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.
17
18 """
19
20 def __init__(self):
21
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
29
30 # time handling event handlers. They should overwritten with care
31
32 def update_time(self, new_time=0, relative=1):
33 """
34 Updates the time, if relative is true, new_time is relative,
35 else it's absolute.
36 """
37 if relative:
38 self._relative_time = new_time
39 self._absolute_time += new_time
40 else:
41 self._absolute_time = new_time
42 self._relative_time = new_time - self._absolute_time
43
44 def rel_time(self):
45 "Returns the relative time"
46 return self._relative_time
47
48 def abs_time(self):
49 "Returns the absolute time"
50 return self._absolute_time
51
52 # track handling event handlers
53
54 def set_current_track(self, new_track):
55 "Sets the current track number"
56 self._current_track = new_track
57
58 def get_current_track(self):
59 "Returns the current track number"
60 return self._current_track
61
62
63 #####################
64 ## Midi events
65
66
67 def channel_message(self, message_type, channel, data):
68 """The default event handler for channel messages"""
69 pass
70
71
72 #####################
73 ## Common events
74
75 def system_exclusive(self, data):
76
77 """The default event handler for system_exclusive messages"""
78 pass
79
80
81 def system_common(self, common_type, common_data):
82
83 """The default event handler for system common messages"""
84 pass
85
86
87 #########################
88 # header does not really belong here. But anyhoo!!!
89
90 def header(self, format, nTracks, division):
91
92 """
93 format: type of midi file in [1,2]
94 nTracks: number of tracks
95 division: timing division
96 """
97 pass
98
99
100 def start_of_track(self, n_track=0):
101
102 """
103 n_track: number of track
104 """
105 pass
106
107
108 def eof(self):
109
110 """
111 End of file. No more events to be processed.
112 """
113 pass
114
115
116 #####################
117 ## meta events
118
119
120 def meta_event(self, meta_type, data, time):
121
122 """The default event handler for meta_events"""
123 pass
124
125
126
127
128 if __name__ == '__main__':
129
130 midiOut = MidiOutStreamBase()
131 midiOut.update_time(0,0)
132 midiOut.note_on(0, 63, 127)
133 midiOut.note_off(0, 63, 127)
134
135