更新指令格式

This commit is contained in:
bgArray 2022-12-29 11:09:30 +08:00
parent 88d36f94f0
commit b04c01772f

View File

@ -66,7 +66,7 @@ def makeZip(sourceDir, outFilename, compression=8, exceptFile=None):
class SingleNote:
def __init__(self, instrument: int, pitch: int, velocity, startTime, lastTime):
"""用于存储单个音符的类
:param inst 乐器编号
:param instrument 乐器编号
:param pitch 音符编号
:param velocity 力度/响度
:param startTime 开始之时(ms)
@ -502,14 +502,13 @@ class midiConvert:
for msg in track:
ticks += msg.time
# print(msg)
if msg.is_meta:
if msg.type == "set_tempo":
tempo = msg.tempo
else:
if msg.type == "program_change":
# print("TT")
instrumentID = msg.program
if msg.type == "note_on" and msg.velocity != 0:
try:
nowscore = round(
@ -520,14 +519,27 @@ class midiConvert:
raise NotDefineTempoError("计算当前分数时出错 未定义参量 Tempo")
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)}"
)
# /playsound <sound: string> [player: target] [position: x y z]
# [volume: float] [pitch: float] [minimumVolume: float]
volume_d = 1 / volume - 1
if volume_d == 0.0:
volume_d = ""
command_now = "playsound {0} @a[scores={{{1}}}] ~ ~{2} ~ {3} {4}" \
.format(soundID, "{}={}".format(scoreboardname,
nowscore), volume_d,
msg.velocity, 2 ** ((msg.note - 60 - _X) / 12))
singleTrack.append(command_now)
# singleTrack.append(
# "execute @a[scores={"
# + str(scoreboardname)
# + "="
# + str(nowscore)
# + "}"
# + f"] ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ "
# f"{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)
@ -774,7 +786,6 @@ class midiConvert:
noteMsgs.pop(MsgIndex.index(msg[1]))
MsgIndex.pop(MsgIndex.index(msg[1]))
tracks = []
cmdAmount = 0
maxScore = 0
@ -791,7 +802,8 @@ class midiConvert:
totalCount = int(note.lastTime / 500000)
for i in range(totalCount):
result.append((note.startTime+i*500000,note.instrument,note.pitch,note.velocity,MaxVolume*((totalCount-i)/totalCount)))
result.append((note.startTime + i * 500000, note.instrument, note.pitch, note.velocity,
MaxVolume * ((totalCount - i) / totalCount)))
return result
@ -811,7 +823,6 @@ class midiConvert:
for note in track:
for everynote in _linearFun(note):
# 应该是计算的时候出了点小问题
# 我们应该用一个MC帧作为时间单位而不是半秒
@ -1034,7 +1045,6 @@ class midiConvert:
:return 成功与否成功返回(True,True)失败返回(False,str失败原因)
"""
# try:
cmdlist, maxlen, maxscore = self.methods[method - 1](
scoreboardname, volume, speed
@ -1151,7 +1161,6 @@ class midiConvert:
return (True, f"转换完成,总长度{maxlen}")
def toBDXfile(
self,
method: int = 1,
@ -1185,7 +1194,7 @@ class midiConvert:
if not os.path.exists(self.outputPath):
os.makedirs(self.outputPath)
with open(os.path.abspath(os.path.join(self.outputPath,f"{self.midFileName}.bdx")), "w+") as f:
with open(os.path.abspath(os.path.join(self.outputPath, f"{self.midFileName}.bdx")), "w+") as f:
f.write("BD@")
_bytes = (
@ -1284,7 +1293,7 @@ class midiConvert:
_bytes += key[y][int(yforward)]
with open(os.path.abspath(os.path.join(self.outputPath,f"{self.midFileName}.bdx")), "ab+") as f:
with open(os.path.abspath(os.path.join(self.outputPath, f"{self.midFileName}.bdx")), "ab+") as f:
f.write(brotli.compress(_bytes + b"XE"))
return (True, _bytes, (nowx, maxheight, _sideLength))
@ -1321,7 +1330,7 @@ class midiConvert:
if not os.path.exists(self.outputPath):
os.makedirs(self.outputPath)
with open(os.path.abspath(os.path.join(self.outputPath,f"{self.midFileName}.bdx")), "w+") as f:
with open(os.path.abspath(os.path.join(self.outputPath, f"{self.midFileName}.bdx")), "w+") as f:
f.write("BD@")
_bytes = (
@ -1396,12 +1405,11 @@ class midiConvert:
_bytes += key[y][int(yforward)]
with open(os.path.abspath(os.path.join(self.outputPath,f"{self.midFileName}.bdx")), "ab+") as f:
with open(os.path.abspath(os.path.join(self.outputPath, f"{self.midFileName}.bdx")), "ab+") as f:
f.write(brotli.compress(_bytes + b"XE"))
return (True, _bytes, (nowx, maxheight, _sideLength))
# def isProgressBar(pgbarLike:str):
# '''判断所输入数据是否为进度条式样数据
# 注意,使用本函数时不得直接放在 if 后,正确用法如下:
@ -1428,6 +1436,3 @@ class midiConvert:
# return (r"▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]",("§e=§r", "§7=§r"),)
# elif pgbarLike.lower() in ('false','0'):
# return ()