mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2024-11-13 10:57:43 +08:00
Merge branch 'master' of https://gitee.com/EillesWan/Musicreater
This commit is contained in:
commit
bf3367c7e4
253
Musicreater.py
253
Musicreater.py
@ -50,6 +50,7 @@ import os
|
||||
import shutil
|
||||
import sys
|
||||
import threading
|
||||
import pickle
|
||||
import tkinter as tk
|
||||
import tkinter.filedialog
|
||||
import tkinter.messagebox
|
||||
@ -65,8 +66,6 @@ dire = ""
|
||||
begp = ""
|
||||
endp = ""
|
||||
|
||||
|
||||
|
||||
print('建立变量,存入内存,载入字典常量函数')
|
||||
|
||||
# 主体部分
|
||||
@ -111,6 +110,7 @@ dataset=[
|
||||
dataset = [
|
||||
{
|
||||
'mainset': {
|
||||
'ReadMethod': 'old',
|
||||
'PackName': 'Ryoun',
|
||||
'MusicTitle': 'Noname',
|
||||
'IsRepeat': False,
|
||||
@ -170,6 +170,7 @@ def __main__():
|
||||
|
||||
print('载入日志功能...')
|
||||
from nmcsup.log import log
|
||||
from nmcsup.log import end
|
||||
print('完成!')
|
||||
|
||||
print('更新执行位置...')
|
||||
@ -209,12 +210,24 @@ def __main__():
|
||||
else:
|
||||
return k
|
||||
|
||||
def LoadMidi(midfile: str): # -> str
|
||||
from nmcsup.nmcreader import midi_conversion
|
||||
k = midi_conversion(midfile)
|
||||
if k is False:
|
||||
tk.messagebox.showerror(title=READABLETEXT[0], message=READABLETEXT[105].format(midfile))
|
||||
return
|
||||
else:
|
||||
return k
|
||||
|
||||
print('完成!')
|
||||
|
||||
# 菜单命令
|
||||
print('加载菜单命令...')
|
||||
|
||||
def exitapp():
|
||||
if os.path.isfile("1.pkl"):
|
||||
# os.remove("1.pkl")
|
||||
pass
|
||||
global is_save
|
||||
if is_save is not True:
|
||||
if tkinter.messagebox.askyesno(title=READABLETEXT[1], message=READABLETEXT[106]):
|
||||
@ -227,25 +240,31 @@ def __main__():
|
||||
global root
|
||||
root.destroy()
|
||||
del root
|
||||
except FileNotFoundError: # 程序规范修改:根据新的语法标准:except后面不能没有错误类型,所以既然是pass就随便填一个错误
|
||||
except tkinter.TclError:
|
||||
pass
|
||||
|
||||
if clearLog:
|
||||
print(READABLETEXT[2])
|
||||
err = True
|
||||
try:
|
||||
# err = True
|
||||
# try:
|
||||
end()
|
||||
if os.path.exists('./log/'):
|
||||
shutil.rmtree('./log/')
|
||||
if os.path.exists('./logs/'):
|
||||
shutil.rmtree('./logs/')
|
||||
if os.path.exists('./cache/'):
|
||||
shutil.rmtree('./cache/')
|
||||
err = False
|
||||
except ZeroDivisionError: # 程序规范修改:根据新的语法标准:except后面不能没有错误类型,所以既然是pass就随便填一个错误
|
||||
print(READABLETEXT[3])
|
||||
finally:
|
||||
if err is True:
|
||||
print(READABLETEXT[3])
|
||||
if os.path.exists('./nmcsup/log/'):
|
||||
shutil.rmtree('./nmcsup/log/')
|
||||
if os.path.exists('./nmcsup/logs/'):
|
||||
shutil.rmtree('./nmcsup/logs/')
|
||||
# err = False
|
||||
# except:
|
||||
# print(READABLETEXT[3])
|
||||
#
|
||||
# finally:
|
||||
# if err is True:
|
||||
# print(READABLETEXT[3])
|
||||
|
||||
exit()
|
||||
|
||||
@ -257,6 +276,7 @@ def __main__():
|
||||
SaveAsProject()
|
||||
return
|
||||
else:
|
||||
try:
|
||||
# 旧项目旧存着吧
|
||||
log('存储已有文件:{}'.format(ProjectName))
|
||||
with open(ProjectName, 'w', encoding='utf-8') as f:
|
||||
@ -264,6 +284,21 @@ def __main__():
|
||||
tkinter.messagebox.showinfo(title=READABLETEXT[4], message=READABLETEXT[107].format(ProjectName))
|
||||
global is_save
|
||||
is_save = True
|
||||
except TypeError:
|
||||
SaveNewProject()
|
||||
return
|
||||
|
||||
def SaveNewProject():
|
||||
if is_new_file:
|
||||
# 新的项目相等于另存为
|
||||
SaveAsNewProject()
|
||||
return
|
||||
else:
|
||||
with open(ProjectName, 'wb') as f:
|
||||
pickle.dump(dataset, f)
|
||||
tkinter.messagebox.showinfo(title=READABLETEXT[4], message=READABLETEXT[107].format(ProjectName))
|
||||
global is_save
|
||||
is_save = True
|
||||
|
||||
print('保存项目命令加载完成!')
|
||||
|
||||
@ -274,12 +309,32 @@ def __main__():
|
||||
defaultextension='Noname.msct')
|
||||
if fn is None or fn == '':
|
||||
return
|
||||
try:
|
||||
Project_Name = fn
|
||||
with open(Project_Name, 'w', encoding='utf-8') as f:
|
||||
json.dump(dataset[0], f)
|
||||
tkinter.messagebox.showinfo(title=READABLETEXT[4], message=READABLETEXT[107].format(Project_Name))
|
||||
global is_save
|
||||
is_save = True
|
||||
except TypeError:
|
||||
Project_Name = fn
|
||||
with open(Project_Name, 'wb') as f:
|
||||
pickle.dump(dataset[0], f)
|
||||
tkinter.messagebox.showinfo(title=READABLETEXT[4], message=READABLETEXT[107].format(Project_Name))
|
||||
is_save = True
|
||||
|
||||
def SaveAsNewProject():
|
||||
fn = tkinter.filedialog.asksaveasfilename(title=READABLETEXT[5], initialdir=r'./',
|
||||
filetypes=[(READABLETEXT[108], '.msct'), (READABLETEXT[109], '*')],
|
||||
defaultextension='Noname.msct')
|
||||
if fn is None or fn == '':
|
||||
return
|
||||
Project_Name = fn
|
||||
with open(Project_Name, 'wb') as f:
|
||||
pickle.dump(dataset[0], f)
|
||||
tkinter.messagebox.showinfo(title=READABLETEXT[4], message=READABLETEXT[107].format(Project_Name))
|
||||
global is_save
|
||||
is_save = True
|
||||
|
||||
print('另存项目命令加载完成!')
|
||||
|
||||
@ -331,6 +386,41 @@ def __main__():
|
||||
RefreshMain()
|
||||
RefreshMusic(NowMusic)
|
||||
|
||||
def openNewProject():
|
||||
global is_save
|
||||
if is_save is not True:
|
||||
result = tkinter.messagebox.askyesno(title=READABLETEXT[1], message=READABLETEXT[106])
|
||||
if result:
|
||||
SaveProject()
|
||||
fn = tkinter.filedialog.askopenfilename(title=READABLETEXT[7], initialdir=r'./',
|
||||
filetypes=[(READABLETEXT[108], '.msct'), (READABLETEXT[112], '*')],
|
||||
multiple=True)
|
||||
if fn is None or fn == '':
|
||||
return
|
||||
else:
|
||||
fn = fn[0]
|
||||
try:
|
||||
try:
|
||||
with open(fn, 'rb') as C:
|
||||
dataset[0] = pickle.load(C)
|
||||
except IndexError:
|
||||
with open(fn, 'rb') as C:
|
||||
dataset[0] = pickle.load(C)[0]
|
||||
|
||||
except pickle.UnpicklingError: # 程序规范修改:根据新的语法标准:except后面不能没有错误类型,测试后改为:
|
||||
# pickle.UnpicklingError
|
||||
print(READABLETEXT[8].format(fn))
|
||||
log('无法打开{}'.format(fn))
|
||||
return
|
||||
global is_new_file
|
||||
global ProjectName
|
||||
is_new_file = False
|
||||
ProjectName = fn
|
||||
del fn
|
||||
global NowMusic
|
||||
RefreshMain()
|
||||
RefreshMusic(NowMusic)
|
||||
|
||||
print('打开项目命令加载完成!')
|
||||
|
||||
def appabout():
|
||||
@ -441,6 +531,36 @@ def __main__():
|
||||
threading.Thread(target=midiSPT, args=(th,)).start()
|
||||
del th
|
||||
|
||||
def MidiClass():
|
||||
log('从midi导入音乐并采用新读取方式')
|
||||
midfile = tkinter.filedialog.askopenfilename(title=READABLETEXT[21], initialdir=r'./',
|
||||
filetypes=[(READABLETEXT[114], '.mid .midi'),
|
||||
(READABLETEXT[112], '*')], multiple=True)
|
||||
if midfile is None or midfile == '':
|
||||
log('取消')
|
||||
return
|
||||
else:
|
||||
midfile = midfile[0]
|
||||
th = NewThread(LoadMidi, (midfile,))
|
||||
th.start()
|
||||
del midfile
|
||||
|
||||
def midiSPT(th_):
|
||||
for i in th_.getResult():
|
||||
datas = DMM()
|
||||
datas['notes'] = i
|
||||
dataset[0]['musics'].append(datas)
|
||||
del th_
|
||||
global is_save
|
||||
is_save = False
|
||||
global NowMusic
|
||||
RefreshMain()
|
||||
RefreshMusic(NowMusic)
|
||||
|
||||
threading.Thread(target=midiSPT, args=(th,)).start()
|
||||
del th
|
||||
dataset[0]['mainset']['ReadMethod'] = "new"
|
||||
|
||||
print('读midi命令加载完成!')
|
||||
|
||||
def FromForm():
|
||||
@ -512,6 +632,16 @@ def __main__():
|
||||
else:
|
||||
makeFuncFiles(dataset[0], file + '/')
|
||||
|
||||
def MakeNewCMD():
|
||||
log('生成新文件')
|
||||
from msctspt.funcOpera import makeNewFuncFiles
|
||||
file = tkinter.filedialog.askdirectory(title=READABLETEXT[25], initialdir=r'./')
|
||||
if file is None or file == '':
|
||||
log('取消')
|
||||
return
|
||||
else:
|
||||
makeNewFuncFiles(dataset[0], file + '/')
|
||||
|
||||
def MakeCMDdir():
|
||||
log('生成函数包')
|
||||
from msctspt.funcOpera import makeFunDir
|
||||
@ -522,6 +652,16 @@ def __main__():
|
||||
else:
|
||||
makeFunDir(dataset[0], file + '/')
|
||||
|
||||
def MakeNewCMDdir():
|
||||
log('生成新函数包与材质包')
|
||||
from msctspt.funcOpera import makeNewFunDir
|
||||
file = tkinter.filedialog.askdirectory(title=READABLETEXT[26], initialdir=r'./')
|
||||
if file is None or file == '':
|
||||
log('取消')
|
||||
return
|
||||
else:
|
||||
makeNewFunDir(dataset[0], file + '/')
|
||||
|
||||
def MakePackFile():
|
||||
file = tkinter.filedialog.askdirectory(title=READABLETEXT[27], initialdir=r'./')
|
||||
if file is None or file == '':
|
||||
@ -549,6 +689,63 @@ def __main__():
|
||||
shutil.move('./manifest.json', './temp/')
|
||||
shutil.rmtree('./temp/')
|
||||
|
||||
def MakeNewFunctionPackFile():
|
||||
file = tkinter.filedialog.askdirectory(title=READABLETEXT[27], initialdir=r'./')
|
||||
if file is None or file == '':
|
||||
log('取消')
|
||||
return
|
||||
import zipfile
|
||||
|
||||
from msctspt.funcOpera import makeNewFunDir
|
||||
log('生成附加包文件')
|
||||
if not os.path.exists('./temp/'):
|
||||
os.makedirs('./temp/')
|
||||
makeNewFunDir(dataset[0], './temp/')
|
||||
|
||||
shutil.move('./temp/{}Pack/behavior_packs/{}/functions'.format(dataset[0]['mainset']['PackName'],
|
||||
dataset[0]['mainset']['PackName']), './')
|
||||
|
||||
shutil.move('./temp/{}Pack/behavior_packs/{}/manifest.json'.format(dataset[0]['mainset']['PackName'],
|
||||
dataset[0]['mainset']['PackName']), './')
|
||||
|
||||
with zipfile.ZipFile('{}/{}.mcpack'.format(file, dataset[0]['mainset']['PackName']), 'w') as zipobj:
|
||||
for i in os.listdir('./functions/'):
|
||||
zipobj.write('./functions/{}'.format(i))
|
||||
zipobj.write('./manifest.json')
|
||||
shutil.move('./functions', './temp/')
|
||||
shutil.move('./manifest.json', './temp/')
|
||||
shutil.rmtree('./temp/')
|
||||
|
||||
def MakeNewFunctionPack_ResourcesPacks_File(): # 这个是直接复制资源包(散包)
|
||||
file = tkinter.filedialog.askdirectory(title=READABLETEXT[27], initialdir=r'./')
|
||||
if file is None or file == '':
|
||||
log('取消')
|
||||
return
|
||||
from bgArrayLib.sy_resourcesPacker import scatteredPack
|
||||
scatteredPack(file)
|
||||
import zipfile
|
||||
|
||||
from msctspt.funcOpera import makeNewFunDir
|
||||
log('生成附加包文件')
|
||||
if not os.path.exists('./temp/'):
|
||||
os.makedirs('./temp/')
|
||||
makeNewFunDir(dataset[0], './temp/')
|
||||
|
||||
shutil.move('./temp/{}Pack/behavior_packs/{}/functions'.format(dataset[0]['mainset']['PackName'],
|
||||
dataset[0]['mainset']['PackName']), './')
|
||||
|
||||
shutil.move('./temp/{}Pack/behavior_packs/{}/manifest.json'.format(dataset[0]['mainset']['PackName'],
|
||||
dataset[0]['mainset']['PackName']), './')
|
||||
|
||||
with zipfile.ZipFile('{}/{}.mcpack'.format(file, dataset[0]['mainset']['PackName']), 'w') as zipobj:
|
||||
for i in os.listdir('./functions/'):
|
||||
zipobj.write('./functions/{}'.format(i))
|
||||
zipobj.write('./manifest.json')
|
||||
shutil.move('./functions', './temp/')
|
||||
shutil.move('./manifest.json', './temp/')
|
||||
shutil.rmtree('./temp/')
|
||||
|
||||
|
||||
# 转为空方块世界
|
||||
def ToBlockWorldEpt():
|
||||
import zipfile
|
||||
@ -836,13 +1033,9 @@ def __main__():
|
||||
res = note2bdx(fileName, dire, dataset[0]['musics'][NowMusic]['notes'],
|
||||
dataset[0]['musics'][NowMusic]['set']['ScoreboardName'],
|
||||
dataset[0]['musics'][NowMusic]['set']['Instrument'], dataset[0]['mainset']['PlayerSelect'])
|
||||
|
||||
log('转换结束!\n' + str(res))
|
||||
tkinter.messagebox.showinfo(READABLETEXT[33], READABLETEXT[124].format(str(res)))
|
||||
|
||||
|
||||
|
||||
|
||||
def wsPlay():
|
||||
from msctspt.transfer import note2webs
|
||||
spd = tkinter.simpledialog.askfloat(READABLETEXT[34], prompt=READABLETEXT[125], initialvalue='5.0')
|
||||
@ -944,19 +1137,19 @@ def __main__():
|
||||
from msctspt.transfer import ryStruct
|
||||
rys = ryStruct(outdir)
|
||||
rys.world2Rys(begp, endp, isAir)
|
||||
error1 = True
|
||||
# error1 = True
|
||||
try:
|
||||
with open(fileName, 'w', encoding='utf-8') as f:
|
||||
json.dump(rys.RyStruct, f, sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False)
|
||||
tkinter.messagebox.showinfo(READABLETEXT[33], READABLETEXT[131].format(fileName))
|
||||
error1 = False
|
||||
except FileNotFoundError:
|
||||
tkinter.messagebox.showerror(READABLETEXT[39], READABLETEXT[132].format(fileName, str(rys.RyStruct)))
|
||||
rys.closeLevel()
|
||||
finally:
|
||||
if error1 is True:
|
||||
# error1 = False
|
||||
except:
|
||||
tkinter.messagebox.showerror(READABLETEXT[39], READABLETEXT[132].format(fileName, str(rys.RyStruct)))
|
||||
rys.closeLevel()
|
||||
# finally:
|
||||
# if error1 is True:
|
||||
# tkinter.messagebox.showerror(READABLETEXT[39], READABLETEXT[132].format(fileName, str(rys.RyStruct)))
|
||||
# rys.closeLevel()
|
||||
|
||||
def world2BDX():
|
||||
tkinter.messagebox.showerror(READABLETEXT[0], READABLETEXT[133])
|
||||
@ -1029,6 +1222,7 @@ def __main__():
|
||||
# 刷新主要部分
|
||||
def RefreshMain():
|
||||
LabelPackName['text'] = READABLETEXT[46].format(str(dataset[0]['mainset']['PackName']))
|
||||
# print(LabelPackName)
|
||||
LabelMusicTitle['text'] = READABLETEXT[47].format(str(dataset[0]['mainset']['MusicTitle']))
|
||||
LabelIsRepeat['text'] = READABLETEXT[48].format(str(dataset[0]['mainset']['IsRepeat']))
|
||||
LabelPlayerSelect['text'] = READABLETEXT[49].format(str(dataset[0]['mainset']['PlayerSelect']))
|
||||
@ -1162,6 +1356,12 @@ def __main__():
|
||||
filemenu.add_command(label=READABLETEXT[55], command=SaveProject)
|
||||
filemenu.add_command(label=READABLETEXT[56], command=SaveAsProject)
|
||||
|
||||
filemenu.add_separator()
|
||||
|
||||
filemenu.add_command(label=READABLETEXT[149], command=openNewProject)
|
||||
filemenu.add_command(label=READABLETEXT[150], command=SaveNewProject)
|
||||
filemenu.add_command(label=READABLETEXT[151], command=SaveAsNewProject)
|
||||
|
||||
filemenu.add_separator() # 分隔符
|
||||
|
||||
filemenu.add_command(label=READABLETEXT[57], command=exitapp)
|
||||
@ -1175,6 +1375,8 @@ def __main__():
|
||||
editmenu.add_command(label=READABLETEXT[60], command=FromMidi)
|
||||
editmenu.add_command(label=READABLETEXT[61], command=FromForm)
|
||||
editmenu.add_command(label=READABLETEXT[62], command=FromText)
|
||||
editmenu.add_separator()
|
||||
editmenu.add_command(label=READABLETEXT[148], command=MidiClass)
|
||||
# 将子菜单加入到菜单条中
|
||||
main_menu_bar.add_cascade(label=READABLETEXT[63], menu=editmenu)
|
||||
|
||||
@ -1183,6 +1385,12 @@ def __main__():
|
||||
funcmenu.add_command(label=READABLETEXT[64], command=MakeCMD)
|
||||
funcmenu.add_command(label=READABLETEXT[65], command=MakeCMDdir)
|
||||
funcmenu.add_command(label=READABLETEXT[66], command=MakePackFile)
|
||||
funcmenu.add_separator()
|
||||
funcmenu.add_command(label=READABLETEXT[147], command=MakeNewCMD)
|
||||
funcmenu.add_command(label=READABLETEXT[153], command=MakeNewCMDdir)
|
||||
funcmenu.add_command(label=READABLETEXT[154], command=MakeNewFunctionPackFile)
|
||||
funcmenu.add_command(label=READABLETEXT[155], command=MakeNewFunctionPack_ResourcesPacks_File)
|
||||
|
||||
# 将子菜单加入到菜单条中
|
||||
main_menu_bar.add_cascade(label=READABLETEXT[67], menu=funcmenu)
|
||||
|
||||
@ -1223,6 +1431,7 @@ def __main__():
|
||||
helpmenu = tk.Menu(main_menu_bar, tearoff=0)
|
||||
helpmenu.add_command(label=READABLETEXT[85], command=ClearLog)
|
||||
helpmenu.add_command(label=READABLETEXT[86], command=resetver)
|
||||
helpmenu.add_command(label=READABLETEXT[152], command=end)
|
||||
|
||||
helpmenu.add_separator() # 分隔符
|
||||
|
||||
|
0
bgArrayLib/__init__.py
Normal file
0
bgArrayLib/__init__.py
Normal file
BIN
bgArrayLib/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
bgArrayLib/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
bgArrayLib/__pycache__/bpm.cpython-39.pyc
Normal file
BIN
bgArrayLib/__pycache__/bpm.cpython-39.pyc
Normal file
Binary file not shown.
BIN
bgArrayLib/__pycache__/compute.cpython-39.pyc
Normal file
BIN
bgArrayLib/__pycache__/compute.cpython-39.pyc
Normal file
Binary file not shown.
BIN
bgArrayLib/__pycache__/namesConstant.cpython-39.pyc
Normal file
BIN
bgArrayLib/__pycache__/namesConstant.cpython-39.pyc
Normal file
Binary file not shown.
BIN
bgArrayLib/__pycache__/sy_resourcesPacker.cpython-39.pyc
Normal file
BIN
bgArrayLib/__pycache__/sy_resourcesPacker.cpython-39.pyc
Normal file
Binary file not shown.
57
bgArrayLib/bpm.py
Normal file
57
bgArrayLib/bpm.py
Normal file
@ -0,0 +1,57 @@
|
||||
import mido
|
||||
import numpy
|
||||
|
||||
|
||||
def mt2gt(mt, tpb_a, bpm_a):
|
||||
return round(mt / tpb_a / bpm_a * 60)
|
||||
|
||||
|
||||
def get(mf):
|
||||
mid = mido.MidiFile(mf)
|
||||
long = mid.length
|
||||
tpb = mid.ticks_per_beat
|
||||
bpm = 20
|
||||
gotV = 0
|
||||
|
||||
for track in mid.tracks:
|
||||
global_time = 0
|
||||
for msg in track:
|
||||
global_time += msg.time
|
||||
if msg.type == "note_on" and msg.velocity > 0:
|
||||
gotV = mt2gt(global_time, tpb, bpm)
|
||||
errorV = numpy.fabs(gotV - long)
|
||||
last_dic = {bpm: errorV}
|
||||
if last_dic.get(bpm) > errorV:
|
||||
last_dic = {bpm: errorV}
|
||||
bpm += 2
|
||||
|
||||
while True:
|
||||
for track in mid.tracks:
|
||||
global_time = 0
|
||||
for msg in track:
|
||||
global_time += msg.time
|
||||
if msg.type == "note_on" and msg.velocity > 0:
|
||||
gotV = mt2gt(global_time, tpb, bpm)
|
||||
errorV = numpy.fabs(gotV - long)
|
||||
try:
|
||||
if last_dic.get(bpm - 2) > errorV:
|
||||
last_dic = {bpm: errorV}
|
||||
except TypeError:
|
||||
pass
|
||||
bpm += 2
|
||||
if bpm >= 252:
|
||||
break
|
||||
print(list(last_dic.keys())[0])
|
||||
return list(last_dic.keys())[0]
|
||||
|
||||
|
||||
def compute(mf):
|
||||
mid = mido.MidiFile(mf)
|
||||
answer = 60000000/mid.ticks_per_beat
|
||||
print(answer)
|
||||
return answer
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
get(r"C:\Users\lc\Documents\MuseScore3\乐谱\乐谱\Bad style - Time back.mid")
|
||||
compute(r"C:\Users\lc\Documents\MuseScore3\乐谱\乐谱\Bad style - Time back.mid")
|
40
bgArrayLib/compute.py
Normal file
40
bgArrayLib/compute.py
Normal file
@ -0,0 +1,40 @@
|
||||
def round_up(num, power=0):
|
||||
"""
|
||||
实现精确四舍五入,包含正、负小数多种场景
|
||||
:param num: 需要四舍五入的小数
|
||||
:param power: 四舍五入位数,支持0-∞
|
||||
:return: 返回四舍五入后的结果
|
||||
"""
|
||||
try:
|
||||
print(1 / 0)
|
||||
except ZeroDivisionError:
|
||||
digit = 10 ** power
|
||||
num2 = float(int(num * digit))
|
||||
# 处理正数,power不为0的情况
|
||||
if num >= 0 and power != 0:
|
||||
tag = num * digit - num2 + 1 / (digit * 10)
|
||||
if tag >= 0.5:
|
||||
return (num2 + 1) / digit
|
||||
else:
|
||||
return num2 / digit
|
||||
# 处理正数,power为0取整的情况
|
||||
elif num >= 0 and power == 0:
|
||||
tag = num * digit - int(num)
|
||||
if tag >= 0.5:
|
||||
return (num2 + 1) / digit
|
||||
else:
|
||||
return num2 / digit
|
||||
# 处理负数,power为0取整的情况
|
||||
elif power == 0 and num < 0:
|
||||
tag = num * digit - int(num)
|
||||
if tag <= -0.5:
|
||||
return (num2 - 1) / digit
|
||||
else:
|
||||
return num2 / digit
|
||||
# 处理负数,power不为0的情况
|
||||
else:
|
||||
tag = num * digit - num2 - 1 / (digit * 10)
|
||||
if tag <= -0.5:
|
||||
return (num2 - 1) / digit
|
||||
else:
|
||||
return num2 / digit
|
92
bgArrayLib/namesConstant.py
Normal file
92
bgArrayLib/namesConstant.py
Normal file
@ -0,0 +1,92 @@
|
||||
zip_name = {-1: '-1.Acoustic_Kit_打击乐.zip', 0: '0.Acoustic_Grand_Piano_大钢琴.zip', 1: '1.Bright_Acoustic_Piano_亮音大钢琴.zip',
|
||||
10: '10.Music_Box_八音盒.zip', 100: '100.FX_brightness_合成特效-亮音.zip', 101: '101.FX_goblins_合成特效-小妖.zip',
|
||||
102: '102.FX_echoes_合成特效-回声.zip', 103: '103.FX_sci-fi_合成特效-科幻.zip', 104: '104.Sitar_锡塔尔.zip',
|
||||
105: '105.Banjo_班卓.zip', 106: '106.Shamisen_三味线.zip', 107: '107.Koto_筝.zip', 108: '108.Kalimba_卡林巴.zip',
|
||||
109: '109.Bagpipe_风笛.zip', 11: '11.Vibraphone_电颤琴.zip', 110: '110.Fiddle_古提琴.zip', 111: '111.Shanai_唢呐.zip',
|
||||
112: '112.Tinkle_Bell_铃铛.zip', 113: '113.Agogo_拉丁打铃.zip', 114: '114.Steel_Drums_钢鼓.zip',
|
||||
115: '115.Woodblock_木块.zip', 116: '116.Taiko_Drum_太鼓.zip', 117: '117.Melodic_Tom_嗵鼓.zip',
|
||||
118: '118.Synth_Drum_合成鼓.zip', 119: '119.Reverse_Cymbal_镲波形反转.zip', 12: '12.Marimba_马林巴.zip',
|
||||
13: '13.Xylophone_木琴.zip', 14: '14.Tubular_Bells_管钟.zip', 15: '15.Dulcimer_扬琴.zip',
|
||||
16: '16.Drawbar_Organ_击杆风琴.zip', 17: '17.Percussive_Organ_打击型风琴.zip', 18: '18.Rock_Organ_摇滚风琴.zip',
|
||||
19: '19.Church_Organ_管风琴.zip', 2: '2.Electric_Grand_Piano_电子大钢琴.zip', 20: '20.Reed_Organ_簧风琴.zip',
|
||||
21: '21.Accordion_手风琴.zip', 22: '22.Harmonica_口琴.zip', 23: '23.Tango_Accordian_探戈手风琴.zip',
|
||||
24: '24.Acoustic_Guitar_(nylon)_尼龙弦吉他.zip', 25: '25.Acoustic_Guitar(steel)_钢弦吉他.zip',
|
||||
26: '26.Electric_Guitar_(jazz)_爵士乐电吉他.zip', 27: '27.Electric_Guitar_(clean)_清音电吉他.zip',
|
||||
28: '28.Electric_Guitar_(muted)_弱音电吉他.zip', 29: '29.Overdriven_Guitar_驱动音效吉他.zip',
|
||||
3: '3.Honky-Tonk_Piano_酒吧钢琴.zip', 30: '30.Distortion_Guitar_失真音效吉他.zip', 31: '31.Guitar_Harmonics_吉他泛音.zip',
|
||||
32: '32.Acoustic_Bass_原声贝司.zip', 33: '33.Electric_Bass(finger)_指拨电贝司.zip',
|
||||
34: '34.Electric_Bass(pick)_拨片拨电贝司.zip', 35: '35.Fretless_Bass_无品贝司.zip', 36: '36.Slap_Bass_A_击弦贝司A.zip',
|
||||
37: '37.Slap_Bass_B_击弦贝司B.zip', 38: '38.Synth_Bass_A_合成贝司A.zip', 39: '39.Synth_Bass_B_合成贝司B.zip',
|
||||
4: '4.Electric_Piano_1_电钢琴A.zip', 40: '40.Violin_小提琴.zip', 41: '41.Viola_中提琴.zip', 42: '42.Cello_大提琴.zip',
|
||||
43: '43.Contrabass_低音提琴.zip', 44: '44.Tremolo_Strings_弦乐震音.zip', 45: '45.Pizzicato_Strings_弦乐拨奏.zip',
|
||||
46: '46.Orchestral_Harp_竖琴.zip', 47: '47.Timpani_定音鼓.zip', 48: '48.String_Ensemble_A_弦乐合奏A.zip',
|
||||
49: '49.String_Ensemble_B_弦乐合奏B.zip', 5: '5.Electric_Piano_2_电钢琴B.zip', 50: '50.SynthStrings_A_合成弦乐A.zip',
|
||||
51: '51.SynthStrings_B_合成弦乐B.zip', 52: '52.Choir_Aahs_合唱“啊”音.zip', 53: '53.Voice_Oohs_人声“哦”音.zip',
|
||||
54: '54.Synth_Voice_合成人声.zip', 55: '55.Orchestra_Hit_乐队打击乐.zip', 56: '56.Trumpet_小号.zip',
|
||||
57: '57.Trombone_长号.zip', 58: '58.Tuba_大号.zip', 59: '59.Muted_Trumpet_弱音小号.zip',
|
||||
6: '6.Harpsichord_拨弦古钢琴.zip', 60: '60.French_Horn_圆号.zip', 61: '61.Brass_Section_铜管组.zip',
|
||||
62: '62.Synth_Brass_A_合成铜管A.zip', 63: '63.Synth_Brass_A_合成铜管B.zip', 64: '64.Soprano_Sax_高音萨克斯.zip',
|
||||
65: '65.Alto_Sax_中音萨克斯.zip', 66: '66.Tenor_Sax_次中音萨克斯.zip', 67: '67.Baritone_Sax_上低音萨克斯.zip',
|
||||
68: '68.Oboe_双簧管.zip', 69: '69.English_Horn_英国管.zip', 7: '7.Clavinet_击弦古钢琴.zip', 70: '70.Bassoon_大管.zip',
|
||||
71: '71.Clarinet_单簧管.zip', 72: '72.Piccolo_短笛.zip', 73: '73.Flute_长笛.zip', 74: '74.Recorder_竖笛.zip',
|
||||
75: '75.Pan_Flute_排笛.zip', 76: '76.Bottle_Blow_吹瓶口.zip', 77: '77.Skakuhachi_尺八.zip', 78: '78.Whistle_哨.zip',
|
||||
79: '79.Ocarina_洋埙.zip', 8: '8.Celesta_钢片琴.zip', 80: '80.Lead_square_合成主音-方波.zip',
|
||||
81: '81.Lead_sawtooth_合成主音-锯齿波.zip', 82: '82.Lead_calliope_lead_合成主音-汽笛风琴.zip',
|
||||
83: '83.Lead_chiff_lead_合成主音-吹管.zip', 84: '84.Lead_charang_合成主音5-吉他.zip', 85: '85.Lead_voice_合成主音-人声.zip',
|
||||
86: '86.Lead_fifths_合成主音-五度.zip', 87: '87.Lead_bass+lead_合成主音-低音加主音.zip', 88: '88.Pad_new_age_合成柔音-新时代.zip',
|
||||
89: '89.Pad_warm_合成柔音-暖音.zip', 9: '9.Glockenspiel_钟琴.zip', 90: '90.Pad_polysynth_合成柔音-复合成.zip',
|
||||
91: '91.Pad_choir_合成柔音-合唱.zip', 92: '92.Pad_bowed_合成柔音-弓弦.zip', 93: '93.Pad_metallic_合成柔音-金属.zip',
|
||||
94: '94.Pad_halo_合成柔音-光环.zip', 95: '95.Pad_sweep_合成柔音-扫弦.zip', 96: '96.FX_rain_合成特效-雨.zip',
|
||||
97: '97.FX_soundtrack_合成特效-音轨.zip', 98: '98.FX_crystal_合成特效-水晶.zip', 99: '99.FX_atmosphere_合成特效-大气.zip'}
|
||||
|
||||
mcpack_name = {-1: '-1.Acoustic_Kit_打击乐.mcpack', 0: '0.Acoustic_Grand_Piano_大钢琴.mcpack',
|
||||
1: '1.Bright_Acoustic_Piano_亮音大钢琴.mcpack', 10: '10.Music_Box_八音盒.mcpack',
|
||||
100: '100.FX_brightness_合成特效-亮音.mcpack', 101: '101.FX_goblins_合成特效-小妖.mcpack',
|
||||
102: '102.FX_echoes_合成特效-回声.mcpack', 103: '103.FX_sci-fi_合成特效-科幻.mcpack', 104: '104.Sitar_锡塔尔.mcpack',
|
||||
105: '105.Banjo_班卓.mcpack', 106: '106.Shamisen_三味线.mcpack', 107: '107.Koto_筝.mcpack',
|
||||
108: '108.Kalimba_卡林巴.mcpack', 109: '109.Bagpipe_风笛.mcpack', 11: '11.Vibraphone_电颤琴.mcpack',
|
||||
110: '110.Fiddle_古提琴.mcpack', 111: '111.Shanai_唢呐.mcpack', 112: '112.Tinkle_Bell_铃铛.mcpack',
|
||||
113: '113.Agogo_拉丁打铃.mcpack', 114: '114.Steel_Drums_钢鼓.mcpack', 115: '115.Woodblock_木块.mcpack',
|
||||
116: '116.Taiko_Drum_太鼓.mcpack', 117: '117.Melodic_Tom_嗵鼓.mcpack', 118: '118.Synth_Drum_合成鼓.mcpack',
|
||||
119: '119.Reverse_Cymbal_镲波形反转.mcpack', 12: '12.Marimba_马林巴.mcpack', 13: '13.Xylophone_木琴.mcpack',
|
||||
14: '14.Tubular_Bells_管钟.mcpack', 15: '15.Dulcimer_扬琴.mcpack', 16: '16.Drawbar_Organ_击杆风琴.mcpack',
|
||||
17: '17.Percussive_Organ_打击型风琴.mcpack', 18: '18.Rock_Organ_摇滚风琴.mcpack',
|
||||
19: '19.Church_Organ_管风琴.mcpack', 2: '2.Electric_Grand_Piano_电子大钢琴.mcpack',
|
||||
20: '20.Reed_Organ_簧风琴.mcpack', 21: '21.Accordion_手风琴.mcpack', 22: '22.Harmonica_口琴.mcpack',
|
||||
23: '23.Tango_Accordian_探戈手风琴.mcpack', 24: '24.Acoustic_Guitar_(nylon)_尼龙弦吉他.mcpack',
|
||||
25: '25.Acoustic_Guitar(steel)_钢弦吉他.mcpack', 26: '26.Electric_Guitar_(jazz)_爵士乐电吉他.mcpack',
|
||||
27: '27.Electric_Guitar_(clean)_清音电吉他.mcpack', 28: '28.Electric_Guitar_(muted)_弱音电吉他.mcpack',
|
||||
29: '29.Overdriven_Guitar_驱动音效吉他.mcpack', 3: '3.Honky-Tonk_Piano_酒吧钢琴.mcpack',
|
||||
30: '30.Distortion_Guitar_失真音效吉他.mcpack', 31: '31.Guitar_Harmonics_吉他泛音.mcpack',
|
||||
32: '32.Acoustic_Bass_原声贝司.mcpack', 33: '33.Electric_Bass(finger)_指拨电贝司.mcpack',
|
||||
34: '34.Electric_Bass(pick)_拨片拨电贝司.mcpack', 35: '35.Fretless_Bass_无品贝司.mcpack',
|
||||
36: '36.Slap_Bass_A_击弦贝司A.mcpack', 37: '37.Slap_Bass_B_击弦贝司B.mcpack', 38: '38.Synth_Bass_A_合成贝司A.mcpack',
|
||||
39: '39.Synth_Bass_B_合成贝司B.mcpack', 4: '4.Electric_Piano_1_电钢琴A.mcpack', 40: '40.Violin_小提琴.mcpack',
|
||||
41: '41.Viola_中提琴.mcpack', 42: '42.Cello_大提琴.mcpack', 43: '43.Contrabass_低音提琴.mcpack',
|
||||
44: '44.Tremolo_Strings_弦乐震音.mcpack', 45: '45.Pizzicato_Strings_弦乐拨奏.mcpack',
|
||||
46: '46.Orchestral_Harp_竖琴.mcpack', 47: '47.Timpani_定音鼓.mcpack', 48: '48.String_Ensemble_A_弦乐合奏A.mcpack',
|
||||
49: '49.String_Ensemble_B_弦乐合奏B.mcpack', 5: '5.Electric_Piano_2_电钢琴B.mcpack',
|
||||
50: '50.SynthStrings_A_合成弦乐A.mcpack', 51: '51.SynthStrings_B_合成弦乐B.mcpack',
|
||||
52: '52.Choir_Aahs_合唱“啊”音.mcpack', 53: '53.Voice_Oohs_人声“哦”音.mcpack', 54: '54.Synth_Voice_合成人声.mcpack',
|
||||
55: '55.Orchestra_Hit_乐队打击乐.mcpack', 56: '56.Trumpet_小号.mcpack', 57: '57.Trombone_长号.mcpack',
|
||||
58: '58.Tuba_大号.mcpack', 59: '59.Muted_Trumpet_弱音小号.mcpack', 6: '6.Harpsichord_拨弦古钢琴.mcpack',
|
||||
60: '60.French_Horn_圆号.mcpack', 61: '61.Brass_Section_铜管组.mcpack', 62: '62.Synth_Brass_A_合成铜管A.mcpack',
|
||||
63: '63.Synth_Brass_A_合成铜管B.mcpack', 64: '64.Soprano_Sax_高音萨克斯.mcpack', 65: '65.Alto_Sax_中音萨克斯.mcpack',
|
||||
66: '66.Tenor_Sax_次中音萨克斯.mcpack', 67: '67.Baritone_Sax_上低音萨克斯.mcpack', 68: '68.Oboe_双簧管.mcpack',
|
||||
69: '69.English_Horn_英国管.mcpack', 7: '7.Clavinet_击弦古钢琴.mcpack', 70: '70.Bassoon_大管.mcpack',
|
||||
71: '71.Clarinet_单簧管.mcpack', 72: '72.Piccolo_短笛.mcpack', 73: '73.Flute_长笛.mcpack',
|
||||
74: '74.Recorder_竖笛.mcpack', 75: '75.Pan_Flute_排笛.mcpack', 76: '76.Bottle_Blow_吹瓶口.mcpack',
|
||||
77: '77.Skakuhachi_尺八.mcpack', 78: '78.Whistle_哨.mcpack', 79: '79.Ocarina_洋埙.mcpack',
|
||||
8: '8.Celesta_钢片琴.mcpack', 80: '80.Lead_square_合成主音-方波.mcpack', 81: '81.Lead_sawtooth_合成主音-锯齿波.mcpack',
|
||||
82: '82.Lead_calliope_lead_合成主音-汽笛风琴.mcpack', 83: '83.Lead_chiff_lead_合成主音-吹管.mcpack',
|
||||
84: '84.Lead_charang_合成主音5-吉他.mcpack', 85: '85.Lead_voice_合成主音-人声.mcpack',
|
||||
86: '86.Lead_fifths_合成主音-五度.mcpack', 87: '87.Lead_bass+lead_合成主音-低音加主音.mcpack',
|
||||
88: '88.Pad_new_age_合成柔音-新时代.mcpack', 89: '89.Pad_warm_合成柔音-暖音.mcpack', 9: '9.Glockenspiel_钟琴.mcpack',
|
||||
90: '90.Pad_polysynth_合成柔音-复合成.mcpack', 91: '91.Pad_choir_合成柔音-合唱.mcpack',
|
||||
92: '92.Pad_bowed_合成柔音-弓弦.mcpack', 93: '93.Pad_metallic_合成柔音-金属.mcpack',
|
||||
94: '94.Pad_halo_合成柔音-光环.mcpack', 95: '95.Pad_sweep_合成柔音-扫弦.mcpack', 96: '96.FX_rain_合成特效-雨.mcpack',
|
||||
97: '97.FX_soundtrack_合成特效-音轨.mcpack', 98: '98.FX_crystal_合成特效-水晶.mcpack',
|
||||
99: '99.FX_atmosphere_合成特效-大气.mcpack'}
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(zip_name[0])
|
130
bgArrayLib/sy_resourcesPacker.py
Normal file
130
bgArrayLib/sy_resourcesPacker.py
Normal file
@ -0,0 +1,130 @@
|
||||
import os
|
||||
import pickle
|
||||
# import tkinter.filedialog
|
||||
# from namesConstant import zip_name
|
||||
# from namesConstant import mcpack_name
|
||||
import bgArrayLib.namesConstant
|
||||
import shutil
|
||||
zipN = bgArrayLib.namesConstant.zip_name
|
||||
mpN = bgArrayLib.namesConstant.mcpack_name
|
||||
|
||||
manifest = {
|
||||
"format_version": 1,
|
||||
"header": {
|
||||
"name": "羽音缭绕-midiout_25.5--音创使用",
|
||||
"description": "羽音缭绕-midiout_25.0--音创使用",
|
||||
"uuid": "c1adbda4-3b3e-4e5b-a57e-cde8ac80ee19",
|
||||
"version": [25, 5, 0]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"description": "羽音缭绕-midiout_25.0--音创使用",
|
||||
"type": "resources",
|
||||
"uuid": "c13455d5-b9f3-47f2-9706-c05ad86b3180 ",
|
||||
"version": [25, 5, 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def resources_pathSetting(newPath: str = ""):
|
||||
if not os.path.isfile("./bgArrayLib/resourcesPath.rpposi") and newPath == "":
|
||||
return [False, 1] # 1:没有路径文件
|
||||
elif not os.path.isfile("./bgArrayLib/resourcesPath.rpposi") and newPath != "":
|
||||
path = newPath
|
||||
with open("./bgArrayLib/resourcesPath.rpposi", 'w') as w:
|
||||
path = w.write(path)
|
||||
if "mcpack(国际版推荐)格式_25.0" in os.listdir(path) and "zip格式_25.0" in os.listdir(path):
|
||||
return [True, path, 1] # 1:都有
|
||||
elif "mcpack(国际版推荐)格式_25.0" in os.listdir(path) and "zip格式_25.0" not in os.listdir(path):
|
||||
return [True, path, 2] # 2:有pack
|
||||
elif "mcpack(国际版推荐)格式_25.0" not in os.listdir(path) and "zip格式_25.0" in os.listdir(path):
|
||||
return [True, path, 3] # 3:有zip
|
||||
else:
|
||||
return [False, 2] # 2:路径文件指示错误
|
||||
if os.path.isfile("./bgArrayLib/resourcesPath.rpposi"):
|
||||
with open("./bgArrayLib/resourcesPath.rpposi", 'r') as f:
|
||||
path = f.read()
|
||||
if "mcpack(国际版推荐)格式_25.0" in os.listdir(path) and "zip格式_25.0" in os.listdir(path):
|
||||
return [True, path, 1] # 1:都有
|
||||
elif "mcpack(国际版推荐)格式_25.0" in os.listdir(path) and "zip格式_25.0" not in os.listdir(path):
|
||||
return [True, path, 2] # 2:有pack
|
||||
elif "mcpack(国际版推荐)格式_25.0" not in os.listdir(path) and "zip格式_25.0" in os.listdir(path):
|
||||
return [True, path, 3] # 3:有zip
|
||||
else:
|
||||
return [False, 2] # 2:路径文件指示错误
|
||||
|
||||
|
||||
def choose_resources():
|
||||
global zipN
|
||||
global mpN
|
||||
back_list = []
|
||||
try:
|
||||
with open(r"L:\0WorldMusicCreater-MFMS new edition\框架\v0.3.2\Musicreater\1.pkl", 'rb') as rb:
|
||||
instrument = list(pickle.load(rb))
|
||||
print(instrument)
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
with open(r"L:\0WorldMusicCreater-MFMS new edition\框架\v0.3.2\Musicreater\nmcsup\1.pkl", 'rb') as rb:
|
||||
instrument = list(pickle.load(rb))
|
||||
print(instrument)
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
path = resources_pathSetting()
|
||||
if path.__len__() == 2:
|
||||
return path
|
||||
else:
|
||||
dataT = path[2]
|
||||
pathT = path[1]
|
||||
if dataT == 1:
|
||||
if instrument[1] is True:
|
||||
index = zipN.get(-1)
|
||||
percussion_instrument = str(pathT) + "\\zip格式_25.0\\" + index
|
||||
# print(percussion_instrument)
|
||||
back_list.append(percussion_instrument)
|
||||
for i in instrument[0]:
|
||||
ins_p = str(pathT) + "\\zip格式_25.0\\" + str(zipN.get(i))
|
||||
# print(ins_p)
|
||||
back_list.append(ins_p)
|
||||
print(back_list)
|
||||
return back_list
|
||||
elif dataT == 2:
|
||||
if instrument[1] is True:
|
||||
index = mpN.get(-1)
|
||||
percussion_instrument = str(pathT) + "\\mcpack(国际版推荐)格式_25.0\\" + index
|
||||
# print(percussion_instrument)
|
||||
back_list.append(percussion_instrument)
|
||||
for i in instrument[0]:
|
||||
ins_p = str(pathT) + "\\mcpack(国际版推荐)格式_25.0\\" + str(mpN.get(i))
|
||||
# print(ins_p)
|
||||
back_list.append(ins_p)
|
||||
print(back_list)
|
||||
return back_list
|
||||
elif dataT == 3:
|
||||
if instrument[1] is True:
|
||||
index = zipN.get(-1)
|
||||
percussion_instrument = str(pathT) + "\\zip格式_25.0\\" + index
|
||||
# print(percussion_instrument)
|
||||
back_list.append(percussion_instrument)
|
||||
for i in instrument[0]:
|
||||
ins_p = str(pathT) + "\\zip格式_25.0\\" + str(zipN.get(i))
|
||||
# print(ins_p)
|
||||
back_list.append(ins_p)
|
||||
print(back_list)
|
||||
return back_list
|
||||
|
||||
|
||||
def scatteredPack(path):
|
||||
pack_list = choose_resources()
|
||||
print(pack_list)
|
||||
print(path)
|
||||
# os.close("L:/0WorldMusicCreater-MFMS new edition")
|
||||
# shutil.copy("L:\\shenyu\\音源的资源包\\羽音缭绕-midiout_25.0\\mcpack(国际版推荐)格式_25.0\\0.Acoustic_Grand_Piano_大钢琴.mcpack",
|
||||
# "L:/0WorldMusicCreater-MFMS new edition")
|
||||
for i in pack_list:
|
||||
shutil.copy(i, path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# print(resources_pathSetting(r"L:\shenyu\音源的资源包\羽音缭绕-midiout_25.0"))
|
||||
choose_resources()
|
@ -158,5 +158,15 @@ READABLETEXT = {
|
||||
144: "修改本音轨所用乐器",
|
||||
145: "您输入的乐器并非游戏内置乐器,是否继续用您输入的字符作为乐器?",
|
||||
146: "修改本音轨生成的文件名",
|
||||
# -----2022.1.25更新
|
||||
147: "生成新文件至...",
|
||||
148: "从midi导入音轨且用新方法解析",
|
||||
149: "打开 新: 音·创项目...",
|
||||
150: "保存为新项目",
|
||||
151: "另存为新项...",
|
||||
152: "(开发调试)关闭本次日志记录",
|
||||
153: "生成新函数包至...",
|
||||
154: "生成新函数附加包文件至...",
|
||||
155: "生成新函数附加包文件,并将神羽资源包以散包形式放置至...",
|
||||
|
||||
}
|
||||
|
BIN
msctspt/__init__.pyc
Normal file
BIN
msctspt/__init__.pyc
Normal file
Binary file not shown.
@ -11,7 +11,6 @@ def delPart(Data, starter, ender, includeStart: bool = True, includend: bool = T
|
||||
"""删除序列从starter物件到ender物件之间的部分\n
|
||||
includeStart与inclodend分别控制此函数是否包括starter和ender物件所在部分,默认为真\n
|
||||
starter与ender若为None则默认从首或尾开始"""
|
||||
e = True
|
||||
try:
|
||||
if starter is None:
|
||||
includeStart = True
|
||||
@ -21,22 +20,15 @@ def delPart(Data, starter, ender, includeStart: bool = True, includend: bool = T
|
||||
ender = Data[len(Data) - 1]
|
||||
if includend:
|
||||
if includeStart:
|
||||
e = False
|
||||
return Data[Data.index(starter):len(Data) - Data[len(Data)::-1].index(ender)]
|
||||
else:
|
||||
e = False
|
||||
return Data[Data.index(starter) + 1:len(Data) - Data[len(Data)::-1].index(ender)]
|
||||
else:
|
||||
if includeStart:
|
||||
e = False
|
||||
return Data[Data.index(starter):len(Data) - Data[len(Data)::-1].index(ender) - 1]
|
||||
else:
|
||||
e = False
|
||||
return Data[Data.index(starter) + 1:len(Data) - Data[len(Data)::-1].index(ender) - 1]
|
||||
except ValueError:
|
||||
return 0
|
||||
finally:
|
||||
if e is True:
|
||||
except:
|
||||
return 0
|
||||
|
||||
|
||||
@ -44,7 +36,6 @@ def keepart(Data, starter, ender, includeStart: bool = True, includend: bool = T
|
||||
"""保留序列从starter物件到ender物件之间的部分\n
|
||||
includeStart与inclodend分别控制此函数是否包括starter和ender物件所在部分,默认为真\n
|
||||
starter与ender若为None则默认从首或尾开始"""
|
||||
e = True
|
||||
try:
|
||||
if starter is None:
|
||||
includeStart = True
|
||||
@ -54,39 +45,27 @@ def keepart(Data, starter, ender, includeStart: bool = True, includend: bool = T
|
||||
ender = Data[len(Data) - 1]
|
||||
if includend:
|
||||
if includeStart:
|
||||
e = False
|
||||
return Data[Data.index(starter):Data.index(ender) + 1]
|
||||
else:
|
||||
e = False
|
||||
return Data[Data.index(starter) + 1:Data.index(ender) + 1]
|
||||
else:
|
||||
if includeStart:
|
||||
e = False
|
||||
return Data[Data.index(starter):Data.index(ender)]
|
||||
else:
|
||||
e = False
|
||||
return Data[Data.index(starter) + 1:Data.index(ender)]
|
||||
except ValueError:
|
||||
return 0
|
||||
finally:
|
||||
if e is True:
|
||||
except:
|
||||
return 0
|
||||
|
||||
|
||||
def lenFunction(fun) -> int:
|
||||
"""取得函数指令部分长度,即忽略#开头的注释"""
|
||||
e = True
|
||||
try:
|
||||
f = 0
|
||||
for i in fun:
|
||||
if i.replace(" ", '')[0] == '#':
|
||||
f += 1
|
||||
e = False
|
||||
return len(fun) - f
|
||||
except IndexError:
|
||||
return -1
|
||||
finally:
|
||||
if e is True:
|
||||
except:
|
||||
return -1
|
||||
|
||||
|
||||
@ -159,6 +138,94 @@ def makeFuncFiles(musicset, path='./'):
|
||||
log("完成============================")
|
||||
|
||||
|
||||
def makeNewFuncFiles(musicset, path='./'):
|
||||
"""在指定目录下生成函数文件"""
|
||||
from nmcsup.trans import classList_conversion
|
||||
commands = []
|
||||
starts = []
|
||||
starts.__len__()
|
||||
starts.append("scoreboard objectives add " + musicset['musics'][0]['set']['ScoreboardName'] + " dummy\n")
|
||||
starts.append("summon armor_stand " + musicset['musics'][0]['set']['EntityName'] + '\n')
|
||||
starts.append("scoreboard objectives setdisplay sidebar " + musicset['musics'][0]['set']['ScoreboardName'] + '\n')
|
||||
starts.append("scoreboard players set @e[type=armor_stand, name=\"" + musicset['musics'][0]['set']['EntityName'] +
|
||||
"\"] " + musicset['musics'][0]['set']['ScoreboardName'] + " 0" + '\n')
|
||||
log("=========================正在在此处生成文件:" + path)
|
||||
commands.append("scoreboard players add @e[name=\"" + musicset['musics'][0]['set']['EntityName'] + "\"] " +
|
||||
musicset['musics'][0]['set']['ScoreboardName'] + " 1\n")
|
||||
maxlen = -1
|
||||
for i in range(len(musicset['musics'])):
|
||||
log('写入第' + str(i) + '个数据')
|
||||
# commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
|
||||
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset'][
|
||||
# 'PlayerSelect'] + " title " + musicset['mainset']['MusicTitle'] + "\n")
|
||||
# commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
|
||||
# musicset['musics'][i]['set']['ScoreboardName'] + "=1..10}] ~~~ title @a" + musicset['mainset'][
|
||||
# 'PlayerSelect'] + " subtitle 本函数乐曲由§b§l凌云§r§3函数音乐创建§r生成\n")
|
||||
if len(musicset['musics'][i]['notes']) > maxlen:
|
||||
maxlen = len(musicset['musics'][i]['notes'])
|
||||
with open(path + musicset['mainset']['MusicTitle'] + '_Part' + str(i) + '.mcfunction', 'w',
|
||||
encoding='UTF-8') as f:
|
||||
f.writelines(classList_conversion(musicset['musics'][i]['notes'],
|
||||
musicset['musics'][i]['set']['ScoreboardName']))
|
||||
if musicset['mainset']['IsRepeat']:
|
||||
log("增加重复语句")
|
||||
for i in range(len(musicset['musics'])):
|
||||
commands.append("execute @e[name=\"" + musicset['musics'][i]['set']['EntityName'] + "\",scores={" +
|
||||
musicset['musics'][i]['set']['ScoreboardName'] + "=" + str(
|
||||
(maxlen + 2) * 10) + "}] ~~~ scoreboard players set @e[name=\"" + musicset['musics'][i]['set'][
|
||||
'EntityName'] + "\"] " + musicset['musics'][i]['set']['ScoreboardName'] + " -1\n")
|
||||
log("增加版权语句")
|
||||
commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI(金羿),bgArray(诸葛亮与八卦阵)\n")
|
||||
starts.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI(金羿),bgArray(诸葛亮与八卦阵)\n")
|
||||
log("写入支持文件")
|
||||
with open(path + musicset['mainset']['MusicTitle'] + '_Support.mcfunction', 'w', encoding='UTF-8') as f:
|
||||
f.writelines(commands)
|
||||
log("写入开始文件")
|
||||
with open(path + 'Start_' + musicset['mainset']['MusicTitle'] + '.mcfunction', 'w', encoding='UTF-8') as f:
|
||||
f.writelines(starts)
|
||||
del commands, starts, maxlen
|
||||
log("完成============================")
|
||||
|
||||
|
||||
def makeNewFunDir(musicset, path='./'):
|
||||
"""在指定目录下生成函数包文件夹"""
|
||||
import os
|
||||
import uuid
|
||||
log("=============================生成函数包文件夹")
|
||||
# note,packname="Ryoun",FileName="Music",EntityName_='music_support',ScoreboardName_='music_support',
|
||||
# MusicTitle_='Noname',PlayerSelect_='',Repeat_=False,Instrument_='harp'
|
||||
try:
|
||||
os.makedirs(path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
|
||||
'PackName'] + "/functions")
|
||||
log("已创建目录" + path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
|
||||
'PackName'] + "/functions")
|
||||
except FileExistsError:
|
||||
log("目录已有无需创建")
|
||||
pass
|
||||
# 判断文件皆存在
|
||||
if not (os.path.exists(
|
||||
path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json") and os.path.exists(
|
||||
path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
|
||||
'PackName'] + "/manifest.json")):
|
||||
log("创建manifest.json以及world_behavior_packs.json")
|
||||
behaviorUuid = uuid.uuid4()
|
||||
with open(path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json", "w") as f:
|
||||
f.write("[\n {\"pack_id\": \"" + str(behaviorUuid) + "\",\n \"version\": [ 0, 0, 1 ]}\n]")
|
||||
p = path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset']['PackName'] + \
|
||||
"/manifest.json"
|
||||
with open(p, "w") as f:
|
||||
f.write("{\n \"format_version\": 1,\n \"header\": {\n \"description\": \"" + musicset['mainset'][
|
||||
'PackName'] + " Pack : behavior pack\",\n \"version\": [ 0, 0, 1 ],\n \"name\": \"" +
|
||||
musicset['mainset']['PackName'] + "Pack\",\n \"uuid\": \"" + str(
|
||||
behaviorUuid) + "\"\n },\n \"modules\": [\n {\n \"description\": \"" + musicset['mainset'][
|
||||
'PackName'] + " Pack : behavior pack\",\n \"type\": \"data\",\n \"version\":"
|
||||
" [ 0, 0, 1 ],\n \"uuid\": \"" + str(
|
||||
uuid.uuid4()) + "\"\n }\n ]\n}")
|
||||
makeNewFuncFiles(musicset, path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
|
||||
'PackName'] + "/functions/")
|
||||
log("完成============================")
|
||||
|
||||
|
||||
def makeFunDir(musicset, path='./'):
|
||||
"""在指定目录下生成函数包文件夹"""
|
||||
import os
|
||||
@ -179,6 +246,7 @@ def makeFunDir(musicset, path='./'):
|
||||
path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json") and os.path.exists(
|
||||
path + musicset['mainset']['PackName'] + "Pack/behavior_packs/" + musicset['mainset'][
|
||||
'PackName'] + "/manifest.json")):
|
||||
|
||||
log("创建manifest.json以及world_behavior_packs.json")
|
||||
behaviorUuid = uuid.uuid4()
|
||||
with open(path + musicset['mainset']['PackName'] + "Pack/world_behavior_packs.json", "w") as f:
|
||||
|
@ -87,22 +87,22 @@ def note2bdx(filePath: str, dire: list, Notes: list, ScoreboardName: str, Instru
|
||||
height: 生成结构的最高高度
|
||||
:return 返回一个BdxConverter类(实际上没研究过),同时在指定位置生成.bdx文件"""
|
||||
|
||||
from msctspt.transfer import formCmdBlock
|
||||
# from msctspt.transfer import formCmdBlock
|
||||
from nmcsup.trans import Note2Cmd
|
||||
from msctspt.bdxOpera_CP import BdxConverter
|
||||
cmd = Note2Cmd(Notes, ScoreboardName, Instrument, PlayerSelect, isProsess)
|
||||
cdl = []
|
||||
for i in cmd:
|
||||
e = True
|
||||
# e = True
|
||||
try:
|
||||
if (i[:i.index('#')].replace(' ', '') != '\n') and (i[:i.index('#')].replace(' ', '') != ''):
|
||||
cdl.append(i[:i.index('#')])
|
||||
e = False
|
||||
except ValueError:
|
||||
cdl.append(i)
|
||||
finally:
|
||||
if e is True:
|
||||
# e = False
|
||||
except: # ValueError
|
||||
cdl.append(i)
|
||||
# finally:
|
||||
# if e is True:
|
||||
# cdl.append(i)
|
||||
i = 0
|
||||
down = False
|
||||
blocks = [formCmdBlock(dire, cdl.pop(0), 1, 1)]
|
||||
@ -137,7 +137,7 @@ def note2webs(Notes: list, Instrument: str, speed: float = 5.0, PlayerSelect: st
|
||||
|
||||
import time
|
||||
import fcwslib
|
||||
import asyncio
|
||||
# import asyncio
|
||||
from nmcsup.log import log
|
||||
from nmcsup.vers import VER
|
||||
|
||||
@ -146,15 +146,14 @@ def note2webs(Notes: list, Instrument: str, speed: float = 5.0, PlayerSelect: st
|
||||
await fcwslib.tellraw(websocket, '已连接服务器——音·创' + VER[1] + VER[0] + ' 作者:金羿(W-YI)')
|
||||
length = len(Notes)
|
||||
j = 1
|
||||
if isProsess:
|
||||
length = len(Notes)
|
||||
j = 1
|
||||
for i in range(len(Notes)):
|
||||
await fcwslib.send_command(websocket,
|
||||
f'execute @a{PlayerSelect} ~ ~ ~ playsound {Instrument} @s ~ ~ ~ 1000 {Notes[i][0]} 1000')
|
||||
f'execute @a{PlayerSelect} ~ ~ ~ playsound {Instrument} @s ~ ~ ~ 1000 '
|
||||
f'{Notes[i][0]} 1000')
|
||||
if isProsess:
|
||||
fcwslib.send_command(websocket,
|
||||
'execute @a' + PlayerSelect + ' ~ ~ ~ title @s actionbar §e▶ 播放中: §a' + str(
|
||||
await fcwslib.send_command(websocket,
|
||||
'execute @a' + PlayerSelect + ' ~ ~ ~ title @s actionbar §e▶ 播放中: §a' +
|
||||
str(
|
||||
j) + '/' + str(length) + ' || ' + str(int(j / length * 1000) / 10))
|
||||
j += 1
|
||||
time.sleep(Notes[i][1] / speed)
|
||||
@ -256,15 +255,15 @@ def note2RSworld(world: str, startpos: list, notes: list, instrument: str, speed
|
||||
startpos[1] += posadder[1]
|
||||
startpos[2] += posadder[2]
|
||||
|
||||
e = True
|
||||
# e = True
|
||||
try:
|
||||
placeNoteBlock()
|
||||
e = False
|
||||
except ValueError:
|
||||
log("无法放置方块了,可能是因为区块未加载叭")
|
||||
finally:
|
||||
if e:
|
||||
# e = False
|
||||
except: # ValueError
|
||||
log("无法放置方块了,可能是因为区块未加载叭")
|
||||
# finally:
|
||||
# if e:
|
||||
# log("无法放置方块了,可能是因为区块未加载叭")
|
||||
level.save()
|
||||
level.close()
|
||||
|
||||
@ -278,26 +277,26 @@ class ryStruct:
|
||||
self._level = amulet.load_level(world)
|
||||
|
||||
def reloadLevel(self):
|
||||
e = True
|
||||
# e = True
|
||||
try:
|
||||
self._level = amulet.load_level(self.world)
|
||||
e = False
|
||||
except ValueError:
|
||||
log("无法重载地图")
|
||||
finally:
|
||||
if e:
|
||||
# e = False
|
||||
except: # ValueError
|
||||
log("无法重载地图")
|
||||
# finally:
|
||||
# if e:
|
||||
# log("无法重载地图")
|
||||
|
||||
def closeLevel(self):
|
||||
e = True
|
||||
# e = True
|
||||
try:
|
||||
self._level.close()
|
||||
e = False
|
||||
except ValueError:
|
||||
# e = False
|
||||
except: # ValueError
|
||||
log("无法关闭地图")
|
||||
finally:
|
||||
if e:
|
||||
log("无法重载地图")
|
||||
# finally:
|
||||
# if e:
|
||||
# log("无法重载地图")
|
||||
|
||||
def world2Rys(self, startp: list, endp: list, includeAir: bool = False):
|
||||
"""将世界转换为RyStruct字典,注意,此函数运行成功后将关闭地图,若要打开需要运行 reloadLevel
|
||||
|
134
nmcsup/const.py
134
nmcsup/const.py
@ -310,3 +310,137 @@ Instuments = {
|
||||
'''乐器对照表\n
|
||||
乐器英文:中文
|
||||
翻译:雪莹工坊Fun-Fer'''
|
||||
pitch = {
|
||||
'0': '0.0220970869120796',
|
||||
'1': '0.0234110480761981',
|
||||
'2': '0.0248031414370031',
|
||||
'3': '0.0262780129766786',
|
||||
'4': '0.0278405849418856',
|
||||
'5': '0.0294960722713029',
|
||||
'6': '0.03125',
|
||||
'7': '0.033108221698728',
|
||||
'8': '0.0350769390096679',
|
||||
'9': '0.037162722343835',
|
||||
'10': '0.0393725328092148',
|
||||
'11': '0.0417137454428136',
|
||||
'12': '0.0441941738241592',
|
||||
'13': '0.0468220961523963',
|
||||
'14': '0.0496062828740062',
|
||||
'15': '0.0525560259533572',
|
||||
'16': '0.0556811698837712',
|
||||
'17': '0.0589921445426059',
|
||||
'18': '0.0625',
|
||||
'19': '0.066216443397456',
|
||||
'20': '0.0701538780193358',
|
||||
'21': '0.0743254446876701',
|
||||
'22': '0.0787450656184296',
|
||||
'23': '0.0834274908856271',
|
||||
'24': '0.0883883476483184',
|
||||
'25': '0.0936441923047926',
|
||||
'26': '0.0992125657480125',
|
||||
'27': '0.105112051906714',
|
||||
'28': '0.111362339767542',
|
||||
'29': '0.117984289085212',
|
||||
'30': '0.125',
|
||||
'31': '0.132432886794912',
|
||||
'32': '0.140307756038672',
|
||||
'33': '0.14865088937534',
|
||||
'34': '0.157490131236859',
|
||||
'35': '0.166854981771254',
|
||||
'36': '0.176776695296637',
|
||||
'37': '0.187288384609585',
|
||||
'38': '0.198425131496025',
|
||||
'39': '0.210224103813429',
|
||||
'40': '0.222724679535085',
|
||||
'41': '0.235968578170423',
|
||||
'42': '0.25',
|
||||
'43': '0.264865773589824',
|
||||
'44': '0.280615512077343',
|
||||
'45': '0.29730177875068',
|
||||
'46': '0.314980262473718',
|
||||
'47': '0.333709963542509',
|
||||
'48': '0.353553390593274',
|
||||
'49': '0.37457676921917',
|
||||
'50': '0.39685026299205',
|
||||
'51': '0.420448207626857',
|
||||
'52': '0.44544935907017',
|
||||
'53': '0.471937156340847',
|
||||
'54': '0.5',
|
||||
'55': '0.529731547179648',
|
||||
'56': '0.561231024154687',
|
||||
'57': '0.594603557501361',
|
||||
'58': '0.629960524947437',
|
||||
'59': '0.667419927085017',
|
||||
'60': '0.707106781186548',
|
||||
'61': '0.749153538438341',
|
||||
'62': '0.7937005259841',
|
||||
'63': '0.840896415253715',
|
||||
'64': '0.890898718140339',
|
||||
'65': '0.943874312681694',
|
||||
'66': '1',
|
||||
'67': '1.0594630943593',
|
||||
'68': '1.12246204830937',
|
||||
'69': '1.18920711500272',
|
||||
'70': '1.25992104989487',
|
||||
'71': '1.33483985417003',
|
||||
'72': '1.4142135623731',
|
||||
'73': '1.49830707687668',
|
||||
'74': '1.5874010519682',
|
||||
'75': '1.68179283050743',
|
||||
'76': '1.78179743628068',
|
||||
'77': '1.88774862536339',
|
||||
'78': '2',
|
||||
'79': '2.11892618871859',
|
||||
'80': '2.24492409661875',
|
||||
'81': '2.37841423000544',
|
||||
'82': '2.51984209978975',
|
||||
'83': '2.66967970834007',
|
||||
'84': '2.82842712474619',
|
||||
'85': '2.99661415375336',
|
||||
'86': '3.1748021039364',
|
||||
'87': '3.36358566101486',
|
||||
'88': '3.56359487256136',
|
||||
'89': '3.77549725072677',
|
||||
'90': '4',
|
||||
'91': '4.23785237743718',
|
||||
'92': '4.48984819323749',
|
||||
'93': '4.75682846001088',
|
||||
'94': '5.03968419957949',
|
||||
'95': '5.33935941668014',
|
||||
'96': '5.65685424949238',
|
||||
'97': '5.99322830750673',
|
||||
'98': '6.3496042078728',
|
||||
'99': '6.72717132202972',
|
||||
'100': '7.12718974512272',
|
||||
'101': '7.55099450145355',
|
||||
'102': '8',
|
||||
'103': '8.47570475487436',
|
||||
'104': '8.97969638647498',
|
||||
'105': '9.51365692002177',
|
||||
'106': '10.079368399159',
|
||||
'107': '10.6787188333603',
|
||||
'108': '11.3137084989848',
|
||||
'109': '11.9864566150135',
|
||||
'110': '12.6992084157456',
|
||||
'111': '13.4543426440594',
|
||||
'112': '14.2543794902454',
|
||||
'113': '15.1019890029071',
|
||||
'114': '16',
|
||||
'115': '16.9514095097487',
|
||||
'116': '17.95939277295',
|
||||
'117': '19.0273138400435',
|
||||
'118': '20.158736798318',
|
||||
'119': '21.3574376667206',
|
||||
'120': '22.6274169979695',
|
||||
'121': '23.9729132300269',
|
||||
'122': '25.3984168314912',
|
||||
'123': '26.9086852881189',
|
||||
'124': '28.5087589804909',
|
||||
'125': '30.2039780058142',
|
||||
'126': '32',
|
||||
'127': '33.9028190194974',
|
||||
'128': '35.9187855458999',
|
||||
'129': '38.0546276800871',
|
||||
'130': '40.3174735966359',
|
||||
'131': '42.7148753334411'
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
import logging
|
||||
import os
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
StrStartTime = str(datetime.datetime.now()).replace(':', '_')[:-7]
|
||||
time = StrStartTime
|
||||
@ -14,11 +13,16 @@ main_path = './log/'
|
||||
|
||||
position = main_path + time
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(level=logging.INFO)
|
||||
|
||||
if not os.path.exists('./log/'):
|
||||
os.makedirs('./log/')
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(level=logging.INFO)
|
||||
# try:
|
||||
# handler = logging.FileHandler(position + ".logger")
|
||||
# except FileNotFoundError:
|
||||
# os.makedirs('./log/')
|
||||
handler = logging.FileHandler(position + ".logger")
|
||||
print(position + ".logger")
|
||||
|
||||
@ -32,9 +36,6 @@ console.setLevel(logging.INFO)
|
||||
logger.addHandler(handler)
|
||||
logger.addHandler(console)
|
||||
|
||||
print("using Timbre_resources_package_generator_lib \n --made by 诸葛亮与八卦阵")
|
||||
print(sys.path[0].replace("nmcsup\\logger", "log\\"))
|
||||
|
||||
# import logger
|
||||
|
||||
# 载入日志功能
|
||||
@ -43,14 +44,25 @@ StrStartTime = str(datetime.datetime.now()).replace(':', '_')[:-7]
|
||||
"""字符串型的程序开始时间"""
|
||||
|
||||
|
||||
def log(info: str = '', isPrinted: bool = True, isLoggerLibRecord: bool = True):
|
||||
# isLoggerLibRecord: 是否同时在logger库中记录
|
||||
def log(info: str = '', isPrinted: bool = False, isLoggerLibRecord: bool = True, isWrite: bool = False):
|
||||
"""
|
||||
info: 信息
|
||||
isPrinted: 是否print(仅限金羿log,python官方的logging照常输出)
|
||||
isLoggerLibRecord: 是否同时在logger库中记录
|
||||
isWrite: 是否write(仅限金羿log,python官方的logging照常输出)
|
||||
"""
|
||||
"""将信息连同当前时间载入日志"""
|
||||
if not os.path.exists('./log/'):
|
||||
os.makedirs('./log/')
|
||||
if isWrite:
|
||||
with open('./log/' + StrStartTime + '.msct.log', 'a', encoding='UTF-8') as f:
|
||||
f.write(str(datetime.datetime.now())[11:19] + ' ' + info + '\n')
|
||||
if isPrinted:
|
||||
print(str(datetime.datetime.now())[11:19] + ' ' + info)
|
||||
if isLoggerLibRecord:
|
||||
logger.info(info)
|
||||
|
||||
|
||||
def end():
|
||||
logging.disable(logging.INFO)
|
||||
logging.shutdown()
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
from nmcsup.log import log
|
||||
from nmcsup.const import notes
|
||||
import pickle
|
||||
|
||||
|
||||
# 从格式文本文件读入一个音轨并存入一个列表
|
||||
@ -67,6 +68,113 @@ 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 ReadOldProject(fn: str): # -> list
|
||||
import json
|
||||
from nmcsup.trans import note2list
|
||||
@ -82,3 +190,12 @@ def ReadOldProject(fn: str): # -> list
|
||||
dataset['musics'][i]['notes'] = note2list(dataset['musics'][i]['notes'])
|
||||
# 返回 音轨列表 选择器
|
||||
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")
|
||||
a = midi_conversion(r"C:\Users\lc\Documents\MuseScore3\乐谱\stay2.mid")
|
||||
# print(a)
|
||||
|
@ -88,7 +88,6 @@ def Note2Cmd(Notes: list, ScoreboardName: str, Instrument: str, PlayerSelect: st
|
||||
isProsess: bool = False) -> list:
|
||||
commands = []
|
||||
a = 0.0
|
||||
if isProsess:
|
||||
length = len(Notes)
|
||||
j = 1
|
||||
for i in range(len(Notes)):
|
||||
@ -103,6 +102,44 @@ def Note2Cmd(Notes: list, ScoreboardName: str, Instrument: str, PlayerSelect: st
|
||||
j += 1
|
||||
commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI(金羿)\n")
|
||||
return commands
|
||||
# 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
|
||||
|
||||
|
||||
# 简单载入方块
|
||||
@ -117,16 +154,16 @@ def Cmd2World(cmd: list, world: str, dire: list):
|
||||
level = amulet.load_level(world)
|
||||
cdl = []
|
||||
for i in cmd:
|
||||
e = True
|
||||
# e = True
|
||||
try:
|
||||
if (i[:i.index('#')].replace(' ', '') != '\n') and (i[:i.index('#')].replace(' ', '') != ''):
|
||||
cdl.append(i[:i.index('#')])
|
||||
e = False
|
||||
except ValueError:
|
||||
cdl.append(i)
|
||||
finally:
|
||||
if e is True:
|
||||
# e = False
|
||||
except:
|
||||
cdl.append(i)
|
||||
# finally:
|
||||
# if e is True:
|
||||
# cdl.append(i)
|
||||
i = 0
|
||||
# 第一个是特殊
|
||||
universal_block = Block('universal_minecraft', 'command_block',
|
||||
@ -243,3 +280,10 @@ def Notes2Player(Note, dire: list, CmdData: dict):
|
||||
def Datas2BlkWorld(NoteData, world: str, dire: list):
|
||||
for i in range(len(NoteData)):
|
||||
Blocks2World(world, [dire[0], dire[1], dire[2] + i], NoteData[i])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from nmcreader import midi_conversion
|
||||
path = "L:\\0WorldMusicCreater-MFMS new edition\\框架\\v0.3.2\\Musicreater\\测试用\\同道殊途标准.mid"
|
||||
b = midi_conversion(path)
|
||||
classList_conversion(b, "n")
|
||||
|
1
测试用/1.msct
Normal file
1
测试用/1.msct
Normal file
File diff suppressed because one or more lines are too long
1
测试用/2.msct
Normal file
1
测试用/2.msct
Normal file
File diff suppressed because one or more lines are too long
1
测试用/3.msct
Normal file
1
测试用/3.msct
Normal file
File diff suppressed because one or more lines are too long
1
测试用/4.msct
Normal file
1
测试用/4.msct
Normal file
File diff suppressed because one or more lines are too long
BIN
测试用/Illusionary_Daytime_--------幻昼.mid
Normal file
BIN
测试用/Illusionary_Daytime_--------幻昼.mid
Normal file
Binary file not shown.
BIN
测试用/不知名文件.7z
Normal file
BIN
测试用/不知名文件.7z
Normal file
Binary file not shown.
BIN
测试用/同道殊途标准.mid
Normal file
BIN
测试用/同道殊途标准.mid
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user