Пример #1
0
    def parse_varbyte_as_int(self, fp, return_bytes_read=True):
        """Read a variable length byte from the file and return the
        corresponding integer."""
        result = 0
        bytes_read = 0
        r = 0x80
        while r & 0x80:
            try:
                r = self.bytes_to_int(fp.read(1))
                self.bytes_read += 1
            except:
                raise IOError("Couldn't read variable length byte from file.")
            if r & 0x80:
                result = (result << 7) + (r & 0x7F)
            else:
                result = (result << 7) + r
            bytes_read += 1
        if not return_bytes_read:
            return result
        else:
            return (result, bytes_read)


if __name__ == '__main__':
    from sys import argv
    import fluidsynth
    import MidiFileOut
    fluidsynth.init()
    (m, bpm) = MIDI_to_Composition(argv[1])
    MidiFileOut.write_Composition('test.mid', m, bpm)
Пример #2
0
integer."""

        result = 0
        bytes_read = 0
        r = 0x80
        while r & 0x80:
            try:
                r = self.bytes_to_int(fp.read(1))
                self.bytes_read += 1
            except:
                (IOError, "Couldn't read variable length byte from file.")
            if r & 0x80:
                result = (result << 7) + (r & 0x7F)
            else:
                result = (result << 7) + r
            bytes_read += 1
        if not return_bytes_read:
            return result
        else:
            return (result, bytes_read)


if __name__ == '__main__':
    from sys import argv
    import fluidsynth
    import MidiFileOut
    fluidsynth.init()
    (m, bpm) = MIDI_to_Composition(argv[1])
    MidiFileOut.write_Composition('test.mid', m, bpm)