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