structure.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:midi 作者: MicroTransactionsMatterToo 项目源码 文件源码
def __init__(self, data: Union[FileIO, BufferedReader]) -> None:
        chunk_type = data.read(4)
        if chunk_type != b'MThd':
            raise ValueError("File had invalid header chunk type")

        header_length = int.from_bytes(data.read(4), 'big')
        if header_length != 6:
            raise ValueError("File has unsupported header length")
        self.length = header_length

        format = int.from_bytes(data.read(2), 'big')
        if format not in [0, 1, 2]:
            raise ValueError("File has unsupported format")
        self.format = format

        ntrks = int.from_bytes(data.read(2), 'big')
        if ntrks > 0 and format == 0:
            raise ValueError("Multiple tracks in single track format")
        self.ntrks = ntrks

        self.tpqn = int.from_bytes(data.read(2), 'big')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号