mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2026-04-17 06:08:00 +00:00
修复小bug,完成转指令的插件功能。
This commit is contained in:
@@ -19,10 +19,46 @@ Terms & Conditions: License.md in the root directory
|
||||
|
||||
from .main import MidiImportConfig, MidiImport2MusicPlugin
|
||||
|
||||
# constants 里面那些对照表也要导进来写 __all__ 里
|
||||
# utils 里面那些拟合曲线也要
|
||||
|
||||
from .constants import (
|
||||
MIDI_DEFAULT_PROGRAM_VALUE,
|
||||
MIDI_DEFAULT_VOLUME_VALUE,
|
||||
MM_CLASSIC_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_CLASSIC_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_TOUCH_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_DISLINK_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_DISLINK_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_NBS_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_NBS_PERCUSSION_INSTRUMENT_TABLE,
|
||||
)
|
||||
|
||||
from .utils import (
|
||||
volume_2_distance_natural,
|
||||
volume_2_distance_straight,
|
||||
panning_2_rotation_linear,
|
||||
panning_2_rotation_trigonometric,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# 插件参数和插件本体类
|
||||
"MidiImportConfig",
|
||||
"MidiImport2MusicPlugin",
|
||||
]
|
||||
# 内置的拟合函数
|
||||
"volume_2_distance_straight",
|
||||
"volume_2_distance_natural",
|
||||
"panning_2_rotation_linear",
|
||||
"panning_2_rotation_trigonometric",
|
||||
# Midi 相关默认值
|
||||
"MIDI_DEFAULT_PROGRAM_VALUE",
|
||||
"MIDI_DEFAULT_VOLUME_VALUE",
|
||||
# Midi 与 游戏内容 的对照表
|
||||
"MM_CLASSIC_PITCHED_INSTRUMENT_TABLE",
|
||||
"MM_CLASSIC_PERCUSSION_INSTRUMENT_TABLE",
|
||||
"MM_TOUCH_PITCHED_INSTRUMENT_TABLE",
|
||||
"MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE",
|
||||
"MM_DISLINK_PITCHED_INSTRUMENT_TABLE",
|
||||
"MM_DISLINK_PERCUSSION_INSTRUMENT_TABLE",
|
||||
"MM_NBS_PITCHED_INSTRUMENT_TABLE",
|
||||
"MM_NBS_PERCUSSION_INSTRUMENT_TABLE",
|
||||
]
|
||||
|
||||
@@ -67,7 +67,7 @@ class MidiImportConfig(PluginConfig):
|
||||
default_volume_value: int = MIDI_DEFAULT_VOLUME_VALUE
|
||||
default_tempo_value: int = mido.midifiles.midifiles.DEFAULT_TEMPO
|
||||
|
||||
# 对照表
|
||||
# 对照表,此处 None 值在下边 post init 函数中有处理
|
||||
pitched_note_reference_table: Mapping[int, str] = None # type: ignore
|
||||
percussion_note_reference_table: Mapping[int, str] = None # type: ignore
|
||||
note_replacement_table: Mapping[str, str] = None # type: ignore
|
||||
@@ -102,6 +102,10 @@ class MidiImportConfig(PluginConfig):
|
||||
|
||||
|
||||
class ControlerKeys(Enum):
|
||||
"""
|
||||
Midi 控制器键
|
||||
"""
|
||||
|
||||
MIDI_PROGRAM = "midi_program"
|
||||
MIDI_VOLUME = "midi_volume"
|
||||
MIDI_PAN = "midi_pan"
|
||||
@@ -121,6 +125,8 @@ class TrackDivisionDict(
|
||||
):
|
||||
"""
|
||||
音轨分轨字典
|
||||
键为音轨信息元组[音轨编号, 通道编号, 音符名称, 音量, 声相]
|
||||
值为音轨对象
|
||||
"""
|
||||
|
||||
division_by_miditrack: bool = True
|
||||
@@ -433,18 +439,6 @@ class MidiImport2MusicPlugin(MusicInputPluginBase):
|
||||
"无法在上文中找到与之匹配的音符开音消息。",
|
||||
)
|
||||
|
||||
"""整合后的音乐通道格式
|
||||
每个通道包括若干消息元素其中逃不过这三种:
|
||||
|
||||
1 切换乐器消息
|
||||
("PgmC", 切换后的乐器ID: int, 距离演奏开始的毫秒)
|
||||
|
||||
2 音符开始消息
|
||||
("NoteS", 开始的音符ID, 力度(响度), 距离演奏开始的毫秒)
|
||||
|
||||
3 音符结束消息
|
||||
("NoteE", 结束的音符ID, 距离演奏开始的毫秒)"""
|
||||
|
||||
del midi_tempo
|
||||
|
||||
if midi_lyric_cache:
|
||||
|
||||
@@ -16,9 +16,18 @@ Terms & Conditions: License.md in the root directory
|
||||
# Email TriM-Organization@hotmail.com
|
||||
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
|
||||
|
||||
from .main import CommandConvertionConfig, NoteDataConvert2CommandPlugin
|
||||
from .main import NoteDataConvert2CommandPlugin, MineCommand
|
||||
|
||||
from .progressbar import ProgressBarStyle, DEFAULT_PROGRESSBAR_STYLE
|
||||
|
||||
__all__ = [
|
||||
"CommandConvertionConfig",
|
||||
# "CommandConvertionConfig",
|
||||
# 插件主类
|
||||
"NoteDataConvert2CommandPlugin",
|
||||
# 进度条样式类
|
||||
"ProgressBarStyle",
|
||||
# Minecraft 指令类
|
||||
"MineCommand",
|
||||
# 默认进度条样式
|
||||
"DEFAULT_PROGRESSBAR_STYLE",
|
||||
]
|
||||
|
||||
@@ -38,9 +38,9 @@ from .progressbar import ProgressBarStyle, DEFAULT_PROGRESSBAR_STYLE, mctick2tim
|
||||
from .utils import minenote_to_command_parameters
|
||||
|
||||
|
||||
@dataclass
|
||||
class CommandConvertionConfig(PluginConfig):
|
||||
execute_command_head: str = "execute as {} at @s positioned ~ ~ ~ run "
|
||||
# @dataclass
|
||||
# class CommandConvertionConfig(PluginConfig):
|
||||
# execute_command_head: str = "execute as {} at @s positioned ~ ~ ~ run "
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -541,14 +541,15 @@ class NoteDataConvert2CommandPlugin(LibraryPluginBase):
|
||||
)
|
||||
),
|
||||
annotation=(
|
||||
"在{}播放噪音{}".format(
|
||||
"[{}] 打击乐音符{}".format(
|
||||
mctick2timestr(note.start_tick),
|
||||
track.instrument,
|
||||
note.instrument,
|
||||
)
|
||||
if note.percussive
|
||||
else "在{}播放乐音{}".format(
|
||||
else "[{}] 音符{}:{:.2f}".format(
|
||||
mctick2timestr(note.start_tick),
|
||||
"{}:{:.2f}".format(track.instrument, mc_pitch),
|
||||
note.instrument,
|
||||
mc_pitch,
|
||||
)
|
||||
),
|
||||
),
|
||||
@@ -619,14 +620,15 @@ class NoteDataConvert2CommandPlugin(LibraryPluginBase):
|
||||
)
|
||||
),
|
||||
annotation=(
|
||||
"在{}播放噪音{}".format(
|
||||
"[{}] 打击乐音符{}".format(
|
||||
mctick2timestr(note.start_tick),
|
||||
note.instrument,
|
||||
)
|
||||
if note.percussive
|
||||
else "在{}播放乐音{}".format(
|
||||
else "[{}] 音符{}:{:.2f}".format(
|
||||
mctick2timestr(note.start_tick),
|
||||
"{}:{:.2f}".format(note.instrument, mc_pitch),
|
||||
note.instrument,
|
||||
mc_pitch,
|
||||
)
|
||||
),
|
||||
delay=tickdelay,
|
||||
|
||||
@@ -132,7 +132,7 @@ class SingleNote:
|
||||
"""存储单个音符的类"""
|
||||
|
||||
midi_pitch: int
|
||||
"""midi音高"""
|
||||
"""Midi 音高"""
|
||||
|
||||
volume: int
|
||||
"""力度/播放响度 0~100 百分比"""
|
||||
@@ -164,7 +164,7 @@ class SingleNote:
|
||||
Parameters
|
||||
------------
|
||||
midi_pitch: int
|
||||
midi音高
|
||||
Midi 音高
|
||||
note_volume: int
|
||||
响度/力度(百分比, 0~100)
|
||||
start_time: int
|
||||
@@ -185,7 +185,7 @@ class SingleNote:
|
||||
"""
|
||||
|
||||
self.midi_pitch: int = 66 if note_pitch is None else note_pitch
|
||||
"""midi音高"""
|
||||
"""Midi 音高"""
|
||||
self.volume: int = note_volume
|
||||
"""响度(力度)"""
|
||||
self.start_time: int = start_tick
|
||||
@@ -349,7 +349,7 @@ class SingleNote:
|
||||
|
||||
|
||||
class CurvableParam(str, Enum):
|
||||
"""可曲线化的参数枚举类"""
|
||||
"""可曲线化的参数 枚举类"""
|
||||
|
||||
PITCH = "adjust_note_pitch"
|
||||
VOLUME = "adjust_note_volume"
|
||||
@@ -640,9 +640,9 @@ class SingleMusic(List[SingleTrack]):
|
||||
*args: SingleTrack,
|
||||
name: str = "未命名乐曲",
|
||||
creator: str = "未命名制作者",
|
||||
original_author: str = "未命名原作者",
|
||||
description: str = "未命名简介",
|
||||
credits: str = "未命名版权信息",
|
||||
original_author: str = "未命名原曲作",
|
||||
description: str = "无简介",
|
||||
credits: str = "保留所有权利。All Rights Reserved.",
|
||||
extra_information: Dict[str, Any] = {},
|
||||
):
|
||||
self.music_name = name
|
||||
|
||||
@@ -134,7 +134,7 @@ def load_plugin_module(package: Union[Path, str]):
|
||||
else:
|
||||
return importlib.import_module(package)
|
||||
except ModuleNotFoundError as e:
|
||||
raise PluginNotFoundError("无法找到名为`{}`的插件包".format(package))
|
||||
raise PluginNotFoundError("无法找到名为`{}`的插件包".format(package)) from e
|
||||
|
||||
|
||||
class PluginRegistry:
|
||||
@@ -177,9 +177,13 @@ class PluginRegistry:
|
||||
plg_id, plg_class.metainfo
|
||||
)
|
||||
)
|
||||
if (i for i in plg_class.metainfo.dependencies if i not in self._all_plugin_id):
|
||||
if missing_requirements := [
|
||||
i for i in plg_class.metainfo.dependencies if i not in self._all_plugin_id
|
||||
]:
|
||||
raise PluginDependencyNotFound(
|
||||
"插件 `{}` 依赖于这些插件:`{}`。载入此插件时,请务必将后者提前载入。"
|
||||
"插件 `{}` 依赖于这些插件:`{}`;当前环境中缺失:`{}`。加载此插件时,请务必将被依赖的插件提前载入。".format(
|
||||
plg_id, plg_class.metainfo.dependencies, missing_requirements
|
||||
)
|
||||
)
|
||||
cls_dict[plg_id] = plg_class()
|
||||
self._all_plugin_id.append(plg_id)
|
||||
|
||||
@@ -85,7 +85,14 @@ __all__ = [
|
||||
"midi_inst_to_mc_sound",
|
||||
]
|
||||
|
||||
from .old_main import MusicSequence, MidiConvert
|
||||
from .old_main import (
|
||||
MusicSequence,
|
||||
MidiConvert,
|
||||
# 字典键
|
||||
MIDI_PROGRAM,
|
||||
MIDI_PAN,
|
||||
MIDI_VOLUME,
|
||||
)
|
||||
|
||||
from .subclass import (
|
||||
MineNote,
|
||||
@@ -96,7 +103,7 @@ from .subclass import (
|
||||
DEFAULT_PROGRESSBAR_STYLE,
|
||||
)
|
||||
|
||||
from .utils import (
|
||||
from .old_utils import (
|
||||
# 兼容性函数
|
||||
load_decode_musicsequence_metainfo,
|
||||
load_decode_msq_flush_release,
|
||||
@@ -104,21 +111,26 @@ from .utils import (
|
||||
# 工具函数
|
||||
guess_deviation,
|
||||
midi_inst_to_mc_sound,
|
||||
# 处理用函数
|
||||
velocity_2_distance_natural,
|
||||
velocity_2_distance_straight,
|
||||
panning_2_rotation_linear,
|
||||
panning_2_rotation_trigonometric,
|
||||
)
|
||||
|
||||
from .constants import (
|
||||
# 字典键
|
||||
MIDI_PROGRAM,
|
||||
MIDI_PAN,
|
||||
MIDI_VOLUME,
|
||||
# 默认值
|
||||
MIDI_DEFAULT_PROGRAM_VALUE,
|
||||
from Musicreater.builtin_plugins.midi_read import (
|
||||
MIDI_DEFAULT_VOLUME_VALUE,
|
||||
MIDI_DEFAULT_PROGRAM_VALUE,
|
||||
volume_2_distance_straight as velocity_2_distance_straight,
|
||||
volume_2_distance_natural as velocity_2_distance_natural,
|
||||
panning_2_rotation_linear,
|
||||
panning_2_rotation_trigonometric,
|
||||
MM_CLASSIC_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_CLASSIC_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_TOUCH_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_DISLINK_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_DISLINK_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_NBS_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_NBS_PERCUSSION_INSTRUMENT_TABLE,
|
||||
)
|
||||
|
||||
from Musicreater.constants import (
|
||||
# MIDI 表
|
||||
MIDI_PITCH_NAME_TABLE,
|
||||
MIDI_PITCHED_NOTE_NAME_GROUP,
|
||||
@@ -133,12 +145,4 @@ from .constants import (
|
||||
# MIDI 到 我的世界 表
|
||||
MM_INSTRUMENT_RANGE_TABLE,
|
||||
MM_INSTRUMENT_DEVIATION_TABLE,
|
||||
MM_CLASSIC_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_CLASSIC_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_TOUCH_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_DISLINK_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_DISLINK_PERCUSSION_INSTRUMENT_TABLE,
|
||||
MM_NBS_PITCHED_INSTRUMENT_TABLE,
|
||||
MM_NBS_PERCUSSION_INSTRUMENT_TABLE,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user