mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2024-11-11 01:27:35 +08:00
update 2023/5/6 nbs基础
This commit is contained in:
parent
cb95c51a47
commit
1f226b1fab
@ -198,3 +198,22 @@ instrument_to_blocks_list = {
|
||||
"note.bassattack": ("command_block",), # 无法找到此音效
|
||||
"note.harp": ("glass",),
|
||||
}
|
||||
|
||||
nbs_instrument_to_name = {
|
||||
0: "Piano", # (air)
|
||||
1: "Double Bass", # (Wood)
|
||||
2: "Bass Drum", # (Stone)
|
||||
3: "Snare Drum", # (Sand)
|
||||
4: "Click", # (Glass)
|
||||
5: "Guitar", # (Wool)
|
||||
6: "Flute", # (Clay)
|
||||
7: "Bell", # (Block of Gold)
|
||||
8: "Chime", # (Packed Ice)
|
||||
9: "Xylophone", # (Bone Block)
|
||||
10: "Iron Xylophone", # (Iron Block)
|
||||
11: "Cow Bell", # (Soul Sand)
|
||||
12: "Didgeridoo", # (Pumpkin)
|
||||
13: "Bit", # (Block of Emerald)
|
||||
14: "Banjo", # (Hay)
|
||||
15: "Pling", # (Glowstone)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ from typing import TypeVar, Union
|
||||
|
||||
import brotli
|
||||
import mido
|
||||
# import pathlib
|
||||
|
||||
from .exceptions import *
|
||||
from .instConstants import *
|
||||
@ -34,6 +35,7 @@ from .utils import *
|
||||
|
||||
T = TypeVar("T") # Declare type variable
|
||||
VM = TypeVar("VM", mido.MidiFile, None) # void mido
|
||||
# PATH = TypeVar("PATH", str, pathlib.Path) # path
|
||||
|
||||
DEFAULT_PROGRESSBAR_STYLE = (
|
||||
r"▶ %%N [ %%s/%^s %%% __________ %%t|%^t ]",
|
||||
@ -288,8 +290,6 @@ class midiConvert:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
maxscore: int
|
||||
midi的乐器ID
|
||||
|
||||
scoreboard_name: str
|
||||
所使用的计分板名称
|
||||
@ -746,7 +746,7 @@ class midiConvert:
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if not track_no in channels[msg.channel].keys():
|
||||
if track_no not in channels[msg.channel].keys():
|
||||
channels[msg.channel][track_no] = []
|
||||
if msg.type == "program_change":
|
||||
channels[msg.channel][track_no].append(
|
||||
@ -1327,7 +1327,7 @@ class midiConvert:
|
||||
try:
|
||||
if msg.channel > 15 and self.debug_mode:
|
||||
raise ChannelOverFlowError(f"当前消息 {msg} 的通道超限(≤15)")
|
||||
if not track_no in channels[msg.channel].keys():
|
||||
if track_no not in channels[msg.channel].keys():
|
||||
channels[msg.channel][track_no] = []
|
||||
except AttributeError:
|
||||
pass
|
||||
@ -1587,7 +1587,6 @@ class midiConvert:
|
||||
"""
|
||||
使用method指定的转换算法,将midi转换为mcstructure结构文件后打包成mcpack文件
|
||||
:param method: 转换算法
|
||||
:param author: 作者名称
|
||||
:param progressbar: 进度条,(当此参数为True时使用默认进度条,为其他的值为真的参数时识别为进度条自定义参数,为其他值为假的时候不生成进度条)
|
||||
:param max_height: 生成结构最大高度
|
||||
:param volume: 音量,注意:这里的音量范围为(0,1],如果超出将被处理为正确值,其原理为在距离玩家 (1 / volume -1) 的地方播放音频
|
||||
@ -1730,7 +1729,7 @@ class midiConvert:
|
||||
r"scoreboard players reset {} {}".format(player, scb_name),
|
||||
(0, 0, 0),
|
||||
1,
|
||||
0,
|
||||
0 + 0, # 不要问为什么这样写,因为要避免
|
||||
alwaysRun=False,
|
||||
customName="重置进度条计分板",
|
||||
),
|
||||
@ -1785,8 +1784,6 @@ class midiConvert:
|
||||
"""
|
||||
使用method指定的转换算法,将midi转换为mcstructure结构文件
|
||||
:param method: 转换算法
|
||||
:param author: 作者名称
|
||||
:param progressbar: 进度条,(当此参数为True时使用默认进度条,为其他的值为真的参数时识别为进度条自定义参数,为其他值为假的时候不生成进度条)
|
||||
:param max_height: 生成结构最大高度
|
||||
:param volume: 音量,注意:这里的音量范围为(0,1],如果超出将被处理为正确值,其原理为在距离玩家 (1 / volume -1) 的地方播放音频
|
||||
:param speed: 速度,注意:这里的速度指的是播放倍率,其原理为在播放音频的时候,每个音符的播放时间除以 speed
|
||||
@ -2087,7 +2084,7 @@ class midiConvert:
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if not track_no in channels[msg.channel].keys():
|
||||
if track_no not in channels[msg.channel].keys():
|
||||
channels[msg.channel][track_no] = []
|
||||
if msg.type == "program_change":
|
||||
channels[msg.channel][track_no].append(
|
||||
@ -2119,3 +2116,30 @@ class midiConvert:
|
||||
("NoteS", 结束的音符ID, 距离演奏开始的毫秒)"""
|
||||
|
||||
return channels
|
||||
|
||||
@staticmethod
|
||||
def prt(anything):
|
||||
print(anything)
|
||||
|
||||
|
||||
class nbsConvert:
|
||||
def __init__(self, file_path: str = ""):
|
||||
self.file_path = file_path
|
||||
|
||||
def load(self):
|
||||
import pynbs
|
||||
demo_song = pynbs.read(self.file_path)
|
||||
first_custom_instrument = demo_song.instruments
|
||||
print(first_custom_instrument)
|
||||
for tick, chord in pynbs.read(self.file_path):
|
||||
print(tick, chord)
|
||||
print(tick, [note.key for note in chord])
|
||||
# 乐器id 可以查instC里的表
|
||||
# key解析规则: 0-87, where 0 is A0 and 87 is C8
|
||||
# mid: AO 21 C8 108
|
||||
# 所以 pitch_id = key - 21
|
||||
|
||||
# velocity解析规则: 0-100
|
||||
# panning: The stereo panning of the note. (between -100 and 100)
|
||||
# note.pitch: The detune of the note, in cents. (between -1200 and 1200)
|
||||
# 也就是说这个pitch是半音的偏移量
|
||||
|
BIN
Musicreater/test/compat_demo_song.nbs
Normal file
BIN
Musicreater/test/compat_demo_song.nbs
Normal file
Binary file not shown.
BIN
Musicreater/test/compat_old_demo_song.nbs
Normal file
BIN
Musicreater/test/compat_old_demo_song.nbs
Normal file
Binary file not shown.
BIN
Musicreater/test/megalovania.nbs
Normal file
BIN
Musicreater/test/megalovania.nbs
Normal file
Binary file not shown.
BIN
Musicreater/test/nyan_cat.nbs
Normal file
BIN
Musicreater/test/nyan_cat.nbs
Normal file
Binary file not shown.
BIN
Musicreater/test/test.nbs
Normal file
BIN
Musicreater/test/test.nbs
Normal file
Binary file not shown.
BIN
Musicreater/test/the_grounds_colour_is_yellow.nbs
Normal file
BIN
Musicreater/test/the_grounds_colour_is_yellow.nbs
Normal file
Binary file not shown.
BIN
Musicreater/test/turkish_march.nbs
Normal file
BIN
Musicreater/test/turkish_march.nbs
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user