1  
 
  2  
 
  4  
 
  5  
 
  6      """
 
  7  
 
  8      MidiOutstream is Basically an eventhandler. It is the most central
 
  9      class in the Midi library. You use it both for writing events to
 
 10      an output stream, and as an event handler for an input stream.
 
 11  
 
 12      This makes it extremely easy to take input from one stream and
 
 13      send it to another. Ie. if you want to read a Midi file, do some
 
 14      processing, and send it to a midiport.
 
 15  
 
 16      All time values are in absolute values from the opening of a
 
 17      stream. To calculate time values, please use the MidiTime and
 
 18      MidiDeltaTime classes.
 
 19  
 
 20      """ 
 21  
 
 23          
 
 24          
 
 25          
 
 26          
 
 27          
 
 28          self._absolute_time = 0 
 29          self._relative_time = 0 
 30          self._current_track = 0 
 31          self._running_status = None 
  32  
 
 33      
 
 34  
 
 36          """
 
 37          Updates the time, if relative is true, new_time is relative, 
 
 38          else it's absolute.
 
 39          """ 
 40          if relative: 
 41              self._relative_time = new_time 
 42              self._absolute_time += new_time 
 43          else: 
 44              self._relative_time = new_time - self._absolute_time 
 45              self._absolute_time = new_time 
  46  
 
 48          """
 
 49          reset time to 0
 
 50          """ 
 51          self._relative_time = 0 
 52          self._absolute_time = 0 
  53          
 
 55          "Returns the relative time" 
 56          return self._relative_time 
  57  
 
 59          "Returns the absolute time" 
 60          return self._absolute_time 
  61  
 
 62      
 
 63      
 
 65          "Invalidates the running status" 
 66          self._running_status = None 
  67  
 
 69          "Set the new running status" 
 70          self._running_status = new_status 
  71  
 
 73          "Set the new running status" 
 74          return self._running_status 
  75  
 
 76      
 
 77      
 
 79          "Sets the current track number" 
 80          self._current_track = new_track 
  81      
 
 83          "Returns the current track number" 
 84          return self._current_track 
  85      
 
 86      
 
 87      
 
 88      
 
 89  
 
 90  
 
 92          """The default event handler for channel messages""" 
 93          pass 
  94  
 
 95  
 
 96 -    def note_on(self, channel=0, note=0x40, velocity=0x40): 
  97  
 
 98          """
 
 99          channel: 0-15
 
100          note, velocity: 0-127
 
101          """ 
102          pass 
 103  
 
104  
 
105 -    def note_off(self, channel=0, note=0x40, velocity=0x40): 
 106  
 
107          """
 
108          channel: 0-15
 
109          note, velocity: 0-127
 
110          """ 
111          pass 
 112  
 
113  
 
114 -    def aftertouch(self, channel=0, note=0x40, velocity=0x40): 
 115  
 
116          """
 
117          channel: 0-15
 
118          note, velocity: 0-127
 
119          """ 
120          pass 
 121  
 
122  
 
124  
 
125          """
 
126          channel: 0-15
 
127          controller, value: 0-127
 
128          """ 
129          pass 
 130  
 
131  
 
133  
 
134          """
 
135          channel: 0-15
 
136          patch: 0-127
 
137          """ 
138          pass 
 139  
 
140  
 
142  
 
143          """
 
144          channel: 0-15
 
145          pressure: 0-127
 
146          """ 
147          pass 
 148  
 
149  
 
151  
 
152          """
 
153          channel: 0-15
 
154          value: 0-16383
 
155  
 
156          """ 
157          pass 
 158  
 
159  
 
160  
 
161  
 
162      
 
163      
 
164  
 
166  
 
167          """
 
168          data: list of values in range(128)
 
169          """ 
170          pass 
 171  
 
172  
 
173      
 
174      
 
175  
 
177  
 
178          """
 
179          value: 0-16383
 
180          """ 
181          pass 
 182  
 
183  
 
185  
 
186          """
 
187          songNumber: 0-127
 
188          """ 
189          pass 
 190  
 
191  
 
193  
 
194          """
 
195          No values passed
 
196          """ 
197          pass 
 198  
 
199              
 
201          """
 
202          msg_type: 0-7
 
203          values: 0-15
 
204          """ 
205          pass 
 206  
 
207  
 
208      
 
209      
 
210      
 
212  
 
213          """
 
214          format: type of midi file in [1,2]
 
215          nTracks: number of tracks
 
216          division: timing division
 
217          """ 
218          pass 
 219  
 
220  
 
222  
 
223          """
 
224          End of file. No more events to be processed.
 
225          """ 
226          pass 
 227  
 
228  
 
