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')
评论列表
文章目录