def test_parsing_format_0_file_results_in_header_and_track_chunk(self): with open(FORMAT_0_EXAMPLE, "rb") as f: chunks = parse_chunks(f) self.assertEqual(len(chunks), 2) self.assertEqual(chunks[0]["type"], HEADER) self.assertEqual(chunks[1]["type"], TRACK)
def test_parsing_format_1_file_parses_header_correctly(self): with open(FORMAT_1_EXAMPLE, "rb") as f: chunks = parse_chunks(f) header = chunks[0] self.assertEqual(header["type"], HEADER) self.assertEqual(header["format"], 1) self.assertEqual(header["track_count"], 4) division = header["division"] self.assertEqual(division["format"], "time units per quarter note") self.assertEqual(division["time_units"], 96)
def main(file): log.debug("opening file '{}'...".format(file)) with open(file, "rb") as f: chunks = parse_chunks(f) # basic track printing routine print("\n") for chunk in chunks: if not chunk: print("Missing/Unparseable chunk. Skipping...\n") continue type_ = chunk["type"] print("{} chunk".format(type_)) if type_ == "header": for k, v in chunk.items(): if k != "type": print(k, v) else: for evt in chunk["events"]: print("Delta: {}".format(evt[0])) for k, v in evt[1].items(): print(k, v) print("") print("")
def test_parsing_format_1_file_parses_tempo_track_correctly(self): with open(FORMAT_1_EXAMPLE, "rb") as f: chunks = parse_chunks(f) tempo_track = chunks[1] self.assertEqual(tempo_track["type"], TRACK) self.assertEqual(len(tempo_track["events"]), 3) # only testing overall sequence of events, rather than every event field events = tempo_track["events"] self.assertEqual(events[0][0], 0) self.assertEqual(events[0][1]["type"], META) self.assertEqual(events[0][1]["sub_type"], "Time Signature") self.assertEqual(events[1][0], 0) self.assertEqual(events[1][1]["type"], META) self.assertEqual(events[1][1]["sub_type"], "Set Tempo") self.assertEqual(events[2][0], 384) self.assertEqual(events[2][1]["type"], META) self.assertEqual(events[2][1]["sub_type"], "End of Track")