👍修复已知问题

This commit is contained in:
EillesWan 2024-07-23 23:13:27 +08:00
parent 907740172b
commit 86378e2ec0
5 changed files with 171 additions and 140 deletions

View File

@ -44,7 +44,7 @@
- `-p | --player-selector <字符串>` : **仅当结果类型包含 `*-delay` 之一时生效、不可多填** : 播放使用的玩家选择器;默认为`@a`
- `-h | --height-limit <整数>` : **仅当结果类型包含 `*-delay`、`bdx-*` 之一时生效** : 生成结构的最大高度限制;默认为`32`
- `-l | --height-limit <整数>` : **仅当结果类型包含 `*-delay`、`bdx-*` 之一时生效** : 生成结构的最大高度限制;默认为`32`
- `-a | --author <字符串>` : **仅当结果类型包含 `bdx-*` 之一时生效、不可多填** : 音乐文件的作者署名;默认为`Eilles`
@ -54,13 +54,16 @@
生成 midi 音乐的《我的世界》播放预览效果。每次转换基础随机消耗一次点数,**若短时间内已使用同样的参数运行过一次 音乐转换 命令,则不消耗基础点数**,并随机消耗附加点数 [1.3, 2.9] 。该命令与上文中的 `音乐转换` 命令共享点数信息。
- `-n | --file-name` : 缓存中的 midi 文件名称,需提前上传 mid 文件;默认为`all`
- `-n | -f | --file-name` : 缓存中的 midi 文件名称,需提前上传 mid 文件;默认为`all`
- `-m | --mode` : 合成模式,支持以下内容。默认为 `0`
- 0 原始长度,不变化时长
- 1 拉伸至 mc 播放器定义(我的世界效果)
- 2 根据 midi 音符长度裁剪
- 3 混音预留
- 4 匹配 midi 音符长度(最佳效果)
- `-g | --get-value-method` : GVM取值法支持以下内容。默认为 `1`
- 0 均值化
- 1 钳制位
- `-o | --output-file` : 是否输出文件,默认为`False`
- 以下命令同上 音乐转换 参数
- `-emr | --enable-mismatch-error`

Binary file not shown.

Before

Width:  |  Height:  |  Size: 564 KiB

After

Width:  |  Height:  |  Size: 662 KiB

View File

