From 041c64ff65ffb3ed387971eeac197b9875e29db2 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Sat, 3 Feb 2024 16:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96example=E7=BB=93=E6=9E=84?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81mcstructure=E7=9A=84=E8=AE=A1?= =?UTF-8?q?=E5=88=86=E6=9D=BF=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + Musicreater/__init__.py | 8 +- Musicreater/constants.py | 4 +- Musicreater/exceptions.py | 4 +- Musicreater/experiment.py | 4 +- Musicreater/magicmain.py | 4 +- Musicreater/main.py | 6 +- Musicreater/plugin/__init__.py | 55 +++++++- Musicreater/plugin/addonpack/__init__.py | 4 +- Musicreater/plugin/addonpack/main.py | 4 +- Musicreater/plugin/archive.py | 4 +- Musicreater/plugin/bdx.py | 27 ++-- Musicreater/plugin/bdxfile/__init__.py | 4 +- Musicreater/plugin/bdxfile/main.py | 4 +- Musicreater/plugin/common.py | 4 +- Musicreater/plugin/main.py | 4 +- Musicreater/plugin/mcstructfile/__init__.py | 7 +- Musicreater/plugin/mcstructfile/main.py | 83 +++++++++++- Musicreater/plugin/mcstructure.py | 4 +- Musicreater/plugin/noteblock.py | 4 +- Musicreater/plugin/schematic.py | 4 +- Musicreater/plugin/schematic/__init__.py | 4 +- Musicreater/plugin/schematic/main.py | 4 +- Musicreater/plugin/websocket.py | 4 +- Musicreater/plugin/websocket/__init__.py | 4 +- Musicreater/plugin/websocket/main.py | 4 +- Musicreater/previous.py | 4 +- Musicreater/subclass.py | 4 +- Musicreater/types.py | 4 +- Musicreater/utils.py | 4 +- Packer/MSCT_Packer.py | 70 ++++++++++ docs/转换乐器对照表.md | 4 +- example.py | 142 +++++++++++++++----- example_mcstructure.py | 11 -- example_mcstructure_rcd.py | 10 -- example_mcstructure_rcd_future.py | 12 -- resources/音乐测试片段版权声明.txt | 2 +- 37 files changed, 380 insertions(+), 152 deletions(-) create mode 100644 Packer/MSCT_Packer.py delete mode 100644 example_mcstructure.py delete mode 100644 example_mcstructure_rcd.py delete mode 100644 example_mcstructure_rcd_future.py diff --git a/.gitignore b/.gitignore index e819f29..24180ea 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ /utils test.py RES.txt +/MSCT_Packer.py +/Packer/*.MPK +/Packer/checksum.txt # Byte-compiled / optimized __pycache__/ diff --git a/Musicreater/__init__.py b/Musicreater/__init__.py index 7dc30a7..df5b74f 100644 --- a/Musicreater/__init__.py +++ b/Musicreater/__init__.py @@ -5,8 +5,8 @@ Musicreater(音·创) A free open source library used for convert midi file into formats that is suitable for **Minecraft**. -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory @@ -17,8 +17,8 @@ Terms & Conditions: License.md in the root directory # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md -__version__ = "1.7.2.1" -__vername__ = "修复指令错误问题" +__version__ = "1.7.3" +__vername__ = "功能结构化" __author__ = ( ("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray"), diff --git a/Musicreater/constants.py b/Musicreater/constants.py index 714c1d4..5f37ecb 100644 --- a/Musicreater/constants.py +++ b/Musicreater/constants.py @@ -5,8 +5,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/exceptions.py b/Musicreater/exceptions.py index 8550f75..4318d04 100644 --- a/Musicreater/exceptions.py +++ b/Musicreater/exceptions.py @@ -5,8 +5,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/experiment.py b/Musicreater/experiment.py index a754e01..375a223 100644 --- a/Musicreater/experiment.py +++ b/Musicreater/experiment.py @@ -5,8 +5,8 @@ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/magicmain.py b/Musicreater/magicmain.py index 7075397..1d5fecc 100644 --- a/Musicreater/magicmain.py +++ b/Musicreater/magicmain.py @@ -22,8 +22,8 @@ Musicreater (音·创) A free open source library used for convert midi file into formats that is suitable for **Minecraft**. -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 ../License.md Terms & Conditions: ../License.md diff --git a/Musicreater/main.py b/Musicreater/main.py index 92f471d..7fc7b91 100644 --- a/Musicreater/main.py +++ b/Musicreater/main.py @@ -7,8 +7,8 @@ Musicreater (音·创) A free open source library used for convert midi file into formats that is suitable for **Minecraft**. -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory @@ -724,7 +724,7 @@ class MidiConvert: command_channels.append(this_channel) self.music_tick_num = max_score - return (command_channels, command_amount, max_score) + return command_channels, command_amount, max_score def to_command_list_in_delay( self, diff --git a/Musicreater/plugin/__init__.py b/Musicreater/plugin/__init__.py index 1b9a73e..c9a7506 100644 --- a/Musicreater/plugin/__init__.py +++ b/Musicreater/plugin/__init__.py @@ -2,8 +2,8 @@ """ 存放非音·创本体的附加内容(插件?) -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory @@ -15,8 +15,57 @@ Terms & Conditions: License.md in the root directory __all__ = [ + # 通用 "ConvertConfig", + "bottem_side_length_of_smallest_square_bottom_box", + # 打包 + "compress_zipfile", + "behavior_mcpack_manifest", + # MCSTRUCTURE 函数 + "antiaxis", + "forward_IER", + "command_statevalue", + "form_note_block_in_NBT_struct", + "form_repeater_in_NBT_struct", + "form_command_block_in_NBT_struct", + "commands_to_structure", + "commands_to_redstone_delay_structure", + # MCSTRUCTURE 常量 + "AXIS_PARTICULAR_VALUE", + "COMPABILITY_VERSION_117", + "COMPABILITY_VERSION_119", + # BDX 函数 + "bdx_move", + "form_command_block_in_BDX_bytes", + "commands_to_BDX_bytes", + # BDX 常量 + "BDX_MOVE_KEY", ] __author__ = (("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray")) -from .main import * +from .main import ConvertConfig + +from .archive import compress_zipfile, behavior_mcpack_manifest + +from .bdx import ( + BDX_MOVE_KEY, + bdx_move, + form_command_block_in_BDX_bytes, + commands_to_BDX_bytes, +) + +from .common import bottem_side_length_of_smallest_square_bottom_box + +from .mcstructure import ( + antiaxis, + forward_IER, + AXIS_PARTICULAR_VALUE, + COMPABILITY_VERSION_119, + COMPABILITY_VERSION_117, + command_statevalue, + form_note_block_in_NBT_struct, + form_repeater_in_NBT_struct, + form_command_block_in_NBT_struct, + commands_to_structure, + commands_to_redstone_delay_structure, +) diff --git a/Musicreater/plugin/addonpack/__init__.py b/Musicreater/plugin/addonpack/__init__.py index 5364a40..8fe5539 100644 --- a/Musicreater/plugin/addonpack/__init__.py +++ b/Musicreater/plugin/addonpack/__init__.py @@ -2,8 +2,8 @@ """ 用以生成附加包的附加功能 -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/addonpack/main.py b/Musicreater/plugin/addonpack/main.py index 8d5069c..75b2a04 100644 --- a/Musicreater/plugin/addonpack/main.py +++ b/Musicreater/plugin/addonpack/main.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/archive.py b/Musicreater/plugin/archive.py index d13fd2f..d5b9fbb 100644 --- a/Musicreater/plugin/archive.py +++ b/Musicreater/plugin/archive.py @@ -5,8 +5,8 @@ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/bdx.py b/Musicreater/plugin/bdx.py index 407af4d..8677164 100644 --- a/Musicreater/plugin/bdx.py +++ b/Musicreater/plugin/bdx.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory @@ -21,7 +21,7 @@ from ..constants import x, y, z from ..subclass import SingleCommand from .common import bottem_side_length_of_smallest_square_bottom_box -bdx_key = { +BDX_MOVE_KEY = { "x": [b"\x0f", b"\x0e", b"\x1c", b"\x14", b"\x15"], "y": [b"\x11", b"\x10", b"\x1d", b"\x16", b"\x17"], "z": [b"\x13", b"\x12", b"\x1e", b"\x18", b"\x19"], @@ -34,21 +34,18 @@ def bdx_move(axis: str, value: int): if value == 0: return b"" if abs(value) == 1: - return bdx_key[axis][0 if value == -1 else 1] + return BDX_MOVE_KEY[axis][0 if value == -1 else 1] pointer = sum( [ - 1 if i else 0 - for i in ( - value != -1, - value < -1 or value > 1, - value < -128 or value > 127, - value < -32768 or value > 32767, - ) + value != -1, + value < -1 or value > 1, + value < -128 or value > 127, + value < -32768 or value > 32767, ] ) - return bdx_key[axis][pointer] + value.to_bytes( + return BDX_MOVE_KEY[axis][pointer] + value.to_bytes( 2 ** (pointer - 2), "big", signed=True ) @@ -198,13 +195,13 @@ def commands_to_BDX_bytes( ): now_z -= 1 if z_forward else -1 z_forward = not z_forward - _bytes += bdx_key[x][1] + _bytes += BDX_MOVE_KEY[x][1] now_x += 1 else: - _bytes += bdx_key[z][int(z_forward)] + _bytes += BDX_MOVE_KEY[z][int(z_forward)] else: - _bytes += bdx_key[y][int(y_forward)] + _bytes += BDX_MOVE_KEY[y][int(y_forward)] return ( _bytes, diff --git a/Musicreater/plugin/bdxfile/__init__.py b/Musicreater/plugin/bdxfile/__init__.py index 87b38ca..f9b9f8f 100644 --- a/Musicreater/plugin/bdxfile/__init__.py +++ b/Musicreater/plugin/bdxfile/__init__.py @@ -2,8 +2,8 @@ """ 用以生成BDX结构文件的附加功能 -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/bdxfile/main.py b/Musicreater/plugin/bdxfile/main.py index 1665dde..41db20b 100644 --- a/Musicreater/plugin/bdxfile/main.py +++ b/Musicreater/plugin/bdxfile/main.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/common.py b/Musicreater/plugin/common.py index 16bea9a..8fb350c 100644 --- a/Musicreater/plugin/common.py +++ b/Musicreater/plugin/common.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/main.py b/Musicreater/plugin/main.py index d2d692d..83d6f94 100644 --- a/Musicreater/plugin/main.py +++ b/Musicreater/plugin/main.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/mcstructfile/__init__.py b/Musicreater/plugin/mcstructfile/__init__.py index 91b826f..cb43943 100644 --- a/Musicreater/plugin/mcstructfile/__init__.py +++ b/Musicreater/plugin/mcstructfile/__init__.py @@ -2,8 +2,8 @@ """ 用以生成单个mcstructure文件的附加功能 -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory @@ -17,7 +17,8 @@ Terms & Conditions: License.md in the root directory __all__ = [ "to_mcstructure_file_in_delay", "to_mcstructure_file_in_repeater", + "to_mcstructure_file_in_score", ] __author__ = (("金羿", "Eilles Wan"),) -from .main import to_mcstructure_file_in_delay, to_mcstructure_file_in_repeater +from .main import to_mcstructure_file_in_delay, to_mcstructure_file_in_repeater, to_mcstructure_file_in_score diff --git a/Musicreater/plugin/mcstructfile/main.py b/Musicreater/plugin/mcstructfile/main.py index 057e522..9b8f29a 100644 --- a/Musicreater/plugin/mcstructfile/main.py +++ b/Musicreater/plugin/mcstructfile/main.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory @@ -14,9 +14,10 @@ Terms & Conditions: License.md in the root directory import os from typing import Literal -from ...exceptions import CommandFormatError +# from ...exceptions import CommandFormatError from ...main import MidiConvert from ..main import ConvertConfig +from ...subclass import SingleCommand from ..mcstructure import ( COMPABILITY_VERSION_117, COMPABILITY_VERSION_119, @@ -47,7 +48,7 @@ def to_mcstructure_file_in_delay( Returns ------- - tuple[tuple[int,]结构大小, int音乐总延迟] + tuple[tuple[int,int,int]结构大小, int音乐总延迟] """ compability_ver = ( @@ -80,6 +81,78 @@ def to_mcstructure_file_in_delay( return size, max_delay +def to_mcstructure_file_in_score( + midi_cvt: MidiConvert, + data_cfg: ConvertConfig, + scoreboard_name: str = "mscplay", + auto_reset: bool = False, + max_height: int = 64, +): + """ + 将midi以延迟播放器形式转换为mcstructure结构文件 + + Parameters + ---------- + midi_cvt: MidiConvert 对象 + 用于转换的MidiConvert对象 + data_cfg: ConvertConfig 对象 + 部分转换通用参数 + scoreboard_name: str + 我的世界的计分板名称 + auto_reset: bool + 是否自动重置计分板 + max_height: int + 生成结构最大高度 + + Returns + ------- + tuple[tuple[int,int,int]结构大小, int音乐总延迟, int指令数量 + """ + + compability_ver = ( + COMPABILITY_VERSION_117 + if midi_cvt.enable_old_exe_format + else COMPABILITY_VERSION_119 + ) + + cmd_list, cmd_count, max_delay = midi_cvt.to_command_list_in_score( + scoreboard_name, + data_cfg.volume_ratio, + data_cfg.speed_multiplier, + ) + + if not os.path.exists(data_cfg.dist_path): + os.makedirs(data_cfg.dist_path) + + struct, size, end_pos = commands_to_structure( + midi_cvt.music_command_list+( + [ + SingleCommand( + command="scoreboard players reset @a[scores={" + + scoreboard_name + + "=" + + str(max_delay + 20) + + "}] " + + scoreboard_name, + annotation="自动重置计分板", + ) + ] + if auto_reset + else [] + ), max_height - 1, compability_version_=compability_ver + ) + + with open( + os.path.abspath( + os.path.join(data_cfg.dist_path, f"{midi_cvt.midi_music_name}.mcstructure") + ), + "wb+", + ) as f: + struct.dump(f) + + return size, max_delay, cmd_count + + def to_mcstructure_file_in_repeater( midi_cvt: MidiConvert, data_cfg: ConvertConfig, @@ -105,7 +178,7 @@ def to_mcstructure_file_in_repeater( Returns ------- - tuple[tuple[int,]结构大小, int音乐总延迟] + tuple[tuple[int,int,int]结构大小, int音乐总延迟] """ compability_ver = ( diff --git a/Musicreater/plugin/mcstructure.py b/Musicreater/plugin/mcstructure.py index 2f48287..99b5985 100644 --- a/Musicreater/plugin/mcstructure.py +++ b/Musicreater/plugin/mcstructure.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/noteblock.py b/Musicreater/plugin/noteblock.py index aaf0196..9465425 100644 --- a/Musicreater/plugin/noteblock.py +++ b/Musicreater/plugin/noteblock.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/schematic.py b/Musicreater/plugin/schematic.py index 9d55c64..3138e22 100644 --- a/Musicreater/plugin/schematic.py +++ b/Musicreater/plugin/schematic.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/schematic/__init__.py b/Musicreater/plugin/schematic/__init__.py index 125d634..ffccd9a 100644 --- a/Musicreater/plugin/schematic/__init__.py +++ b/Musicreater/plugin/schematic/__init__.py @@ -2,8 +2,8 @@ """ 用以生成Schematic结构的附加功能 -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/schematic/main.py b/Musicreater/plugin/schematic/main.py index e6d0982..a03f615 100644 --- a/Musicreater/plugin/schematic/main.py +++ b/Musicreater/plugin/schematic/main.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/websocket.py b/Musicreater/plugin/websocket.py index e37b357..13b1b5e 100644 --- a/Musicreater/plugin/websocket.py +++ b/Musicreater/plugin/websocket.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/websocket/__init__.py b/Musicreater/plugin/websocket/__init__.py index c8d5185..c05b970 100644 --- a/Musicreater/plugin/websocket/__init__.py +++ b/Musicreater/plugin/websocket/__init__.py @@ -2,8 +2,8 @@ """ 用以启动WebSocket服务器播放的附加功能 -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/plugin/websocket/main.py b/Musicreater/plugin/websocket/main.py index 2286d88..0e7e986 100644 --- a/Musicreater/plugin/websocket/main.py +++ b/Musicreater/plugin/websocket/main.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/previous.py b/Musicreater/previous.py index f76b88c..5b266c3 100644 --- a/Musicreater/previous.py +++ b/Musicreater/previous.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/subclass.py b/Musicreater/subclass.py index a3c49a1..f77790c 100644 --- a/Musicreater/subclass.py +++ b/Musicreater/subclass.py @@ -5,8 +5,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/types.py b/Musicreater/types.py index 6f90959..c3670df 100644 --- a/Musicreater/types.py +++ b/Musicreater/types.py @@ -5,8 +5,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Musicreater/utils.py b/Musicreater/utils.py index 8e3fe87..cc1bbf7 100644 --- a/Musicreater/utils.py +++ b/Musicreater/utils.py @@ -4,8 +4,8 @@ """ """ -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 仓库根目录下的 License.md Terms & Conditions: License.md in the root directory diff --git a/Packer/MSCT_Packer.py b/Packer/MSCT_Packer.py new file mode 100644 index 0000000..f3ff80f --- /dev/null +++ b/Packer/MSCT_Packer.py @@ -0,0 +1,70 @@ +import Musicreater +import Musicreater.experiment +import Musicreater.previous + +import Musicreater.plugin + +from Musicreater.plugin.addonpack import ( + to_addon_pack_in_delay, + to_addon_pack_in_repeater, + to_addon_pack_in_score, +) +from Musicreater.plugin.mcstructfile import ( + to_mcstructure_file_in_delay, + to_mcstructure_file_in_repeater, + to_mcstructure_file_in_score, +) + +from Musicreater.plugin.bdxfile import to_BDX_file_in_delay, to_BDX_file_in_score + +MSCT_MAIN = ( + Musicreater, + Musicreater.experiment, + Musicreater.previous, +) + +MSCT_PLUGIN = (Musicreater.plugin,) + +MSCT_PLUGIN_FUNCTION = ( + to_addon_pack_in_delay, + to_addon_pack_in_repeater, + to_addon_pack_in_score, + to_mcstructure_file_in_delay, + to_mcstructure_file_in_repeater, + to_mcstructure_file_in_score, + to_BDX_file_in_delay, + to_BDX_file_in_score, +) + +import hashlib + +import dill +import brotli + + +def enpack_llc_pack(sth, to_dist: str): + packing_bytes = brotli.compress( + dill.dumps( + sth, + ) + ) + with open( + to_dist, + "wb", + ) as f: + f.write(packing_bytes) + + return hashlib.sha256(packing_bytes) + + +with open("./Packer/checksum.txt", "w", encoding="utf-8") as f: + f.write("MSCT_MAIN:\n") + f.write(enpack_llc_pack(MSCT_MAIN, "./Packer/MSCT_MAIN.MPK").hexdigest()) + f.write("\nMSCT_PLUGIN:\n") + f.write(enpack_llc_pack(MSCT_PLUGIN, "./Packer/MSCT_PLUGIN.MPK").hexdigest()) + f.write("\nMSCT_PLUGIN_FUNCTION:\n") + f.write( + enpack_llc_pack( + MSCT_PLUGIN_FUNCTION, "./Packer/MSCT_PLUGIN_FUNCTION.MPK" + ).hexdigest() + ) diff --git a/docs/转换乐器对照表.md b/docs/转换乐器对照表.md index 88ca822..bb7ba7f 100644 --- a/docs/转换乐器对照表.md +++ b/docs/转换乐器对照表.md @@ -12,8 +12,8 @@ **_使用时请遵循协议规定_** -- 版权所有 © 2023 音·创 开发者 -- Copyright © 2023 all the developers of Musicreater +- 版权所有 © 2024 音·创 开发者 +- Copyright © 2024 all the developers of Musicreater * 开源相关声明请见 仓库根目录下的 License.md * Terms & Conditions: License.md in the root directory diff --git a/example.py b/example.py index 63ef167..e78f567 100644 --- a/example.py +++ b/example.py @@ -9,8 +9,8 @@ Musicreater (音·创) A free open source library used for convert midi file into formats that is suitable for **Minecraft**. -版权所有 © 2023 音·创 开发者 -Copyright © 2023 all the developers of Musicreater +版权所有 © 2024 音·创 开发者 +Copyright © 2024 all the developers of Musicreater 开源相关声明请见 ./License.md Terms & Conditions: ./License.md @@ -25,6 +25,12 @@ from Musicreater.plugin.addonpack import ( to_addon_pack_in_repeater, to_addon_pack_in_score, ) +from Musicreater.plugin.mcstructfile import ( + to_mcstructure_file_in_delay, + to_mcstructure_file_in_repeater, + to_mcstructure_file_in_score, +) + from Musicreater.plugin.bdxfile import to_BDX_file_in_delay, to_BDX_file_in_score # 获取midi列表 @@ -36,7 +42,9 @@ out_path = input(f"请输入输出路径:") # 选择输出格式 -fileFormat = int(input(f"请输入输出格式[BDX(1) 或 MCPACK(0)]:").lower()) +fileFormat = int( + input(f"请输入输出格式[MCSTRUCTURE(2) 或 BDX(1) 或 MCPACK(0)]:").lower() +) playerFormat = int(input(f"请选择播放方式[红石(2) 或 计分板(1) 或 延迟(0)]:").lower()) @@ -50,7 +58,17 @@ def bool_str(sth: str): elif str(sth).lower() in ("false", "假", "否", "f", "n"): return False else: - raise ValueError("布尔字符串啊?") + raise ValueError("非法逻辑字串") + + +def isin(sth: str, range_list: dict): + sth = sth.lower() + for bool_value, res_list in range_list.items(): + if sth in res_list: + return bool_value + raise ValueError( + "不在可选范围内:{}".format([j for i in range_list.values() for j in i]) + ) if os.path.exists("./demo_config.json"): @@ -74,31 +92,63 @@ else: bool_str, ), ( - f"计分板名称:", - str, - ) - if playerFormat == 1 - else ( - f"玩家选择器:", - str, + ( + f"计分板名称:", + str, + ) + if playerFormat == 1 + else ( + f"玩家选择器:", + str, + ) ), ( - f"是否自动重置计分板:", - bool_str, - ) - if playerFormat == 1 - else (), + ( + f"是否自动重置计分板:", + bool_str, + ) + if playerFormat == 1 + else () + ), ( - f"作者名称:", - str, - ) - if fileFormat == 1 - else (), - () - if playerFormat == 1 - else ( - f"最大结构高度:", - int, + ( + f"BDX作者署名:", + str, + ) + if fileFormat == 1 + else ( + ( + ( + "结构延展方向:", + lambda a: isin( + a, + { + "z+": ["z+", "Z+"], + "x+": ["X+", "x+"], + "z-": ["Z-", "z-"], + "x-": ["x-", "X-"], + }, + ), + ) + if (playerFormat == 2 and fileFormat == 2) + else () + ), + ) + ), + ( + () + if playerFormat == 1 + else ( + ( + "基础空白方块:", + str, + ) + if (playerFormat == 2 and fileFormat == 2) + else ( + f"最大结构高度:", + int, + ) + ) ), ]: if args: @@ -109,12 +159,20 @@ print(f"正在处理 {midi_path} :") cvt_mid = Musicreater.MidiConvert.from_midi_file(midi_path, old_exe_format=False) cvt_cfg = ConvertConfig(out_path, *prompts[:3]) -if playerFormat == 1: - cvt_method = to_addon_pack_in_score -elif playerFormat == 0: - cvt_method = to_addon_pack_in_delay -elif playerFormat == 2: - cvt_method = to_addon_pack_in_repeater +if fileFormat == 0: + if playerFormat == 1: + cvt_method = to_addon_pack_in_score + elif playerFormat == 0: + cvt_method = to_addon_pack_in_delay + elif playerFormat == 2: + cvt_method = to_addon_pack_in_repeater +elif fileFormat == 2: + if playerFormat == 1: + cvt_method = to_mcstructure_file_in_score + elif playerFormat == 0: + cvt_method = to_mcstructure_file_in_delay + elif playerFormat == 2: + cvt_method = to_mcstructure_file_in_repeater print( @@ -122,11 +180,21 @@ print( *(cvt_method(cvt_mid, cvt_cfg, *prompts[3:])) # type: ignore ) if fileFormat == 0 - else " 指令总长:{},最高延迟:{},结构大小{},终点坐标{}".format( - *( - to_BDX_file_in_score(cvt_mid, cvt_cfg, *prompts[3:]) - if playerFormat == 1 - else to_BDX_file_in_delay(cvt_mid, cvt_cfg, *prompts[3:]) + else ( + " 指令总长:{},最高延迟:{},结构大小{},终点坐标{}".format( + *( + to_BDX_file_in_score(cvt_mid, cvt_cfg, *prompts[3:]) + if playerFormat == 1 + else to_BDX_file_in_delay(cvt_mid, cvt_cfg, *prompts[3:]) + ) + ) + if fileFormat == 1 + else (" 结构大小:{},延迟总数:{},指令数量:{}".format( + *(cvt_method(cvt_mid, cvt_cfg, *prompts[3:])) # type: ignore + ) if playerFormat == 2 else + " 结构大小:{},延迟总数:{}".format( + *(cvt_method(cvt_mid, cvt_cfg, *prompts[3:])) # type: ignore + ) ) ) ) diff --git a/example_mcstructure.py b/example_mcstructure.py deleted file mode 100644 index 52832ac..0000000 --- a/example_mcstructure.py +++ /dev/null @@ -1,11 +0,0 @@ -import Musicreater -import Musicreater.plugin -import Musicreater.plugin.mcstructfile - -print( - Musicreater.plugin.mcstructfile.to_mcstructure_file_in_delay( - Musicreater.MidiConvert.from_midi_file(input("midi路径:"), old_exe_format=False), - Musicreater.plugin.ConvertConfig(input("输出路径:"), volume=1), - max_height=32, - ) -) diff --git a/example_mcstructure_rcd.py b/example_mcstructure_rcd.py deleted file mode 100644 index 0200b67..0000000 --- a/example_mcstructure_rcd.py +++ /dev/null @@ -1,10 +0,0 @@ -import Musicreater -import Musicreater.plugin -import Musicreater.plugin.mcstructfile - -print( - Musicreater.plugin.mcstructfile.to_mcstructure_file_in_repeater( - Musicreater.MidiConvert.from_midi_file(input("midi路径:"), old_exe_format=False), - Musicreater.plugin.ConvertConfig(input("输出路径:"), volume=1), - ) -) diff --git a/example_mcstructure_rcd_future.py b/example_mcstructure_rcd_future.py deleted file mode 100644 index dca0b1f..0000000 --- a/example_mcstructure_rcd_future.py +++ /dev/null @@ -1,12 +0,0 @@ -import Musicreater.experiment -import Musicreater.plugin -import Musicreater.plugin.mcstructfile - -print( - Musicreater.plugin.mcstructfile.to_mcstructure_file_in_repeater( - Musicreater.experiment.FutureMidiConvertM4.from_midi_file( - input("midi路径:"), old_exe_format=False - ), - Musicreater.plugin.ConvertConfig(input("输出路径:"), volume=1), - ) -) diff --git a/resources/音乐测试片段版权声明.txt b/resources/音乐测试片段版权声明.txt index 8b0d40a..de9c726 100644 --- a/resources/音乐测试片段版权声明.txt +++ b/resources/音乐测试片段版权声明.txt @@ -11,4 +11,4 @@ 不得用于商业用途 若 音·创 库被用于商业用途,应当将其剔除 -版权所有 © 2023 诸葛亮与八卦阵 \ No newline at end of file +版权所有 © 2024 诸葛亮与八卦阵 \ No newline at end of file