mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2025-09-03 19:06:23 +00:00
修复部分bug,增加部分bug
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -44,7 +44,7 @@ StrStartTime = str(datetime.datetime.now()).replace(':', '_')[:-7]
|
||||
"""字符串型的程序开始时间"""
|
||||
|
||||
|
||||
def log(info: str = '', isPrinted: bool = False, isLoggerLibRecord: bool = True, isWrite: bool = False):
|
||||
def log(info: str = '', isWrite: bool = True, isPrinted: bool = False, isLoggerLibRecord: bool = True):
|
||||
"""
|
||||
info: 信息
|
||||
isPrinted: 是否print(仅限金羿log,python官方的logging照常输出)
|
||||
@ -52,6 +52,9 @@ def log(info: str = '', isPrinted: bool = False, isLoggerLibRecord: bool = True,
|
||||
isWrite: 是否write(仅限金羿log,python官方的logging照常输出)
|
||||
"""
|
||||
"""将信息连同当前时间载入日志"""
|
||||
# 致后来的开发者:请让金羿的log存在吧,不然他自己都看不懂你们写了什么了
|
||||
# 我指的是程序内部
|
||||
# ——金羿
|
||||
if not os.path.exists('./log/'):
|
||||
os.makedirs('./log/')
|
||||
if isWrite:
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
from nmcsup.log import log
|
||||
from nmcsup.const import notes
|
||||
import pickle
|
||||
|
||||
|
||||
|
||||
# 从格式文本文件读入一个音轨并存入一个列表
|
||||
@ -68,145 +68,7 @@ def ReadMidi(midfile: str): # -> list
|
||||
return Notes
|
||||
|
||||
|
||||
class Note:
|
||||
def __init__(self, channel, pitch, velocity, time, time_position, instrument):
|
||||
self.channel = channel
|
||||
self.pitch = pitch
|
||||
self.velocity = velocity
|
||||
self.delay = time
|
||||
self.time_position = time_position
|
||||
self.instrument = instrument
|
||||
self.CD = "d"
|
||||
|
||||
def get_CD(self, start, end):
|
||||
if end - start > 1.00:
|
||||
self.CD = "c"
|
||||
else:
|
||||
self.CD = "d"
|
||||
|
||||
|
||||
def midi_conversion(midfile: str):
|
||||
import mido
|
||||
# from msctspt.threadOpera import NewThread
|
||||
from bgArrayLib.bpm import get
|
||||
|
||||
def Time(mt, tpb_a, bpm_a):
|
||||
return round(mt / tpb_a / bpm_a * 60 * 20)
|
||||
|
||||
Notes = []
|
||||
tracks = []
|
||||
note_list = []
|
||||
close = []
|
||||
on = []
|
||||
off = []
|
||||
instruments = []
|
||||
isPercussion = False
|
||||
try:
|
||||
mid = mido.MidiFile(midfile)
|
||||
except FileNotFoundError:
|
||||
log("找不到文件或无法读取文件" + midfile)
|
||||
return False
|
||||
tpb = mid.ticks_per_beat
|
||||
bpm = get(midfile)
|
||||
# 解析
|
||||
# def loadMidi(track1):
|
||||
for track in mid.tracks:
|
||||
overallTime = 0.0
|
||||
instrument = 0
|
||||
for i in track:
|
||||
overallTime += i.time
|
||||
try:
|
||||
if i.channel != 9:
|
||||
# try:
|
||||
# log("event_type(事件): " + str(i.type) + " channel(音轨): " + str(i.channel) +
|
||||
# " note/pitch(音高): " +
|
||||
# str(i[2]) +
|
||||
# " velocity(力度): " + str(i.velocity) + " time(间隔时间): " + str(i.time) +
|
||||
# " overallTime/globalTime/timePosition: " + str(overallTime) + " \n")
|
||||
# except AttributeError:
|
||||
# log("event_type(事件): " + str(i.type) + " thing(内容):" + str(i) + " \n")
|
||||
if 'program_change' in str(i):
|
||||
instrument = i.program
|
||||
if instrument > 119: # 音色不够
|
||||
pass
|
||||
else:
|
||||
instruments.append(i.program)
|
||||
if 'note_on' in str(i) and i.velocity > 0:
|
||||
print(i)
|
||||
# print(i.note)
|
||||
# print([Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), instrument)])
|
||||
tracks.append(
|
||||
[Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), instrument)])
|
||||
note_list.append(
|
||||
[i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), instrument])
|
||||
on.append([i.note, Time(overallTime, tpb, bpm)])
|
||||
# return [Note(i.channel, i, i.velocity, i.time, Time(overallTime, tpb, bpm))]
|
||||
if 'note_off' in str(i) or 'note_on' in str(i) and i.velocity == 0:
|
||||
# print(i)
|
||||
# print([Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm))])
|
||||
close.append(
|
||||
[Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), instrument)])
|
||||
off.append([i.note, Time(overallTime, tpb, bpm)])
|
||||
# return [Note(i.channel, i, i.velocity, i.time, Time(overallTime, tpb, bpm))]
|
||||
except AttributeError:
|
||||
pass
|
||||
if 'note_on' in str(i) and i.channel == 9:
|
||||
if 'note_on' in str(i) and i.velocity > 0:
|
||||
print(i)
|
||||
# print(i.note)
|
||||
# print([Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), -1)])
|
||||
tracks.append([Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), -1)])
|
||||
note_list.append([i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), -1])
|
||||
on.append([i.note, Time(overallTime, tpb, bpm)])
|
||||
isPercussion = True
|
||||
# return [Note(i.channel, i, i.velocity, i.time, Time(overallTime, tpb, bpm))]
|
||||
Notes.append(tracks)
|
||||
if instruments is []:
|
||||
instruments.append(0)
|
||||
instruments = list(set(instruments))
|
||||
with open("1.pkl", 'wb') as b:
|
||||
pickle.dump([instruments, isPercussion], b)
|
||||
|
||||
# for j, track in enumerate(mid.tracks):
|
||||
# th = NewThread(loadMidi, (track,))
|
||||
# th.start()
|
||||
# Notes.append(th.getResult())
|
||||
|
||||
# print(Notes)
|
||||
print(Notes.__len__())
|
||||
# print(note_list)
|
||||
print(instruments)
|
||||
return Notes
|
||||
# return [Notes, note_list]
|
||||
|
||||
|
||||
def midiClassReader(midfile: str):
|
||||
import mido
|
||||
from bgArrayLib.bpm import get
|
||||
|
||||
def Time(mt, tpb_a, bpm_a):
|
||||
return round(mt / tpb_a / bpm_a * 60 * 20)
|
||||
Notes = []
|
||||
tracks = []
|
||||
try:
|
||||
mid = mido.MidiFile(midfile)
|
||||
except FileNotFoundError:
|
||||
log("找不到文件或无法读取文件" + midfile)
|
||||
return False
|
||||
tpb = mid.ticks_per_beat
|
||||
bpm = get(midfile)
|
||||
for track in mid.tracks:
|
||||
overallTime = 0.0
|
||||
instrument = 0
|
||||
for i in track:
|
||||
overallTime += i.time
|
||||
if 'note_on' in str(i) and i.velocity > 0:
|
||||
print(i)
|
||||
tracks.append(
|
||||
[Note(i.channel, i.note, i.velocity, i.time, Time(overallTime, tpb, bpm), instrument)])
|
||||
Notes.append(tracks)
|
||||
print(Notes.__len__())
|
||||
return Notes
|
||||
|
||||
|
||||
def ReadOldProject(fn: str): # -> list
|
||||
@ -226,10 +88,41 @@ def ReadOldProject(fn: str): # -> list
|
||||
return dataset
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# a = midi_conversion("L:\\0WorldMusicCreater-MFMS new edition\\框架\\v0.3.2\\Musicreater\\测试用\\同道殊途标准.mid")
|
||||
# midi_conversion("L:\\0WorldMusicCreater-MFMS new edition\\框架\\v0.3.2\\Musicreater\\测试用\\"
|
||||
# "Illusionary_Daytime_--------幻昼.mid")
|
||||
# a = midi_conversion(r"C:\Users\lc\Documents\MuseScore3\乐谱\架子鼓.mid")
|
||||
from bgArrayLib.reader import midi_conversion
|
||||
a = midi_conversion(r"C:\Users\lc\Documents\MuseScore3\乐谱\stay2.mid")
|
||||
# print(a)
|
||||
|
@ -83,6 +83,9 @@ def Mp32Mid(mp3File, midFile):
|
||||
PianoTranscription(device="cpu").transcribe(audio, midFile)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 传入一个音符列表转为指令列表
|
||||
def Note2Cmd(Notes: list, ScoreboardName: str, Instrument: str, PlayerSelect: str = '',
|
||||
isProsess: bool = False) -> list:
|
||||
@ -105,41 +108,22 @@ def Note2Cmd(Notes: list, ScoreboardName: str, Instrument: str, PlayerSelect: st
|
||||
# def newDataStructureCounterChange():
|
||||
|
||||
|
||||
def classList_conversion(List: list, ScoreboardName: str,
|
||||
isProsess: bool = False) -> list:
|
||||
from bgArrayLib.compute import round_up
|
||||
commands = []
|
||||
length = len(List)
|
||||
j = 1
|
||||
print(List)
|
||||
for k in range(len(List)):
|
||||
i = List[k][0]
|
||||
print(i)
|
||||
print(type(i))
|
||||
try:
|
||||
if i.instrument > 119:
|
||||
pass
|
||||
else:
|
||||
commands.append("execute @e[scores={" +
|
||||
ScoreboardName + "=" + str(round_up(i.time_position)).replace(".0", "") + "}] ~ ~" +
|
||||
str(127 - i.velocity) +
|
||||
" ~ playsound " +
|
||||
str(i.instrument) +
|
||||
str(i.CD) + "." +
|
||||
str(i.pitch)
|
||||
+ " @a ~ ~ ~ 1000 1.0 1000\n")
|
||||
if isProsess:
|
||||
commands.append("execute @a"" ~ ~ ~ execute @s[scores={" + ScoreboardName + "=" +
|
||||
str(round_up(i.time_position)).replace(".0", "") +
|
||||
"}] ~ ~ ~ title @s actionbar §e▶ 播放中: §a" +
|
||||
str(j) + "/" + str(length) + " || " + str(int(j / length * 1000) / 10) + "\n")
|
||||
j += 1
|
||||
except AttributeError:
|
||||
pass
|
||||
# a += List[i][1]
|
||||
commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI(金羿)\n")
|
||||
print(commands)
|
||||
return commands
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 简单载入方块
|
||||
|
Reference in New Issue
Block a user