mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2025-09-24 05:16:34 +00:00
修bug,准备合并
This commit is contained in:
@ -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
|
Reference in New Issue
Block a user