mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2024-11-11 01:27:35 +08:00
增加对于不正规Midi兼容性的支持,避免转换错误的情况发生。
This commit is contained in:
parent
f73c1be944
commit
70674ec6f7
@ -17,8 +17,8 @@ Terms & Conditions: License.md in the root directory
|
|||||||
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
|
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
|
||||||
|
|
||||||
|
|
||||||
__version__ = "1.2.0"
|
__version__ = "1.2.1"
|
||||||
__vername__ = "更高效的算法管理"
|
__vername__ = "扩大对有问题的Midi文件的兼容性"
|
||||||
__author__ = (("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray"), ("鸣凤鸽子", "MingFengPigeon"))
|
__author__ = (("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray"), ("鸣凤鸽子", "MingFengPigeon"))
|
||||||
__all__ = [
|
__all__ = [
|
||||||
# 主要类
|
# 主要类
|
||||||
|
@ -183,7 +183,7 @@ class MidiConvert:
|
|||||||
"""文件名,不含路径且不含后缀"""
|
"""文件名,不含路径且不含后缀"""
|
||||||
|
|
||||||
try:
|
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:
|
except (ValueError, TypeError) as E:
|
||||||
raise MidiDestroyedError(f"文件{midi_file_path}损坏:{E}")
|
raise MidiDestroyedError(f"文件{midi_file_path}损坏:{E}")
|
||||||
except FileNotFoundError as E:
|
except FileNotFoundError as E:
|
||||||
@ -537,18 +537,14 @@ class MidiConvert:
|
|||||||
midi_channels: ChannelType = empty_midi_channels()
|
midi_channels: ChannelType = empty_midi_channels()
|
||||||
tempo = mido.midifiles.midifiles.DEFAULT_TEMPO
|
tempo = mido.midifiles.midifiles.DEFAULT_TEMPO
|
||||||
|
|
||||||
# a = 0
|
|
||||||
# 我们来用通道统计音乐信息
|
# 我们来用通道统计音乐信息
|
||||||
# 但是是用分轨的思路的
|
# 但是是用分轨的思路的
|
||||||
for track_no, track in enumerate(self.midi.tracks):
|
for track_no, track in enumerate(self.midi.tracks):
|
||||||
# print(track_no,track)
|
|
||||||
microseconds = 0
|
microseconds = 0
|
||||||
if not track:
|
if not track:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# print(track_no,"="*20)
|
|
||||||
for msg in track:
|
for msg in track:
|
||||||
# print("+++",msg)
|
|
||||||
if msg.time != 0:
|
if msg.time != 0:
|
||||||
microseconds += msg.time * tempo / self.midi.ticks_per_beat / 1000
|
microseconds += msg.time * tempo / self.midi.ticks_per_beat / 1000
|
||||||
|
|
||||||
@ -556,9 +552,13 @@ class MidiConvert:
|
|||||||
if msg.type == "set_tempo":
|
if msg.type == "set_tempo":
|
||||||
tempo = msg.tempo
|
tempo = msg.tempo
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if not track_no in midi_channels[msg.channel].keys():
|
try:
|
||||||
midi_channels[msg.channel][track_no] = []
|
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":
|
if msg.type == "program_change":
|
||||||
midi_channels[msg.channel][track_no].append(
|
midi_channels[msg.channel][track_no].append(
|
||||||
("PgmC", msg.program, microseconds)
|
("PgmC", msg.program, microseconds)
|
||||||
@ -568,7 +568,6 @@ class MidiConvert:
|
|||||||
midi_channels[msg.channel][track_no].append(
|
midi_channels[msg.channel][track_no].append(
|
||||||
("NoteS", msg.note, msg.velocity, microseconds)
|
("NoteS", msg.note, msg.velocity, microseconds)
|
||||||
)
|
)
|
||||||
# a+=1
|
|
||||||
|
|
||||||
elif (msg.type == "note_on" and msg.velocity == 0) or (
|
elif (msg.type == "note_on" and msg.velocity == 0) or (
|
||||||
msg.type == "note_off"
|
msg.type == "note_off"
|
||||||
@ -577,7 +576,6 @@ class MidiConvert:
|
|||||||
("NoteE", msg.note, microseconds)
|
("NoteE", msg.note, microseconds)
|
||||||
)
|
)
|
||||||
|
|
||||||
# print(a)
|
|
||||||
|
|
||||||
"""整合后的音乐通道格式
|
"""整合后的音乐通道格式
|
||||||
每个通道包括若干消息元素其中逃不过这三种:
|
每个通道包括若干消息元素其中逃不过这三种:
|
||||||
@ -638,8 +636,6 @@ class MidiConvert:
|
|||||||
# 第十通道是打击乐通道
|
# 第十通道是打击乐通道
|
||||||
SpecialBits = True if i == 9 else False
|
SpecialBits = True if i == 9 else False
|
||||||
|
|
||||||
# nowChannel = []
|
|
||||||
|
|
||||||
for track_no, track in self.channels[i].items():
|
for track_no, track in self.channels[i].items():
|
||||||
nowTrack = []
|
nowTrack = []
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
python -m build
|
python setup.py sdist bdist_wheel
|
||||||
python -m twine upload dist/*
|
python -m twine upload dist/*
|
||||||
python clean_update.py
|
python clean_update.py
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
python -m build
|
|
||||||
python -m twine upload dist/*
|
|
||||||
python clean_update.py
|
|
@ -1,3 +0,0 @@
|
|||||||
python setup.py sdist bdist_wheel
|
|
||||||
python -m twine upload dist/*
|
|
||||||
python clean_update.py
|
|
Loading…
Reference in New Issue
Block a user