@ -56,7 +56,7 @@ from src.utils.base.language import get_user_lang
from src.utils.message.message import MarkdownMessage
from .execute_auto_translator import auto_translate # type: ignore
from .utils import utime_hanzify
nonebot.require("nonebot_plugin_alconna")
nonebot.require("nonebot_plugin_apscheduler")
@ -206,6 +206,7 @@ async def _():
file_to_delete = []
@scheduler.scheduled_job("interval", seconds=30)
async def _():
nonebot.logger.info(
@ -762,60 +763,9 @@ async def _(
all_files[file_to_convert] = {}
if (
((msct_obj := query_convert_points(usr_id, "music", 0)[0]) is None)
or (
isinstance(msct_obj, tuple)
and (
(
isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1]
!= (
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
)
)
or (
msct_obj[0].music_name
!= os.path.splitext(
os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_")
)
)
)
) and go_chk_point():
msct_obj = Musicreater.MidiConvert.from_midi_file(
midi_file_path=usr_data_path / file_to_convert,
mismatch_error_ignorance=not _args["enable-mismatch-error"],
play_speed=_args["play-speed"],
default_tempo=_args["default-tempo"],
pitched_note_table=pitched_notechart,
percussion_note_table=percussion_notechart,
old_exe_format=_args["old-execute-format"],
min_volume=_args["minimal-volume"],
vol_processing_func=volume_curve,
)
query_convert_points(
usr_id,
"music",
0,
(
msct_obj,
(
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
),
),
)
elif isinstance(msct_obj, tuple) and (
if isinstance(
msct_obj := query_convert_points(usr_id, "music", 0)[0], tuple
) and (
isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1]
== (
@ -828,22 +778,53 @@ async def _(
)
and (
msct_obj[0].music_name
!= os.path.splitext(
== os.path.splitext(
os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_")
)
):
nonebot.logger.info("载入已有缓存。")
msct_obj = msct_obj[0]
msct_obj.redefine_execute_format(_args["old-execute-format"])
msct_obj.set_min_volume(_args["minimal-volume"])
# msct_obj.set_deviation()
else:
buffer.write(
"点数不足或出现错误:{}".format(
_args,
if go_chk_point():
msct_obj = Musicreater.MidiConvert.from_midi_file(
midi_file_path=usr_data_path / file_to_convert,
mismatch_error_ignorance=not _args["enable-mismatch-error"],
play_speed=_args["play-speed"],
default_tempo=_args["default-tempo"],
pitched_note_table=pitched_notechart,
percussion_note_table=percussion_notechart,
old_exe_format=_args["old-execute-format"],
min_volume=_args["minimal-volume"],
vol_processing_func=volume_curve,
)
)
break
query_convert_points(
usr_id,
"music",
0,
(
msct_obj,
(
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
),
),
)
else:
buffer.write(
"点数不足或出现错误:{}".format(
_args,
)
)
break
# people_convert_point[usr_id] += 0.5
if "msq" in all_cvt_types:
@ -974,19 +955,30 @@ async def _(
"无可供转换的文件",
)
await linglun_convert.finish(
UniMessage("不是哥们,空气咱这转不成面包,那是中科院的事。")
UniMessage("不是哥们,二氧化碳咱这转不成面包,那是中科院的事。")
)
except Exception as e:
nonebot.logger.error("转换存在错误:{}".format(e))
buffer.write("[ERROR] {}\n".format(e))
buffer.write(
"[ERROR] {}\n".format(e).replace(
"C:\\Users\\Administrator\\Desktop\\RyBot\\", "[]"
)
)
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
Musicreater.plugin.archive.compress_zipfile(
usr_temp_path,
fp := str(temporary_dir / (fn := "result-{}.zip".format(usr_id))),
fp := str(
temporary_dir
/ (
fn := "msctr[{}]-{}.zip".format(
utime_hanzify(zhDateTime.DateTime.now().to_lunar()), usr_id
)
)
),
)
shutil.rmtree(usr_temp_path)

View File

@ -5,12 +5,14 @@ import shutil
import random
from io import StringIO
# from pathlib import Path
# import nonebot.rule
import nonebot
import soundfile
import zhDateTime
import Musicreater
import Musicreater.plugin
import nonebot.adapters.onebot.v11.exception
@ -50,12 +52,16 @@ from .msctexec import (
temporary_dir,
file_to_delete,
)
from .utils import utime_hanzify
mspv_sync = on_alconna(
Alconna(
"音乐合成",
Option("-n|--file-name", default="all", args=Args["file-name", str, "all"]),
Option("-n|-f|--file-name", default="all", args=Args["file-name", str, "all"]),
Option("-m|--mode", default=0, args=Args["mode", int, 0]),
Option(
"-g|--get-value-method", default=1, args=Args["get-value-method", int, 1]
),
Option("-o|--output-file", default=False, action=store_true),
Option("-emr|--enable-mismatch-error", default=False, action=store_true),
Option("-ps|--play-speed", default=1.0, args=Args["play-speed", float, 1.0]),
@ -129,6 +135,7 @@ async def _(
"file-name": "all",
"output-file": False,
"mode": 0,
"get-value-method": 1,
"enable-mismatch-error": False,
"play-speed": 1.0,
"default-tempo": 500000,
@ -156,6 +163,16 @@ async def _(
UniMessage.text("模式 {} 不存在,请详阅文档。".format(_args["mode"]))
)
if _args["get-value-method"] not in [
0,
1,
]:
await mspv_sync.finish(
UniMessage.text(
"取值法 {} 不存在,请详阅文档。".format(_args["get-value-method"])
)
)
usr_data_path = database_dir / usr_id
(usr_temp_path := temporary_dir / usr_id).mkdir(exist_ok=True)
@ -256,71 +273,25 @@ async def _(
nonebot.logger.info("载入待合成文件:{}".format(file_to_convert))
# print("1")
# await mspv_sync.finish("处理中")
if (
((msct_obj := query_convert_points(usr_id, "music", 0)[0]) is None)
or (
isinstance(msct_obj, tuple)
and (
(
isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1]
!= (
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
)
)
or (
msct_obj[0].music_name
!= os.path.splitext(
os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_")
)
)
)
) and go_chk_point():
msct_obj = Musicreater.MidiConvert.from_midi_file(
midi_file_path=usr_data_path / file_to_convert,
mismatch_error_ignorance=not _args["enable-mismatch-error"],
play_speed=_args["play-speed"],
default_tempo=_args["default-tempo"],
pitched_note_table=pitched_notechart,
percussion_note_table=percussion_notechart,
vol_processing_func=volume_curve,
)
query_convert_points(
usr_id,
"music",
0,
(
msct_obj,
(
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
),
),
)
elif isinstance(msct_obj, tuple) and (
if isinstance(
msct_obj := query_convert_points(usr_id, "music", 0)[0], tuple
) and (
isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1]
== (
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
and (
msct_obj[1]
== (
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
)
)
and (
msct_obj[0].music_name
!= os.path.splitext(
== os.path.splitext(
os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_")
)
@ -328,19 +299,47 @@ async def _(
nonebot.logger.info("载入已有缓存。")
msct_obj = msct_obj[0]
else:
buffer.write(
"点数不足或出现错误:\n{}".format(
_args,
if go_chk_point():
msct_obj = Musicreater.MidiConvert.from_midi_file(
midi_file_path=usr_data_path / file_to_convert,
mismatch_error_ignorance=not _args["enable-mismatch-error"],
play_speed=_args["play-speed"],
default_tempo=_args["default-tempo"],
pitched_note_table=pitched_notechart,
percussion_note_table=percussion_notechart,
vol_processing_func=volume_curve,
)
)
break
query_convert_points(
usr_id,
"music",
0,
(
msct_obj,
(
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
),
),
)
else:
buffer.write(
"点数不足或出现错误:\n{}".format(
_args,
)
)
break
all_files.append(file_to_convert)
music_temp = PreviewMusic(
msct_obj,
mode=1,
gvm=1,
mode=_args["mode"],
gvm=_args["get-value-method"],
default_channel_num=1,
overlay_channels=1,
out_sr=44100,
@ -385,7 +384,11 @@ async def _(
except Exception as e:
nonebot.logger.error("合成存在错误:{}".format(e))
buffer.write("[ERROR] {}\n".format(e))
buffer.write(
"[ERROR] {}\n".format(e).replace(
"C:\\Users\\Administrator\\Desktop\\RyBot\\", "[]"
)
)
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
@ -393,7 +396,14 @@ async def _(
if _args["output-file"]:
Musicreater.plugin.archive.compress_zipfile(
usr_temp_path,
fp := str(temporary_dir / (fn := "mpr-wav-{}.zip".format(usr_id))),
fp := str(
temporary_dir
/ (
fn := "mprwav[{}]{}.zip".format(
utime_hanzify(zhDateTime.DateTime.now().to_lunar()), usr_id
)
)
),
)
try:
@ -424,7 +434,6 @@ async def _(
# nonebot.logger.info(buffer.getvalue())
shutil.rmtree(usr_temp_path)
await mspv_sync.finish(

View File

@ -0,0 +1,27 @@
import zhDateTime
def utime_hanzify(
zhd: zhDateTime.zhDateTime = zhDateTime.DateTime.now().to_lunar(),
) -> str:
return "{地支时}{刻}{分}{秒}".format(
地支时=zhDateTime.DÌZHĪ[zhd.shichen]
+ (
""
if ((zhd.quarters) or (zhd.minutes) or (zhd.seconds) or (zhd.microseconds))
else ""
),
=(
(zhDateTime.HANNUM[zhd.quarters])
+ ("" if ((zhd.minutes) or (zhd.seconds) or (zhd.microseconds)) else "")
),
=(
zhDateTime.lkint_hànzìfy(zhd.minutes)
+ ("" if ((zhd.seconds) or (zhd.microseconds)) else "")
),
=(
zhDateTime.HANNUM[zhd.seconds // 10]
+ zhDateTime.HANNUM[zhd.seconds % 10]
+ ("" if (zhd.microseconds) else "")
),
).strip()