From e0557da3cf466f2221822d73541f30bab02fd9fc Mon Sep 17 00:00:00 2001 From: EillesWan Date: Fri, 20 Jan 2023 22:26:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=8A=E5=B9=B4=E5=B0=B1=E8=BF=99=E6=A0=B7?= =?UTF-8?q?=E7=BD=A2=EF=BC=8C=E6=88=91=E6=91=86=E4=BA=86=EF=BC=8C=E7=B4=A7?= =?UTF-8?q?=E6=80=A5=E6=9B=B4=E6=96=B0=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E7=82=B9=E7=82=B9=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- magicDemo.py | 14 +++++++++----- msctPkgver/__init__.py | 2 +- msctPkgver/main.py | 42 +++++++++++++++++------------------------- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 2df5f24..c4beaef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ *.midi *.mcpack *.bdx -demo_config.json +*.json # Byte-compiled / optimized __pycache__/ diff --git a/magicDemo.py b/magicDemo.py index 3ee92a1..5fcdc96 100644 --- a/magicDemo.py +++ b/magicDemo.py @@ -249,7 +249,7 @@ while True: continue break - +debug = False # 真假字符串判断 def boolstr(sth: str) -> bool: try: @@ -265,6 +265,9 @@ def boolstr(sth: str) -> bool: if os.path.exists("./demo_config.json"): import json prompts = json.load(open("./demo_config.json",'r',encoding="utf-8")) + if prompts[-1] == "debug": + debug = True + prompts = prompts[:-1] else: prompts = [] # 提示语 检测函数 错误提示语 @@ -317,10 +320,14 @@ else: -conversion = msctPkgver.midiConvert() +conversion = msctPkgver.midiConvert(debug) for singleMidi in midis: prt("\n"f"{_('Dealing')} {singleMidi} {_(':')}") conversion.convert(singleMidi, outpath) + if debug: + with open("./records.json",'a',encoding="utf-8") as f: + json.dump(conversion.toDICT(),f) + f.write(5*"\n") conversion_result = ( conversion.tomcpack(2, *prompts) if fileFormat == 0 @@ -330,9 +337,6 @@ for singleMidi in midis: else conversion.toBDXfile_withDelay(1, *prompts) ) ) - if prompts[-1] == "debug": - with open("./records.json",'a',encoding="utf-8") as f: - json.dump(prompts,f) if conversion_result[0]: prt( diff --git a/msctPkgver/__init__.py b/msctPkgver/__init__.py index ae4fdd0..3e37ec1 100644 --- a/msctPkgver/__init__.py +++ b/msctPkgver/__init__.py @@ -7,7 +7,7 @@ # 若需转载或借鉴 许可声明请查看仓库目录下的 Lisence.md -__version__ = '0.2.1' +__version__ = '0.2.1.1' __all__ = [] __author__ = (('金羿', 'Eilles Wan'), ('诸葛亮与八卦阵', 'bgArray'), ('鸣凤鸽子', 'MingFengPigeon')) diff --git a/msctPkgver/main.py b/msctPkgver/main.py index 99b9655..3238762 100644 --- a/msctPkgver/main.py +++ b/msctPkgver/main.py @@ -628,7 +628,7 @@ class midiConvert: MaxVolume = 1 if MaxVolume > 1 else (0.001 if MaxVolume <= 0 else MaxVolume) # 一个midi中仅有16通道 我们通过通道来识别而不是音轨 - channels = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []] + channels = {} microseconds = 0 @@ -640,7 +640,10 @@ class midiConvert: microseconds += msg.time * tempo / self.midi.ticks_per_beat # print(microseconds) except NameError: - raise NotDefineTempoError("计算当前分数时出错 未定义参量 Tempo") + if self.debugMode: + raise NotDefineTempoError("计算当前分数时出错 未定义参量 Tempo") + else: + microseconds += msg.time * mido.midifiles.midifiles.DEFAULT_TEMPO / self.midi.ticks_per_beat if msg.is_meta: if msg.type == "set_tempo": @@ -649,14 +652,12 @@ class midiConvert: self.prt(f"TEMPO更改:{tempo}(毫秒每拍)") else: - try: - msg.channel - channelMsg = True - except: - channelMsg = False - if channelMsg: - if msg.channel > 15: - raise ChannelOverFlowError(f"当前消息 {msg} 的通道超限(≤15)") + if self.debugMode: + try: + if msg.channel > 15: + raise ChannelOverFlowError(f"当前消息 {msg} 的通道超限(≤15)") + except: + pass if msg.type == "program_change": channels[msg.channel].append(("PgmC", msg.program, microseconds)) @@ -684,14 +685,14 @@ class midiConvert: ("NoteS", 结束的音符ID, 距离演奏开始的毫秒)""" if self.debugMode: - self.prt(dict(enumerate(channels))) + self.prt(channels) tracks = [] cmdAmount = 0 maxScore = 0 # 此处 我们把通道视为音轨 - for i in range(len(channels)): + for i in channels.keys(): # 如果当前通道为空 则跳过 if not channels[i]: continue @@ -1343,7 +1344,7 @@ class midiConvert: """ # 一个midi中仅有16通道 我们通过通道来识别而不是音轨 - channels = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []] + channels = {} microseconds = 0 # 我们来用通道统计音乐信息 @@ -1353,23 +1354,14 @@ class midiConvert: try: microseconds += msg.time * tempo / self.midi.ticks_per_beat # print(microseconds) - except NameError: - raise NotDefineTempoError("计算当前分数时出错 未定义参量 Tempo") + except: + microseconds += msg.time * mido.midifiles.midifiles.DEFAULT_TEMPO / self.midi.ticks_per_beat if msg.is_meta: if msg.type == "set_tempo": tempo = msg.tempo else: - try: - msg.channel - channelMsg = True - except: - channelMsg = False - if channelMsg: - if msg.channel > 15: - raise ChannelOverFlowError(f"当前消息 {msg} 的通道超限(≤15)") - if msg.type == "program_change": channels[msg.channel].append(("PgmC", msg.program, microseconds)) @@ -1395,4 +1387,4 @@ class midiConvert: 3 音符结束消息 ("NoteS", 结束的音符ID, 距离演奏开始的毫秒)""" - return dict(enumerate(channels)) \ No newline at end of file + return channels \ No newline at end of file