mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2024-11-11 01:27:35 +08:00
修bug,准备合并
This commit is contained in:
parent
53fda9c986
commit
5cce59135a
@ -23,6 +23,12 @@
|
||||
|
||||
欢迎加群:[861684859](https://jq.qq.com/?_wv=1027&k=hpeRxrYr)
|
||||
|
||||
## 文档📄
|
||||
|
||||
[生成文件的使用](./docs/%E7%94%9F%E6%88%90%E6%96%87%E4%BB%B6%E7%9A%84%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E.md)
|
||||
|
||||
[仓库API文档](./docs/%E5%BA%93%E7%9A%84%E7%94%9F%E6%88%90%E4%B8%8E%E5%8A%9F%E8%83%BD%E6%96%87%E6%A1%A3.md)
|
||||
|
||||
## 作者✒
|
||||
|
||||
金羿 Eilles:我的世界基岩版指令师,个人开发者,B站不知名UP主,江西在校高中生。
|
||||
@ -40,7 +46,8 @@
|
||||
- 感谢 **Mono**\<QQ738893087\> 反馈安装时的问题,辅助我们找到了视窗操作系统下的兼容性问题
|
||||
- 感谢 **Ammelia “艾米利亚”**\<QQ2838334637\> 敦促我们进行新的功能开发,并为新功能提出了非常优秀的大量建议,以及提供的BDX导入测试支持,为我们的新结构生成算法提供了大量的实际理论支持
|
||||
- 感谢 **[神羽](https://gitee.com/snowykami) “[SnowyKami](https://github.com/snowyfirefly)”** 对我们项目的支持与宣传
|
||||
- 感谢 **“playjuice123” 指令师_苦力怕**\<QQ240667197\>为我们的程序找出错误,并提醒我们修复一个一直存在的大bug。
|
||||
- 感谢 **指令师_苦力怕 playjuice123**\<QQ240667197\>为我们的程序找出错误,并提醒我们修复一个一直存在的大bug。
|
||||
- 感谢 **雷霆**\<QQ3555268519\>为我们的程序找出错误,并提醒修复bug。
|
||||
|
||||
> 感谢广大群友为此程序提供的测试等支持
|
||||
>
|
||||
|
62
magicDemo.py
62
magicDemo.py
@ -35,8 +35,8 @@ languages = {
|
||||
",": ",",
|
||||
".": "。",
|
||||
"ChoosePath": "请输入MIDI路径或所在文件夹",
|
||||
"ChooseFileFormat": "请输入输出格式[BDX(1)或MCPACK(0)]",
|
||||
"EnterMethod": "请输入转换算法",
|
||||
"ChooseFileFormat": "请输入输出格式[BDX(1) 或 MCPACK(0)]",
|
||||
"EnterMethod": "请输入转换算法[{}~{}]",
|
||||
"MethodRangeErr": "输入的转换算法应为 [{},{}](首尾皆含)之间的一个整数。",
|
||||
"ChoosePlayer": "请选择播放方式[计分板(1) 或 延迟(0)]",
|
||||
"WhetherArgEntering": "是否为文件夹内文件的转换统一参数[是(1) 或 否(0)]",
|
||||
@ -96,11 +96,9 @@ try:
|
||||
import requests
|
||||
except ModuleNotFoundError as E:
|
||||
if input(
|
||||
"您需要安装以下模块才能使用这个样例\nrequests==2.28.1\nrich==12.6.0\nzhdate==0.1\n请问是否安装?(y/n):"
|
||||
"您需要安装以下模块才能使用这个样例\nrequests==2.28.1\nrich==12.6.0\nzhdate==0.1\n请问是否安装?(y/n):"
|
||||
).lower() in ("y", "1"):
|
||||
open("Demo_Requirements.txt", "w").write(
|
||||
"requests==2.28.1\nrich==12.6.0"
|
||||
)
|
||||
open("Demo_Requirements.txt", "w").write("requests==2.28.1\nrich==12.6.0")
|
||||
os.system("pip install -r Demo_Requirements.txt")
|
||||
os.remove("./Demo_Requirements.txt")
|
||||
from msctPkgver.magicBeing import *
|
||||
@ -144,8 +142,8 @@ else:
|
||||
requests.get(
|
||||
"https://gitee.com/TriM-Organization/LinglunStudio/raw/master/resources/myWords.txt"
|
||||
)
|
||||
.text.strip("\r\n")
|
||||
.split("\r\n")
|
||||
.text.strip("\n")
|
||||
.split("\n")
|
||||
)
|
||||
),
|
||||
style="#121110 on #F0F2F4",
|
||||
@ -156,10 +154,10 @@ prt(f"{_('LangChd')}{_(':')}{_(currentLang)}")
|
||||
|
||||
|
||||
def format_ipt(
|
||||
notice: str,
|
||||
fun,
|
||||
err_note: str = f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||
*extraArg,
|
||||
notice: str,
|
||||
fun,
|
||||
err_note: str = f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||
*extraArg,
|
||||
):
|
||||
"""循环输入,以某种格式
|
||||
notice: 输入时的提示
|
||||
@ -216,9 +214,11 @@ def isMethodOK(sth: str):
|
||||
raise ValueError
|
||||
|
||||
|
||||
convert_method = \
|
||||
format_ipt(f"{_('EnterMethod')}{_(':')}", isMethodOK, f"{_('MethodRangeErr').format(1, len(conversion.methods))}")[
|
||||
1]
|
||||
convert_method = format_ipt(
|
||||
f"{_('EnterMethod').format(1, len(conversion.methods))}{_(':')}",
|
||||
isMethodOK,
|
||||
f"{_('MethodRangeErr').format(1, len(conversion.methods))}",
|
||||
)[1]
|
||||
|
||||
# 选择输出格式
|
||||
while True:
|
||||
@ -273,41 +273,41 @@ else:
|
||||
# 提示语 检测函数 错误提示语
|
||||
for args in [
|
||||
(
|
||||
f'{_("EnterVolume")}{_(":")}',
|
||||
float,
|
||||
f'{_("EnterVolume")}{_(":")}',
|
||||
float,
|
||||
),
|
||||
(
|
||||
f'{_("EnterSpeed")}{_(":")}',
|
||||
float,
|
||||
f'{_("EnterSpeed")}{_(":")}',
|
||||
float,
|
||||
),
|
||||
(
|
||||
f'{_("WhetherPgb")}{_(":")}',
|
||||
bool_str,
|
||||
f'{_("WhetherPgb")}{_(":")}',
|
||||
bool_str,
|
||||
),
|
||||
(
|
||||
f'{_("EnterSbName")}{_(":")}',
|
||||
str,
|
||||
f'{_("EnterSbName")}{_(":")}',
|
||||
str,
|
||||
)
|
||||
if playerFormat == 1
|
||||
else (
|
||||
f'{_("EnterSelecter")}{_(":")}',
|
||||
str,
|
||||
f'{_("EnterSelecter")}{_(":")}',
|
||||
str,
|
||||
),
|
||||
(
|
||||
f'{_("WhetherSbReset")}{_(":")}',
|
||||
bool_str,
|
||||
f'{_("WhetherSbReset")}{_(":")}',
|
||||
bool_str,
|
||||
)
|
||||
if playerFormat == 1
|
||||
else (),
|
||||
(
|
||||
f'{_("EnterAuthor")}{_(":")}',
|
||||
str,
|
||||
f'{_("EnterAuthor")}{_(":")}',
|
||||
str,
|
||||
)
|
||||
if fileFormat == 1
|
||||
else (),
|
||||
(
|
||||
f'{_("EnterMaxHeight")}{_(":")}',
|
||||
int,
|
||||
f'{_("EnterMaxHeight")}{_(":")}',
|
||||
int,
|
||||
)
|
||||
if fileFormat == 1
|
||||
else (),
|
||||
|
@ -1,3 +1 @@
|
||||
import brotli
|
||||
|
||||
input(brotli.decompress(open(input("BDX文件:"), "rb").read()[3:]))
|
||||
import brotli;input(brotli.decompress(open(input("BDX文件:"), "rb").read()[3:]))
|
@ -35,7 +35,7 @@ class MSCTBaseException(Exception):
|
||||
|
||||
def crash_it(self):
|
||||
raise self
|
||||
|
||||
|
||||
|
||||
class CrossNoteError(MSCTBaseException):
|
||||
"""同通道下同音符交叉出现所产生的错误"""
|
||||
@ -65,3 +65,9 @@ class NotDefineProgramError(MSCTBaseException):
|
||||
"""没有Program设定导致没有乐器可以选择的错误"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ZeroSpeedError(MSCTBaseException):
|
||||
"""以0作为播放速度的错误"""
|
||||
|
||||
pass
|
@ -415,6 +415,10 @@ class midiConvert:
|
||||
"""
|
||||
# :param volume: 音量,注意:这里的音量范围为(0,1],如果超出将被处理为正确值,其原理为在距离玩家 (1 / volume -1) 的地方播放音频
|
||||
tracks = []
|
||||
if speed <= 0:
|
||||
if self.debugMode:
|
||||
raise ZeroSpeedError("播放速度仅可为正实数")
|
||||
speed = 0.00001
|
||||
MaxVolume = 1 if MaxVolume > 1 else (0.001 if MaxVolume <= 0 else MaxVolume)
|
||||
|
||||
commands = 0
|
||||
@ -481,6 +485,10 @@ class midiConvert:
|
||||
:return: tuple(命令列表, 命令个数, 计分板最大值)
|
||||
"""
|
||||
|
||||
if speed <= 0:
|
||||
if self.debugMode:
|
||||
raise ZeroSpeedError("播放速度仅可为正实数")
|
||||
speed = 0.00001
|
||||
MaxVolume = 1 if MaxVolume > 1 else (0.001 if MaxVolume <= 0 else MaxVolume)
|
||||
|
||||
# 一个midi中仅有16个通道 我们通过通道来识别而不是音轨
|
||||
@ -635,6 +643,10 @@ class midiConvert:
|
||||
"""
|
||||
# TODO: 这里的时间转换不知道有没有问题
|
||||
|
||||
if speed <= 0:
|
||||
if self.debugMode:
|
||||
raise ZeroSpeedError("播放速度仅可为正实数")
|
||||
speed = 0.00001
|
||||
if MaxVolume > 1:
|
||||
MaxVolume = 1.0
|
||||
if MaxVolume <= 0:
|
||||
@ -819,6 +831,10 @@ class midiConvert:
|
||||
"""
|
||||
# :param volume: 音量,注意:这里的音量范围为(0,1],如果超出将被处理为正确值,其原理为在距离玩家 (1 / volume -1) 的地方播放音频
|
||||
tracks = {}
|
||||
if speed <= 0:
|
||||
if self.debugMode:
|
||||
raise ZeroSpeedError("播放速度仅可为正实数")
|
||||
speed = 0.00001
|
||||
|
||||
MaxVolume = 1 if MaxVolume > 1 else (0.001 if MaxVolume <= 0 else MaxVolume)
|
||||
|
||||
@ -887,6 +903,10 @@ class midiConvert:
|
||||
"""
|
||||
# :param volume: 音量,注意:这里的音量范围为(0,1],如果超出将被处理为正确值,其原理为在距离玩家 (1 / volume -1) 的地方播放音频
|
||||
tracks = {}
|
||||
if speed <= 0:
|
||||
if self.debugMode:
|
||||
raise ZeroSpeedError("播放速度仅可为正实数")
|
||||
speed = 0.00001
|
||||
|
||||
MaxVolume = 1 if MaxVolume > 1 else (0.001 if MaxVolume <= 0 else MaxVolume)
|
||||
|
||||
@ -1165,7 +1185,7 @@ class midiConvert:
|
||||
|
||||
if os.path.exists(f"{self.outputPath}/{self.midFileName}.mcpack"):
|
||||
os.remove(f"{self.outputPath}/{self.midFileName}.mcpack")
|
||||
compressZipFile(
|
||||
compress_zipfile(
|
||||
f"{self.outputPath}/temp/", f"{self.outputPath}/{self.midFileName}.mcpack"
|
||||
)
|
||||
|
||||
|
@ -35,7 +35,7 @@ def move(axis: str, value: int):
|
||||
return key[axis][pointer] + value.to_bytes(2 ** (pointer - 2), "big", signed=True)
|
||||
|
||||
|
||||
def compressZipFile(sourceDir, outFilename, compression=8, exceptFile=None):
|
||||
def compress_zipfile(sourceDir, outFilename, compression=8, exceptFile=None):
|
||||
"""使用compression指定的算法打包目录为zip文件\n
|
||||
默认算法为DEFLATED(8),可用算法如下:\n
|
||||
STORED = 0\n
|
||||
@ -129,7 +129,7 @@ def form_command_block_in_BDX_bytes(
|
||||
return block
|
||||
|
||||
|
||||
def __fillSquareSideLength(total: int, maxHeight: int):
|
||||
def bottem_side_length_of_smallest_square_bottom_box(total: int, maxHeight: int):
|
||||
"""给定总方块数量和最大高度,返回所构成的图形外切正方形的边长
|
||||
:param total: 总方块数量
|
||||
:param maxHeight: 最大高度
|
||||
@ -147,7 +147,7 @@ def to_BDX_bytes(
|
||||
:return 成功与否,成功返回(True,未经过压缩的源,结构占用大小),失败返回(False,str失败原因)
|
||||
"""
|
||||
|
||||
_sideLength = __fillSquareSideLength(len(commands), max_height)
|
||||
_sideLength = bottem_side_length_of_smallest_square_bottom_box(len(commands), max_height)
|
||||
_bytes = b""
|
||||
|
||||
y_forward = True
|
||||
|
@ -359,7 +359,7 @@ def format_ipt(notice: str, fun, err_note: str = "", *extraArg):
|
||||
try:
|
||||
fun_result = fun(result, *extraArg)
|
||||
break
|
||||
except BaseError:
|
||||
except ValueError:
|
||||
print(err_note)
|
||||
continue
|
||||
return result, fun_result
|
Loading…
Reference in New Issue
Block a user