从note block studio读取和写入.nbs文件的简单python库

pynbs的Python项目详细描述


Pynbs

PyPIPyPI - Python Version

A simple python library to read and write .nbs files from Open Note Block Studio. Compatible with python 2 and 3.

pynbs使得可以轻松地在note block studio歌曲上迭代。

importpynbsfortick,chordinpynbs.read('demo_song.nbs'):print(tick,[note.keyfornoteinchord])

您还可以使用pynbs以编程方式生成新歌曲。

importpynbsnew_file=pynbs.new_file(song_name='Hello world')new_file.notes.extend([pynbs.Note(tick=i,layer=0,instrument=0,key=i+35)foriinrange(10)])new_file.save('new_file.nbs')

安装

可以使用pip安装包。

$ pip install pynbs

最新版本遵循NBS文件格式的最新版本 specification (版本3)。

基本用法

读取文件

您可以使用read()函数读取和解析特定的nbs文件。

demo_song=pynbs.read('demo_song.nbs')

read()函数返回一个pynbs文件对象。这些物体有几个 映射NBS文件二进制结构的属性。

标题

第一个属性是文件头header。它包含有关 文件。

header=demo_song.header
AttributeTypeDetails
^{}^{}The NBS format version.
^{}^{}The amount of instruments from vanilla Minecraft in the song.
^{}^{}The length of the song, measured in ticks.
^{}^{}The id of the last layer with at least one note block in it.
^{}^{}The name of the song.
^{}^{}The author of the song.
^{}^{}The original song author of the song.
^{}^{}The description of the song.
^{}^{}The tempo of the song.
^{}^{}Whether auto-saving has been enabled.
^{}^{}The amount of minutes between each auto-save.
^{}^{}The time signature of the song.
^{}^{}The amount of minutes spent on the project.
^{}^{}The amount of times the user have left clicked.
^{}^{}The amount of times the user have right clicked.
^{}^{}The amount of times the user have added a block.
^{}^{}The amount of times the user have removed a block.
^{}^{}The file name of the original midi or schematic.

For more information about all these fields, check out the official specification.

注释

notes属性按顺序保存歌曲所有音符的列表。

first_note=demo_song.notes[0]
AttributeTypeDetails
^{}^{}The tick at which the note plays.
^{}^{}The id of the layer in which the note is placed.
^{}^{}The id of the instrument.
^{}^{}The key of the note. (between 0 and 87)

layers属性按顺序保存歌曲所有层的列表。

first_layer=demo_song.layers[0]
AttributeTypeDetails
^{}^{}The id of the layer.
^{}^{}The name of the layer.
^{}^{}The volume of the layer.
^{}^{}The stereo panning of the layer.

仪器

instruments属性包含 按顺序唱。

first_custom_instrument=demo_song.instruments[0]
AttributeTypeDetails
^{}^{}The id of the instrument.
^{}^{}The name of the instrument.
^{}^{}The name of the sound file of the instrument.
^{}^{}The pitch of the instrument. (between 0 and 87)
^{}^{}Whether the piano should automatically press keys with the instrument when the marker passes them.

在歌曲上迭代

pynbs文件对象上迭代将连续生成歌曲的所有和弦 关联的勾号。

fortick,chordindemo_song:...

chord是在滴答声中播放的所有音符的列表。

创建新文件

可以使用new_file()函数创建新文件。函数允许 可以使用关键字参数指定头属性。

new_file=pynbs.new_file(song_name='Hello world')

函数返回一个新的pynbs文件对象,您现在可以编辑它 以编程方式。

保存文件

您可以使用save()方法对文件进行编码并将其写入指定的 地点。

new_file.save('new_file.nbs')

升级旧文件

pynbs是最新的开源延续规范 在Minecraft Note Block Studio中,原始文件格式仍受 read()函数,使将歌曲批量升级到新格式成为可能。

importglobimportpynbsforold_fileinglob.glob('*.nbs'):pynbs.read(old_file).save(old_file)

许可证-MIT

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
具有多用户OU和多访问CNs的java Spring LDAP身份验证   java分配的变量神秘地变为null   java比较两个表或文本文件,并用行号和列输出差异   java如何在同一构建目录中设置netbeans中的文件路径?   java如何在avro模式中定义byte[]和LocalDateTime?   java在多个活动和片段中使用相同的微调器。实施它的最佳方式是什么?   java使用OOPS扩展已编写的类   java如何在特定于文件的基础上禁用Eclipse中的编译器警告?   java将字符串转换为日期的格式不正确   Java文件从一台服务器复制到另一台服务器   java Jacksonal和JacksonApperasl的最新jar版本是什么?   java如何在使用selenium chrome web驱动程序时禁用chrome中的身份验证提示   java是什么。推荐人和推荐人。Eclipse工作区中的元数据以及它们是否应该在设备之间同步?   java我应该把sqlite db文件放在哪里,这样我的jar就可以访问它了?这对连接字符串有何影响?   java如何在选择单元格时设置JTable标题背景色   java Cassandra 2 Hector:复合行键上的范围切片查询返回空行   java方法注释继承   Python字节对象与java   java Android和从sqlite数据库加载listview