mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2025-02-07 19:36:46 +08:00
增加调试功能,降低容错率(不是,我真的没有反向更新(((
但是修改了算法1,算法1的响度错误解决了。但是我仍然推荐算法2
This commit is contained in:
parent
502f4eb54d
commit
7d6faebc5b
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,6 +7,9 @@
|
|||||||
/.vscode
|
/.vscode
|
||||||
*.mid
|
*.mid
|
||||||
*.midi
|
*.midi
|
||||||
|
*.mcpack
|
||||||
|
*.bdx
|
||||||
|
demo_config.json
|
||||||
|
|
||||||
# Byte-compiled / optimized
|
# Byte-compiled / optimized
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
30
README.md
30
README.md
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
**此分支为音·创的包版本,即便于其他软件使用的可被import版本**
|
**此分支为音·创的包版本,即便于其他软件使用的可被import版本**
|
||||||
|
|
||||||
### **看这看这!看这看这!看这看这!教程:[教程链接](./docs/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E.md)**
|
### **如果希望直接使用演示程序转换MIDI音乐,请:[看这看这!看这看这!看这看这!](./docs/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E.md)**
|
||||||
|
|
||||||
## 软件作者✒
|
## 软件作者✒
|
||||||
|
|
||||||
@ -40,32 +40,26 @@
|
|||||||
|
|
||||||
|
|
||||||
## 致谢🙏
|
## 致谢🙏
|
||||||
|
本致谢列表排名无顺序。
|
||||||
|
|
||||||
- 感谢 **昀梦**\<QQ1515399885\> 找出指令生成错误bug并指正
|
- 感谢 **昀梦**\<QQ1515399885\> 找出指令生成错误bug并指正
|
||||||
- 感谢由 **Charlie_Ping “查理平”** 带来的bdx文件转换参考,
|
- 感谢由 **Charlie_Ping “查理平”** 带来的BDX文件转换参考,以及MIDI-我的世界对应乐器参考表格
|
||||||
以及mid转我的世界乐器参考表格
|
- 感谢由 **CMA_2401PT** 为我们的软件开发的一些方面进行指导,同时我们参考了他的BDXworkshop作为BDX结构编辑的参考
|
||||||
- 感谢由 **CMA_2401PT** 为我们的软件开发进行指导
|
- 感谢由 **Dislink Sforza “断联·斯福尔扎”**\<QQ1600515314\> 带来的midi音色解析以及转换指令的算法,我们将其改编并应用;同时,感谢他的[网页版转换器](https://dislink.github.io/midi2bdx/)给我们的开发与更新带来巨大的压力和动力,让我们在原本一骑绝尘的摸鱼道路上转向开发,希望他能考上一个理想的大学!
|
||||||
- 感谢由 **Dislink Sforza “断联·斯福尔扎”**\<QQ1600515314\>带来的midi音色解析以及转换指令的算法,我们将其改编并应用;同时,感谢他的[网页版转换器](https://dislink.github.io/midi2bdx/)给我们的开发与更新带来巨大的压力和动力,让我们在原本一骑绝尘的摸鱼道路上转向开发
|
- 感谢 **Touch “偷吃”**\<QQ1793537164\> 提供的BDX导入测试支持,并对程序的改进提供了丰富的意见;同时也感谢他的不断尝试新的内容,使我们的排错更进一步
|
||||||
- 感谢 **Touch “偷吃”**\<QQ1793537164\>提供的测试支持,并对程序的改进提供了丰富的意见;同时也感谢他的不断尝试新的内容,使我们的排错更进一步
|
- 感谢 **Mono**\<QQ738893087\> 反馈安装时的问题,辅助我们找到了视窗操作系统下的兼容性问题
|
||||||
- 感谢 **Mono**\<QQ738893087\>反馈安装时的问题
|
- 感谢 **Ammelia**\<QQ2838334637\> 敦促我们进行新的功能开发,并为新功能提出了非常优秀的大量建议,以及提供的BDX导入测试支持,为我们的新结构生成算法提供了大量的实际理论支持
|
||||||
- 感谢 **Ammelia** 敦促我们进行新的功能开发,并为新功能提出了非常优秀的大量建议
|
- 感谢 **神羽** 对我们项目的支持与宣传
|
||||||
|
|
||||||
> 感谢广大群友为此程序提供的测试等支持
|
> 感谢广大群友为此程序提供的测试等支持
|
||||||
>
|
>
|
||||||
> 若您对我们有所贡献但您的名字没有显示在此列表中,请联系我!
|
> 若您对我们有所贡献但您的名字没有显示在此列表中,请联系我们!
|
||||||
|
|
||||||
## 联系我们📞
|
## 联系我们📞
|
||||||
|
|
||||||
### 作者\<*金羿*\>(Eilles)联系方式
|
若遇到库中的问题,欢迎在[此](https://gitee.com/EillesWan/Musicreater/issues/new)提出你的issue。
|
||||||
|
|
||||||
1. QQ 2647547478
|
如果需要与开发组进行交流,欢迎加入我们的[开发闲聊Q群](https://jq.qq.com/?_wv=1027&k=hpeRxrYr)。
|
||||||
2. 电邮 EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com
|
|
||||||
3. 微信 WYI_DoctorYI
|
|
||||||
4. Telegram [@EillesWan](https://t.me/EillesWan)
|
|
||||||
|
|
||||||
### 作者\<*诸葛亮与八卦阵*\>(bgArray)联系方式
|
|
||||||
|
|
||||||
1. QQ 4740437765
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,11 +154,10 @@ pkg install git
|
|||||||
|
|
||||||
1. 开始使用演示程序
|
1. 开始使用演示程序
|
||||||
|
|
||||||
依照你的需要,执行以下命令之一:
|
依照你的需要,执行以下命令以运行库的演示程序:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python demo_convert.py #计分板播放器,支持mcpack与BDX
|
python magicDemo.py
|
||||||
python demo_convert_bdx_byDelay.py #延迟播放器,仅支持BDX
|
|
||||||
```
|
```
|
||||||
|
|
||||||
运行成功了,哦耶!
|
运行成功了,哦耶!
|
||||||
|
@ -95,10 +95,9 @@
|
|||||||
|
|
||||||
1. 开始使用
|
1. 开始使用
|
||||||
|
|
||||||
在目录下打开终端,执行以下命令:(选择你需要的)
|
在目录下打开终端,执行以下命令以运行演示程序:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python demo_convert.py #计分板播放器,支持mcpack与BDX
|
python magicDemo.py
|
||||||
python demo_convert_bdx_byDelay.py #延迟播放器,仅支持BDX
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@
|
|||||||
|
|
||||||
1. 开始使用
|
1. 开始使用
|
||||||
|
|
||||||
|
您可以直接双击 `magicDemo.py` 以运行演示程序,或者按照以下步骤使用终端应用运行。
|
||||||
|
|
||||||
在目录下打开终端。
|
在目录下打开终端。
|
||||||
|
|
||||||
例如:打开命令行:请进入到目录下,在文件资源管理器的地址框内输入`cmd`:
|
例如:打开命令行:请进入到目录下,在文件资源管理器的地址框内输入`cmd`:
|
||||||
@ -67,11 +69,8 @@
|
|||||||
<img src=https://foruda.gitee.com/images/1659974437388532868/输入.png>
|
<img src=https://foruda.gitee.com/images/1659974437388532868/输入.png>
|
||||||
<img src=https://foruda.gitee.com/images/1659974754378201859/输入c.png>
|
<img src=https://foruda.gitee.com/images/1659974754378201859/输入c.png>
|
||||||
|
|
||||||
执行以下命令:(选择你需要的)
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python demo_convert.py #计分板播放器,支持mcpack与BDX
|
python ./magicDemo.py
|
||||||
python demo_convert_bdx_byDelay.py #延迟播放器,仅支持BDX
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 三、安装时错误的补充说明
|
## 三、安装时错误的补充说明
|
||||||
@ -86,4 +85,4 @@
|
|||||||
> [下载64位VCREDIST安装包](https://aka.ms/vs/17/release/vc_redist.x64.exe)
|
> [下载64位VCREDIST安装包](https://aka.ms/vs/17/release/vc_redist.x64.exe)
|
||||||
> [下载32位VCREDIST安装包](https://aka.ms/vs/17/release/vc_redist.x86.exe)
|
> [下载32位VCREDIST安装包](https://aka.ms/vs/17/release/vc_redist.x86.exe)
|
||||||
|
|
||||||
感谢群友Mono帮我们发现这个问题。
|
感谢群友*Mono*帮我们发现这个问题。
|
@ -8,6 +8,41 @@
|
|||||||
|
|
||||||
**此为开发相关文档,内容包括:所生成文件结构的详细说明、特殊参数的详细解释**
|
**此为开发相关文档,内容包括:所生成文件结构的详细说明、特殊参数的详细解释**
|
||||||
|
|
||||||
|
# 库的简单调用
|
||||||
|
|
||||||
|
参见[magicDemo.py的相关部分](../magicDemo.py#L436),使用此库进行MIDI转换非常简单。
|
||||||
|
|
||||||
|
```python
|
||||||
|
import msctPkgver # 导入转换库
|
||||||
|
|
||||||
|
# 首先新建转换对象。
|
||||||
|
conversion = msctPkgver.midiConvert()
|
||||||
|
# 值得注意的是,一个转换对象可以转换多个文件。
|
||||||
|
# 也就是在实例化的时候不进行对文件的绑定。
|
||||||
|
# 如果有调试需要,可以在实例化时传入参数 debug = True
|
||||||
|
# 如:conversion = msctPkgver.midiConvert(debug=True)
|
||||||
|
|
||||||
|
# 设置输入输出地址,并指定execute指令语法
|
||||||
|
# 地址都为字符串类型,不能传入文件流
|
||||||
|
midi_path = "./where/you/place/.midi/files.mid"
|
||||||
|
output_folder = "./where/you/want2/convert/into/"
|
||||||
|
old_execute_format = False # 指定是否使用旧的execute指令语法(即1.18及以前的《我的世界:基岩版》语法)
|
||||||
|
conversion.convert(midi_path,output_folder,old_execute_format)
|
||||||
|
|
||||||
|
# 进行转换并接受输出,具体的参数均在文档中有相关说明
|
||||||
|
method_id = 2 # 指定使用的转换算法
|
||||||
|
convertion_result = conversion.tomcpack(method_id,*prompts)
|
||||||
|
|
||||||
|
# 转换结果是一个元组。
|
||||||
|
# 若其转换成功,则前三位必为
|
||||||
|
# True, 指令数量, 最大延迟
|
||||||
|
# 其中,最大延迟可以理解为计分板的最大值
|
||||||
|
# 如果转换失败,暂时还没有定返回值的规则
|
||||||
|
# 但是有一点是肯定的,数据结构必定是元组
|
||||||
|
print(convertion_result)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# 生成文件结构
|
# 生成文件结构
|
||||||
|
|
||||||
## 名词解释
|
## 名词解释
|
||||||
|
183
magicDemo.py
183
magicDemo.py
@ -82,38 +82,35 @@ import os
|
|||||||
import random
|
import random
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from msctPkgver.main import *
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from rich.console import Console
|
import msctPkgver
|
||||||
except ModuleNotFoundError as E:
|
except ModuleNotFoundError as E:
|
||||||
if input("您需要安装 Rich 模块才能使用这个样例\n请问是否安装?(y/n)").lower() in ('y', '1'):
|
if input("您需要安装 mido、Brotli 模块才能使用这个样例\n请问是否安装?(y/n):").lower() in ('y', '1'):
|
||||||
os.system("pip install Rich -i https://mirrors.aliyun.com/pypi/")
|
os.system("pip install -r requirements.txt")
|
||||||
from rich.console import Console
|
import msctPkgver
|
||||||
else:
|
else:
|
||||||
raise E
|
raise E
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from msctPkgver.magicBeing import *
|
||||||
|
import requests
|
||||||
import zhdate
|
import zhdate
|
||||||
except ModuleNotFoundError as E:
|
except ModuleNotFoundError as E:
|
||||||
if input("您需要安装 zhdate 模块才能使用这个样例\n请问是否安装?(y/n)").lower() in ('y', '1'):
|
if input(
|
||||||
os.system("pip install zhdate -i https://mirrors.aliyun.com/pypi/")
|
"您需要安装以下模块才能使用这个样例\nrequests==2.28.1\nrich==12.6.0\nzhdate==0.1\n请问是否安装?(y/n):"
|
||||||
|
).lower() in ('y', '1'):
|
||||||
|
open("Demo_Requirements.txt", 'r').write(
|
||||||
|
"requests==2.28.1\nrich==12.6.0\nzhdate==0.1"
|
||||||
|
)
|
||||||
|
os.system("pip install -r Demo_Requirements.txt")
|
||||||
|
os.remove("./Demo_Requirements.txt")
|
||||||
|
from rich.console import Console
|
||||||
|
import requests
|
||||||
import zhdate
|
import zhdate
|
||||||
else:
|
else:
|
||||||
raise E
|
raise E
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
import requests
|
|
||||||
except ModuleNotFoundError as E:
|
|
||||||
if input("您需要安装 requests 模块才能使用这个样例\n请问是否安装?(y/n)").lower() in ('y', '1'):
|
|
||||||
os.system("pip install requests -i https://mirrors.aliyun.com/pypi/")
|
|
||||||
import requests
|
|
||||||
else:
|
|
||||||
raise E
|
|
||||||
|
|
||||||
|
|
||||||
MainConsole = Console()
|
|
||||||
|
|
||||||
MainConsole.print(
|
MainConsole.print(
|
||||||
"[#121110 on #F0F2F4] ",
|
"[#121110 on #F0F2F4] ",
|
||||||
@ -173,132 +170,8 @@ else:
|
|||||||
justify="center",
|
justify="center",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
from typing import Any, Literal, Optional, TextIO
|
|
||||||
|
|
||||||
JustifyMethod = Literal["default", "left", "center", "right", "full"]
|
|
||||||
OverflowMethod = Literal["fold", "crop", "ellipsis", "ignore"]
|
|
||||||
|
|
||||||
# 高级的打印函数
|
|
||||||
def prt(
|
|
||||||
*objects: Any,
|
|
||||||
sep: str = " ",
|
|
||||||
end: str = "\n",
|
|
||||||
justify: Optional[JustifyMethod] = None,
|
|
||||||
overflow: Optional[OverflowMethod] = None,
|
|
||||||
no_wrap: Optional[bool] = None,
|
|
||||||
emoji: Optional[bool] = None,
|
|
||||||
markup: Optional[bool] = None,
|
|
||||||
highlight: Optional[bool] = None,
|
|
||||||
width: Optional[int] = None,
|
|
||||||
height: Optional[int] = None,
|
|
||||||
crop: bool = True,
|
|
||||||
soft_wrap: Optional[bool] = None,
|
|
||||||
new_line_start: bool = False,
|
|
||||||
) -> None:
|
|
||||||
"""打印到控制台。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
objects (位置性的args): 要记录到终端的对象。
|
|
||||||
sep (str, 可选): 要在打印数据之间写入的字符串。默认为""。
|
|
||||||
end (str, optio可选nal): 在打印数据结束时写入的字符串。默认值为"\\\\n"。
|
|
||||||
style (Union[str, Style], 可选): 应用于输出的样式。默认为`None`。
|
|
||||||
justify (str, 可选): 校正位置,可为"default", "left", "right", "center" 或 "full". 默认为`None`。
|
|
||||||
overflow (str, 可选): 控制溢出:"ignore"忽略, "crop"裁剪, "fold"折叠, "ellipsis"省略号。默认为`None`。
|
|
||||||
no_wrap (Optional[bool], 可选): 禁用文字包装。默认为`None`。
|
|
||||||
emoji (Optional[bool], 可选): 启用表情符号代码,或使用控制台默认的`None`。默认为`None`。
|
|
||||||
markup (Optional[bool], 可选): 启用标记,或`None`使用控制台默认值。默认为`None`。
|
|
||||||
highlight (Optional[bool], 可选): 启用自动高亮,或`None`使用控制台默认值。默认为`None`。
|
|
||||||
width (Optional[int], 可选): 输出的宽度,或`None`自动检测。默认为`None`。
|
|
||||||
crop (Optional[bool], 可选): 裁剪输出到终端的宽度。默认为`True`。
|
|
||||||
soft_wrap (bool, 可选): 启用软包装模式,禁止文字包装和裁剪,或`None``用于 控制台默认值。默认为`None`。
|
|
||||||
new_line_start (bool, False): 如果输出包含多行,在开始时插入一个新行。默认值为`False`。
|
|
||||||
"""
|
|
||||||
MainConsole.print(
|
|
||||||
*objects,
|
|
||||||
sep=sep,
|
|
||||||
end=end,
|
|
||||||
style="#F0F2F4 on #121110",
|
|
||||||
justify=justify,
|
|
||||||
overflow=overflow,
|
|
||||||
no_wrap=no_wrap,
|
|
||||||
emoji=emoji,
|
|
||||||
markup=markup,
|
|
||||||
highlight=highlight,
|
|
||||||
width=width,
|
|
||||||
height=height,
|
|
||||||
crop=crop,
|
|
||||||
soft_wrap=soft_wrap,
|
|
||||||
new_line_start=new_line_start,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
prt(f"{_('LangChd')}{_(':')}{_(currentLang)}")
|
prt(f"{_('LangChd')}{_(':')}{_(currentLang)}")
|
||||||
|
|
||||||
# 高级的输入函数
|
|
||||||
def ipt(
|
|
||||||
*objects: Any,
|
|
||||||
sep: str = " ",
|
|
||||||
justify: Optional[JustifyMethod] = None,
|
|
||||||
overflow: Optional[OverflowMethod] = None,
|
|
||||||
no_wrap: Optional[bool] = None,
|
|
||||||
emoji: Optional[bool] = None,
|
|
||||||
markup: Optional[bool] = None,
|
|
||||||
highlight: Optional[bool] = None,
|
|
||||||
width: Optional[int] = None,
|
|
||||||
height: Optional[int] = None,
|
|
||||||
crop: bool = True,
|
|
||||||
soft_wrap: Optional[bool] = None,
|
|
||||||
new_line_start: bool = False,
|
|
||||||
password: bool = False,
|
|
||||||
stream: Optional[TextIO] = None,
|
|
||||||
) -> str:
|
|
||||||
"""显示一个提示并等待用户的输入。
|
|
||||||
|
|
||||||
它的工作方式与Python内建的 :func:`input` 函数相同,如果Python内建的 :mod:`readline` 模块先前已经加载,则提供详细的行编辑和历史功能。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
objects (位置性的args): 要记录到终端的对象。
|
|
||||||
sep (str, 可选): 要在打印数据之间写入的字符串。默认为""。
|
|
||||||
end (str, optio可选nal): 在打印数据结束时写入的字符串。默认值为"\\\\n"。
|
|
||||||
style (Union[str, Style], 可选): 应用于输出的样式。默认为`None`。
|
|
||||||
justify (str, 可选): 校正位置,可为"default", "left", "right", "center" 或 "full". 默认为`None`。
|
|
||||||
overflow (str, 可选): 控制溢出:"ignore"忽略, "crop"裁剪, "fold"折叠, "ellipsis"省略号。默认为`None`。
|
|
||||||
no_wrap (Optional[bool], 可选): 禁用文字包装。默认为`None`。
|
|
||||||
emoji (Optional[bool], 可选): 启用表情符号代码,或使用控制台默认的`None`。默认为`None`。
|
|
||||||
markup (Optional[bool], 可选): 启用标记,或`None`使用控制台默认值。默认为`None`。
|
|
||||||
highlight (Optional[bool], 可选): 启用自动高亮,或`None`使用控制台默认值。默认为`None`。
|
|
||||||
width (Optional[int], 可选): 输出的宽度,或`None`自动检测。默认为`None`。
|
|
||||||
crop (Optional[bool], 可选): 裁剪输出到终端的宽度。默认为`True`。
|
|
||||||
soft_wrap (bool, 可选): 启用软包装模式,禁止文字包装和裁剪,或`None``用于 控制台默认值。默认为`None`。
|
|
||||||
new_line_start (bool, False): 如果输出包含多行,在开始时插入一个新行。默认值为`False`。
|
|
||||||
password (bool, 可选): 隐藏已经输入的文案,默认值为`False`。
|
|
||||||
stream (TextIO, 可选): 可选从文件中读取(而非控制台),默认为 `None`。
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: 从stdin读取的字符串
|
|
||||||
"""
|
|
||||||
MainConsole.print(
|
|
||||||
*objects,
|
|
||||||
sep=sep,
|
|
||||||
end="",
|
|
||||||
style="#F0F2F4 on #121110",
|
|
||||||
justify=justify,
|
|
||||||
overflow=overflow,
|
|
||||||
no_wrap=no_wrap,
|
|
||||||
emoji=emoji,
|
|
||||||
markup=markup,
|
|
||||||
highlight=highlight,
|
|
||||||
width=width,
|
|
||||||
height=height,
|
|
||||||
crop=crop,
|
|
||||||
soft_wrap=soft_wrap,
|
|
||||||
new_line_start=new_line_start,
|
|
||||||
)
|
|
||||||
|
|
||||||
return MainConsole.input("", password=password, stream=stream)
|
|
||||||
|
|
||||||
|
|
||||||
def formatipt(
|
def formatipt(
|
||||||
notice: str,
|
notice: str,
|
||||||
fun,
|
fun,
|
||||||
@ -389,7 +262,10 @@ def boolstr(sth: str) -> bool:
|
|||||||
else:
|
else:
|
||||||
raise "布尔字符串啊?"
|
raise "布尔字符串啊?"
|
||||||
|
|
||||||
|
if os.path.exists("./demo_config.json"):
|
||||||
|
import json
|
||||||
|
prompts = json.load(open("./demo_config.json",'r',encoding="utf-8"))
|
||||||
|
else:
|
||||||
prompts = []
|
prompts = []
|
||||||
# 提示语 检测函数 错误提示语
|
# 提示语 检测函数 错误提示语
|
||||||
for args in [
|
for args in [
|
||||||
@ -437,9 +313,13 @@ for args in [
|
|||||||
prompts.append(formatipt(*args)[1])
|
prompts.append(formatipt(*args)[1])
|
||||||
|
|
||||||
|
|
||||||
newLine = '\n'
|
|
||||||
conversion = midiConvert()
|
|
||||||
|
|
||||||
|
|
||||||
|
conversion = msctPkgver.midiConvert()
|
||||||
for singleMidi in midis:
|
for singleMidi in midis:
|
||||||
|
prt("\n"f"{_('Dealing')} {singleMidi} {_(':')}")
|
||||||
conversion.convert(singleMidi, outpath)
|
conversion.convert(singleMidi, outpath)
|
||||||
conversion_result = (
|
conversion_result = (
|
||||||
conversion.tomcpack(2, *prompts)
|
conversion.tomcpack(2, *prompts)
|
||||||
@ -450,11 +330,18 @@ for singleMidi in midis:
|
|||||||
else conversion.toBDXfile_withDelay(1, *prompts)
|
else conversion.toBDXfile_withDelay(1, *prompts)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if prompts[-1] == "debug":
|
||||||
|
with open("./records.json",'a',encoding="utf-8") as f:
|
||||||
|
json.dump(prompts,f)
|
||||||
|
|
||||||
if conversion_result[0]:
|
if conversion_result[0]:
|
||||||
prt(
|
prt(
|
||||||
f"{newLine}{_('Dealing')} {singleMidi} {_(':')}{newLine} {_('CmdLength')}{_(':')}{conversion_result[1]}{_(',')}{_('MaxDelay')}{_(':')}{conversion_result[2]}{f'''{_(',')}{_('PlaceSize')}{_(':')}{conversion_result[3]}{_(',')}{_('LastPos')}{_(':')}{conversion_result[4]}''' if fileFormat == 1 else ''}"
|
f" {_('CmdLength')}{_(':')}{conversion_result[1]}{_(',')}{_('MaxDelay')}{_(':')}{conversion_result[2]}{f'''{_(',')}{_('PlaceSize')}{_(':')}{conversion_result[3]}{_(',')}{_('LastPos')}{_(':')}{conversion_result[4]}''' if fileFormat == 1 else ''}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
prt(f"{_('Failed')}")
|
prt(f"{_('Failed')}")
|
||||||
|
|
||||||
ipt(_("PressEnterExit"))
|
if ipt(_("PressEnterExit")).lower() == "record":
|
||||||
|
import json
|
||||||
|
with open("./demo_config.json",'w',encoding="utf-8") as f:
|
||||||
|
json.dump(prompts,f)
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
# 若需转载或借鉴 许可声明请查看仓库目录下的 Lisence.md
|
# 若需转载或借鉴 许可声明请查看仓库目录下的 Lisence.md
|
||||||
|
|
||||||
|
|
||||||
__version__ = '0.2.0.1'
|
__version__ = '0.2.1'
|
||||||
__all__ = []
|
__all__ = []
|
||||||
__author__ = (('金羿', 'Eilles Wan'), ('诸葛亮与八卦阵', 'bgArray'), ('鸣凤鸽子', 'MingFengPigeon'))
|
__author__ = (('金羿', 'Eilles Wan'), ('诸葛亮与八卦阵', 'bgArray'), ('鸣凤鸽子', 'MingFengPigeon'))
|
||||||
|
|
||||||
|
150
msctPkgver/magicBeing.py
Normal file
150
msctPkgver/magicBeing.py
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
|
||||||
|
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
|
MainConsole = Console()
|
||||||
|
|
||||||
|
from typing import Any, Literal, Optional, TextIO
|
||||||
|
|
||||||
|
JustifyMethod = Literal["default", "left", "center", "right", "full"]
|
||||||
|
OverflowMethod = Literal["fold", "crop", "ellipsis", "ignore"]
|
||||||
|
|
||||||
|
# 高级的打印函数
|
||||||
|
def prt(
|
||||||
|
*objects: Any,
|
||||||
|
sep: str = " ",
|
||||||
|
end: str = "\n",
|
||||||
|
justify: Optional[JustifyMethod] = None,
|
||||||
|
overflow: Optional[OverflowMethod] = None,
|
||||||
|
no_wrap: Optional[bool] = None,
|
||||||
|
emoji: Optional[bool] = None,
|
||||||
|
markup: Optional[bool] = None,
|
||||||
|
highlight: Optional[bool] = None,
|
||||||
|
width: Optional[int] = None,
|
||||||
|
height: Optional[int] = None,
|
||||||
|
crop: bool = True,
|
||||||
|
soft_wrap: Optional[bool] = None,
|
||||||
|
new_line_start: bool = False,
|
||||||
|
) -> None:
|
||||||
|
"""打印到控制台。
|
||||||
|
|
||||||
|
Args:
|
||||||
|
objects (位置性的args): 要记录到终端的对象。
|
||||||
|
sep (str, 可选): 要在打印数据之间写入的字符串。默认为""。
|
||||||
|
end (str, optio可选nal): 在打印数据结束时写入的字符串。默认值为"\\\\n"。
|
||||||
|
style (Union[str, Style], 可选): 应用于输出的样式。默认为`None`。
|
||||||
|
justify (str, 可选): 校正位置,可为"default", "left", "right", "center" 或 "full". 默认为`None`。
|
||||||
|
overflow (str, 可选): 控制溢出:"ignore"忽略, "crop"裁剪, "fold"折叠, "ellipsis"省略号。默认为`None`。
|
||||||
|
no_wrap (Optional[bool], 可选): 禁用文字包装。默认为`None`。
|
||||||
|
emoji (Optional[bool], 可选): 启用表情符号代码,或使用控制台默认的`None`。默认为`None`。
|
||||||
|
markup (Optional[bool], 可选): 启用标记,或`None`使用控制台默认值。默认为`None`。
|
||||||
|
highlight (Optional[bool], 可选): 启用自动高亮,或`None`使用控制台默认值。默认为`None`。
|
||||||
|
width (Optional[int], 可选): 输出的宽度,或`None`自动检测。默认为`None`。
|
||||||
|
crop (Optional[bool], 可选): 裁剪输出到终端的宽度。默认为`True`。
|
||||||
|
soft_wrap (bool, 可选): 启用软包装模式,禁止文字包装和裁剪,或`None``用于 控制台默认值。默认为`None`。
|
||||||
|
new_line_start (bool, False): 如果输出包含多行,在开始时插入一个新行。默认值为`False`。
|
||||||
|
"""
|
||||||
|
MainConsole.print(
|
||||||
|
*objects,
|
||||||
|
sep=sep,
|
||||||
|
end=end,
|
||||||
|
style="#F0F2F4 on #121110",
|
||||||
|
justify=justify,
|
||||||
|
overflow=overflow,
|
||||||
|
no_wrap=no_wrap,
|
||||||
|
emoji=emoji,
|
||||||
|
markup=markup,
|
||||||
|
highlight=highlight,
|
||||||
|
width=width,
|
||||||
|
height=height,
|
||||||
|
crop=crop,
|
||||||
|
soft_wrap=soft_wrap,
|
||||||
|
new_line_start=new_line_start,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 高级的输入函数
|
||||||
|
def ipt(
|
||||||
|
*objects: Any,
|
||||||
|
sep: str = " ",
|
||||||
|
justify: Optional[JustifyMethod] = None,
|
||||||
|
overflow: Optional[OverflowMethod] = None,
|
||||||
|
no_wrap: Optional[bool] = None,
|
||||||
|
emoji: Optional[bool] = None,
|
||||||
|
markup: Optional[bool] = None,
|
||||||
|
highlight: Optional[bool] = None,
|
||||||
|
width: Optional[int] = None,
|
||||||
|
height: Optional[int] = None,
|
||||||
|
crop: bool = True,
|
||||||
|
soft_wrap: Optional[bool] = None,
|
||||||
|
new_line_start: bool = False,
|
||||||
|
password: bool = False,
|
||||||
|
stream: Optional[TextIO] = None,
|
||||||
|
) -> str:
|
||||||
|
"""显示一个提示并等待用户的输入。
|
||||||
|
|
||||||
|
它的工作方式与Python内建的 :func:`input` 函数相同,如果Python内建的 :mod:`readline` 模块先前已经加载,则提供详细的行编辑和历史功能。
|
||||||
|
|
||||||
|
Args:
|
||||||
|
objects (位置性的args): 要记录到终端的对象。
|
||||||
|
sep (str, 可选): 要在打印数据之间写入的字符串。默认为""。
|
||||||
|
end (str, optio可选nal): 在打印数据结束时写入的字符串。默认值为"\\\\n"。
|
||||||
|
style (Union[str, Style], 可选): 应用于输出的样式。默认为`None`。
|
||||||
|
justify (str, 可选): 校正位置,可为"default", "left", "right", "center" 或 "full". 默认为`None`。
|
||||||
|
overflow (str, 可选): 控制溢出:"ignore"忽略, "crop"裁剪, "fold"折叠, "ellipsis"省略号。默认为`None`。
|
||||||
|
no_wrap (Optional[bool], 可选): 禁用文字包装。默认为`None`。
|
||||||
|
emoji (Optional[bool], 可选): 启用表情符号代码,或使用控制台默认的`None`。默认为`None`。
|
||||||
|
markup (Optional[bool], 可选): 启用标记,或`None`使用控制台默认值。默认为`None`。
|
||||||
|
highlight (Optional[bool], 可选): 启用自动高亮,或`None`使用控制台默认值。默认为`None`。
|
||||||
|
width (Optional[int], 可选): 输出的宽度,或`None`自动检测。默认为`None`。
|
||||||
|
crop (Optional[bool], 可选): 裁剪输出到终端的宽度。默认为`True`。
|
||||||
|
soft_wrap (bool, 可选): 启用软包装模式,禁止文字包装和裁剪,或`None``用于 控制台默认值。默认为`None`。
|
||||||
|
new_line_start (bool, False): 如果输出包含多行,在开始时插入一个新行。默认值为`False`。
|
||||||
|
password (bool, 可选): 隐藏已经输入的文案,默认值为`False`。
|
||||||
|
stream (TextIO, 可选): 可选从文件中读取(而非控制台),默认为 `None`。
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 从stdin读取的字符串
|
||||||
|
"""
|
||||||
|
MainConsole.print(
|
||||||
|
*objects,
|
||||||
|
sep=sep,
|
||||||
|
end="",
|
||||||
|
style="#F0F2F4 on #121110",
|
||||||
|
justify=justify,
|
||||||
|
overflow=overflow,
|
||||||
|
no_wrap=no_wrap,
|
||||||
|
emoji=emoji,
|
||||||
|
markup=markup,
|
||||||
|
highlight=highlight,
|
||||||
|
width=width,
|
||||||
|
height=height,
|
||||||
|
crop=crop,
|
||||||
|
soft_wrap=soft_wrap,
|
||||||
|
new_line_start=new_line_start,
|
||||||
|
)
|
||||||
|
|
||||||
|
return MainConsole.input("", password=password, stream=stream)
|
||||||
|
|
||||||
|
|
||||||
|
def formatipt(
|
||||||
|
notice: str,
|
||||||
|
fun,
|
||||||
|
errnote: str = "",
|
||||||
|
*extraArg,
|
||||||
|
):
|
||||||
|
'''循环输入,以某种格式
|
||||||
|
notice: 输入时的提示
|
||||||
|
fun: 格式函数
|
||||||
|
errnote: 输入不符格式时的提示
|
||||||
|
*extraArg: 对于函数的其他参数'''
|
||||||
|
while True:
|
||||||
|
result = ipt(notice)
|
||||||
|
try:
|
||||||
|
funresult = fun(result, *extraArg)
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
prt(errnote)
|
||||||
|
continue
|
||||||
|
return result, funresult
|
@ -123,6 +123,10 @@ class midiConvert:
|
|||||||
self.methods_byDelay = [
|
self.methods_byDelay = [
|
||||||
self._toCmdList_withDelay_m1,
|
self._toCmdList_withDelay_m1,
|
||||||
]
|
]
|
||||||
|
if self.debugMode:
|
||||||
|
from .magicBeing import prt,ipt
|
||||||
|
self.prt = prt
|
||||||
|
self.ipt = ipt
|
||||||
|
|
||||||
def convert(self, midiFile: str, outputPath: str, oldExeFormat: bool = True):
|
def convert(self, midiFile: str, outputPath: str, oldExeFormat: bool = True):
|
||||||
"""转换前需要先运行此函数来获取基本信息"""
|
"""转换前需要先运行此函数来获取基本信息"""
|
||||||
@ -561,6 +565,8 @@ class midiConvert:
|
|||||||
commands = 0
|
commands = 0
|
||||||
maxscore = 0
|
maxscore = 0
|
||||||
|
|
||||||
|
# 分轨的思路其实并不好,但这个算法就是这样
|
||||||
|
# 所以我建议用第二个方法 _toCmdList_m2
|
||||||
for i, track in enumerate(self.midi.tracks):
|
for i, track in enumerate(self.midi.tracks):
|
||||||
|
|
||||||
ticks = 0
|
ticks = 0
|
||||||
@ -596,8 +602,7 @@ class midiConvert:
|
|||||||
+ "="
|
+ "="
|
||||||
+ str(nowscore)
|
+ str(nowscore)
|
||||||
+ "}"
|
+ "}"
|
||||||
+ f"] ~ ~ ~ playsound {soundID} @s ~ ~{1 / volume - 1} ~ "
|
+ f"] ~ ~ ~ playsound {soundID} @s ^ ^ ^{1 / volume - 1} {msg.velocity/128} {2 ** ((msg.note - 60 - _X) / 12)}"
|
||||||
f"{msg.velocity * (0.7 if msg.channel == 0 else 0.9)} {2 ** ((msg.note - 60 - _X) / 12)}"
|
|
||||||
)
|
)
|
||||||
commands += 1
|
commands += 1
|
||||||
if len(singleTrack) != 0:
|
if len(singleTrack) != 0:
|
||||||
@ -620,10 +625,7 @@ class midiConvert:
|
|||||||
:return: tuple(命令列表, 命令个数, 计分板最大值)
|
:return: tuple(命令列表, 命令个数, 计分板最大值)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if MaxVolume > 1:
|
MaxVolume = 1 if MaxVolume > 1 else (0.001 if MaxVolume <= 0 else MaxVolume)
|
||||||
MaxVolume = 1
|
|
||||||
if MaxVolume <= 0:
|
|
||||||
MaxVolume = 0.001
|
|
||||||
|
|
||||||
# 一个midi中仅有16通道 我们通过通道来识别而不是音轨
|
# 一个midi中仅有16通道 我们通过通道来识别而不是音轨
|
||||||
channels = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
|
channels = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
|
||||||
@ -643,6 +645,8 @@ class midiConvert:
|
|||||||
if msg.is_meta:
|
if msg.is_meta:
|
||||||
if msg.type == "set_tempo":
|
if msg.type == "set_tempo":
|
||||||
tempo = msg.tempo
|
tempo = msg.tempo
|
||||||
|
if self.debugMode:
|
||||||
|
self.prt(f"TEMPO更改:{tempo}(毫秒每拍)")
|
||||||
else:
|
else:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -679,6 +683,9 @@ class midiConvert:
|
|||||||
3 音符结束消息
|
3 音符结束消息
|
||||||
("NoteS", 结束的音符ID, 距离演奏开始的毫秒)"""
|
("NoteS", 结束的音符ID, 距离演奏开始的毫秒)"""
|
||||||
|
|
||||||
|
if self.debugMode:
|
||||||
|
self.prt(dict(enumerate(channels)))
|
||||||
|
|
||||||
tracks = []
|
tracks = []
|
||||||
cmdAmount = 0
|
cmdAmount = 0
|
||||||
maxScore = 0
|
maxScore = 0
|
||||||
@ -702,11 +709,13 @@ class midiConvert:
|
|||||||
InstID = msg[1]
|
InstID = msg[1]
|
||||||
|
|
||||||
elif msg[0] == "NoteS":
|
elif msg[0] == "NoteS":
|
||||||
|
try:
|
||||||
if SpecialBits:
|
soundID, _X = (self.__bitInst2IDwithX(InstID) if SpecialBits else self.__Inst2soundIDwithX(InstID))
|
||||||
soundID, _X = self.__bitInst2IDwithX(InstID)
|
except UnboundLocalError as E:
|
||||||
|
if self.debugMode:
|
||||||
|
raise NotDefineProgramError(f"未定义乐器便提前演奏。\n{E}")
|
||||||
else:
|
else:
|
||||||
soundID, _X = self.__Inst2soundIDwithX(InstID)
|
soundID, _X = (self.__bitInst2IDwithX(-1) if SpecialBits else self.__Inst2soundIDwithX(-1))
|
||||||
score_now = round(msg[-1] / float(speed) / 50)
|
score_now = round(msg[-1] / float(speed) / 50)
|
||||||
maxScore = max(maxScore, score_now)
|
maxScore = max(maxScore, score_now)
|
||||||
|
|
||||||
@ -1117,8 +1126,10 @@ class midiConvert:
|
|||||||
|
|
||||||
indexfile.close()
|
indexfile.close()
|
||||||
|
|
||||||
|
if os.path.exists(f"{self.outputPath}/{self.midFileName}.mcpack"):
|
||||||
|
os.remove(f"{self.outputPath}/{self.midFileName}.mcpack")
|
||||||
makeZip(
|
makeZip(
|
||||||
f"{self.outputPath}/temp/", self.outputPath + f"/{self.midFileName}.mcpack"
|
f"{self.outputPath}/temp/", f"{self.outputPath}/{self.midFileName}.mcpack"
|
||||||
)
|
)
|
||||||
|
|
||||||
shutil.rmtree(f"{self.outputPath}/temp/")
|
shutil.rmtree(f"{self.outputPath}/temp/")
|
||||||
@ -1323,3 +1334,65 @@ class midiConvert:
|
|||||||
return (True, len(cmdlist), maxdelay, size, finalPos)
|
return (True, len(cmdlist), maxdelay, size, finalPos)
|
||||||
|
|
||||||
|
|
||||||
|
def toDICT(
|
||||||
|
self,
|
||||||
|
) -> list:
|
||||||
|
"""
|
||||||
|
使用金羿的转换思路,将midi转换为字典
|
||||||
|
:return: dict()
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 一个midi中仅有16通道 我们通过通道来识别而不是音轨
|
||||||
|
channels = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
|
||||||
|
microseconds = 0
|
||||||
|
|
||||||
|
# 我们来用通道统计音乐信息
|
||||||
|
for msg in self.midi:
|
||||||
|
|
||||||
|
if msg.time != 0:
|
||||||
|
try:
|
||||||
|
microseconds += msg.time * tempo / self.midi.ticks_per_beat
|
||||||
|
# print(microseconds)
|
||||||
|
except NameError:
|
||||||
|
raise NotDefineTempoError("计算当前分数时出错 未定义参量 Tempo")
|
||||||
|
|
||||||
|
if msg.is_meta:
|
||||||
|
if msg.type == "set_tempo":
|
||||||
|
tempo = msg.tempo
|
||||||
|
else:
|
||||||
|
|
||||||
|
try:
|
||||||
|
msg.channel
|
||||||
|
channelMsg = True
|
||||||
|
except:
|
||||||
|
channelMsg = False
|
||||||
|
if channelMsg:
|
||||||
|
if msg.channel > 15:
|
||||||
|
raise ChannelOverFlowError(f"当前消息 {msg} 的通道超限(≤15)")
|
||||||
|
|
||||||
|
if msg.type == "program_change":
|
||||||
|
channels[msg.channel].append(("PgmC", msg.program, microseconds))
|
||||||
|
|
||||||
|
elif msg.type == "note_on" and msg.velocity != 0:
|
||||||
|
channels[msg.channel].append(
|
||||||
|
("NoteS", msg.note, msg.velocity, microseconds)
|
||||||
|
)
|
||||||
|
|
||||||
|
elif (msg.type == "note_on" and msg.velocity == 0) or (
|
||||||
|
msg.type == "note_off"
|
||||||
|
):
|
||||||
|
channels[msg.channel].append(("NoteE", msg.note, microseconds))
|
||||||
|
|
||||||
|
"""整合后的音乐通道格式
|
||||||
|
每个通道包括若干消息元素其中逃不过这三种:
|
||||||
|
|
||||||
|
1 切换乐器消息
|
||||||
|
("PgmC", 切换后的乐器ID: int, 距离演奏开始的毫秒)
|
||||||
|
|
||||||
|
2 音符开始消息
|
||||||
|
("NoteS", 开始的音符ID, 力度(响度), 距离演奏开始的毫秒)
|
||||||
|
|
||||||
|
3 音符结束消息
|
||||||
|
("NoteS", 结束的音符ID, 距离演奏开始的毫秒)"""
|
||||||
|
|
||||||
|
return dict(enumerate(channels))
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Brotli==1.0.9
|
||||||
|
mido==1.2.10
|
Loading…
x
Reference in New Issue
Block a user