This commit is contained in:
EillesWan 2022-10-23 02:12:11 +08:00
parent 0b3a19faad
commit 9c9ebe0a08

View File

@ -30,6 +30,7 @@ Note! Except for this source file, all the files in this repository and this pro
limitations under the License. limitations under the License.
""" """
from operator import index
import os import os
import mido import mido
import brotli import brotli
@ -673,7 +674,7 @@ class midiConvert:
""" """
if MaxVolume > 1: if MaxVolume > 1:
MaxVolume = 1 MaxVolume = 1.0
if MaxVolume <= 0: if MaxVolume <= 0:
MaxVolume = 0.001 MaxVolume = 0.001
@ -744,6 +745,7 @@ class midiConvert:
# 如果当前通道为空 则跳过 # 如果当前通道为空 则跳过
noteMsgs = [] noteMsgs = []
MsgIndex = []
for msg in channels[i]: for msg in channels[i]:
@ -752,30 +754,43 @@ class midiConvert:
elif msg[0] == "NoteS": elif msg[0] == "NoteS":
noteMsgs.append(msg[1:]) noteMsgs.append(msg[1:])
MsgIndex.append(msg[1])
elif msg[0] == "NoteE": elif msg[0] == "NoteE":
record_pop_ids = [] if msg[1] in MsgIndex:
for j in range(len(noteMsgs)): note_channels[i].append(
if noteMsgs[j][0] == msg[1]: SingleNote(
note_channels[i].append( InstID,
SingleNote( msg[1],
InstID, noteMsgs[MsgIndex.index(msg[1])][1],
msg[1], noteMsgs[MsgIndex.index(msg[1])][2],
noteMsgs[j][1], msg[-1] - noteMsgs[MsgIndex.index(msg[1])][2],
noteMsgs[j][2],
msg[-1] - noteMsgs[j][2],
)
) )
record_pop_ids.append(j) )
for j in record_pop_ids: noteMsgs.pop(MsgIndex.index(msg[1]))
noteMsgs.pop(j) MsgIndex.pop(MsgIndex.index(msg[1]))
tracks = []
tracks = []
cmdAmount = 0 cmdAmount = 0
maxScore = 0 maxScore = 0
CheckFirstChannel = False CheckFirstChannel = False
# 临时用的插值计算函数
def _linearFun(note: SingleNote) -> list:
'''传入音符数据,返回以半秒为分割的插值列表
:param note: SingleNote 音符
:return list[tuple(int开始时间毫秒, int乐器, int音符, int力度内置, float音量播放),]'''
result = []
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)))
return result
# 此处 我们把通道视为音轨 # 此处 我们把通道视为音轨
for track in note_channels: for track in note_channels:
# 如果当前通道为空 则跳过 # 如果当前通道为空 则跳过
@ -791,16 +806,15 @@ class midiConvert:
for note in track: for note in track:
for i in range(int(note.lastTime / 500)): for everynote in _linearFun(note):
# 应该是计算的时候出了点小问题 # 应该是计算的时候出了点小问题
# 我们应该用一个MC帧作为时间单位而不是半秒 # 我们应该用一个MC帧作为时间单位而不是半秒
soundID, _X = self.__Inst2soundIDwithX(InstID) soundID, _X = self.__Inst2soundIDwithX(everynote[1])
score_now = round( score_now = round(
note.startTime everynote[0] / speed / 50000
+ i * (note.lastTime / 500) / float(speed) / 50000
) )
maxScore = max(maxScore, score_now) maxScore = max(maxScore, score_now)
@ -811,7 +825,7 @@ class midiConvert:
+ "=" + "="
+ str(score_now) + str(score_now)
+ "}" + "}"
+ f"] ~ ~ ~ playsound {soundID} @s ~ ~{1 / (MaxVolume)*(1-i*500/note.lastTime) - 1} ~ {note.velocity * (0.7 if CheckFirstChannel else 0.9)} {2 ** ((note.note - 60 - _X) / 12)}" + f"] ~ ~ ~ playsound {soundID} @s ~ ~{1 / everynote[4] - 1} ~ {note.velocity * (0.7 if CheckFirstChannel else 0.9)} {2 ** ((note.pitch - 60 - _X) / 12)}"
) )
cmdAmount += 1 cmdAmount += 1