229      
 
230      
 
231  
 
232  
 
239  
 
240  
 
242  
 
243          """
 
244          n_track: number of track
 
245          """ 
246          pass 
 247  
 
248  
 
250  
 
251          """
 
252          n_track: number of track
 
253          """ 
254          pass 
 255  
 
256  
 
258  
 
259          """
 
260          value: 0-16383
 
261          """ 
262          pass 
 263  
 
264  
 
265 -    def text(self, text): 
 266  
 
267          """
 
268          Text event
 
269          text: string
 
270          """ 
271          pass 
 272  
 
273  
 
275  
 
276          """
 
277          Copyright notice
 
278          text: string
 
279          """ 
280          pass 
 281  
 
282  
 
284  
 
285          """
 
286          Sequence/track name
 
287          text: string
 
288          """ 
289          pass 
 290  
 
291  
 
293  
 
294          """
 
295          text: string
 
296          """ 
297          pass 
 298  
 
299  
 
301  
 
302          """
 
303          text: string
 
304          """ 
305          pass 
 306  
 
307  
 
309  
 
310          """
 
311          text: string
 
312          """ 
313          pass 
 314  
 
315  
 
317  
 
318          """
 
319          text: string
 
320          """ 
321          pass 
 322  
 
323  
 
325  
 
326          """
 
327          channel: midi channel for subsequent data (deprecated in the spec)
 
328          """ 
329          pass 
 330  
 
331  
 
333  
 
334          """
 
335          value: Midi port (deprecated in the spec)
 
336          """ 
337          pass 
 338  
 
339  
 
341  
 
342          """
 
343          value: 0-2097151
 
344          tempo in us/quarternote
 
345          (to calculate value from bpm: int(60,000,000.00 / BPM))
 
346          """ 
347          pass 
 348  
 
349  
 
350 -    def smtp_offset(self, hour, minute, second, frame, framePart): 
 351  
 
352          """
 
353          hour,
 
354          minute,
 
355          second: 3 bytes specifying the hour (0-23), minutes (0-59) and 
 
356                  seconds (0-59), respectively. The hour should be 
 
357                  encoded with the SMPTE format, just as it is in MIDI 
 
358                  Time Code.
 
359          frame: A byte specifying the number of frames per second (one 
 
360                 of : 24, 25, 29, 30).
 
361          framePart: A byte specifying the number of fractional frames, 
 
362                     in 100ths of a frame (even in SMPTE-based tracks 
 
363                     using a different frame subdivision, defined in the 
 
364                     MThd chunk).
 
365          """ 
366          pass 
 367  
 
368  
 
369  
 
371  
 
372          """
 
373          nn: Numerator of the signature as notated on sheet music
 
374          dd: Denominator of the signature as notated on sheet music
 
375              The denominator is a negative power of 2: 2 = quarter 
 
376              note, 3 = eighth, etc.
 
377          cc: The number of MIDI clocks in a metronome click
 
378          bb: The number of notated 32nd notes in a MIDI quarter note 
 
379              (24 MIDI clocks)        
 
380          """ 
381          pass 
 382  
 
383  
 
384  
 
386  
 
387          """
 
388          sf: is a byte specifying the number of flats (-ve) or sharps 
 
389              (+ve) that identifies the key signature (-7 = 7 flats, -1 
 
390              = 1 flat, 0 = key of C, 1 = 1 sharp, etc).
 
391          mi: is a byte specifying a major (0) or minor (1) key.
 
392          """ 
393          pass 
 394  
 
395  
 
396  
 
398  
 
399          """
 
400          data: The data as byte values
 
401          """ 
402          pass 
 403  
 
404  
 
405  
 
406  
 
407      
 
408      
 
409  
 
411  
 
412          """
 
413          No values passed
 
414          """ 
415          pass 
 416  
 
417  
 
418  
 
420  
 
421          """
 
422          No values passed
 
423          """ 
424          pass 
 425  
 
426  
 
427  
 
429  
 
430          """
 
431          No values passed
 
432          """ 
433          pass 
 434  
 
435  
 
436  
 
438  
 
439          """
 
440          No values passed
 
441          """ 
442          pass 
 443  
 
444  
 
445  
 
447  
 
448          """
 
449          No values passed
 
450          """ 
451          pass 
 452  
 
453  
 
454  
 
456  
 
457          """
 
458          No values passed
 
459          """ 
460          pass 
  461  
 
462  
 
463  
 
464  if __name__ == '__main__': 
465  
 
466      midiOut = MidiOutStream() 
467      midiOut.update_time(0,0) 
468      midiOut.note_on(0, 63, 127) 
469      midiOut.note_off(0, 63, 127) 
470