Merge remote-tracking branch 'origin/master'

This commit is contained in:
bgArray 2023-04-19 21:18:04 +08:00
commit 882fa4175e
8 changed files with 273 additions and 44 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""一个简单的我的世界音频转换库 """一个简单的我的世界音频转换库
· 库版 (Musicreater) · (Musicreater)
是一款免费开源的针对我的世界的midi音乐转换库 是一款免费开源的针对我的世界的midi音乐转换库
Musicreater(·) Musicreater(·)
A free open source library used for convert midi file into formats that is suitable for **Minecraft**. A free open source library used for convert midi file into formats that is suitable for **Minecraft**.
@ -12,8 +12,8 @@ Copyright © 2023 all the developers of Musicreater
Terms & Conditions: ../License.md Terms & Conditions: ../License.md
""" """
# 音·创 开发交流群 861684859 # 睿穆组织 开发交流群 861684859
# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com # Email TriM-Organization@hotmail.com
# 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon") # 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon")
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md

View File

@ -1,17 +1,17 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 音·创 开发交流群 861684859 # 睿穆组织 开发交流群 861684859
# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com # Email TriM-Organization@hotmail.com
# 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon") # 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon")
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
""" """一个简单的我的世界音频转换库
· 库版 (Musicreater Package Version) · (Musicreater)
是一款免费开源的针对我的世界基岩版的midi音乐转换库 是一款免费开源的针对我的世界的midi音乐转换库
Musicreater pkgver (Package Version · 库版) Musicreater(·)
A free open source library used for convert midi file into formats that is suitable for **Minecraft: Bedrock Edition**. A free open source library used for convert midi file into formats that is suitable for **Minecraft**.
版权所有 © 2023 · 开发者 版权所有 © 2023 · 开发者
Copyright © 2023 all the developers of Musicreater Copyright © 2023 all the developers of Musicreater

View File

@ -2,7 +2,7 @@
# 音·创 开发交流群 861684859 # 音·创 开发交流群 861684859
# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com # Email TriM-Organization@hotmail.com
# 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon") # 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon")
# 若需转载或借鉴 许可声明请查看仓库目录下的 License.md # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md
@ -155,6 +155,7 @@ class midiConvert:
[ [
self._toCmdList_withDelay_m1, self._toCmdList_withDelay_m1,
self._toCmdList_withDelay_m2, self._toCmdList_withDelay_m2,
self._toCmdList_withDelay_m3,
] ]
) )
@ -1457,7 +1458,6 @@ class midiConvert:
speed: float = 1.0, speed: float = 1.0,
progressbar: Union[bool, tuple] = False, progressbar: Union[bool, tuple] = False,
player: str = "@a", player: str = "@a",
author: str = "Eilles",
max_height: int = 64, max_height: int = 64,
): ):
""" """
@ -1471,7 +1471,24 @@ class midiConvert:
:param player: 玩家选择器默认为`@a` :param player: 玩家选择器默认为`@a`
:return 成功与否成功返回(True,未经过压缩的源,结构占用大小)失败返回(False,str失败原因) :return 成功与否成功返回(True,未经过压缩的源,结构占用大小)失败返回(False,str失败原因)
""" """
pass cmdlist, max_delay = self.methods_byDelay[method - 1](
volume,
speed,
player,
)
if not os.path.exists(self.outputPath):
os.makedirs(self.outputPath)
struct, size = to_structure(cmdlist,max_height-1)
with open(
os.path.abspath(os.path.join(self.outputPath, f"{self.midFileName}.mcstructure")),
"wb+",
) as f:
struct.dump(f)
def to_BDX_file( def to_BDX_file(
self, self,
@ -1552,9 +1569,9 @@ class midiConvert:
max_height - 1, max_height - 1,
) )
_bytes += pgbBytes _bytes += pgbBytes
_bytes += move(y, -pgbNowPos[1]) _bytes += bdx_move(y, -pgbNowPos[1])
_bytes += move(z, -pgbNowPos[2]) _bytes += bdx_move(z, -pgbNowPos[2])
_bytes += move(x, 2) _bytes += bdx_move(x, 2)
size[0] += 2 + pgbSize[0] size[0] += 2 + pgbSize[0]
size[1] = max(size[1], pgbSize[1]) size[1] = max(size[1], pgbSize[1])
@ -1632,14 +1649,14 @@ class midiConvert:
1, 1,
customName="初始化进度条", customName="初始化进度条",
) )
_bytes += move(z, 2) _bytes += bdx_move(z, 2)
_bytes += form_command_block_in_BDX_bytes( _bytes += form_command_block_in_BDX_bytes(
r"scoreboard players add {} {} 1".format(player, scb_name), r"scoreboard players add {} {} 1".format(player, scb_name),
1, 1,
1, 1,
customName="显示进度条并加分", customName="显示进度条并加分",
) )
_bytes += move(y, 1) _bytes += bdx_move(y, 1)
pgbBytes, pgbSize, pgbNowPos = to_BDX_bytes( pgbBytes, pgbSize, pgbNowPos = to_BDX_bytes(
[ [
(i, 0) (i, 0)
@ -1648,15 +1665,15 @@ class midiConvert:
max_height - 1, max_height - 1,
) )
_bytes += pgbBytes _bytes += pgbBytes
_bytes += move(y, -1 - pgbNowPos[1]) _bytes += bdx_move(y, -1 - pgbNowPos[1])
_bytes += move(z, -2 - pgbNowPos[2]) _bytes += bdx_move(z, -2 - pgbNowPos[2])
_bytes += move(x, 2) _bytes += bdx_move(x, 2)
_bytes += form_command_block_in_BDX_bytes( _bytes += form_command_block_in_BDX_bytes(
r"scoreboard players reset {} {}".format(player, scb_name), r"scoreboard players reset {} {}".format(player, scb_name),
1, 1,
customName="置零进度条", customName="置零进度条",
) )
_bytes += move(y, 1) _bytes += bdx_move(y, 1)
size[0] += 2 + pgbSize[0] size[0] += 2 + pgbSize[0]
size[1] = max(size[1], pgbSize[1]) size[1] = max(size[1], pgbSize[1])
size[2] = max(size[2], pgbSize[2]) size[2] = max(size[2], pgbSize[2])

View File

@ -14,7 +14,7 @@ y = "y"
z = "z" z = "z"
def move(axis: str, value: int): def bdx_move(axis: str, value: int):
if value == 0: if value == 0:
return b"" return b""
if abs(value) == 1: if abs(value) == 1:
@ -106,13 +106,14 @@ def form_command_block_in_BDX_bytes(
lastOutput: `str` lastOutput: `str`
上次输出字符串注意此处需要留空 上次输出字符串注意此处需要留空
:param executeOnFirstTick: `bool` :param executeOnFirstTick: `bool`
执行第一个已选项(循环指令方块是否激活后立即执行若为False则从激活时起延迟后第一次执行) 首刻执行(循环指令方块是否激活后立即执行若为False则从激活时起延迟后第一次执行)
:param trackOutput: `bool` :param trackOutput: `bool`
是否输出 是否输出
:return:str :return:str
""" """
block = b"\x24" + particularValue.to_bytes(2, byteorder="big", signed=False) block = b"\x24" + \
particularValue.to_bytes(2, byteorder="big", signed=False)
for i in [ for i in [
impluse.to_bytes(4, byteorder="big", signed=False), impluse.to_bytes(4, byteorder="big", signed=False),
@ -147,7 +148,9 @@ def to_BDX_bytes(
:return 成功与否成功返回(True,未经过压缩的源,结构占用大小)失败返回(False,str失败原因) :return 成功与否成功返回(True,未经过压缩的源,结构占用大小)失败返回(False,str失败原因)
""" """
_sideLength = bottem_side_length_of_smallest_square_bottom_box(len(commands), max_height) _sideLength = bottem_side_length_of_smallest_square_bottom_box(
len(commands), max_height
)
_bytes = b"" _bytes = b""
y_forward = True y_forward = True
@ -196,7 +199,7 @@ def to_BDX_bytes(
now_z += 1 if z_forward else -1 now_z += 1 if z_forward else -1
if ((now_z > _sideLength) and z_forward) or ( if ((now_z >= _sideLength) and z_forward) or (
(now_z < 0) and (not z_forward) (now_z < 0) and (not z_forward)
): ):
now_z -= 1 if z_forward else -1 now_z -= 1 if z_forward else -1
@ -220,3 +223,173 @@ def to_BDX_bytes(
], ],
[now_x, now_y, now_z], [now_x, now_y, now_z],
) )
def form_command_block_in_NBT_struct(
command: str,
coordinate: tuple,
particularValue: int,
impluse: int = 0,
condition: bool = False,
alwaysRun: bool = True,
tickDelay: int = 0,
customName: str = "",
executeOnFirstTick: bool = False,
trackOutput: bool = True,
):
"""
使用指定项目返回指定的指令方块结构
:param command: `str`
指令
:param coordinate: `tuple[int,int,int]`
此方块所在之相对坐标
:param particularValue:
方块特殊值即朝向
:0 无条件
:1 无条件
:2 z轴负方向 无条件
:3 z轴正方向 无条件
:4 x轴负方向 无条件
:5 x轴正方向 无条件
:6 无条件
:7 无条件
:8 有条件
:9 有条件
:10 z轴负方向 有条件
:11 z轴正方向 有条件
:12 x轴负方向 有条件
:13 x轴正方向 有条件
:14 有条件
:14 有条件
注意此处特殊值中的条件会被下面condition参数覆写
:param impluse: `int 0|1|2`
方块类型
0脉冲 1循环 2连锁
:param condition: `bool`
是否有条件
:param alwaysRun: `bool`
是否始终执行
:param tickDelay: `int`
执行延时
:param customName: `str`
悬浮字
:param executeOnFirstTick: `bool`
首刻执行(循环指令方块是否激活后立即执行若为False则从激活时起延迟后第一次执行)
:param trackOutput: `bool`
是否输出
:return:str
"""
from TrimMCStruct import Block, TAG_Long
block = Block(
"minecraft",
"command_block" if impluse == 0 else (
"repeating_command_block" if impluse == 1 else "chain_command_block"),
states={"conditional_bit": condition,
"facing_direction": particularValue},
extra_data={
'Command': command,
'CustomName': customName,
'ExecuteOnFirstTick': executeOnFirstTick,
'LPCommandMode': 0,
'LPCondionalMode': False,
'LPRedstoneMode': False,
'LastExecution': TAG_Long(0),
'LastOutput': '',
'LastOutputParams': [],
'SuccessCount': 0,
'TickDelay': tickDelay,
'TrackOutput': trackOutput,
'Version': 25,
'auto': alwaysRun,
'conditionMet': False, # 是否已经满足条件
'conditionalMode': condition,
'id': 'CommandBlock',
'isMovable': True,
'powered': False, # 是否已激活
'x': coordinate[0],
'y': coordinate[1],
'z': coordinate[2],
}
)
return block
def to_structure(
commands: list,
max_height: int = 64,
):
"""
:param commands: 指令列表(指令, 延迟)
:param max_height: 生成结构最大高度
:return 成功与否成功返回(结构类,结构占用大小)失败返回(False,str失败原因)
"""
# 导入库
from TrimMCStruct import Structure
_sideLength = bottem_side_length_of_smallest_square_bottom_box(
len(commands), max_height
)
struct = Structure(
(_sideLength, max_height, _sideLength), # 声明结构大小
)
y_forward = True
z_forward = True
now_y = 0
now_z = 0
now_x = 0
for cmd, delay in commands:
coordinate = (now_x, now_y, now_z)
struct.set_block(coordinate,
form_command_block_in_NBT_struct(
command=cmd,
coordinate=coordinate,
particularValue=(1 if y_forward else 0)
if (
((now_y != 0) and (not y_forward))
or (y_forward and (now_y != (max_height - 1)))
)
else (3 if z_forward else 2)
if (
((now_z != 0) and (not z_forward))
or (z_forward and (now_z != _sideLength))
)
else 5,
impluse=2,
condition=False,
alwaysRun=True,
tickDelay=delay,
customName="",
executeOnFirstTick=False,
trackOutput=True,
))
now_y += 1 if y_forward else -1
if ((now_y >= max_height) and y_forward) or ((now_y < 0) and (not y_forward)):
now_y -= 1 if y_forward else -1
y_forward = not y_forward
now_z += 1 if z_forward else -1
if ((now_z >= _sideLength) and z_forward) or (
(now_z < 0) and (not z_forward)
):
now_z -= 1 if z_forward else -1
z_forward = not z_forward
now_x += 1
return (
struct,
[
now_x + 1,
max_height if now_x or now_z else now_y,
_sideLength if now_x else now_z,
],
)

View File

@ -1,23 +1,39 @@
<h1 align="center">· Musicreater</h1>
<h1 align="center">
· Musicreater
</h1>
<p align="center"> <p align="center">
<img width="128" height="128" src="https://s1.ax1x.com/2022/05/06/Ouhghj.md.png" > <img width="128" height="128" src="https://s1.ax1x.com/2022/05/06/Ouhghj.md.png">
</img>
</p> </p>
<h3 align="center">一款免费开源的 我的世界 MIDI音乐转换库</h3> <h3 align="center">一款免费开源的 我的世界 MIDI音乐转换库</h3>
<p align="center"> <p align="center">
<img src="https://forthebadge.com/images/badges/built-with-love.svg"> <img src="https://forthebadge.com/images/badges/built-with-love.svg">
<a href='https://gitee.com/TriM-Organization/Musicreater'>
<img align="right" src='https://gitee.com/TriM-Organization/Musicreater/widgets/widget_1.svg' alt='Fork me on Gitee'>
</img>
</a>
<p> <p>
[![][Bilibili: 凌云金羿]](https://space.bilibili.com/397369002/)
[![][Bilibili: 金羿ELS]](https://space.bilibili.com/397369002/)
[![][Bilibili: 诸葛亮与八卦阵]](https://space.bilibili.com/604072474) [![][Bilibili: 诸葛亮与八卦阵]](https://space.bilibili.com/604072474)
[![CodeStyle: black]](https://github.com/psf/black) [![CodeStyle: black]](https://github.com/psf/black)
[![][python]](https://www.python.org/) [![][python]](https://www.python.org/)
[![][license]](LICENSE) [![][license]](LICENSE)
[![][release]](../../releases) [![][release]](../../releases)
[![GiteeStar](https://gitee.com/TriM-Organization/Musicreater/badge/star.svg?theme=gray)](https://gitee.com/TriM-Organization/Musicreater/stargazers)
[![GiteeFork](https://gitee.com/TriM-Organization/Musicreater/badge/fork.svg?theme=gray)](https://gitee.com/TriM-Organization/Musicreater/members)
[![GitHub Repo stars](https://img.shields.io/github/stars/TriM-Organization/Musicreater?color=white&logo=GitHub&style=plastic)](https://github.com/TriM-Organization/Musicreater/stargazers)
[![GitHub Repo Forks](https://img.shields.io/github/forks/TriM-Organization/Musicreater?color=white&logo=GitHub&style=plastic)](https://github.com/TriM-Organization/Musicreater/forks)
简体中文🇨🇳 | [English🇬🇧](README_EN.md) 简体中文🇨🇳 | [English🇬🇧](README_EN.md)
@ -91,19 +107,25 @@
-------------------------------------------- --------------------------------------------
NOT AN OFFICIAL MINECRAFT PRODUCT.
NOT APPROVED BY OR ASSOCIATED WITH MOJANG OR MICROSOFT.
此项目并非一个官方 我的世界*Minecraft*项目 此项目并非一个官方 我的世界*Minecraft*项目
此项目不隶属或关联于 Mojang Studios 微软 此项目不隶属或关联于 Mojang Studios 微软
此项目亦不与 网易 相关
Minecraft Mojang Synergies AB 的商标此项目中所有对于我的世界Minecraft等相关称呼均为引用性使用
* 上文提及的 网易 公司指代的是在中国大陆运营我的世界中国版的上海网之易网络科技发展有限公司
NOT AN OFFICIAL MINECRAFT PRODUCT.
NOT APPROVED BY OR ASSOCIATED WITH MOJANG OR MICROSOFT.
[Bilibili: 凌云金羿]: https://img.shields.io/badge/Bilibili-%E5%87%8C%E4%BA%91%E9%87%91%E7%BE%BF-00A1E7?style=for-the-badge
[Bilibili: 金羿ELS]: https://img.shields.io/badge/Bilibili-%E5%87%8C%E4%BA%91%E9%87%91%E7%BE%BF-00A1E7?style=for-the-badge
[Bilibili: 诸葛亮与八卦阵]: https://img.shields.io/badge/Bilibili-%E8%AF%B8%E8%91%9B%E4%BA%AE%E4%B8%8E%E5%85%AB%E5%8D%A6%E9%98%B5-00A1E7?style=for-the-badge [Bilibili: 诸葛亮与八卦阵]: https://img.shields.io/badge/Bilibili-%E8%AF%B8%E8%91%9B%E4%BA%AE%E4%B8%8E%E5%85%AB%E5%8D%A6%E9%98%B5-00A1E7?style=for-the-badge
[CodeStyle: black]: https://img.shields.io/badge/code%20style-black-121110.svg?style=for-the-badge [CodeStyle: black]: https://img.shields.io/badge/code%20style-black-121110.svg?style=for-the-badge
[python]: https://img.shields.io/badge/python-3.6-AB70FF?style=for-the-badge [python]: https://img.shields.io/badge/python-3.6-AB70FF?style=for-the-badge

View File

@ -10,28 +10,38 @@
# 库的简单调用 # 库的简单调用
参见[magicDemo.py的相关部分](../magicDemo.py#L436)使用此库进行MIDI转换非常简单。 参见[example.py的相关部分](../example.py#L120)使用此库进行MIDI转换非常简单。
```python ```python
import msctPkgver # 导入转换库 import Musicreater # 导入转换库
# 首先新建转换对象。 # 首先新建转换对象。
conversion = msctPkgver.midiConvert() conversion = Musicreater.midiConvert()
# 值得注意的是,一个转换对象可以转换多个文件。 # 值得注意的是,一个转换对象可以转换多个文件。
# 也就是在实例化的时候不进行对文件的绑定。 # 也就是在实例化的时候不进行对文件的绑定。
# 如果有调试需要,可以在实例化时传入参数 debug = True # 如果有调试需要,可以在实例化时传入参数 debug = True
# 如conversion = msctPkgver.midiConvert(debug=True) # 如conversion = Musicreater.midiConvert(debug=True)
# 设置输入输出地址并指定execute指令语法 # 设置输入输出地址并指定execute指令语法
# 地址都为字符串类型,不能传入文件流 # 地址都为字符串类型,不能传入文件流
midi_path = "./where/you/place/.midi/files.mid" midi_path = "./where/you/place/.midi/files.mid"
output_folder = "./where/you/want2/convert/into/" output_folder = "./where/you/want2/convert/into/"
old_execute_format = False # 指定是否使用旧的execute指令语法即1.18及以前的《我的世界:基岩版》语法) old_execute_format = False # 指定是否使用旧的execute指令语法即1.18及以前的《我的世界:基岩版》语法)
# 设定基本转换参数
conversion.convert(midi_path,output_folder,old_execute_format) conversion.convert(midi_path,output_folder,old_execute_format)
# 进行转换并接受输出,具体的参数均在文档中有相关说明 # 进行转换并接受输出,具体的参数均在代码之文档中有相关说明
method_id = 2 # 指定使用的转换算法 method_id = 3 # 指定使用的转换算法
convertion_result = conversion.tomcpack(method_id,*prompts)
# 使用计分板播放器,转换为附加包文件
convertion_result = conversion.to_mcpack(method_id,*prompts)
# 使用计分板播放器转换为BDX结构文件
convertion_result = conversion.to_BDX_file(method_id,*prompts)
# 使用延迟播放器转换为BDX结构文件
convertion_result = conversion.to_BDX_file_with_delay(method_id,*prompts)
# 转换结果是一个元组。 # 转换结果是一个元组。
# 若其转换成功,则前三位必为 # 若其转换成功,则前三位必为

6
example_mcstructure.py Normal file
View File

@ -0,0 +1,6 @@
from Musicreater import midiConvert
conversion = midiConvert()
conversion.convert(input("midi path:"),input("out path:"))
conversion.to_mcstructure_file_with_delay(3,)

View File

@ -1,2 +1,3 @@
Brotli>=1.0.9 Brotli>=1.0.9
mido>=1.2.10 mido>=1.2.10
TrimMCStruct>=0.0.5.5