Beispiel #1
0
 def end_of_track(self):
     """
     Writes the track to the buffer.
     >>> from mxm.midifile.src.data_type_converters import readBew
     >>> midi_out = MidiOutFile()
     >>> midi_out.start_of_track()
     >>> midi_out.note_on(channel=0, note=0x40, velocity=0x40)
     >>> midi_out.end_of_track()
     >>> r = list(midi_out.read_all())
     >>> r
     [77, 84, 114, 107, 0, 0, 0, 8, 0, 144, 64, 64, 0, 255, 47, 0]
     >>> bytes(r[:4]), readBew(r[4:8]), r[8:12], r[12:16]
     (b'MTrk', 8, [0, 144, 64, 64], [0, 255, 47, 0])
     """
     raw = self.raw_out
     raw.writeSlice(c.TRACK_HEADER)
     # track_data = self._current_track_buffer.getvalue()
     track_data = self._current_track_buffer.read_all()
     eot_slice = bytes(writeVar(self.rel_time())) + bytes(
         [c.META_EVENT, c.END_OF_TRACK, 0])
     # wee need to know size of track data.
     track_length = len(track_data) + len(eot_slice)
     raw.writeBew(track_length, 4)
     # then write
     raw.writeSlice(track_data)
     raw.writeSlice(eot_slice)
     self._current_track_buffer.close()
     del self._current_track_buffer
Beispiel #2
0
 def sysex_event(self, data):
     """
     data: list of values in range(128)
     """
     super().system_exclusive(data)
     sysex_slice = bytearray([c.SYSTEM_EXCLUSIVE])
     sysex_slice += bytearray(writeVar(len(data) + 1))  # sysex_len
     sysex_slice += data
     sysex_slice += bytearray([c.END_OFF_EXCLUSIVE])
     self.event_slice(sysex_slice)
Beispiel #3
0
 def sequencer_specific(self, id, data):
     """
     id: manufacturer id. 1 or 3 bytes long.
     data: The data as byte values
     """
     super().sequencer_specific(id, data)
     data = bytes(data)
     len_data = len(id) + len(data)
     len_data = writeVar(len_data)
     seq_slice = bytes(len_data) + bytes(id) + data
     self.meta_slice(c.SEQUENCER_SPECIFIC, seq_slice)
Beispiel #4
0
 def meta_slice(self, meta_type, data_slice):
     """
     Writes a meta event. meta_type is a byte from constants. data_slice is bytes
     >>> midi_out = MidiOutFile()
     >>> midi_out.start_of_track()
     >>> midi_out.meta_slice(meta_type=c.TEXT, data_slice=b'pimpf')
     >>> midi_out.end_of_track()
     >>> r = list(midi_out.read_all())
     >>> bytes(r[12:17])
     b'pimpf'
     """
     slc = bytearray()
     slc.append(c.META_EVENT)  # this is a meta event
     slc.append(meta_type)  # the specific meta event.
     slc += bytes(writeVar(len(data_slice)))
     slc += data_slice
     self.event_slice(slc)
 def writeVarLen(self, value):
     "Writes a variable length word to the file"
     self.writeSlice(writeVar(value))