Skip to content

Commit

Permalink
Merge pull request #4 from POZAlabs/mid-815
Browse files Browse the repository at this point in the history
MID-815: key name 자동 변환하여 mido 메세지 생성
  • Loading branch information
hyeonch authored Apr 12, 2024
2 parents 0c46dfc + 5efc51e commit 655b145
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion miditoolkit/midi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ def event_compare(event1, event2):
# 5. Key
key_list = []
for ks in self.key_signature_changes:
key_list.append(mido.MetaMessage("key_signature", time=ks.time, key=ks.key_name))
mido_key_name = _key_number_to_key_name(ks.key_number)
key_list.append(mido.MetaMessage("key_signature", time=ks.time, key=mido_key_name))

# crop segment
start_tick, end_tick = 0, 0
Expand Down Expand Up @@ -731,3 +732,33 @@ def _get_tick_to_second_mapping(
tick_to_time[start_tick : end_tick + 1] = acc_time + seconds_per_tick * ticks
acc_time = tick_to_time[end_tick]
return tick_to_time


def _key_number_to_key_name(key_number: int) -> str:
key_number_to_mido_key_name = [
"C",
"Db",
"D",
"Eb",
"E",
"F",
"F#",
"G",
"Ab",
"A",
"Bb",
"B",
"Cm",
"C#m",
"Dm",
"D#m",
"Em",
"Fm",
"F#m",
"Gm",
"G#m",
"Am",
"Bbm",
"Bm",
]
return key_number_to_mido_key_name[key_number]

0 comments on commit 655b145

Please sign in to comment.