From 5ea47c54cbbf7f65913d8d643490d810c477b0b3 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Wed, 5 Oct 2022 22:18:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E6=98=AF=E5=AD=A6=E6=A0=A1=E9=87=8C?= =?UTF-8?q?=E5=81=9A=E7=9A=84=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 63 -------- demo_convert.py | 6 +- demo_convert_bdx_byDelay.py | 23 ++- docs/使用教程.md | 111 +++++++++++++ example_convert_bdx.py | 16 +- msctPkgver/magicmain.py | 22 +-- msctPkgver/main.py | 299 +++++++++++++++++++----------------- 7 files changed, 306 insertions(+), 234 deletions(-) create mode 100644 docs/使用教程.md diff --git a/README.md b/README.md index 260e6ca..5bbf7a0 100644 --- a/README.md +++ b/README.md @@ -39,69 +39,6 @@ ## 使用教程📕 -> 0. 安装python3.6+ -> -> 在安装时,一定要勾选Add Python 3.X to PATH,不然就要手动设置!! -> -> 同时,装完之后记得在cmd中输入:python 试试是否安装成功, -> python的安装可以去网上随便找一下。 -> 成功安装之后,在cmd中输入python会显示: -> -> 之类的东西。 -> 1. 安装(下载本程序)git的话,可以使用以下命令: -> -> `git clone -b pkgver https://gitee.com/EillesWan/Musicreater.git` -> -> 没有安装git的话,可以下载zip包,解压后进入目录即可。 -> -> 2. 运行(进入目录) -> 在目录下打开cmd,进入到目录下,执行以下命令: -> -> -> 回车一下,然后: -> -> 输入下面的三个指令即可! -> -> `pip install mido` -> -> `pip install brotli` -> -> `pip install openpyxl` -> -> 3. 开始使用! -> 在目录下打开cmd(步骤与上面的图片一致,只是执行的代码换了),进入到目录下,执行以下命令:(选择你需要的) -> -> `python example_convert_bdx.py` -> -> `python example_convert_mcpack.py` -> -> 4. 错误补充说明 -> 如果你遇到了以下这种情况 -> -> 那么,请按照这篇文章指引做: -> https://blog.csdn.net/qq_41179280/article/details/123804948 -> -> 感谢Mono帮我们发现这个问题 -> -> 5. 使用补充说明 -> -> midi路径:含有mid文件路径、文件名、后缀的完整绝对路径 -> -> 输出路径:输出文件夹的路径,就写一个英文.(句号)可以表示生成到当前目录下 -> (意思就是支持相对路径) -> -> 是否重置计分板:1或0(歌曲放完是否重置,推荐1) -> -> 是否启用进度条:1或0(看个人需要) -> -> 计分板名称:游戏内的计分板名称 -> -> 音量:0-1之间的小数(含0,1)正常来说推荐1 -> -> 变速:float数据,一般写1 -> -> 没有报错且在输出路径下找到mcpack或bdx即为生成成功: -> ### 对于 进度条自定义 功能的说明 diff --git a/demo_convert.py b/demo_convert.py index cd4039f..fd2ace7 100644 --- a/demo_convert.py +++ b/demo_convert.py @@ -26,7 +26,6 @@ Musicreater Package Version : Demo for Midi Conversion limitations under the License. """ - from msctPkgver.main import * import os @@ -80,15 +79,14 @@ while True: if isAutoReset != '': isAutoReset = bool(int(isAutoReset)) break - except: + except BaseException: print('输入错误,请重新输入') - if os.path.isdir(midipath): for i in os.listdir(midipath): if i.endswith('.mid'): print(f'正在操作{i}') - convertion.convert(midipath + '/' + i, outpath + '/' + i[:-4] ) + convertion.convert(midipath + '/' + i, outpath + '/' + i[:-4]) if outFormat == 0: convertion.tomcpack( 1, diff --git a/demo_convert_bdx_byDelay.py b/demo_convert_bdx_byDelay.py index d9a209e..62538a2 100644 --- a/demo_convert_bdx_byDelay.py +++ b/demo_convert_bdx_byDelay.py @@ -20,9 +20,19 @@ if not os.path.exists(outpath): while True: try: authorname = input('请输入作者:') - isProgress = input('是否开启进度条(1|0):') - if isProgress != '': - isProgress = bool(int(isProgress)) + while True: + isProgress = input('*进度条[注]:') + if isProgress != '' : + if isProgress in ('1','True'): + isProgress = True + elif isProgress in ('0', 'False'): + isProgress = False + else: + isProgress = isProgress + else: + continue + break + volume = input('请输入音量(0-1):') if volume != '': volume = float(volume) @@ -35,10 +45,9 @@ while True: heightmax = int(heightmax) break - except: + except BaseException: print('输入错误,请重新输入') - if os.path.isdir(midipath): for i in os.listdir(midipath): if i.endswith('.mid'): @@ -47,7 +56,7 @@ if os.path.isdir(midipath): convertion.toBDXfile_withDelay( 1, authorname if authorname != '' else input('请输入作者:'), - isProgress if isProgress != '' else bool(int(input('是否开启进度条(1|0):'))), + isProgress, heightmax if heightmax != '' else int(input('请输入指令结构最大生成高度:')), volume if volume != '' else float(input('请输入音量(0-1]:')), speed if speed != '' else float(input('请输入速度倍率:')), @@ -59,7 +68,7 @@ else: convertion.toBDXfile_withDelay( 1, authorname if authorname != '' else input('请输入作者:'), - isProgress if isProgress != '' else bool(int(input('是否开启进度条(1|0):'))), + isProgress, heightmax if heightmax != '' else int(input('请输入指令结构最大生成高度:')), volume if volume != '' else float(input('请输入音量(0-1]:')), speed if speed != '' else float(input('请输入速度倍率:')), diff --git a/docs/使用教程.md b/docs/使用教程.md new file mode 100644 index 0000000..a6b4ba0 --- /dev/null +++ b/docs/使用教程.md @@ -0,0 +1,111 @@ +# 演示程序使用教程 + +*由于先前的 **读我文件**(README.md) 过于冗杂,现另辟蹊径来给大家全方位的教程。* + +*这是演示程序的使用教程,将在这里提供演示程序的相应的使用教程* + +## 视窗(Windows)操作系统 + +### 运行环境安装 + +0. 安装python3.6+ + + 首先需要下载Python的安装包 + + > [下载64位Python安装包](https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe) + > [下载32位Python安装包](https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe) + + 在安装时,最好需要勾选 `Add Python 3.X to PATH` ,如下图所示,当然,如果您对自己非常自信,您也可以手动设置此项目: + + + + 若您对Python一知半解或者不怎么了解、并对自己的系统盘有大约150*MB*的信心的话,您可以在安装时直接选择*快速安装*(Install Now) + + 若您选择了*自定义安装*(Customize Installation),请务必勾选 `pip` 和 `py launcher` 便于后续安装依赖,如下图: + + + + 安装结束之后可以在*终端*(命令行/PowerShell/Bash/etc)中输入:python 试试是否安装成功,成功安装之后,在终端中输入python会显示诸如如下图片的提示: + + + +1. 下载本代码库以及演示程序 + + - 若您使用git,请直接拷贝本仓库: + + `git clone -b pkgver https://gitee.com/EillesWan/Musicreater.git` + + - 若您不使用git,可以在*码云*(Gitee)或GitHub下载zip包,或者[加入QQ群聊861684859](https://jq.qq.com/?_wv=1027&k=hpeRxrYr),在群文件中获取。 + + + +2. 安装依赖 + + 请以管理员模式打开您的*终端*(命令行/PowerShell/Bash/etc) + + 例如,命令行,可以如此打开:在*视窗开始菜单*(Windows开始)中搜索 `cmd`, 并以管理员身份运行 + + + + 打开了终端之后,请在终端中输入以下指令 + + `pip install mido -i https://mirrors.aliyun.com/pypi/simple/` + + `pip install brotli -i https://mirrors.aliyun.com/pypi/simple/` + + 安装成功后您可能会见到类似下图的提示: + + + + +3. 开始使用 + + 在目录下打开终端,例如,打开命令行,请进入到目录下,在地址框内输入cmd: + + + + 执行以下命令:(选择你需要的) + + `python example_convert_bdx.py` + + `python example_convert_mcpack.py` + +### 补充错误说明 + +1. Microsoft Visual C++ Redistributable 环境出错 + + 如果你遇到了以下这种情况 + + + + 请下载最新的VCREDIST安装包,可以参照[这个网页](https://docs.microsoft.com/zh-CN/cpp/windows/latest-supported-vc-redist)的说明,也可以在这直接选择你需要的安装包下载: + > [下载64位VCREDIST安装包](https://aka.ms/vs/17/release/vc_redist.x64.exe) + > [下载32位VCREDIST安装包](https://aka.ms/vs/17/release/vc_redist.x64.exe) + + 感谢群友Mono帮我们发现这个问题 + +2. 参数补充说明 + + + + - midi路径:含有mid文件路径、文件名、后缀的完整文件路径。可以使用相对或绝对路径皆可 + + - 输出路径:输出文件夹的路径,不需要指示文件名 + + - 是否重置计分板:1或0(歌曲放完是否重置,推荐1) + + - 是否启用进度条:1或0(看个人需要) + + *进度条:是否启用进度条,以及自定义进度条样式。输入0或False表示不启用进度条,输入1或True表示使用默认进度条,其余的输入均表示使用输入的格式作为自定义的进度条样式 + + - 计分板名称:游戏内的计分板名称 + + - 音量:0-1之间的小数(含0,1)正常来说推荐1 + + - 变速:float数据,一般写1 + + - 玩家选择器:包括 `@x` 在内的全部选择器,即若要选择全部标签为Holo的玩家,则需要如此输入:`@a[tag=Holo]` + + - 没有报错且在输出路径下找到mcpack或bdx即为生成成功: + + \ No newline at end of file diff --git a/example_convert_bdx.py b/example_convert_bdx.py index 28397f9..a7d89f8 100644 --- a/example_convert_bdx.py +++ b/example_convert_bdx.py @@ -6,13 +6,13 @@ from msctPkgver.main import * convertion = midiConvert() convertion.convert(input('请输入midi文件路径:'), input('请输入输出路径:')) for i in convertion.toBDXfile( - 1, - input('请输入作者:'), - bool(int(input('是否开启进度条(1|0):'))), - int(input('请输入指令结构最大生成高度:')), - input('请输入计分板名称:'), - float(input('请输入音量(0-1]:')), - float(input('请输入速度倍率:')), - bool(int(input('是否自动重置计分板(1|0):'))), + 1, + input('请输入作者:'), + bool(int(input('是否开启进度条(1|0):'))), + int(input('请输入指令结构最大生成高度:')), + input('请输入计分板名称:'), + float(input('请输入音量(0-1]:')), + float(input('请输入速度倍率:')), + bool(int(input('是否自动重置计分板(1|0):'))), ): print(i) diff --git a/msctPkgver/magicmain.py b/msctPkgver/magicmain.py index baba0db..71975de 100644 --- a/msctPkgver/magicmain.py +++ b/msctPkgver/magicmain.py @@ -31,8 +31,10 @@ Note! Except for this source file, all the files in this repository and this pro def _toCmdList_m1( - self, scoreboardname: str = "mscplay", volume: float = 1.0, speed: float = 1.0 -) -> list: + self, + scoreboardname: str = "mscplay", + volume: float = 1.0, + speed: float = 1.0) -> list: """ 使用Dislink Sforza的转换思路,将midi转换为我的世界命令列表 :param scoreboardname: 我的世界的计分板名称 @@ -73,16 +75,14 @@ def _toCmdList_m1( maxscore = max(maxscore, nowscore) soundID, _X = self.__Inst2soundIDwithX(instrumentID) singleTrack.append( - "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)}" - ) + "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)}") commands += 1 if len(singleTrack) != 0: tracks.append(singleTrack) - return tracks, commands, maxscore - + return [tracks, commands, maxscore] diff --git a/msctPkgver/main.py b/msctPkgver/main.py index 3c5fe8f..f7e3e77 100644 --- a/msctPkgver/main.py +++ b/msctPkgver/main.py @@ -90,7 +90,7 @@ class midiConvert: 钟琴bell、管钟chime、木琴xylophone的时候为4 而存在一些打击乐器basedrum、hat、snare,没有音域,则没有X,那么我们返回7即可 :param instrumentID: midi的乐器ID - :param default: 如果instrumentID不在范围内,返回的默认我的世界乐器名称 + default: 如果instrumentID不在范围内,返回的默认我的世界乐器名称 :return: (str我的世界乐器名, int转换算法中的X)""" try: a = { @@ -223,21 +223,22 @@ class midiConvert: 126: ("note.basedrum", 7), # 打击乐器无音域 127: ("note.snare", 7), # 打击乐器无音域 }[instrumentID] - except: + except BaseException: a = ("note.harp", 6) return a 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] @@ -256,8 +257,11 @@ 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) if times == s.count(tobeReplaced): @@ -306,11 +310,11 @@ class midiConvert: for i in range(maxscore): nowstr = pgsstyle - if ids[r"%%s"] == True: + if ids[r"%%s"]: nowstr = nowstr.replace(r"%%s", str(i + 1)) - if ids[r"%%t"] == True: + if ids[r"%%t"]: nowstr = nowstr.replace(r"%%t", self.__score2time(i + 1)) - if ids[r"%%%"] == True: + if ids[r"%%%"]: nowstr = nowstr.replace( r"%%%", str(int((i + 1) / maxscore * 10000) / 100) + "%" ) @@ -318,29 +322,33 @@ class midiConvert: countof_s = int((i + 1) / maxscore * pgblength) finalprgsbar.append( - "title @a[scores={" - + scoreboardname - + "=" - + str(i + 1) - + "}] actionbar " - + __replace( - nowstr, "_", progressbar[1][0], countof_s, progressbar[1][1] - ) - ) + "title @a[scores={" + + scoreboardname + + "=" + + str( + i + + 1) + + "}] actionbar " + + __replace( + 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, ): """ 使用指定项目返回指定的指令方块放置指令项 @@ -377,7 +385,7 @@ class midiConvert: 执行延时 :param customName: `str` 悬浮字 - :param lastOutput: `str` + lastOutput: `str` 上次输出字符串,注意此处需要留空 :param executeOnFirstTick: `bool` 执行第一个已选项(循环指令方块是否激活后立即执行,若为False,则从激活时起延迟后第一次执行) @@ -386,7 +394,8 @@ class midiConvert: :return:str """ - block = b"\x24" + particularValue.to_bytes(2, byteorder="big", signed=False) + block = b"\x24" + \ + particularValue.to_bytes(2, byteorder="big", signed=False) for i in [ impluse.to_bytes(4, byteorder="big", signed=False), @@ -403,8 +412,10 @@ class midiConvert: return block def _toCmdList_m1( - self, scoreboardname: str = "mscplay", volume: float = 1.0, speed: float = 1.0 - ) -> list: + self, + scoreboardname: str = "mscplay", + volume: float = 1.0, + speed: float = 1.0) -> list: """ 使用Dislink Sforza的转换思路,将midi转换为我的世界命令列表 :param scoreboardname: 我的世界的计分板名称 @@ -445,23 +456,24 @@ class midiConvert: maxscore = max(maxscore, nowscore) soundID, _X = self.__Inst2soundIDwithX(instrumentID) singleTrack.append( - "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)}" - ) + "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)}") commands += 1 if len(singleTrack) != 0: tracks.append(singleTrack) - return tracks, commands, maxscore + return [tracks, commands, maxscore] # 值得注意的是,我这里没有修改 def _toCmdList_m2( - self, scoreboardname: str = "mscplay", volume: float = 1.0, speed: float = 1.0 - ) -> list: + self, + scoreboardname: str = "mscplay", + volume: float = 1.0, + speed: float = 1.0) -> list: """ 使用金羿的转换思路,将midi转换为我的世界命令列表 :param scoreboardname: 我的世界的计分板名称 @@ -502,26 +514,24 @@ class midiConvert: maxscore = max(maxscore, nowscore) soundID, _X = self.__Inst2soundIDwithX(instrumentID) singleTrack.append( - "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)}" - ) + "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)}") commands += 1 if len(singleTrack) != 0: tracks.append(singleTrack) - return tracks, commands, maxscore - + 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转换为我的世界命令列表,并输出每个音符之后的延迟 @@ -538,7 +548,7 @@ class midiConvert: if volume <= 0: volume = 0.001 - if isMixedWithPrograssBar == True: + if isMixedWithPrograssBar: isMixedWithPrograssBar = ( r"▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]", ("§e=§r", "§7=§r"), @@ -567,10 +577,9 @@ class midiConvert: 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)}" ) - except: + except BaseException: 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()) @@ -592,8 +601,11 @@ 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) if times == s.count(tobeReplaced): @@ -656,15 +668,15 @@ class midiConvert: if isMixedWithPrograssBar: nowstr = pgsstyle - if ids[r"%%s"] == True: + if ids[r"%%s"]: 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"%%t"]: nowstr = nowstr.replace( - r"%%%", - str(int((allticks[i] + 1) / allticks[-1] * 10000) / 100) + "%", - ) + r"%%t", self.__score2time( + allticks[i] + 1)) + if ids[r"%%%"]: + nowstr = nowstr.replace(r"%%%", str( + int((allticks[i] + 1) / allticks[-1] * 10000) / 100) + "%", ) countof_s = int((allticks[i] + 1) / allticks[-1] * pgblength) @@ -693,14 +705,14 @@ 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, - ) -> bool: + self, + method: int = 1, + isAutoReset: bool = False, + progressbar=None, + scoreboardname: str = "mscplay", + volume: float = 1.0, + speed: float = 1.0, + ) -> bool or tuple: """ 使用method指定的转换算法,将midi转换为我的世界mcpack格式的包 :param method: 转换算法 @@ -712,7 +724,8 @@ class midiConvert: :return 成功与否,成功返回(True,True),失败返回(False,str失败原因) """ if method == 1: - cmdlist, _a, maxscore = self._toCmdList_m1(scoreboardname, volume, speed) + cmdlist, _a, maxscore = self._toCmdList_m1( + scoreboardname, volume, speed) else: return (False, f"无法找到算法ID{method}对应的转换算法") del _a @@ -725,24 +738,22 @@ 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": "' - + self.midFileName - + ' Pack : behavior pack",\n "version": [ 0, 0, 1 ],\n "name": "' - + self.midFileName - + 'Pack",\n "uuid": "' - + str(uuid.uuid4()) - + '"\n },\n "modules": [\n {\n "description": "' - + f"the Player of the Music {self.midFileName}" - + '",\n "type": "data",\n "version": [ 0, 0, 1 ],\n "uuid": "' - + str(uuid.uuid4()) - + '"\n }\n ]\n}' - ) + f.write('{\n "format_version": 1,\n "header": {\n "description": "' + + self.midFileName + + ' Pack : behavior pack",\n "version": [ 0, 0, 1 ],\n "name": "' + + self.midFileName + + 'Pack",\n "uuid": "' + + str(uuid.uuid4()) + + '"\n },\n "modules": [\n {\n "description": "' + + f"the Player of the Music {self.midFileName}" + + '",\n "type": "data",\n "version": [ 0, 0, 1 ],\n "uuid": "' + + str(uuid.uuid4()) + + '"\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"][ @@ -753,22 +764,22 @@ class midiConvert: 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( - json.dumps(data) - ) + 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" ) 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( @@ -793,20 +804,22 @@ class midiConvert: ) if progressbar: - if progressbar == True: + if progressbar: 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( @@ -819,21 +832,22 @@ 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/") 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结构文件 @@ -902,7 +916,7 @@ class midiConvert: ) if progressbar: - if progressbar == True: + if progressbar: commands += self.__formProgressBar(maxScore, scoreboardname) else: commands += self.__formProgressBar( @@ -934,7 +948,8 @@ class midiConvert: nowy += 1 if yforward else -1 - if ((nowy > maxheight) and (yforward)) or ((nowy < 0) and (not yforward)): + if ((nowy > maxheight) and (yforward)) or ( + (nowy < 0) and (not yforward)): nowy -= 1 if yforward else -1 yforward = not yforward @@ -942,7 +957,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 @@ -962,14 +977,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结构文件 @@ -984,7 +999,8 @@ class midiConvert: """ if method == 1: - cmdlist = self._toCmdList_withDelay_m1(volume, speed, player, progressbar) + cmdlist = self._toCmdList_withDelay_m1( + volume, speed, player, progressbar) else: return (False, f"无法找到算法ID {method} 对应的转换算法") @@ -1044,7 +1060,8 @@ class midiConvert: nowy += 1 if yforward else -1 - if ((nowy > maxheight) and (yforward)) or ((nowy < 0) and (not yforward)): + if ((nowy > maxheight) and (yforward)) or ( + (nowy < 0) and (not yforward)): nowy -= 1 if yforward else -1 yforward = not yforward @@ -1052,7 +1069,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