mirror of
https://github.com/TriM-Organization/Linglun-Converter.git
synced 2025-09-06 12:46:28 +00:00
文档更新,代码更新
This commit is contained in:
252
llc_cli.py
252
llc_cli.py
@ -14,7 +14,7 @@ Copyright © 2023 EillesWan & TriM Org.
|
||||
Terms & Conditions: ./Lisense.md
|
||||
"""
|
||||
|
||||
__version__ = "0.0.5"
|
||||
__version__ = "0.0.6"
|
||||
|
||||
import datetime
|
||||
import os
|
||||
@ -24,15 +24,16 @@ import sys
|
||||
import Musicreater
|
||||
from Musicreater.plugin import ConvertConfig
|
||||
from Musicreater.plugin.bdxfile import to_BDX_file_in_delay, to_BDX_file_in_score
|
||||
from Musicreater.plugin.funcpack import to_function_addon_in_score
|
||||
from Musicreater.plugin.mcstructpack import to_mcstructure_addon_in_delay, to_mcstructure_addon_in_redstone_cd
|
||||
from Musicreater.plugin.addonpack import (
|
||||
to_addon_pack_in_delay,
|
||||
to_addon_pack_in_repeater,
|
||||
to_addon_pack_in_score,
|
||||
)
|
||||
from Musicreater.constants import DEFAULT_PROGRESSBAR_STYLE
|
||||
|
||||
# from Musicreater.plugin.mcstructure import commands_to_structure, commands_to_redstone_delay_structure
|
||||
|
||||
from utils.io import *
|
||||
from languages.lang import languages
|
||||
|
||||
print("小贴:不妨试试Mid-BDX转换网页:在线的多功能Midi转换器")
|
||||
print("https://dislink.github.io/midi2bdx/")
|
||||
|
||||
MainConsole.print(
|
||||
"[#121110 on #F0F2F4] ",
|
||||
@ -44,36 +45,25 @@ osc.project_name = "伶伦转换器"
|
||||
osc.version = __version__
|
||||
|
||||
|
||||
def go_for_args(
|
||||
languageChange: str = "ZH-CN", debugMode: str = "False", logfile: str = "True"
|
||||
):
|
||||
global currentLang
|
||||
global logger
|
||||
currentLang = (
|
||||
languageChange.upper()
|
||||
if languageChange.upper() in languages.keys()
|
||||
else "ZH-CN"
|
||||
)
|
||||
osc.isRelease = False if debugMode.lower() in ("true", "1") else True
|
||||
logger.printing = not osc.isRelease
|
||||
logger.writing = True if logfile.lower() in ("true", "1") else False
|
||||
|
||||
|
||||
if len(sys.argv) > 0:
|
||||
|
||||
def go_for_args(debugMode: str = "False", logfile: str = "True"):
|
||||
global logger
|
||||
osc.isRelease = False if debugMode.lower() in ("true", "1") else True
|
||||
logger.printing = not osc.isRelease
|
||||
logger.writing = True if logfile.lower() in ("true", "1") else False
|
||||
|
||||
go_for_args(*sys.argv)
|
||||
|
||||
|
||||
def _(__):
|
||||
"""
|
||||
`languages`
|
||||
"""
|
||||
return languages[currentLang][__]
|
||||
|
||||
|
||||
# 显示大标题
|
||||
MainConsole.rule(title="[bold #AB70FF]欢迎使用伶伦独立转换器", characters="=", style="#26E2FF")
|
||||
MainConsole.rule(title="[bold #AB70FF]Welcome to Linglun Converter", characters="-")
|
||||
MainConsole.rule(title="[#AB70FF]版本{} | 音·创内核版本{}".format(__version__,Musicreater.__version__), characters="=", style="#26E2FF")
|
||||
# MainConsole.rule(title="[bold #AB70FF]Welcome to Linglun Converter", characters="-")
|
||||
MainConsole.rule(
|
||||
title="[#AB70FF]版本{} | 音·创内核版本{}".format(__version__, Musicreater.__version__),
|
||||
characters="-",
|
||||
style="#26E2FF",
|
||||
)
|
||||
|
||||
nowYang = datetime.datetime.now()
|
||||
|
||||
@ -99,13 +89,13 @@ else:
|
||||
justify="center",
|
||||
)
|
||||
|
||||
prt(f"{_('LangChd')}{_(':')}{_(currentLang)}")
|
||||
# prt(f"{_('LangChd')}{_(':')}{_(currentLang)}")
|
||||
|
||||
|
||||
def format_ipt(
|
||||
notice: str,
|
||||
fun,
|
||||
err_note: str = f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||
err_note: str = "输入内容有误,请重新输入。",
|
||||
*extraArg,
|
||||
):
|
||||
"""循环输入,以某种格式
|
||||
@ -126,167 +116,183 @@ def format_ipt(
|
||||
|
||||
# 获取midi列表
|
||||
while True:
|
||||
midi_path = ipt(f"{_('ChoosePath')}{_(':')}").lower()
|
||||
if os.path.exists(midi_path):
|
||||
if os.path.isfile(midi_path):
|
||||
midis = (midi_path,)
|
||||
elif os.path.isdir(midi_path):
|
||||
midis = tuple(
|
||||
(
|
||||
midi_path = ipt(f"请键入MIDI地址或所在目录地址:")
|
||||
try:
|
||||
if os.path.exists(midi_path):
|
||||
if os.path.isfile(midi_path):
|
||||
midis = (midi_path,)
|
||||
elif os.path.isdir(midi_path):
|
||||
midis = (
|
||||
os.path.join(midi_path, i)
|
||||
for i in os.listdir(midi_path)
|
||||
if i.lower().endswith(".mid") or i.lower().endswith(".midi")
|
||||
)
|
||||
)
|
||||
else:
|
||||
prt("输入内容有误,请重新输入。")
|
||||
continue
|
||||
else:
|
||||
prt(f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}")
|
||||
prt("该地址不存在,或无法访问该地址,请重新输入。")
|
||||
continue
|
||||
else:
|
||||
prt(f"{_('FileNotFound')}{_(',')}{_('Re-Enter')}{_('.')}")
|
||||
except PermissionError:
|
||||
prt("无法访问该地址,请检查是否给予程序相关文件的访问权限。")
|
||||
continue
|
||||
break
|
||||
|
||||
# 获取输出地址
|
||||
out_path = format_ipt(
|
||||
f"{_('ChooseOutPath')}{_(':')}",
|
||||
os.path.exists,
|
||||
f"{_('FileNotFound')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||
)[0].lower()
|
||||
while True:
|
||||
out_path = ipt(f"请键入文件生成输出地址:")
|
||||
try:
|
||||
if not os.path.exists(out_path):
|
||||
prt("该地址不存在,或无法访问该地址,请重新输入。")
|
||||
continue
|
||||
except PermissionError:
|
||||
prt("无法访问该地址,请检查是否给予程序相关文件的访问权限。")
|
||||
continue
|
||||
break
|
||||
|
||||
|
||||
# 选择输出格式
|
||||
|
||||
|
||||
def is_in_bdx_mcpack(sth: str):
|
||||
if sth.lower() in ("0", "mcpack"):
|
||||
return 0
|
||||
|
||||
elif sth.lower() in ("1", "bdx"):
|
||||
return 1
|
||||
|
||||
else:
|
||||
raise ValueError("文件格式字符串啊?")
|
||||
|
||||
|
||||
fileFormat = format_ipt(
|
||||
f"{_('ChooseFileFormat')}{_(':')}",
|
||||
is_in_bdx_mcpack,
|
||||
f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||
)[1]
|
||||
return isin(sth, {1: ("bdx", "1", "币帝查", "币帝·艾克斯"), 0: ("mcpack", "0", "唉姆西·派克")})
|
||||
|
||||
|
||||
def is_in_player(sth: str):
|
||||
if sth.lower() in ("0", "延迟", "delay"):
|
||||
return 0
|
||||
elif sth.lower() in ("1", "计分板", "scoreboard"):
|
||||
return 1
|
||||
elif sth.lower() in ('2', "红石", 'redstone'):
|
||||
return 2
|
||||
else:
|
||||
raise ValueError("播放器字符串啊?")
|
||||
return isin(
|
||||
sth,
|
||||
{
|
||||
0: ("delay", "0", "延迟", "帝蕾"),
|
||||
1: ("score", "1", "计分板", "积分", "积分板", "计分", "斯阔尔"),
|
||||
2: ("repeater", "2", "中继器", "瑞皮特"),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
playerFormat = format_ipt(
|
||||
f"{_('ChoosePlayer')}{_(':')}",
|
||||
is_in_player,
|
||||
f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||
output_file_format = format_ipt(
|
||||
"请键入输出文件类型 (mcpack/0|bdx/1)",
|
||||
is_in_bdx_mcpack,
|
||||
"输入内容有误,请重新输入。",
|
||||
)[1]
|
||||
|
||||
if output_file_format == 0:
|
||||
player_format = format_ipt(
|
||||
"请选择播放器类型 (延迟/0|计分板/1|中继器/2)",
|
||||
is_in_player,
|
||||
"输入内容有误,请重新输入。",
|
||||
)[1]
|
||||
else:
|
||||
player_format = format_ipt(
|
||||
"请选择播放器类型 (延迟/0|计分板/1)",
|
||||
is_in_player,
|
||||
"输入内容有误,请重新输入。",
|
||||
)[1]
|
||||
|
||||
# 真假字符串判断
|
||||
def bool_str(sth: str) -> bool:
|
||||
try:
|
||||
return bool(int(sth))
|
||||
except ValueError:
|
||||
if str(sth).lower() in ("true", "真", "是"):
|
||||
return True
|
||||
elif str(sth).lower() == ("false", "假", "否", "非"):
|
||||
return False
|
||||
else:
|
||||
raise ValueError("布尔字符串啊?")
|
||||
old_exe_enabled = format_ipt(
|
||||
"启用1.19以前的旧版execute指令格式 (否/0|是/1):", bool_str, "输入内容格式错误,应为 是/1/真/t/y 或 否/0/假/f/n"
|
||||
)[1]
|
||||
|
||||
|
||||
if os.path.exists("./demo_config.json"):
|
||||
import json
|
||||
|
||||
prompts = json.load(open("./demo_config.json", "r", encoding="utf-8"))
|
||||
|
||||
|
||||
prompts = prompts[:-1]
|
||||
else:
|
||||
prompts = []
|
||||
# 提示语 检测函数 错误提示语
|
||||
for args in [
|
||||
(
|
||||
f'{_("EnterVolume")}{_(":")}',
|
||||
float,
|
||||
"音量大小 (0,1]:",
|
||||
float_str,
|
||||
),
|
||||
(
|
||||
f'{_("EnterSpeed")}{_(":")}',
|
||||
float,
|
||||
"速度倍率 (0,+∞):",
|
||||
float_str,
|
||||
),
|
||||
(
|
||||
f'{_("WhetherPgb")}{_(":")}',
|
||||
"自动生成进度条 (否/0|是/1):",
|
||||
bool_str,
|
||||
),
|
||||
(
|
||||
f'{_("EnterSbName")}{_(":")}',
|
||||
"计分板名称:",
|
||||
str,
|
||||
)
|
||||
if playerFormat == 1
|
||||
if player_format == 1
|
||||
else (
|
||||
f'{_("EnterSelecter")}{_(":")}',
|
||||
"受播放玩家的选择器:",
|
||||
str,
|
||||
),
|
||||
(
|
||||
f'{_("WhetherSbReset")}{_(":")}',
|
||||
"自动重置计分板 (否/0|是/1):",
|
||||
bool_str,
|
||||
)
|
||||
if playerFormat == 1
|
||||
if player_format == 1
|
||||
else (),
|
||||
(
|
||||
f'{_("EnterAuthor")}{_(":")}',
|
||||
"BDX作者署名:",
|
||||
str,
|
||||
)
|
||||
if fileFormat == 1
|
||||
if output_file_format == 1
|
||||
else (),
|
||||
(
|
||||
f'{_("EnterMaxHeight")}{_(":")}',
|
||||
"结构生成最大高度 (0,+∞):",
|
||||
int,
|
||||
)
|
||||
if playerFormat == 0
|
||||
if player_format == 0
|
||||
else (),
|
||||
]:
|
||||
if args:
|
||||
prompts.append(format_ipt(*args)[1])
|
||||
prompts.append(
|
||||
format_ipt(*args, err_note="输入内容格式错误,应符合 {}".format(args[1]))[1]
|
||||
)
|
||||
|
||||
if prompts[2]:
|
||||
costom_pgb_enabled = format_ipt(
|
||||
"自定义进度条样式 (否/0|是/1):", bool_str, "输入内容格式错误,应为 是/1/真/t/y 或 否/0/假/f/n"
|
||||
)[1]
|
||||
if costom_pgb_enabled:
|
||||
style = ipt("基本样式组 (回车默认):")
|
||||
if not style:
|
||||
style = DEFAULT_PROGRESSBAR_STYLE[0]
|
||||
yet_part = ipt("未播放样式 (回车默认):")
|
||||
if not yet_part:
|
||||
yet_part = DEFAULT_PROGRESSBAR_STYLE[1][1]
|
||||
done_part = ipt("已播放样式 (回车默认):")
|
||||
if not done_part:
|
||||
done_part = DEFAULT_PROGRESSBAR_STYLE[1][0]
|
||||
|
||||
if playerFormat == 1:
|
||||
cvt_method = to_function_addon_in_score
|
||||
elif playerFormat == 0:
|
||||
cvt_method = to_mcstructure_addon_in_delay
|
||||
elif playerFormat == 2:
|
||||
cvt_method = to_mcstructure_addon_in_redstone_cd
|
||||
if player_format == 1:
|
||||
cvt_method = to_addon_pack_in_score
|
||||
elif player_format == 0:
|
||||
cvt_method = to_addon_pack_in_delay
|
||||
elif player_format == 2:
|
||||
cvt_method = to_addon_pack_in_repeater
|
||||
|
||||
|
||||
for singleMidi in midis:
|
||||
prt("\n" f"{_('Dealing')} {singleMidi} {_(':')}")
|
||||
cvt_mid = Musicreater.MidiConvert.from_midi_file(singleMidi, old_exe_format=False)
|
||||
cvt_cfg = ConvertConfig(out_path, *prompts[:3])
|
||||
|
||||
conversion_result = ((
|
||||
cvt_method(cvt_mid, cvt_cfg, *prompts[3:])
|
||||
)if fileFormat == 0
|
||||
prt("\n" f"正在处理 {singleMidi}")
|
||||
cvt_mid = Musicreater.MidiConvert.from_midi_file(
|
||||
singleMidi, old_exe_format=old_exe_enabled
|
||||
)
|
||||
cvt_cfg = ConvertConfig(out_path, *prompts[:2], progressbar=((style, (done_part, yet_part)) if costom_pgb_enabled else True) if prompts[2] else False) # type: ignore
|
||||
|
||||
conversion_result = (
|
||||
(cvt_method(cvt_mid, cvt_cfg, *prompts[3:])) # type: ignore
|
||||
if output_file_format == 0
|
||||
else (
|
||||
to_BDX_file_in_score(cvt_mid, cvt_cfg, *prompts[3:])
|
||||
if playerFormat == 1
|
||||
else to_BDX_file_in_delay(cvt_mid, cvt_cfg, *prompts[3:])
|
||||
))
|
||||
to_BDX_file_in_score(cvt_mid, cvt_cfg, *prompts[3:])
|
||||
if player_format == 1
|
||||
else to_BDX_file_in_delay(cvt_mid, cvt_cfg, *prompts[3:])
|
||||
)
|
||||
)
|
||||
|
||||
prt(
|
||||
f" {_('CmdLength')}{_(':')}{conversion_result[0]}{_(',')}{_('MaxDelay')}{_(':')}{conversion_result[1]}{f'''{_(',')}{_('PlaceSize')}{_(':')}{conversion_result[2]}{_(',')}{_('LastPos')}{_(':')}{conversion_result[3]}''' if fileFormat == 1 else ''}"
|
||||
)
|
||||
f" 指令总长:{conversion_result[0]},播放刻数:{conversion_result[1]}{f''',结构大小:{conversion_result[2]},末点坐标:{conversion_result[3]}''' if output_file_format == 1 else ''}" # type: ignore
|
||||
)
|
||||
|
||||
exitSth = ipt(_("PressEnterExit")).lower()
|
||||
exitSth = ipt("结束。换行以退出程序。")
|
||||
if exitSth == "record":
|
||||
import json
|
||||
|
||||
|
Reference in New Issue
Block a user