From 453ca745af24b48ca9f8f1ab458749c4f29108c2 Mon Sep 17 00:00:00 2001 From: bgArray <474037765@qq.com> Date: Sat, 25 Jun 2022 23:20:56 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AE=97=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=AD=A3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- README_EN.md | 3 +- example_convert_mcpack.py | 7 + msctPkgver/load_InstrumentLabel.py | 51 ++++++ msctPkgver/main.py | 267 +++++++++++++++-------------- msctPkgver/program音色表.xlsx | Bin 0 -> 10787 bytes 6 files changed, 205 insertions(+), 126 deletions(-) create mode 100644 msctPkgver/load_InstrumentLabel.py create mode 100644 msctPkgver/program音色表.xlsx diff --git a/README.md b/README.md index b15dde9..a4f220d 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,8 @@ ## 致谢🙏 - 感谢 昀梦\ 找出指令生成错误bug并指正 -- 感谢由 Charlie_Ping “查理平” 带来的bdx文件转换参考 +- 感谢由 Charlie_Ping “查理平” 带来的bdx文件转换参考, +以及mid转我的世界乐器参考表格 - 感谢由 CMA_2401PT 为我们的软件开发进行指导 - 感谢由 Dislink Sforza \带来的midi音色解析以及转换指令的算法,我们将其加入了我们众多算法之一 - 感谢 Touch \提供的测试支持 diff --git a/README_EN.md b/README_EN.md index 054fb62..2c7ccfe 100644 --- a/README_EN.md +++ b/README_EN.md @@ -123,7 +123,8 @@ This is a default definder parameter: - Thank [Fuckcraft](https://github.com/fuckcraft) *(“鸣凤鸽子” ,etc)* for the function of Creating the Websocket Server for Minecraft: Bedrock Edition. - *!! They have given me the rights to directly copy the lib into Musicreater* - Thank *昀梦*\ for finding and correcting the bugs in the commands that *Musicreater* Created. -- Thank *Charlie_Ping “查理平”* for bdx convert funtion. +- Thank *Charlie_Ping “查理平”* for bdx convert function, and +the data label that's used to convert the mid's instruments into minecraft's instruments. - Thank *CMA_2401PT* for BDXWorkShop as the .bdx structure's operation guide. - Thank *Miracle Plume “神羽”* \ for the Miracle Plume Bedrock Edition Audio Resource Pack - 感谢由 Dislink Sforza \带来的midi转换算法,我们将其加入了我们众多算法之一 diff --git a/example_convert_mcpack.py b/example_convert_mcpack.py index ece9943..7f3202f 100644 --- a/example_convert_mcpack.py +++ b/example_convert_mcpack.py @@ -13,3 +13,10 @@ convertion.tomcpack( float(input('请输入音量(0-1):')), float(input('请输入速度倍率:')), ) + +# for the test +# if __name__ == '__main__': +# convertion = midiConvert() +# convertion.convert(r"C:\Users\lc\Documents\MuseScore3\乐谱\乐谱\victory.mid", ".") +# convertion.tomcpack( +# 1, True, True, "scb", 1, 1) diff --git a/msctPkgver/load_InstrumentLabel.py b/msctPkgver/load_InstrumentLabel.py new file mode 100644 index 0000000..884a2f9 --- /dev/null +++ b/msctPkgver/load_InstrumentLabel.py @@ -0,0 +1,51 @@ +from openpyxl import * + + +def get(): + wb = load_workbook('program音色表.xlsx') + + ws = wb.active + # 所有行 + keys = [] + values = [] + for row in ws.iter_rows(): + for cell in row: + # print(cell.value) + try: + keys.append(int(cell.value)) + except ValueError: + values.append(cell.value) + # # 所有列 + # for column in ws.iter_cols(): + # for cell in column: + # print(cell.value) + out = "" + index = 0 + for i in keys: + out += ", \"" + str(i) + "\": \"" + values[index] + "\"" + index += 1 + + print(out) + + +idList = {"0": "harp", "1": "harp", "2": "pling", "3": "harp", "4": "pling", "5": "pling", "6": "harp", "7": "harp", + "8": "share", "9": "harp", "10": "didgeridoo", "11": "harp", "12": "xylophone", "13": "chime", "14": "harp", + "15": "harp", "16": "bass", "17": "harp", "18": "harp", "19": "harp", "20": "harp", "21": "harp", + "22": "harp", + "23": "guitar", "24": "guitar", "25": "guitar", "26": "guitar", "27": "guitar", "28": "guitar", + "29": "guitar", + "30": "guitar", "31": "bass", "32": "bass", "33": "bass", "34": "bass", "35": "bass", "36": "bass", + "37": "bass", + "38": "bass", "39": "bass", "40": "harp", "41": "harp", "42": "harp", "43": "harp", "44": "iron_xylophone", + "45": "guitar", "46": "harp", "47": "harp", "48": "guitar", "49": "guitar", "50": "bit", "51": "bit", + "52": "harp", "53": "harp", "54": "bit", "55": "flute", "56": "flute", "57": "flute", "58": "flute", + "59": "flute", "60": "flute", "61": "flute", "62": "flute", "63": "flute", "64": "bit", "65": "bit", + "66": "bit", "67": "bit", "68": "flute", "69": "harp", "70": "harp", "71": "flute", "72": "flute", + "73": "flute", "74": "harp", "75": "flute", "76": "harp", "77": "harp", "78": "harp", "79": "harp", + "80": "bit", "81": "bit", "82": "bit", "83": "bit", "84": "bit", "85": "bit", "86": "bit", "87": "bit", + "88": "bit", "89": "bit", "90": "bit", "91": "bit", "92": "bit", "93": "bit", "94": "bit", "95": "bit", + "96": "bit", "97": "bit", "98": "bit", "99": "bit", "100": "bit", "101": "bit", "102": "bit", "103": "bit", + "104": "harp", "105": "banjo", "106": "harp", "107": "harp", "108": "harp", "109": "harp", "110": "harp", + "111": "guitar", "112": "harp", "113": "bell", "114": "harp", "115": "cow_bell", "116": "basedrum", + "117": "bass", "118": "bit", "119": "basedrum", "120": "guitar", "121": "harp", "122": "harp", "123": "harp", + "124": "harp", "125": "hat", "126": "basedrum", "127": "snare"} diff --git a/msctPkgver/main.py b/msctPkgver/main.py index c0758ec..4ed7ae6 100644 --- a/msctPkgver/main.py +++ b/msctPkgver/main.py @@ -88,49 +88,66 @@ class midiConvert: :param default: 如果instrumentID不在范围内,返回的默认我的世界乐器名称 :return: (str我的世界乐器名, int转换算法中的X)""" - if instrumentID == 105: - return 'note.banjo', 6 - if instrumentID in range(32, 40): - return 'note.bass', 8 - if instrumentID in range(115, 119): - return 'note.basedrum', 7 # 注意,这里是底鼓,打击乐器无音域 - if instrumentID == 9 or instrumentID == 14: - return 'note.bell', 4 - if instrumentID == 80 or instrumentID == 81: - return 'note.bit', 6 - if instrumentID == 112: - return 'note.cow_bell', 5 - if instrumentID == -1: - return 'note.didgeridoo', 8 - if instrumentID in range(72, 80): - return 'note.flute', 5 - if instrumentID in range(24, 32): - return 'note.guitar', 7 - if instrumentID == -2: - return 'note.hat', 7 # 注意,这里是击鼓沿,打击乐器无音域 - if instrumentID == 14: - return 'note.chime', 4 - if instrumentID == 8 or instrumentID == 11: - return 'iron_xylophone', 6 - if instrumentID == 2: - return 'note.pling', 6 - if instrumentID == 114: - return 'note.snare', 7 # 注意,这里是小军鼓,打击乐器无音域 - if instrumentID == 13: - return 'note.xylophone', 4 - return 'note.harp', 6 + import msctPkgver.load_InstrumentLabel + X_Range = {"harp": 6, "pling": 6, "banjo": 6, "iron_xylophone": 6, "guitar": 7, "bass": 8, + "didgeridoo": 8, "flute": 5, "xylophone": 4, "cou_bell": 5, "chime": 4, "bell": 4, + "bit": 6, "basedrum": 7, "hat": 7, "snare": 7} + + # 以下为旧版运算算法 + + # if instrumentID == 105: + # return 'note.banjo', 6 + # if instrumentID in range(32, 40): + # return 'note.bass', 8 + # if instrumentID in range(115, 119): + # return 'note.basedrum', 7 # 注意,这里是底鼓,打击乐器无音域 + # if instrumentID == 9 or instrumentID == 14: + # return 'note.bell', 4 + # if instrumentID == 80 or instrumentID == 81: + # return 'note.bit', 6 + # if instrumentID == 112: + # return 'note.cow_bell', 5 + # if instrumentID == -1: + # return 'note.didgeridoo', 8 + # if instrumentID in range(72, 80): + # return 'note.flute', 5 + # if instrumentID in range(24, 32): + # return 'note.guitar', 7 + # if instrumentID == -2: + # return 'note.hat', 7 # 注意,这里是击鼓沿,打击乐器无音域 + # if instrumentID == 14: + # return 'note.chime', 4 + # if instrumentID == 8 or instrumentID == 11: + # return 'iron_xylophone', 6 + # if instrumentID == 2: + # return 'note.pling', 6 + # if instrumentID == 114: + # return 'note.snare', 7 # 注意,这里是小军鼓,打击乐器无音域 + # if instrumentID == 13: + # return 'note.xylophone', 4 + # return 'note.harp', 6 + + # 以下为新版运算算法 + + # print(instrumentID) + # print("note." + msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID))) + # print(X_Range.get(msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID)))) + + return "note." + msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID)), \ + X_Range.get(msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID))) + def __score2time(self, score: int): return str(int(int(score / 20) / 60)) + ':' + str(int(int(score / 20) % 60)) def __formProgressBar( - self, - maxscore: int, - scoreboardname: str, - progressbar: tuple = ( - r'▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]', - ('§e=§r', '§7=§r'), - ), + self, + maxscore: int, + scoreboardname: str, + progressbar: tuple = ( + r'▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]', + ('§e=§r', '§7=§r'), + ), ) -> list: pgsstyle = progressbar[0] @@ -149,7 +166,7 @@ class midiConvert: ''' def __replace( - s: str, tobeReplaced: str, replaceWith: str, times: int, other: str + s: str, tobeReplaced: str, replaceWith: str, times: int, other: str ): if times == 0: return s.replace(tobeReplaced, other) @@ -224,16 +241,16 @@ class midiConvert: return finalprgsbar def __formCMDblk( - self, - command: str, - particularValue: int, - impluse: int = 0, - condition: bool = False, - needRedstone: bool = True, - tickDelay: int = 0, - customName: str = '', - executeOnFirstTick: bool = False, - trackOutput: bool = True, + self, + command: str, + particularValue: int, + impluse: int = 0, + condition: bool = False, + needRedstone: bool = True, + tickDelay: int = 0, + customName: str = '', + executeOnFirstTick: bool = False, + trackOutput: bool = True, ): """ 使用指定项目返回指定的指令方块放置指令项 @@ -296,7 +313,7 @@ class midiConvert: return block def _toCmdList_m1( - self, scoreboardname: str = 'mscplay', volume: float = 1.0, speed: float = 1.0 + self, scoreboardname: str = 'mscplay', volume: float = 1.0, speed: float = 1.0 ) -> list: """ 使用Dislink Sforza的转换思路,将midi转换为我的世界命令列表 @@ -322,12 +339,14 @@ class midiConvert: for msg in track: ticks += msg.time + # print(msg) if msg.is_meta: if msg.type == 'set_tempo': tempo = msg.tempo - if msg.type == 'program_change': - instrumentID = msg.program else: + if msg.type == 'program_change': + # print("TT") + instrumentID = msg.program if msg.type == 'note_on' and msg.velocity != 0: nowscore = round( (ticks * tempo) @@ -341,7 +360,7 @@ class midiConvert: + '=' + str(nowscore) + '}' - + f'] ~ ~ ~ playsound {soundID} @s ~ ~{1/volume-1} ~ {msg.velocity*(0.7 if msg.channel == 0 else 0.9)} {2**((msg.note-60-_X)/12)}' + + f'] ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}' ) commands += 1 if len(singleTrack) != 0: @@ -350,11 +369,11 @@ class midiConvert: return tracks, commands, maxscore def _toCmdList_withDelay_m1( - self, - volume: float = 1.0, - speed: float = 1.0, - player: str = '@a', - isMixedWithPrograssBar=False, + self, + volume: float = 1.0, + speed: float = 1.0, + player: str = '@a', + isMixedWithPrograssBar=False, ) -> list: """ 使用Dislink Sforza的转换思路,将midi转换为我的世界命令列表,并输出每个音符之后的延迟 @@ -398,11 +417,11 @@ class midiConvert: soundID, _X = self.__Inst2soundIDwithX(instrumentID) try: tracks[nowtick].append( - f'execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1/volume-1} ~ {msg.velocity*(0.7 if msg.channel == 0 else 0.9)} {2**((msg.note-60-_X)/12)}' + f'execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}' ) except: tracks[nowtick] = [ - f'execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1/volume-1} ~ {msg.velocity*(0.7 if msg.channel == 0 else 0.9)} {2**((msg.note-60-_X)/12)}', + f'execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}', ] allticks = list(tracks.keys()) @@ -425,7 +444,7 @@ class midiConvert: ''' def __replace( - s: str, tobeReplaced: str, replaceWith: str, times: int, other: str + s: str, tobeReplaced: str, replaceWith: str, times: int, other: str ): if times == 0: return s.replace(tobeReplaced, other) @@ -522,13 +541,13 @@ class midiConvert: return math.ceil(math.sqrt(math.ceil(total / maxHeight))) def tomcpack( - self, - method: int = 1, - isAutoReset: bool = False, - progressbar=None, - scoreboardname: str = 'mscplay', - volume: float = 1.0, - speed: float = 1.0, + self, + method: int = 1, + isAutoReset: bool = False, + progressbar=None, + scoreboardname: str = 'mscplay', + volume: float = 1.0, + speed: float = 1.0, ) -> bool: """ 使用method指定的转换算法,将midi转换为我的世界mcpack格式的包 @@ -558,7 +577,7 @@ class midiConvert: # 写入manifest.json if not os.path.exists(f'{self.outputPath}/temp/manifest.json'): with open( - f"{self.outputPath}/temp/manifest.json", "w", encoding='utf-8' + f"{self.outputPath}/temp/manifest.json", "w", encoding='utf-8' ) as f: f.write( "{\n \"format_version\": 1,\n \"header\": {\n \"description\": \"" @@ -575,7 +594,7 @@ class midiConvert: ) else: with open( - f'{self.outputPath}/temp/manifest.json', 'r', encoding='utf-8' + f'{self.outputPath}/temp/manifest.json', 'r', encoding='utf-8' ) as manifest: data = json.loads(manifest.read()) data['header'][ @@ -599,9 +618,9 @@ class midiConvert: 'function mscplay/track' + str(cmdlist.index(track) + 1) + '\n' ) with open( - f'{self.outputPath}/temp/functions/mscplay/track{cmdlist.index(track)+1}.mcfunction', - 'w', - encoding='utf-8', + f'{self.outputPath}/temp/functions/mscplay/track{cmdlist.index(track) + 1}.mcfunction', + 'w', + encoding='utf-8', ) as f: f.write('\n'.join(track)) indexfile.writelines( @@ -612,12 +631,12 @@ class midiConvert: + scoreboardname + ' 1\n', ( - 'scoreboard players reset @a[scores={' - + scoreboardname - + '=' - + str(maxscore + 20) - + '..}]' - + f' {scoreboardname}\n' + 'scoreboard players reset @a[scores={' + + scoreboardname + + '=' + + str(maxscore + 20) + + '..}]' + + f' {scoreboardname}\n' ) if isAutoReset else '', @@ -628,18 +647,18 @@ class midiConvert: if progressbar: if progressbar == True: with open( - f'{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction', - 'w', - encoding='utf-8', + f'{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction', + 'w', + encoding='utf-8', ) as f: f.writelines( '\n'.join(self.__formProgressBar(maxscore, scoreboardname)) ) else: with open( - f'{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction', - 'w', - encoding='utf-8', + f'{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction', + 'w', + encoding='utf-8', ) as f: f.writelines( '\n'.join( @@ -658,15 +677,15 @@ class midiConvert: shutil.rmtree(f'{self.outputPath}/temp/') def toBDXfile( - self, - method: int = 1, - author: str = 'Eilles', - progressbar=False, - maxheight: int = 64, - scoreboardname: str = 'mscplay', - volume: float = 1.0, - speed: float = 1.0, - isAutoReset: bool = False, + self, + method: int = 1, + author: str = 'Eilles', + progressbar=False, + maxheight: int = 64, + scoreboardname: str = 'mscplay', + volume: float = 1.0, + speed: float = 1.0, + isAutoReset: bool = False, ): """ 使用method指定的转换算法,将midi转换为BDX结构文件 @@ -695,9 +714,9 @@ class midiConvert: f.write("BD@") _bytes = ( - b"BDX\x00" - + author.encode("utf-8") - + b" & Musicreater\x00\x01command_block\x00" + b"BDX\x00" + + author.encode("utf-8") + + b" & Musicreater\x00\x01command_block\x00" ) key = { @@ -726,12 +745,12 @@ class midiConvert: if isAutoReset: commands += ( - 'scoreboard players reset @a[scores={' - + scoreboardname - + '=' - + str(maxScore + 20) - + '}] ' - + scoreboardname + 'scoreboard players reset @a[scores={' + + scoreboardname + + '=' + + str(maxScore + 20) + + '}] ' + + scoreboardname ) if progressbar: @@ -747,13 +766,13 @@ class midiConvert: cmd, (1 if yforward else 0) if ( - ((nowy != 0) and (not yforward)) - or ((yforward) and (nowy != maxheight)) + ((nowy != 0) and (not yforward)) + or ((yforward) and (nowy != maxheight)) ) else (3 if zforward else 2) if ( - ((nowz != 0) and (not zforward)) - or ((zforward) and (nowz != _sideLength)) + ((nowz != 0) and (not zforward)) + or ((zforward) and (nowz != _sideLength)) ) else 5, impluse=2, @@ -775,7 +794,7 @@ class midiConvert: nowz += 1 if zforward else -1 if ((nowz > _sideLength) and (zforward)) or ( - (nowz < 0) and (not zforward) + (nowz < 0) and (not zforward) ): nowz -= 1 if zforward else -1 zforward = not zforward @@ -795,14 +814,14 @@ class midiConvert: return (True, _bytes, (nowx, maxheight, _sideLength)) def toBDXfile_withDelay( - self, - method: int = 1, - author: str = 'Eilles', - progressbar=False, - maxheight: int = 64, - volume: float = 1.0, - speed: float = 1.0, - player: str = '@a', + self, + method: int = 1, + author: str = 'Eilles', + progressbar=False, + maxheight: int = 64, + volume: float = 1.0, + speed: float = 1.0, + player: str = '@a', ): """ 使用method指定的转换算法,将midi转换为BDX结构文件 @@ -828,9 +847,9 @@ class midiConvert: f.write("BD@") _bytes = ( - b"BDX\x00" - + author.encode("utf-8") - + b" & Musicreater\x00\x01command_block\x00" + b"BDX\x00" + + author.encode("utf-8") + + b" & Musicreater\x00\x01command_block\x00" ) key = { @@ -857,13 +876,13 @@ class midiConvert: cmd, (1 if yforward else 0) if ( - ((nowy != 0) and (not yforward)) - or ((yforward) and (nowy != maxheight)) + ((nowy != 0) and (not yforward)) + or ((yforward) and (nowy != maxheight)) ) else (3 if zforward else 2) if ( - ((nowz != 0) and (not zforward)) - or ((zforward) and (nowz != _sideLength)) + ((nowz != 0) and (not zforward)) + or ((zforward) and (nowz != _sideLength)) ) else 5, impluse=2, @@ -885,7 +904,7 @@ class midiConvert: nowz += 1 if zforward else -1 if ((nowz > _sideLength) and (zforward)) or ( - (nowz < 0) and (not zforward) + (nowz < 0) and (not zforward) ): nowz -= 1 if zforward else -1 zforward = not zforward diff --git a/msctPkgver/program音色表.xlsx b/msctPkgver/program音色表.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..b68bcf663ed6d7f034064830c05c7311e461cb57 GIT binary patch literal 10787 zcmeHtby!qe7xy6D!!Sw+4qeiWfPm6ScL;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= =?UTF-8?q?=E5=88=B0=E6=88=91=E5=90=8E=E9=9D=A2=E7=95=99=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E6=89=8B=E5=90=A7=EF=BC=8Cqwq?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- msctPkgver/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msctPkgver/main.py b/msctPkgver/main.py index 4ed7ae6..8602d8c 100644 --- a/msctPkgver/main.py +++ b/msctPkgver/main.py @@ -406,9 +406,9 @@ class midiConvert: if msg.is_meta: if msg.type == 'set_tempo': tempo = msg.tempo + else: if msg.type == 'program_change': instrumentID = msg.program - else: if msg.type == 'note_on' and msg.velocity != 0: nowtick = round( (ticks * tempo) From 887452184bc41407d2633c2f4880639d1442a43a Mon Sep 17 00:00:00 2001 From: bgArray <474037765@qq.com> Date: Sun, 26 Jun 2022 12:06:52 +0000 Subject: [PATCH 3/5] update msctPkgver/load_InstrumentLabel.py. --- msctPkgver/load_InstrumentLabel.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/msctPkgver/load_InstrumentLabel.py b/msctPkgver/load_InstrumentLabel.py index 884a2f9..ce51767 100644 --- a/msctPkgver/load_InstrumentLabel.py +++ b/msctPkgver/load_InstrumentLabel.py @@ -1,7 +1,6 @@ -from openpyxl import * - - def get(): + from openpyxl import * + wb = load_workbook('program音色表.xlsx') ws = wb.active From 9517c49ec5e13314c5d2294e9bbeb5932da3b898 Mon Sep 17 00:00:00 2001 From: bgArray <474037765@qq.com> Date: Tue, 28 Jun 2022 07:43:15 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=BA=93=E5=AF=BC?= =?UTF-8?q?=E5=85=A5BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ README.md | 2 ++ README_EN.md | 2 ++ msctPkgver/load_InstrumentLabel.py | 28 ---------------------------- msctPkgver/readXLSX.py | 28 ++++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 msctPkgver/readXLSX.py diff --git a/.gitignore b/.gitignore index d48cb25..a945659 100644 --- a/.gitignore +++ b/.gitignore @@ -140,3 +140,6 @@ dmypy.json # Cython debug symbols cython_debug/ + +# Pycharm +/.idea diff --git a/README.md b/README.md index a4f220d..0029806 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ > > `pip install brotli` > +> `pip install openpyxl` +> > 3. 开始使用! > 在目录下打开cmd,进入到目录下,执行以下命令:(选择你需要的) > diff --git a/README_EN.md b/README_EN.md index 2c7ccfe..3617f60 100644 --- a/README_EN.md +++ b/README_EN.md @@ -66,6 +66,8 @@ A simple Python package. > > `pip install brotli` > +> `pip install openpyxl` +> > 3. Start using! > > Open CMD in the directory, enter the directory, and execute the following commands: diff --git a/msctPkgver/load_InstrumentLabel.py b/msctPkgver/load_InstrumentLabel.py index ce51767..d847d44 100644 --- a/msctPkgver/load_InstrumentLabel.py +++ b/msctPkgver/load_InstrumentLabel.py @@ -1,31 +1,3 @@ -def get(): - from openpyxl import * - - wb = load_workbook('program音色表.xlsx') - - ws = wb.active - # 所有行 - keys = [] - values = [] - for row in ws.iter_rows(): - for cell in row: - # print(cell.value) - try: - keys.append(int(cell.value)) - except ValueError: - values.append(cell.value) - # # 所有列 - # for column in ws.iter_cols(): - # for cell in column: - # print(cell.value) - out = "" - index = 0 - for i in keys: - out += ", \"" + str(i) + "\": \"" + values[index] + "\"" - index += 1 - - print(out) - idList = {"0": "harp", "1": "harp", "2": "pling", "3": "harp", "4": "pling", "5": "pling", "6": "harp", "7": "harp", "8": "share", "9": "harp", "10": "didgeridoo", "11": "harp", "12": "xylophone", "13": "chime", "14": "harp", diff --git a/msctPkgver/readXLSX.py b/msctPkgver/readXLSX.py new file mode 100644 index 0000000..c5bb33f --- /dev/null +++ b/msctPkgver/readXLSX.py @@ -0,0 +1,28 @@ +from openpyxl import * + + +def get(): + wb = load_workbook('program音色表.xlsx') + + ws = wb.active + # 所有行 + keys = [] + values = [] + for row in ws.iter_rows(): + for cell in row: + # print(cell.value) + try: + keys.append(int(cell.value)) + except ValueError: + values.append(cell.value) + # # 所有列 + # for column in ws.iter_cols(): + # for cell in column: + # print(cell.value) + out = "" + index = 0 + for i in keys: + out += ", \"" + str(i) + "\": \"" + values[index] + "\"" + index += 1 + + print(out) From 2afd6beb3fc663e4ef737d31320204a03a740990 Mon Sep 17 00:00:00 2001 From: CaryXiong Date: Thu, 30 Jun 2022 12:14:22 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- msctPkgver/load_InstrumentLabel.py | 22 -- msctPkgver/main.py | 590 +++++++++++++++++------------ 2 files changed, 339 insertions(+), 273 deletions(-) delete mode 100644 msctPkgver/load_InstrumentLabel.py diff --git a/msctPkgver/load_InstrumentLabel.py b/msctPkgver/load_InstrumentLabel.py deleted file mode 100644 index d847d44..0000000 --- a/msctPkgver/load_InstrumentLabel.py +++ /dev/null @@ -1,22 +0,0 @@ - -idList = {"0": "harp", "1": "harp", "2": "pling", "3": "harp", "4": "pling", "5": "pling", "6": "harp", "7": "harp", - "8": "share", "9": "harp", "10": "didgeridoo", "11": "harp", "12": "xylophone", "13": "chime", "14": "harp", - "15": "harp", "16": "bass", "17": "harp", "18": "harp", "19": "harp", "20": "harp", "21": "harp", - "22": "harp", - "23": "guitar", "24": "guitar", "25": "guitar", "26": "guitar", "27": "guitar", "28": "guitar", - "29": "guitar", - "30": "guitar", "31": "bass", "32": "bass", "33": "bass", "34": "bass", "35": "bass", "36": "bass", - "37": "bass", - "38": "bass", "39": "bass", "40": "harp", "41": "harp", "42": "harp", "43": "harp", "44": "iron_xylophone", - "45": "guitar", "46": "harp", "47": "harp", "48": "guitar", "49": "guitar", "50": "bit", "51": "bit", - "52": "harp", "53": "harp", "54": "bit", "55": "flute", "56": "flute", "57": "flute", "58": "flute", - "59": "flute", "60": "flute", "61": "flute", "62": "flute", "63": "flute", "64": "bit", "65": "bit", - "66": "bit", "67": "bit", "68": "flute", "69": "harp", "70": "harp", "71": "flute", "72": "flute", - "73": "flute", "74": "harp", "75": "flute", "76": "harp", "77": "harp", "78": "harp", "79": "harp", - "80": "bit", "81": "bit", "82": "bit", "83": "bit", "84": "bit", "85": "bit", "86": "bit", "87": "bit", - "88": "bit", "89": "bit", "90": "bit", "91": "bit", "92": "bit", "93": "bit", "94": "bit", "95": "bit", - "96": "bit", "97": "bit", "98": "bit", "99": "bit", "100": "bit", "101": "bit", "102": "bit", "103": "bit", - "104": "harp", "105": "banjo", "106": "harp", "107": "harp", "108": "harp", "109": "harp", "110": "harp", - "111": "guitar", "112": "harp", "113": "bell", "114": "harp", "115": "cow_bell", "116": "basedrum", - "117": "bass", "118": "bit", "119": "basedrum", "120": "guitar", "121": "harp", "122": "harp", "123": "harp", - "124": "harp", "125": "hat", "126": "basedrum", "127": "snare"} diff --git a/msctPkgver/main.py b/msctPkgver/main.py index 8602d8c..011c1eb 100644 --- a/msctPkgver/main.py +++ b/msctPkgver/main.py @@ -33,6 +33,9 @@ Note! Except for this source file, all the files in this repository and this pro import os import mido import brotli +import json +import uuid +import shutil def makeZip(sourceDir, outFilename, compression=8, exceptFile=None): @@ -45,7 +48,7 @@ def makeZip(sourceDir, outFilename, compression=8, exceptFile=None): """ import zipfile - zipf = zipfile.ZipFile(outFilename, 'w', compression) + zipf = zipfile.ZipFile(outFilename, "w", compression) pre_len = len(os.path.dirname(sourceDir)) for parent, dirnames, filenames in os.walk(sourceDir): for filename in filenames: @@ -59,21 +62,21 @@ def makeZip(sourceDir, outFilename, compression=8, exceptFile=None): class midiConvert: def __init__(self): - '''简单的midi转换类,将midi文件转换为我的世界结构或者包''' + """简单的midi转换类,将midi文件转换为我的世界结构或者包""" pass def convert(self, midiFile: str, outputPath: str): - '''转换前需要先运行此函数来获取基本信息''' + """转换前需要先运行此函数来获取基本信息""" self.midiFile = midiFile - '''midi文件路径''' + """midi文件路径""" self.midi = mido.MidiFile(self.midiFile) - '''MidiFile对象''' + """MidiFile对象""" self.outputPath = outputPath - '''输出路径''' + """输出路径""" # 将self.midiFile的文件名,不含路径且不含后缀存入self.midiFileName self.midFileName = os.path.splitext(os.path.basename(self.midiFile))[0] - '''文件名,不含路径且不含后缀''' + """文件名,不含路径且不含后缀""" def __Inst2soundIDwithX(self, instrumentID): """返回midi的乐器ID对应的我的世界乐器名,对于音域转换算法,如下: @@ -84,76 +87,159 @@ class midiConvert: 贝斯bass、迪吉里杜管didgeridoo的时候为8 长笛flute、牛铃cou_bell的时候为5 钟琴bell、管钟chime、木琴xylophone的时候为4 + 而存在一些打击乐器basedrum、hat、snare,没有音域,则没有X,那么我们返回7即可 :param instrumentID: midi的乐器ID :param default: 如果instrumentID不在范围内,返回的默认我的世界乐器名称 :return: (str我的世界乐器名, int转换算法中的X)""" - import msctPkgver.load_InstrumentLabel - X_Range = {"harp": 6, "pling": 6, "banjo": 6, "iron_xylophone": 6, "guitar": 7, "bass": 8, - "didgeridoo": 8, "flute": 5, "xylophone": 4, "cou_bell": 5, "chime": 4, "bell": 4, - "bit": 6, "basedrum": 7, "hat": 7, "snare": 7} - - # 以下为旧版运算算法 - - # if instrumentID == 105: - # return 'note.banjo', 6 - # if instrumentID in range(32, 40): - # return 'note.bass', 8 - # if instrumentID in range(115, 119): - # return 'note.basedrum', 7 # 注意,这里是底鼓,打击乐器无音域 - # if instrumentID == 9 or instrumentID == 14: - # return 'note.bell', 4 - # if instrumentID == 80 or instrumentID == 81: - # return 'note.bit', 6 - # if instrumentID == 112: - # return 'note.cow_bell', 5 - # if instrumentID == -1: - # return 'note.didgeridoo', 8 - # if instrumentID in range(72, 80): - # return 'note.flute', 5 - # if instrumentID in range(24, 32): - # return 'note.guitar', 7 - # if instrumentID == -2: - # return 'note.hat', 7 # 注意,这里是击鼓沿,打击乐器无音域 - # if instrumentID == 14: - # return 'note.chime', 4 - # if instrumentID == 8 or instrumentID == 11: - # return 'iron_xylophone', 6 - # if instrumentID == 2: - # return 'note.pling', 6 - # if instrumentID == 114: - # return 'note.snare', 7 # 注意,这里是小军鼓,打击乐器无音域 - # if instrumentID == 13: - # return 'note.xylophone', 4 - # return 'note.harp', 6 - - # 以下为新版运算算法 - - # print(instrumentID) - # print("note." + msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID))) - # print(X_Range.get(msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID)))) - - return "note." + msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID)), \ - X_Range.get(msctPkgver.load_InstrumentLabel.idList.get(str(instrumentID))) - + return { + 0: ("note.harp", 6), + 1: ("note.harp", 6), + 2: ("note.pling", 6), + 3: ("note.harp", 6), + 4: ("note.pling", 6), + 5: ("note.pling", 6), + 6: ("note.harp", 6), + 7: ("note.harp", 6), + 8: ("note.share", 7), # 打击乐器无音域 + 9: ("note.harp", 6), + 10: ("note.didgeridoo", 8), + 11: ("note.harp", 6), + 12: ("note.xylophone", 4), + 13: ("note.chime", 4), + 14: ("note.harp", 6), + 15: ("note.harp", 6), + 16: ("note.bass", 8), + 17: ("note.harp", 6), + 18: ("note.harp", 6), + 19: ("note.harp", 6), + 20: ("note.harp", 6), + 21: ("note.harp", 6), + 22: ("note.harp", 6), + 23: ("note.guitar", 7), + 24: ("note.guitar", 7), + 25: ("note.guitar", 7), + 26: ("note.guitar", 7), + 27: ("note.guitar", 7), + 28: ("note.guitar", 7), + 29: ("note.guitar", 7), + 30: ("note.guitar", 7), + 31: ("note.bass", 8), + 32: ("note.bass", 8), + 33: ("note.bass", 8), + 34: ("note.bass", 8), + 35: ("note.bass", 8), + 36: ("note.bass", 8), + 37: ("note.bass", 8), + 38: ("note.bass", 8), + 39: ("note.bass", 8), + 40: ("note.harp", 6), + 41: ("note.harp", 6), + 42: ("note.harp", 6), + 43: ("note.harp", 6), + 44: ("note.iron_xylophone", 6), + 45: ("note.guitar", 7), + 46: ("note.harp", 6), + 47: ("note.harp", 6), + 48: ("note.guitar", 7), + 49: ("note.guitar", 7), + 50: ("note.bit", 6), + 51: ("note.bit", 6), + 52: ("note.harp", 6), + 53: ("note.harp", 6), + 54: ("note.bit", 6), + 55: ("note.flute", 5), + 56: ("note.flute", 5), + 57: ("note.flute", 5), + 58: ("note.flute", 5), + 59: ("note.flute", 5), + 60: ("note.flute", 5), + 61: ("note.flute", 5), + 62: ("note.flute", 5), + 63: ("note.flute", 5), + 64: ("note.bit", 6), + 65: ("note.bit", 6), + 66: ("note.bit", 6), + 67: ("note.bit", 6), + 68: ("note.flute", 5), + 69: ("note.harp", 6), + 70: ("note.harp", 6), + 71: ("note.flute", 5), + 72: ("note.flute", 5), + 73: ("note.flute", 5), + 74: ("note.harp", 6), + 75: ("note.flute", 5), + 76: ("note.harp", 6), + 77: ("note.harp", 6), + 78: ("note.harp", 6), + 79: ("note.harp", 6), + 80: ("note.bit", 6), + 81: ("note.bit", 6), + 82: ("note.bit", 6), + 83: ("note.bit", 6), + 84: ("note.bit", 6), + 85: ("note.bit", 6), + 86: ("note.bit", 6), + 87: ("note.bit", 6), + 88: ("note.bit", 6), + 89: ("note.bit", 6), + 90: ("note.bit", 6), + 91: ("note.bit", 6), + 92: ("note.bit", 6), + 93: ("note.bit", 6), + 94: ("note.bit", 6), + 95: ("note.bit", 6), + 96: ("note.bit", 6), + 97: ("note.bit", 6), + 98: ("note.bit", 6), + 99: ("note.bit", 6), + 100: ("note.bit", 6), + 101: ("note.bit", 6), + 102: ("note.bit", 6), + 103: ("note.bit", 6), + 104: ("note.harp", 6), + 105: ("note.banjo", 6), + 106: ("note.harp", 6), + 107: ("note.harp", 6), + 108: ("note.harp", 6), + 109: ("note.harp", 6), + 110: ("note.harp", 6), + 111: ("note.guitar", 7), + 112: ("note.harp", 6), + 113: ("note.bell", 4), + 114: ("note.harp", 6), + 115: ("note.cow_bell", 5), + 116: ("note.basedrum", 7), # 打击乐器无音域 + 117: ("note.bass", 8), + 118: ("note.bit", 6), + 119: ("note.basedrum", 7), # 打击乐器无音域 + 120: ("note.guitar", 7), + 121: ("note.harp", 6), + 122: ("note.harp", 6), + 123: ("note.harp", 6), + 124: ("note.harp", 6), + 125: ("note.hat", 7), # 打击乐器无音域 + 126: ("note.basedrum", 7), # 打击乐器无音域 + 127: ("note.snare", 7), # 打击乐器无音域 + }[instrumentID] def __score2time(self, score: int): - return str(int(int(score / 20) / 60)) + ':' + str(int(int(score / 20) % 60)) + return str(int(int(score / 20) / 60)) + ":" + str(int(int(score / 20) % 60)) def __formProgressBar( - self, - maxscore: int, - scoreboardname: str, - progressbar: tuple = ( - r'▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]', - ('§e=§r', '§7=§r'), - ), + self, + maxscore: int, + scoreboardname: str, + progressbar: tuple = ( + r"▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]", + ("§e=§r", "§7=§r"), + ), ) -> list: pgsstyle = progressbar[0] - '''用于被替换的进度条原始样式''' + """用于被替换的进度条原始样式""" - ''' + """ | 标识符 | 指定的可变量 | |---------|----------------| | `%%N` | 乐曲名(即传入的文件名)| @@ -163,16 +249,16 @@ class midiConvert: | `%^t` | 曲目总时长 | | `%%%` | 当前进度比率 | | `_` | 用以表示进度条占位| - ''' + """ def __replace( - s: str, tobeReplaced: str, replaceWith: str, times: int, other: str + s: str, tobeReplaced: str, replaceWith: str, times: int, other: str ): if times == 0: return s.replace(tobeReplaced, other) if times == s.count(tobeReplaced): return s.replace(tobeReplaced, replaceWith) - result = '' + result = "" t = 0 for i in s: if i == tobeReplaced: @@ -187,12 +273,12 @@ class midiConvert: return result idlist = { - r'%%N': self.midFileName, - r'%%s': r'%%s', - r'%^s': str(maxscore), - r'%%t': r'%%t', - r'%^t': self.__score2time(maxscore), - r'%%%': r'%%%', + r"%%N": self.midFileName, + r"%%s": r"%%s", + r"%^s": str(maxscore), + r"%%t": r"%%t", + r"%^t": self.__score2time(maxscore), + r"%%%": r"%%%", } ids = {} @@ -209,48 +295,48 @@ class midiConvert: del idlist - pgblength = pgsstyle.count('_') - '''进度条的“条”长度''' + pgblength = pgsstyle.count("_") + """进度条的“条”长度""" finalprgsbar = [] for i in range(maxscore): nowstr = pgsstyle - if ids[r'%%s'] == True: - nowstr = nowstr.replace(r'%%s', str(i + 1)) - if ids[r'%%t'] == True: - nowstr = nowstr.replace(r'%%t', self.__score2time(i + 1)) - if ids[r'%%%'] == True: + if ids[r"%%s"] == True: + nowstr = nowstr.replace(r"%%s", str(i + 1)) + if ids[r"%%t"] == True: + nowstr = nowstr.replace(r"%%t", self.__score2time(i + 1)) + if ids[r"%%%"] == True: nowstr = nowstr.replace( - r'%%%', str(int((i + 1) / maxscore * 10000) / 100) + '%' + r"%%%", str(int((i + 1) / maxscore * 10000) / 100) + "%" ) countof_s = int((i + 1) / maxscore * pgblength) finalprgsbar.append( - 'title @a[scores={' + "title @a[scores={" + scoreboardname - + '=' + + "=" + str(i + 1) - + '}] actionbar ' + + "}] actionbar " + __replace( - nowstr, '_', progressbar[1][0], countof_s, progressbar[1][1] + nowstr, "_", progressbar[1][0], countof_s, progressbar[1][1] ) ) return finalprgsbar def __formCMDblk( - self, - command: str, - particularValue: int, - impluse: int = 0, - condition: bool = False, - needRedstone: bool = True, - tickDelay: int = 0, - customName: str = '', - executeOnFirstTick: bool = False, - trackOutput: bool = True, + self, + command: str, + particularValue: int, + impluse: int = 0, + condition: bool = False, + needRedstone: bool = True, + tickDelay: int = 0, + customName: str = "", + executeOnFirstTick: bool = False, + trackOutput: bool = True, ): """ 使用指定项目返回指定的指令方块放置指令项 @@ -302,7 +388,7 @@ class midiConvert: impluse.to_bytes(4, byteorder="big", signed=False), bytes(command, encoding="utf-8") + b"\x00", bytes(customName, encoding="utf-8") + b"\x00", - bytes('', encoding="utf-8") + b"\x00", + bytes("", encoding="utf-8") + b"\x00", tickDelay.to_bytes(4, byteorder="big", signed=True), executeOnFirstTick.to_bytes(1, byteorder="big"), trackOutput.to_bytes(1, byteorder="big"), @@ -313,7 +399,7 @@ class midiConvert: return block def _toCmdList_m1( - self, scoreboardname: str = 'mscplay', volume: float = 1.0, speed: float = 1.0 + self, scoreboardname: str = "mscplay", volume: float = 1.0, speed: float = 1.0 ) -> list: """ 使用Dislink Sforza的转换思路,将midi转换为我的世界命令列表 @@ -341,13 +427,13 @@ class midiConvert: ticks += msg.time # print(msg) if msg.is_meta: - if msg.type == 'set_tempo': + if msg.type == "set_tempo": tempo = msg.tempo else: - if msg.type == 'program_change': + if msg.type == "program_change": # print("TT") instrumentID = msg.program - if msg.type == 'note_on' and msg.velocity != 0: + if msg.type == "note_on" and msg.velocity != 0: nowscore = round( (ticks * tempo) / ((self.midi.ticks_per_beat * float(speed)) * 50000) @@ -355,12 +441,12 @@ class midiConvert: maxscore = max(maxscore, nowscore) soundID, _X = self.__Inst2soundIDwithX(instrumentID) singleTrack.append( - 'execute @a[scores={' + "execute @a[scores={" + str(scoreboardname) - + '=' + + "=" + str(nowscore) - + '}' - + f'] ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}' + + "}" + + f"] ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}" ) commands += 1 if len(singleTrack) != 0: @@ -369,11 +455,11 @@ class midiConvert: return tracks, commands, maxscore def _toCmdList_withDelay_m1( - self, - volume: float = 1.0, - speed: float = 1.0, - player: str = '@a', - isMixedWithPrograssBar=False, + self, + volume: float = 1.0, + speed: float = 1.0, + player: str = "@a", + isMixedWithPrograssBar=False, ) -> list: """ 使用Dislink Sforza的转换思路,将midi转换为我的世界命令列表,并输出每个音符之后的延迟 @@ -392,8 +478,8 @@ class midiConvert: if isMixedWithPrograssBar == True: isMixedWithPrograssBar = ( - r'▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]', - ('§e=§r', '§7=§r'), + r"▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]", + ("§e=§r", "§7=§r"), ) for i, track in enumerate(self.midi.tracks): @@ -404,12 +490,12 @@ class midiConvert: for msg in track: ticks += msg.time if msg.is_meta: - if msg.type == 'set_tempo': + if msg.type == "set_tempo": tempo = msg.tempo else: - if msg.type == 'program_change': + if msg.type == "program_change": instrumentID = msg.program - if msg.type == 'note_on' and msg.velocity != 0: + if msg.type == "note_on" and msg.velocity != 0: nowtick = round( (ticks * tempo) / ((self.midi.ticks_per_beat * float(speed)) * 50000) @@ -417,11 +503,11 @@ class midiConvert: soundID, _X = self.__Inst2soundIDwithX(instrumentID) try: tracks[nowtick].append( - f'execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}' + f"execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}" ) except: tracks[nowtick] = [ - f'execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}', + f"execute {player} ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ {msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}", ] allticks = list(tracks.keys()) @@ -429,9 +515,9 @@ class midiConvert: if isMixedWithPrograssBar: pgsstyle = isMixedWithPrograssBar[0] - '''用于被替换的进度条原始样式''' + """用于被替换的进度条原始样式""" - ''' + """ | 标识符 | 指定的可变量 | |---------|----------------| | `%%N` | 乐曲名(即传入的文件名)| @@ -441,16 +527,16 @@ class midiConvert: | `%^t` | 曲目总时长 | | `%%%` | 当前进度比率 | | `_` | 用以表示进度条占位| - ''' + """ def __replace( - s: str, tobeReplaced: str, replaceWith: str, times: int, other: str + s: str, tobeReplaced: str, replaceWith: str, times: int, other: str ): if times == 0: return s.replace(tobeReplaced, other) if times == s.count(tobeReplaced): return s.replace(tobeReplaced, replaceWith) - result = '' + result = "" t = 0 for i in s: if i == tobeReplaced: @@ -465,12 +551,12 @@ class midiConvert: return result idlist = { - r'%%N': self.midFileName, - r'%%s': r'%%s', - r'%^s': str(allticks[-1]), - r'%%t': r'%%t', - r'%^t': self.__score2time(allticks[-1]), - r'%%%': r'%%%', + r"%%N": self.midFileName, + r"%%s": r"%%s", + r"%^s": str(allticks[-1]), + r"%%t": r"%%t", + r"%^t": self.__score2time(allticks[-1]), + r"%%%": r"%%%", } ids = {} @@ -487,8 +573,8 @@ class midiConvert: del idlist - pgblength = pgsstyle.count('_') - '''进度条的“条”长度''' + pgblength = pgsstyle.count("_") + """进度条的“条”长度""" results = [] @@ -508,46 +594,52 @@ class midiConvert: if isMixedWithPrograssBar: nowstr = pgsstyle - if ids[r'%%s'] == True: - nowstr = nowstr.replace(r'%%s', str(allticks[i] + 1)) - if ids[r'%%t'] == True: - nowstr = nowstr.replace(r'%%t', self.__score2time(allticks[i] + 1)) - if ids[r'%%%'] == True: + if ids[r"%%s"] == True: + nowstr = nowstr.replace(r"%%s", str(allticks[i] + 1)) + if ids[r"%%t"] == True: + nowstr = nowstr.replace(r"%%t", self.__score2time(allticks[i] + 1)) + if ids[r"%%%"] == True: nowstr = nowstr.replace( - r'%%%', str(int((allticks[i] + 1) / allticks[-1] * 10000) / 100) + '%' + r"%%%", + str(int((allticks[i] + 1) / allticks[-1] * 10000) / 100) + "%", ) countof_s = int((allticks[i] + 1) / allticks[-1] * pgblength) titlenow = __replace( nowstr, - '_', + "_", isMixedWithPrograssBar[1][0], countof_s, isMixedWithPrograssBar[1][1], ) - results.append((f'title {player} actionbar {titlenow}', 0,)) + results.append( + ( + f"title {player} actionbar {titlenow}", + 0, + ) + ) return results def __fillSquareSideLength(self, total: int, maxHeight: int): - '''给定总方块数量和最大高度,返回所构成的图形外切正方形的边长 + """给定总方块数量和最大高度,返回所构成的图形外切正方形的边长 :param total: 总方块数量 :param maxHeight: 最大高度 - :return: 外切正方形的边长 int''' + :return: 外切正方形的边长 int""" import math return math.ceil(math.sqrt(math.ceil(total / maxHeight))) def tomcpack( - self, - method: int = 1, - isAutoReset: bool = False, - progressbar=None, - scoreboardname: str = 'mscplay', - volume: float = 1.0, - speed: float = 1.0, + self, + method: int = 1, + isAutoReset: bool = False, + progressbar=None, + scoreboardname: str = "mscplay", + volume: float = 1.0, + speed: float = 1.0, ) -> bool: """ 使用method指定的转换算法,将midi转换为我的世界mcpack格式的包 @@ -562,106 +654,102 @@ class midiConvert: if method == 1: cmdlist, _a, maxscore = self._toCmdList_m1(scoreboardname, volume, speed) else: - return (False, f'无法找到算法ID{method}对应的转换算法') + return (False, f"无法找到算法ID{method}对应的转换算法") del _a - import json - import uuid - import shutil - # 当文件f夹{self.outputPath}/temp/functions存在时清空其下所有项目,若其不存在则创建 - if os.path.exists(f'{self.outputPath}/temp/functions/'): - shutil.rmtree(f'{self.outputPath}/temp/functions/') - os.makedirs(f'{self.outputPath}/temp/functions/mscplay') + if os.path.exists(f"{self.outputPath}/temp/functions/"): + shutil.rmtree(f"{self.outputPath}/temp/functions/") + os.makedirs(f"{self.outputPath}/temp/functions/mscplay") # 写入manifest.json - if not os.path.exists(f'{self.outputPath}/temp/manifest.json'): + if not os.path.exists(f"{self.outputPath}/temp/manifest.json"): with open( - f"{self.outputPath}/temp/manifest.json", "w", encoding='utf-8' + f"{self.outputPath}/temp/manifest.json", "w", encoding="utf-8" ) as f: f.write( - "{\n \"format_version\": 1,\n \"header\": {\n \"description\": \"" + '{\n "format_version": 1,\n "header": {\n "description": "' + self.midFileName - + " Pack : behavior pack\",\n \"version\": [ 0, 0, 1 ],\n \"name\": \"" + + ' Pack : behavior pack",\n "version": [ 0, 0, 1 ],\n "name": "' + self.midFileName - + "Pack\",\n \"uuid\": \"" + + 'Pack",\n "uuid": "' + str(uuid.uuid4()) - + "\"\n },\n \"modules\": [\n {\n \"description\": \"" + + '"\n },\n "modules": [\n {\n "description": "' + f"the Player of the Music {self.midFileName}" - + "\",\n \"type\": \"data\",\n \"version\": [ 0, 0, 1 ],\n \"uuid\": \"" + + '",\n "type": "data",\n "version": [ 0, 0, 1 ],\n "uuid": "' + str(uuid.uuid4()) - + "\"\n }\n ]\n}" + + '"\n }\n ]\n}' ) else: with open( - f'{self.outputPath}/temp/manifest.json', 'r', encoding='utf-8' + f"{self.outputPath}/temp/manifest.json", "r", encoding="utf-8" ) as manifest: data = json.loads(manifest.read()) - data['header'][ - 'description' + data["header"][ + "description" ] = f"the Player of the Music {self.midFileName}" - data['header']['name'] = self.midFileName - data['header']['uuid'] = str(uuid.uuid4()) - data['modules'][0]['description'] = 'None' - data['modules'][0]['uuid'] = str(uuid.uuid4()) + data["header"]["name"] = self.midFileName + data["header"]["uuid"] = str(uuid.uuid4()) + data["modules"][0]["description"] = "None" + data["modules"][0]["uuid"] = str(uuid.uuid4()) manifest.close() - open(f'{self.outputPath}/temp/manifest.json', 'w', encoding='utf-8').write( + open(f"{self.outputPath}/temp/manifest.json", "w", encoding="utf-8").write( json.dumps(data) ) # 将命令列表写入文件 indexfile = open( - f'{self.outputPath}/temp/functions/index.mcfunction', 'w', encoding='utf-8' + f"{self.outputPath}/temp/functions/index.mcfunction", "w", encoding="utf-8" ) for track in cmdlist: indexfile.write( - 'function mscplay/track' + str(cmdlist.index(track) + 1) + '\n' + "function mscplay/track" + str(cmdlist.index(track) + 1) + "\n" ) with open( - f'{self.outputPath}/temp/functions/mscplay/track{cmdlist.index(track) + 1}.mcfunction', - 'w', - encoding='utf-8', + f"{self.outputPath}/temp/functions/mscplay/track{cmdlist.index(track) + 1}.mcfunction", + "w", + encoding="utf-8", ) as f: - f.write('\n'.join(track)) + f.write("\n".join(track)) indexfile.writelines( ( - 'scoreboard players add @a[scores={' + "scoreboard players add @a[scores={" + scoreboardname - + '=1..}] ' + + "=1..}] " + scoreboardname - + ' 1\n', + + " 1\n", ( - 'scoreboard players reset @a[scores={' - + scoreboardname - + '=' - + str(maxscore + 20) - + '..}]' - + f' {scoreboardname}\n' + "scoreboard players reset @a[scores={" + + scoreboardname + + "=" + + str(maxscore + 20) + + "..}]" + + f" {scoreboardname}\n" ) if isAutoReset - else '', - f'function mscplay/progressShow\n' if progressbar else '', + else "", + f"function mscplay/progressShow\n" if progressbar else "", ) ) if progressbar: if progressbar == True: with open( - f'{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction', - 'w', - encoding='utf-8', + f"{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction", + "w", + encoding="utf-8", ) as f: f.writelines( - '\n'.join(self.__formProgressBar(maxscore, scoreboardname)) + "\n".join(self.__formProgressBar(maxscore, scoreboardname)) ) else: with open( - f'{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction', - 'w', - encoding='utf-8', + f"{self.outputPath}/temp/functions/mscplay/progressShow.mcfunction", + "w", + encoding="utf-8", ) as f: f.writelines( - '\n'.join( + "\n".join( self.__formProgressBar( maxscore, scoreboardname, progressbar ) @@ -671,21 +759,21 @@ class midiConvert: indexfile.close() makeZip( - f'{self.outputPath}/temp/', self.outputPath + f'/{self.midFileName}.mcpack' + f"{self.outputPath}/temp/", self.outputPath + f"/{self.midFileName}.mcpack" ) - shutil.rmtree(f'{self.outputPath}/temp/') + shutil.rmtree(f"{self.outputPath}/temp/") def toBDXfile( - self, - method: int = 1, - author: str = 'Eilles', - progressbar=False, - maxheight: int = 64, - scoreboardname: str = 'mscplay', - volume: float = 1.0, - speed: float = 1.0, - isAutoReset: bool = False, + self, + method: int = 1, + author: str = "Eilles", + progressbar=False, + maxheight: int = 64, + scoreboardname: str = "mscplay", + volume: float = 1.0, + speed: float = 1.0, + isAutoReset: bool = False, ): """ 使用method指定的转换算法,将midi转换为BDX结构文件 @@ -705,7 +793,7 @@ class midiConvert: scoreboardname, volume, speed ) else: - return (False, f'无法找到算法ID {method} 对应的转换算法') + return (False, f"无法找到算法ID {method} 对应的转换算法") if not os.path.exists(self.outputPath): os.makedirs(self.outputPath) @@ -714,9 +802,9 @@ class midiConvert: f.write("BD@") _bytes = ( - b"BDX\x00" - + author.encode("utf-8") - + b" & Musicreater\x00\x01command_block\x00" + b"BDX\x00" + + author.encode("utf-8") + + b" & Musicreater\x00\x01command_block\x00" ) key = { @@ -724,10 +812,10 @@ class midiConvert: "y": (b"\x11", b"\x10"), "z": (b"\x13", b"\x12"), } - '''key存储了方块移动指令的数据,其中可以用key[x|y|z][0|1]来表示xyz的减或增''' - x = 'x' - y = 'y' - z = 'z' + """key存储了方块移动指令的数据,其中可以用key[x|y|z][0|1]来表示xyz的减或增""" + x = "x" + y = "y" + z = "z" _sideLength = self.__fillSquareSideLength(totalcount, maxheight) @@ -745,12 +833,12 @@ class midiConvert: if isAutoReset: commands += ( - 'scoreboard players reset @a[scores={' - + scoreboardname - + '=' - + str(maxScore + 20) - + '}] ' - + scoreboardname + "scoreboard players reset @a[scores={" + + scoreboardname + + "=" + + str(maxScore + 20) + + "}] " + + scoreboardname ) if progressbar: @@ -766,20 +854,20 @@ class midiConvert: cmd, (1 if yforward else 0) if ( - ((nowy != 0) and (not yforward)) - or ((yforward) and (nowy != maxheight)) + ((nowy != 0) and (not yforward)) + or ((yforward) and (nowy != maxheight)) ) else (3 if zforward else 2) if ( - ((nowz != 0) and (not zforward)) - or ((zforward) and (nowz != _sideLength)) + ((nowz != 0) and (not zforward)) + or ((zforward) and (nowz != _sideLength)) ) else 5, impluse=2, condition=False, needRedstone=False, tickDelay=0, - customName='', + customName="", executeOnFirstTick=False, trackOutput=True, ) @@ -794,7 +882,7 @@ class midiConvert: nowz += 1 if zforward else -1 if ((nowz > _sideLength) and (zforward)) or ( - (nowz < 0) and (not zforward) + (nowz < 0) and (not zforward) ): nowz -= 1 if zforward else -1 zforward = not zforward @@ -809,19 +897,19 @@ class midiConvert: _bytes += key[y][int(yforward)] with open(f"{self.outputPath}/{self.midFileName}.bdx", "ab+") as f: - f.write(brotli.compress(_bytes + b'XE')) + f.write(brotli.compress(_bytes + b"XE")) return (True, _bytes, (nowx, maxheight, _sideLength)) def toBDXfile_withDelay( - self, - method: int = 1, - author: str = 'Eilles', - progressbar=False, - maxheight: int = 64, - volume: float = 1.0, - speed: float = 1.0, - player: str = '@a', + self, + method: int = 1, + author: str = "Eilles", + progressbar=False, + maxheight: int = 64, + volume: float = 1.0, + speed: float = 1.0, + player: str = "@a", ): """ 使用method指定的转换算法,将midi转换为BDX结构文件 @@ -838,7 +926,7 @@ class midiConvert: if method == 1: cmdlist = self._toCmdList_withDelay_m1(volume, speed, player, progressbar) else: - return (False, f'无法找到算法ID {method} 对应的转换算法') + return (False, f"无法找到算法ID {method} 对应的转换算法") if not os.path.exists(self.outputPath): os.makedirs(self.outputPath) @@ -847,9 +935,9 @@ class midiConvert: f.write("BD@") _bytes = ( - b"BDX\x00" - + author.encode("utf-8") - + b" & Musicreater\x00\x01command_block\x00" + b"BDX\x00" + + author.encode("utf-8") + + b" & Musicreater\x00\x01command_block\x00" ) key = { @@ -857,10 +945,10 @@ class midiConvert: "y": (b"\x11", b"\x10"), "z": (b"\x13", b"\x12"), } - '''key存储了方块移动指令的数据,其中可以用key[x|y|z][0|1]来表示xyz的减或增''' - x = 'x' - y = 'y' - z = 'z' + """key存储了方块移动指令的数据,其中可以用key[x|y|z][0|1]来表示xyz的减或增""" + x = "x" + y = "y" + z = "z" _sideLength = self.__fillSquareSideLength(len(cmdlist), maxheight) @@ -876,20 +964,20 @@ class midiConvert: cmd, (1 if yforward else 0) if ( - ((nowy != 0) and (not yforward)) - or ((yforward) and (nowy != maxheight)) + ((nowy != 0) and (not yforward)) + or ((yforward) and (nowy != maxheight)) ) else (3 if zforward else 2) if ( - ((nowz != 0) and (not zforward)) - or ((zforward) and (nowz != _sideLength)) + ((nowz != 0) and (not zforward)) + or ((zforward) and (nowz != _sideLength)) ) else 5, impluse=2, condition=False, needRedstone=False, tickDelay=delay, - customName='', + customName="", executeOnFirstTick=False, trackOutput=True, ) @@ -904,7 +992,7 @@ class midiConvert: nowz += 1 if zforward else -1 if ((nowz > _sideLength) and (zforward)) or ( - (nowz < 0) and (not zforward) + (nowz < 0) and (not zforward) ): nowz -= 1 if zforward else -1 zforward = not zforward @@ -919,6 +1007,6 @@ class midiConvert: _bytes += key[y][int(yforward)] with open(f"{self.outputPath}/{self.midFileName}.bdx", "ab+") as f: - f.write(brotli.compress(_bytes + b'XE')) + f.write(brotli.compress(_bytes + b"XE")) return (True, _bytes, (nowx, maxheight, _sideLength))