新增部分可指定的默认值,增加默认乐器替换表

This commit is contained in:
EillesWan 2025-04-15 21:14:38 +08:00
parent 64048a5e31
commit 7a1ca86132
5 changed files with 71 additions and 18 deletions

View File

@ -22,8 +22,8 @@ The Licensor of Musicreater("this project") is Eilles, bgArray.
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
__version__ = "2.3.0.2" __version__ = "2.3.1"
__vername__ = "FSQ 完全流式音符读写适配,修复插件的兼容性问题" __vername__ = "新增部分新可指定的默认值"
__author__ = ( __author__ = (
("金羿", "Eilles"), ("金羿", "Eilles"),
("诸葛亮与八卦阵", "bgArray"), ("诸葛亮与八卦阵", "bgArray"),
@ -42,6 +42,7 @@ __all__ = [
"ProgressBarStyle", "ProgressBarStyle",
# "TimeStamp", 未来功能 # "TimeStamp", 未来功能
# 默认值 # 默认值
"MIDI_DEFAULT_PROGRAM_VALUE",
"DEFAULT_PROGRESSBAR_STYLE", "DEFAULT_PROGRESSBAR_STYLE",
"MM_INSTRUMENT_RANGE_TABLE", "MM_INSTRUMENT_RANGE_TABLE",
"MM_CLASSIC_PITCHED_INSTRUMENT_TABLE", "MM_CLASSIC_PITCHED_INSTRUMENT_TABLE",

View File

@ -37,6 +37,10 @@ z
# Midi用对照表 # Midi用对照表
MIDI_DEFAULT_PROGRAM_VALUE: int = (
74 # 当 Midi 本身与用户皆未指定音色时,默认 Flute 长笛
)
MIDI_PITCH_NAME_TABLE: Dict[int, str] = { MIDI_PITCH_NAME_TABLE: Dict[int, str] = {
0: "C", 0: "C",
1: "C#", 1: "C#",
@ -430,6 +434,33 @@ MC_INSTRUMENT_BLOCKS_TABLE: Dict[str, Tuple[str, ...]] = {
} }
"""MC乐器对音符盒下垫方块对照表""" """MC乐器对音符盒下垫方块对照表"""
MC_EILLES_RTJE12_INSTRUMENT_REPLACE_TABLE: Dict[str, str] = {
"note.iron_xylophone": "note.xylophone",
"note.cow_bell": "note.xylophone",
"note.didgeridoo": "note.guitar",
"note.bit": "note.harp",
"note.banjo": "note.flute",
"note.pling": "note.harp",
}
"""在 Minecraft JE 1.12 ~ JE 1.14 的版本中,部分乐器是没有的,这是金羿的乐器替换表"""
MC_EILLES_RTBETA_INSTRUMENT_REPLACE_TABLE: Dict[str, str] = {
# lt je 12
"note.bell": "note.harp",
"note.flute": "note.harp",
"note.chime": "note.harp",
"note.guitar": "note.bass",
"note.xylophone": "note.hat",
# rt je 12
"note.iron_xylophone": "note.hat",
"note.cow_bell": "note.ha",
"note.didgeridoo": "note.bass",
"note.bit": "note.harp",
"note.banjo": "note.harp",
"note.pling": "note.harp",
}
"""在 Minecraft JE Beta1.2 / BE 0.13.0 ~ JE 1.12 / BE 1.13.0 的版本中,部分乐器是没有的,这是金羿的乐器替换表"""
# Midi对MC通用对照表 # Midi对MC通用对照表
MM_INSTRUMENT_RANGE_TABLE: Dict[str, Tuple[Tuple[int, int], int]] = { MM_INSTRUMENT_RANGE_TABLE: Dict[str, Tuple[Tuple[int, int], int]] = {

View File

@ -163,6 +163,7 @@ class MusicSequence:
midi_music_name: str, midi_music_name: str,
mismatch_error_ignorance: bool = True, mismatch_error_ignorance: bool = True,
speed_multiplier: float = 1, speed_multiplier: float = 1,
default_midi_program: int = MIDI_DEFAULT_PROGRAM_VALUE,
default_tempo: int = mido.midifiles.midifiles.DEFAULT_TEMPO, default_tempo: int = mido.midifiles.midifiles.DEFAULT_TEMPO,
pitched_note_referance_table: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE, pitched_note_referance_table: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE,
percussion_note_referance_table: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE, percussion_note_referance_table: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE,
@ -184,6 +185,8 @@ class MusicSequence:
是否在导入时忽略音符不匹配错误 是否在导入时忽略音符不匹配错误
speed_multiplier: float speed_multiplier: float
音乐播放速度倍数 音乐播放速度倍数
default_midi_program: int
默认的MIDI Program值
default_tempo: int default_tempo: int
默认的MIDI TEMPO值 默认的MIDI TEMPO值
pitched_note_referance_table: Dict[int, Tuple[str, int]] pitched_note_referance_table: Dict[int, Tuple[str, int]]
@ -196,7 +199,10 @@ class MusicSequence:
声像偏移拟合函数 声像偏移拟合函数
deviation: float deviation: float
全曲音调偏移值 全曲音调偏移值
note_referance_table_replacement: Dict[str, str]
MC 音符乐器替换表如果在不希望使用某种 MC 乐器的时候进行替换
""" """
if mido_file: if mido_file:
( (
note_channels, note_channels,
@ -205,9 +211,9 @@ class MusicSequence:
) = cls.to_music_note_channels( ) = cls.to_music_note_channels(
midi=mido_file, midi=mido_file,
speed=speed_multiplier, speed=speed_multiplier,
default_program_value=-1, # TODO 默认音色可调
pitched_note_rtable=pitched_note_referance_table, pitched_note_rtable=pitched_note_referance_table,
percussion_note_rtable=percussion_note_referance_table, percussion_note_rtable=percussion_note_referance_table,
default_program_value=default_midi_program,
default_tempo_value=default_tempo, default_tempo_value=default_tempo,
vol_processing_function=volume_processing_function, vol_processing_function=volume_processing_function,
ignore_mismatch_error=mismatch_error_ignorance, ignore_mismatch_error=mismatch_error_ignorance,
@ -806,6 +812,8 @@ class MusicSequence:
打击乐器Midi-MC对照表 打击乐器Midi-MC对照表
vol_processing_function: Callable[[float], float] vol_processing_function: Callable[[float], float]
声像偏移拟合函数 声像偏移拟合函数
note_rtable_replacement: Dict[str, str]
音符名称替换表此表用于对 Minecraft 乐器名称进行替换而非 Midi Program 的替换
Returns Returns
------- -------
@ -976,12 +984,14 @@ class MidiConvert(MusicSequence):
midi_name: str, midi_name: str,
ignore_mismatch_error: bool = True, ignore_mismatch_error: bool = True,
playment_speed: float = 1, playment_speed: float = 1,
default_midi_program_value: int = MIDI_DEFAULT_PROGRAM_VALUE,
default_tempo_value: int = mido.midifiles.midifiles.DEFAULT_TEMPO, default_tempo_value: int = mido.midifiles.midifiles.DEFAULT_TEMPO,
pitched_note_rtable: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE, pitched_note_rtable: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE,
percussion_note_rtable: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE, percussion_note_rtable: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE,
enable_old_exe_format: bool = False, enable_old_exe_format: bool = False,
minimum_volume: float = 0.1, minimum_volume: float = 0.1,
vol_processing_function: FittingFunctionType = natural_curve, vol_processing_function: FittingFunctionType = natural_curve,
pitch_deviation: float = 0,
note_rtable_replacement: Dict[str, str] = {}, note_rtable_replacement: Dict[str, str] = {},
): ):
""" """
@ -993,12 +1003,14 @@ class MidiConvert(MusicSequence):
需要处理的midi对象 需要处理的midi对象
midi_name: str midi_name: str
此音乐之名称 此音乐之名称
ignore_mismatch_error bool ignore_mismatch_error: bool
是否在导入时忽略音符不匹配错误 是否在导入时忽略音符不匹配错误
playment_speed: float playment_speed: float
音乐播放速度倍数 音乐播放速度倍数
default_midi_program_value: int
默认的 MIDI Program Midi 文件没有指定 Program 值时使用此值
default_tempo_value: int default_tempo_value: int
默认的MIDI TEMPO值 默认的 MIDI TEMPO 同上理
pitched_note_rtable: Dict[int, Tuple[str, int]] pitched_note_rtable: Dict[int, Tuple[str, int]]
乐音乐器Midi-MC对照表 乐音乐器Midi-MC对照表
percussion_note_rtable: Dict[int, Tuple[str, int]] percussion_note_rtable: Dict[int, Tuple[str, int]]
@ -1009,6 +1021,10 @@ class MidiConvert(MusicSequence):
最小播放音量 最小播放音量
vol_processing_function: Callable[[float], float] vol_processing_function: Callable[[float], float]
声像偏移拟合函数 声像偏移拟合函数
pitch_deviation: float
音调偏移量手动指定全曲音调偏移量
note_rtable_replacement: Dict[str, str]
Minecraft 音符 ID 替换表可在不希望使用某些乐器的时候进行替换
""" """
cls.enable_old_exe_format: bool = enable_old_exe_format cls.enable_old_exe_format: bool = enable_old_exe_format
@ -1027,12 +1043,13 @@ class MidiConvert(MusicSequence):
midi_music_name=midi_name, midi_music_name=midi_name,
mismatch_error_ignorance=ignore_mismatch_error, mismatch_error_ignorance=ignore_mismatch_error,
speed_multiplier=playment_speed, speed_multiplier=playment_speed,
default_midi_program=default_midi_program_value,
default_tempo=default_tempo_value, default_tempo=default_tempo_value,
pitched_note_referance_table=pitched_note_rtable, pitched_note_referance_table=pitched_note_rtable,
percussion_note_referance_table=percussion_note_rtable, percussion_note_referance_table=percussion_note_rtable,
minimum_vol=minimum_volume, minimum_vol=minimum_volume,
volume_processing_function=vol_processing_function, volume_processing_function=vol_processing_function,
deviation=0, # 加么?感觉不加也没问题……? deviation=pitch_deviation,
note_referance_table_replacement=note_rtable_replacement, note_referance_table_replacement=note_rtable_replacement,
) )
@ -1042,25 +1059,29 @@ class MidiConvert(MusicSequence):
midi_file_path: str, midi_file_path: str,
mismatch_error_ignorance: bool = True, mismatch_error_ignorance: bool = True,
play_speed: float = 1, play_speed: float = 1,
default_midi_program: int = MIDI_DEFAULT_PROGRAM_VALUE,
default_tempo: int = mido.midifiles.midifiles.DEFAULT_TEMPO, default_tempo: int = mido.midifiles.midifiles.DEFAULT_TEMPO,
pitched_note_table: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE, pitched_note_table: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE,
percussion_note_table: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE, percussion_note_table: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE,
old_exe_format: bool = False, old_exe_format: bool = False,
min_volume: float = 0.1, min_volume: float = 0.1,
vol_processing_func: FittingFunctionType = natural_curve, vol_processing_func: FittingFunctionType = natural_curve,
music_pitch_deviation: float = 0,
note_table_replacement: Dict[str, str] = {}, note_table_replacement: Dict[str, str] = {},
): ):
""" """
直接输入文件地址midi文件读入 直接输入文件地址 midi 文件读入
Parameters Parameters
---------- ----------
midi_file_path: str midi_file_path: str
midi文件地址 midi文件地址
mismatch_error_ignorance bool mismatch_error_ignorance: bool
是否在导入时忽略音符不匹配错误 是否在导入时忽略音符不匹配错误
play_speed: float play_speed: float
音乐播放速度倍数 音乐播放速度倍数
default_midi_program: int
默认的 MIDI Program Midi 文件没有指定 Program 值时使用此值
default_tempo: int default_tempo: int
默认的MIDI TEMPO值 默认的MIDI TEMPO值
pitched_note_table: Dict[int, Tuple[str, int]] pitched_note_table: Dict[int, Tuple[str, int]]
@ -1073,6 +1094,10 @@ class MidiConvert(MusicSequence):
最小播放音量 最小播放音量
vol_processing_func: Callable[[float], float] vol_processing_func: Callable[[float], float]
声像偏移拟合函数 声像偏移拟合函数
music_pitch_deviation: float
全曲音符的音调偏移量
note_table_replacement: Dict[str, str]
音符 ID 替换表用于在不希望使用某些 Minecraft 乐器的时候替换之
""" """
midi_music_name = os.path.splitext(os.path.basename(midi_file_path))[0].replace( midi_music_name = os.path.splitext(os.path.basename(midi_file_path))[0].replace(
@ -1089,12 +1114,14 @@ class MidiConvert(MusicSequence):
midi_name=midi_music_name, midi_name=midi_music_name,
ignore_mismatch_error=mismatch_error_ignorance, ignore_mismatch_error=mismatch_error_ignorance,
playment_speed=play_speed, playment_speed=play_speed,
default_midi_program_value=default_midi_program,
default_tempo_value=default_tempo, default_tempo_value=default_tempo,
pitched_note_rtable=pitched_note_table, pitched_note_rtable=pitched_note_table,
percussion_note_rtable=percussion_note_table, percussion_note_rtable=percussion_note_table,
enable_old_exe_format=old_exe_format, enable_old_exe_format=old_exe_format,
minimum_volume=min_volume, minimum_volume=min_volume,
vol_processing_function=vol_processing_func, vol_processing_function=vol_processing_func,
pitch_deviation=music_pitch_deviation,
note_rtable_replacement=note_table_replacement, note_rtable_replacement=note_table_replacement,
) )
except (ValueError, TypeError) as E: except (ValueError, TypeError) as E:
@ -1138,7 +1165,7 @@ class MidiConvert(MusicSequence):
| `%%%` | 当前进度比率 | | `%%%` | 当前进度比率 |
| `_` | 用以表示进度条占位| | `_` | 用以表示进度条占位|
""" """
perEach = max_score / pgs_style.count("_") per_value_in_each = max_score / pgs_style.count("_")
"""每个进度条代表的分值""" """每个进度条代表的分值"""
result: List[MineCommand] = [] result: List[MineCommand] = []
@ -1337,7 +1364,7 @@ class MidiConvert(MusicSequence):
self.execute_cmd_head.format( self.execute_cmd_head.format(
r"@a[scores={" r"@a[scores={"
+ scoreboard_name + scoreboard_name
+ f"={int(i * perEach)}..{math.ceil((i + 1) * perEach)}" + f"={int(i * per_value_in_each)}..{math.ceil((i + 1) * per_value_in_each)}"
+ r"}]" + r"}]"
) )
+ r'titleraw @s actionbar {"rawtext":[{"text":"' + r'titleraw @s actionbar {"rawtext":[{"text":"'

View File

@ -271,6 +271,7 @@ def midi_msgs_to_minenote(
:param play_speed: float 曲目播放速度 :param play_speed: float 曲目播放速度
:param midi_reference_table: Dict[int, str] 转换对照表 :param midi_reference_table: Dict[int, str] 转换对照表
:param volume_proccessing_method_: Callable[[float], float] 音量处理函数 :param volume_proccessing_method_: Callable[[float], float] 音量处理函数
:param note_table_replacement: Dict[str, str] 音符替换表定义 Minecraft 音符字串的替换
:return MineNote我的世界音符对象 :return MineNote我的世界音符对象
""" """

View File

@ -123,14 +123,7 @@ msc_cvt = Musicreater.experiment.FutureMidiConvertJavaE.from_midi_file(
input("midi路径"), input("midi路径"),
play_speed=float(input("播放速度:")), play_speed=float(input("播放速度:")),
old_exe_format=True, old_exe_format=True,
note_table_replacement={ note_table_replacement=Musicreater.MC_EILLES_RTJE12_INSTRUMENT_REPLACE_TABLE,
"note.iron_xylophone": "note.xylophone",
"note.cow_bell": "note.xylophone",
"note.didgeridoo": "note.guitar",
"note.bit": "note.harp",
"note.banjo": "note.flute",
"note.pling": "note.harp",
},
# pitched_note_table=Musicreater.MM_NBS_PITCHED_INSTRUMENT_TABLE, # pitched_note_table=Musicreater.MM_NBS_PITCHED_INSTRUMENT_TABLE,
) )