mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2026-04-17 06:08:00 +00:00
73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
示例插件:导入音符数据
|
|
"""
|
|
|
|
"""
|
|
版权所有 © 2026 金羿
|
|
Copyright © 2026 Eilles
|
|
"""
|
|
|
|
# 睿乐组织 开发交流群 861684859
|
|
# Email TriM-Organization@hotmail.com
|
|
|
|
"""
|
|
本示例模块开放授权,本文件已开放至公共领域。
|
|
请注意:
|
|
若是对本文件的直接转载(在形式上没有修改、增删、添加注释,或单纯修改排版、翻译、录屏、截图)
|
|
则该使用者需要在转载所及之处,明确在转载的内容开头标注本文之原始著作权人
|
|
在当前文件下,该原始著作权人为金羿(Eilles)
|
|
如果是对本文进行了一定程度上的修改和补充、或者以不同方式演绎本文件(如制成视频教程等)
|
|
则无需标注原作者,允许该使用者自行署名
|
|
|
|
本声明仅限于包含此声明的本文件,本声明与项目内其他文件无关。
|
|
"""
|
|
|
|
from typing import BinaryIO, Optional
|
|
from pathlib import Path
|
|
from dataclasses import dataclass
|
|
|
|
from Musicreater import SingleMusic
|
|
from Musicreater.plugins import (
|
|
music_input_plugin,
|
|
PluginConfig,
|
|
PluginMetaInformation,
|
|
PluginTypes,
|
|
MusicInputPluginBase,
|
|
)
|
|
|
|
|
|
@dataclass
|
|
class ExampleImportConfig(PluginConfig):
|
|
example_config_item3: bool
|
|
example_config_item1: str = "example_config_item"
|
|
example_config_item2: int = 0
|
|
|
|
|
|
@music_input_plugin("something_convert_to_music")
|
|
class ExampleImportPlugin(MusicInputPluginBase):
|
|
metainfo = PluginMetaInformation(
|
|
name="示例导入插件",
|
|
author="金羿",
|
|
description="这是一个示例导入插件",
|
|
version=(0, 0, 1),
|
|
type=PluginTypes.FUNCTION_MUSIC_IMPORT,
|
|
license="The Unlicense",
|
|
dependencies=("something_convertion_library"),
|
|
)
|
|
|
|
supported_formats = ("EXP", "example_format")
|
|
|
|
def loadbytes(
|
|
self, bytes_buffer_in: BinaryIO, config: Optional[ExampleImportConfig]
|
|
) -> "SingleMusic":
|
|
return SingleMusic()
|
|
|
|
# 插件可选地定义 load 方法,从文件导入数据。下面展示的是不定义 load 方法时候的实现方式
|
|
def load(
|
|
self, file_path: Path, config: Optional[ExampleImportConfig]
|
|
) -> "SingleMusic":
|
|
with file_path.open("rb") as f:
|
|
return self.loadbytes(f, config)
|