From d7e3c62deb80468a31086dd7554635ebbda823da Mon Sep 17 00:00:00 2001 From: EillesWan Date: Tue, 23 Jan 2024 17:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B1=BB=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Musicreater/__init__.py | 4 ++-- Musicreater/main.py | 28 ++++++++++------------------ Musicreater/types.py | 16 ++++++++++++++-- Musicreater/utils.py | 6 +++--- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Musicreater/__init__.py b/Musicreater/__init__.py index d14d22d..d39d3d1 100644 --- a/Musicreater/__init__.py +++ b/Musicreater/__init__.py @@ -17,8 +17,8 @@ Terms & Conditions: License.md in the root directory # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md -__version__ = "1.7.0" -__vername__ = "更高的自定义化程度" +__version__ = "1.7.1" +__vername__ = "更高的自定义化程度—修复类型定义的重复问题" __author__ = ( ("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray"), diff --git a/Musicreater/main.py b/Musicreater/main.py index 9dddbfb..fbd97e6 100644 --- a/Musicreater/main.py +++ b/Musicreater/main.py @@ -77,13 +77,13 @@ class MidiConvert: midi: VoidMido """MidiFile对象""" - pitched_note_reference_table: Dict[int, Tuple[str, int]] + pitched_note_reference_table: MidiInstrumentTableType """乐音乐器Midi-MC对照表""" - percussion_note_referrence_table: Dict[int, Tuple[str, int]] + percussion_note_referrence_table: MidiInstrumentTableType """打击乐器Midi-MC对照表""" - volume_processing_function: Callable[[float], float] + volume_processing_function: FittingFunctionType """音量处理函数""" midi_music_name: str @@ -112,13 +112,9 @@ class MidiConvert: midi_obj: VoidMido, midi_name: str, enable_old_exe_format: bool = False, - pitched_note_rtable: Dict[ - int, Tuple[str, int] - ] = MM_TOUCH_PITCHED_INSTRUMENT_TABLE, - percussion_note_rtable: Dict[ - int, Tuple[str, int] - ] = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE, - vol_processing_function: Callable[[float], float] = natural_curve, + pitched_note_rtable: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE, + percussion_note_rtable: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE, + vol_processing_function: FittingFunctionType = natural_curve, ): """ 简单的midi转换类,将midi对象转换为我的世界结构或者包 @@ -162,13 +158,9 @@ class MidiConvert: cls, midi_file_path: str, old_exe_format: bool = False, - pitched_note_table: Dict[ - int, Tuple[str, int] - ] = MM_TOUCH_PITCHED_INSTRUMENT_TABLE, - percussion_note_table: Dict[ - int, Tuple[str, int] - ] = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE, - vol_processing_func: Callable[[float], float] = natural_curve, + pitched_note_table: MidiInstrumentTableType = MM_TOUCH_PITCHED_INSTRUMENT_TABLE, + percussion_note_table: MidiInstrumentTableType = MM_TOUCH_PERCUSSION_INSTRUMENT_TABLE, + vol_processing_func: FittingFunctionType = natural_curve, ): """ 直接输入文件地址,将midi文件读入 @@ -211,7 +203,7 @@ class MidiConvert: self, max_score: int, scoreboard_name: str, - progressbar_style: tuple = DEFAULT_PROGRESSBAR_STYLE, + progressbar_style: ProgressBarStyleType = DEFAULT_PROGRESSBAR_STYLE, ) -> List[SingleCommand]: """ 生成进度条 diff --git a/Musicreater/types.py b/Musicreater/types.py index 3a09fff..cb3b9f2 100644 --- a/Musicreater/types.py +++ b/Musicreater/types.py @@ -16,13 +16,25 @@ Terms & Conditions: License.md in the root directory # Email TriM-Organization@hotmail.com # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md -from typing import Any, Dict, List, Literal, Optional, Tuple, Union +from typing import Any, Dict, List, Literal, Optional, Tuple, Union, Iterable, Sequence, Mapping, Callable import mido from .subclass import SingleNote -ProgressStyle = Tuple[str, Tuple[str, str]] +MidiNoteNameTableType = Mapping[int, Tuple[str, ...]] +""" +Midi音符名称对照表类型 +""" + +MidiInstrumentTableType = Mapping[int, Tuple[str, int]] +""" +Midi乐器对照表类型 +""" + +FittingFunctionType = Callable[[float], float] + +ProgressBarStyleType = Tuple[str, Tuple[str, str]] """ 进度条样式类型 """ diff --git a/Musicreater/utils.py b/Musicreater/utils.py index fdebdc7..14a6a51 100644 --- a/Musicreater/utils.py +++ b/Musicreater/utils.py @@ -21,7 +21,7 @@ import random from .constants import MM_INSTRUMENT_DEVIATION_TABLE, MC_INSTRUMENT_BLOCKS_TABLE from .subclass import SingleNote -from typing import Any, Dict, Tuple, Optional, Callable, Literal, Union +from .types import Any, Dict, Tuple, Optional, Callable, Literal, Union, MidiInstrumentTableType def mctick2timestr(mc_tick: int) -> str: @@ -47,7 +47,7 @@ def empty_midi_channels(channel_count: int = 17, staff: Any = {}) -> Dict[int, A def inst_to_sould_with_deviation( instrumentID: int, - reference_table: Dict[int, Tuple[str, int]], + reference_table: MidiInstrumentTableType, default_instrument: str = "note.flute", default_deviation: Optional[int] = 5, ) -> Tuple[str, int]: @@ -133,7 +133,7 @@ def straight_line(vol: float) -> float: def note_to_command_parameters( note_: SingleNote, - reference_table: Dict[int, Tuple[str, int]], + reference_table: MidiInstrumentTableType, volume_percentage: float = 1, volume_processing_method: Callable[[float], float] = natural_curve, ) -> Tuple[str, float, float, Union[float, Literal[None]],]: