增加对于不正规Midi兼容性的支持,避免转换错误的情况发生。

This commit is contained in:
EillesWan 2023-07-31 22:28:14 +09:00
parent f73c1be944
commit 70674ec6f7
5 changed files with 11 additions and 22 deletions

View File

@ -17,8 +17,8 @@ Terms & Conditions: License.md in the root directory
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
__version__ = "1.2.0"
__vername__ = "更高效的算法管理"
__version__ = "1.2.1"
__vername__ = "扩大对有问题的Midi文件的兼容性"
__author__ = (("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray"), ("鸣凤鸽子", "MingFengPigeon"))
__all__ = [
# 主要类

View File

@ -183,7 +183,7 @@ class MidiConvert:
"""文件名,不含路径且不含后缀"""
try:
return cls(mido.MidiFile(midi_file_path), midi_music_name, old_exe_format)
return cls(mido.MidiFile(midi_file_path,clip=True), midi_music_name, old_exe_format)
except (ValueError, TypeError) as E:
raise MidiDestroyedError(f"文件{midi_file_path}损坏:{E}")
except FileNotFoundError as E:
@ -537,18 +537,14 @@ class MidiConvert:
midi_channels: ChannelType = empty_midi_channels()
tempo = mido.midifiles.midifiles.DEFAULT_TEMPO
# a = 0
# 我们来用通道统计音乐信息
# 但是是用分轨的思路的
for track_no, track in enumerate(self.midi.tracks):
# print(track_no,track)
microseconds = 0
if not track:
continue
# print(track_no,"="*20)
for msg in track:
# print("+++",msg)
if msg.time != 0:
microseconds += msg.time * tempo / self.midi.ticks_per_beat / 1000
@ -557,8 +553,12 @@ class MidiConvert:
tempo = msg.tempo
else:
if not track_no in midi_channels[msg.channel].keys():
midi_channels[msg.channel][track_no] = []
try:
if not track_no in midi_channels[msg.channel].keys():
midi_channels[msg.channel][track_no] = []
except AttributeError as E:
print(msg,E)
if msg.type == "program_change":
midi_channels[msg.channel][track_no].append(
("PgmC", msg.program, microseconds)
@ -568,7 +568,6 @@ class MidiConvert:
midi_channels[msg.channel][track_no].append(
("NoteS", msg.note, msg.velocity, microseconds)
)
# a+=1
elif (msg.type == "note_on" and msg.velocity == 0) or (
msg.type == "note_off"
@ -577,7 +576,6 @@ class MidiConvert:
("NoteE", msg.note, microseconds)
)
# print(a)
"""整合后的音乐通道格式
每个通道包括若干消息元素其中逃不过这三种
@ -638,8 +636,6 @@ class MidiConvert:
# 第十通道是打击乐通道
SpecialBits = True if i == 9 else False
# nowChannel = []
for track_no, track in self.channels[i].items():
nowTrack = []

View File

@ -1,3 +1,3 @@
python -m build
python setup.py sdist bdist_wheel
python -m twine upload dist/*
python clean_update.py

View File

@ -1,4 +0,0 @@
#!/usr/bin/env bash
python -m build
python -m twine upload dist/*
python clean_update.py

View File

@ -1,3 +0,0 @@
python setup.py sdist bdist_wheel
python -m twine upload dist/*
python clean_update.py