From 00c445f7ad2732364c4db419e1814469ee226b66 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Mon, 2 Mar 2026 11:58:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=83=A8=E5=88=86=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E5=88=87=E6=8D=A2=E5=88=B0=E5=AD=A6=E6=A0=A1?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builtin_plugins/to_commands/main.py | 19 ++++++------ .../to_commands/progressbar.py | 2 +- README.md | 1 + docs/编写插件.md | 4 +-- old-things/Musicreater/old_main.py | 30 +++++++++++++++---- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Musicreater/builtin_plugins/to_commands/main.py b/Musicreater/builtin_plugins/to_commands/main.py index 407cc1e..8b93b55 100644 --- a/Musicreater/builtin_plugins/to_commands/main.py +++ b/Musicreater/builtin_plugins/to_commands/main.py @@ -109,6 +109,7 @@ class NoteDataConvert2CommandPlugin(LibraryPluginBase): # 暂时没有适配动画内容和替换顺序 # 金羿正在处理这个,不需要改 # 但是返回值和接口内容不会变,直接用即可 + # @staticmethod def generate_progressbar( max_score: int, @@ -320,21 +321,13 @@ class NoteDataConvert2CommandPlugin(LibraryPluginBase): for i in range(orignal_style_string.count("_")): npg_stl = ( - orignal_style_string.replace("_", progressbar_style.progress_played, i + 1) - .replace("_", progressbar_style.progress_toplay) - .replace("%%N", music_name) + orignal_style_string .replace( "%%s", '"},{"score":{"name":"*","objective":"' + scoreboard_name + '"}},{"text":"', ) - .replace( - "%%%", - '"},{"score":{"name":"*","objective":"' - + sbn_pc - + 'PercT"}},{"text":"%', - ) .replace( "%%t", '"},{"score":{"name":"*","objective":"{-}TMinT"}},{"text":":"},' @@ -342,6 +335,14 @@ class NoteDataConvert2CommandPlugin(LibraryPluginBase): "{-}", sbn_pc ), ) + .replace("%%N", music_name) + .replace( + "%%%", + '"},{"score":{"name":"*","objective":"' + + sbn_pc + + 'PercT"}},{"text":"%', + ).replace("_", progressbar_style.progress_played, i + 1) + .replace("_", progressbar_style.progress_toplay) ) result.append( MineCommand( diff --git a/Musicreater/builtin_plugins/to_commands/progressbar.py b/Musicreater/builtin_plugins/to_commands/progressbar.py index 09da8cc..f482570 100644 --- a/Musicreater/builtin_plugins/to_commands/progressbar.py +++ b/Musicreater/builtin_plugins/to_commands/progressbar.py @@ -64,7 +64,7 @@ class ProgressBarStyle: | `%^t` | 曲目总时长 | | `%%%` | 当前进度比率 | | `_` | 用以表示进度条占位| - | `%*%` | 指定*的动画内容 |a + | `%*%` | 指定*的动画内容 | Parameters ------------ diff --git a/README.md b/README.md index 9f43211..bebcc64 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ - 感谢 **雨**\ 反馈在新版本的指令格式下,计分板播放器的附加包无法播放的问题。 - 感谢 **梦幻duang**\ 为我们提供 Java 1.12.2 版本命令格式参考。 - 感谢 [_Open Note Block Studio_](https://github.com/OpenNBS/NoteBlockStudio) 项目的开发为我们提供持续的追赶动力。 +- 感谢 **启航与凡凡**\ 找到 **音·创 v2** 版本音符序列文件解码的错误并指出修正方式。 > 感谢广大群友为此库提供的测试和建议等 > 若您对我们有所贡献但您的名字没有出现在此列表中,请联系我们! diff --git a/docs/编写插件.md b/docs/编写插件.md index 4da9bd0..2097183 100644 --- a/docs/编写插件.md +++ b/docs/编写插件.md @@ -32,7 +32,7 @@ Email [TriM-Organization@hotmail.com](mailto:TriM-Organization@hotmail.com) 这就意味着,承载插件的模块本质上可以是多个 Python 的 `.py` 文件组成的,带有 `__init__.py` 的一个文件夹; 或者是一个简单的 `.py` 文件。 -我们有这种共识:大家已经知道了模块的相关知识,后面的教程中你已经理解 **音·创 v3** 插件和 Python 模块的区别。 +我们有这种共识:大家已经知道了模块的相关知识,后面的教程中你将会理解 **音·创 v3** 插件是什么东西,以及它和 Python 模块的关联和区别。 ## 开始动笔 @@ -41,7 +41,7 @@ Email [TriM-Organization@hotmail.com](mailto:TriM-Organization@hotmail.com) 如果插件需要配置项,则需进行此节。 从 `Musicreater.plugins` 导入 `PluginConfig` 类,并从此继承一个类,且须用 dataclass 装饰器来注册之:这就成为了一个插件的配置类。 -_对于这个 `dataclass` “数据类”的使用方式,可以阅读 dataclass 的官方文档,或者直接在实例后面打个 `.`,直接看看能干哈子_ +_对于这个 `dataclass` “数据类”的使用方式,可以阅读 dataclass 的官方文档,或者直接在实例后面打个 `.`,让代码提示告诉你它能干什么_ ```python from Musicreater.plugins import PluginConfig diff --git a/old-things/Musicreater/old_main.py b/old-things/Musicreater/old_main.py index a536b3e..2f6d6de 100644 --- a/old-things/Musicreater/old_main.py +++ b/old-things/Musicreater/old_main.py @@ -292,7 +292,7 @@ class MusicSequence: if bytes_buffer_in[:4] in (b"MSQ!", b"MSQ$"): - note_format_v3 = bytes_buffer_in[0] == b"MSQ$" + note_format_v3 = bytes_buffer_in[:4] == b"MSQ$" group_1 = int.from_bytes(bytes_buffer_in[4:6], "big", signed=False) group_2 = int.from_bytes(bytes_buffer_in[6:8], "big", signed=False) @@ -446,6 +446,16 @@ class MusicSequence: _t6_buffer = _t2_buffer = 0 _channel_inst_chart: Dict[str, Dict[str, int]] = {} + """ + 乐器对应通道的表 + { + 乐器名: { + "CNT": 当前通道的音符数量, + "INDEX": 当前乐器在通道中的索引 + } + } + 也就是说,一个通道可以对应多个乐器(多个乐器可能分配到同一个通道) + """ channels_: MineNoteChannelType = enumerated_stuffcopy_dictionary(staff=[]) for i in range(total_note_count): @@ -503,17 +513,27 @@ class MusicSequence: "所截取的音符码:", bytes_buffer_in[stt_index:end_index] ) from _err + # 按照乐器分配通道 if _read_note.sound_name in _channel_inst_chart: + # 如果本身已经有这个乐器了,那就直接加一个计数就可以了 _channel_inst_chart[_read_note.sound_name]["CNT"] += 1 else: + # 如果没有这个乐器 if len(_channel_inst_chart) >= 16: + # 已经超过了 16 个乐器,当前通道数量是装不下的 + # 那就找一个音符数量最少的通道,把这个通道引用为 + # 当前这个乐器的通道 _channel_inst_chart[_read_note.sound_name] = min( _channel_inst_chart.values(), key=lambda x: x["CNT"] ) # 此处是指针式内存引用 - _channel_inst_chart[_read_note.sound_name] = { - "CNT": 1, - "INDEX": len(_channel_inst_chart), - } + _channel_inst_chart[_read_note.sound_name]["CNT"] += 1 + else: + # 没有超过 16 个乐器,那就加! + _channel_inst_chart[_read_note.sound_name] = { + "CNT": 1, + "INDEX": len(_channel_inst_chart), + } + # 把音符添加到对应的通道里边 channels_[_channel_inst_chart[_read_note.sound_name]["INDEX"]].append( _read_note )