# Parser()
构造函数 Parser()。通过 XML 文件解析为 JSON 格式数据。
# 配置
名称 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
debug | number | false | 否 | 是否调试模式 |
speed | number | 1 | 否 | 自定义速度(从 0 ~ 1) |
xmlStr | string | - | 是 | MusicXML文本 |
# 方法
名称 | 类型 | 说明 |
---|---|---|
getMeasureById | function(measureId: string): Measure | 通过ID获取小节 |
getNoteById | function(noteId: string): Note | 通过ID获取音符 |
# 返回值
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
parts | Part[] | [] | 声部 |
title | string | "" | 标题 |
# 示例
const configs = {
36: { code: 36, name: 'Kick', value: [36], index: 0 },
37: { code: 37, name: 'Snare', value: [37], index: 1 },
38: { code: 38, name: 'Snare', value: [38, 125], index: 2 }
}
import { Parser } from 'musicxml2json-drum'
const parser = new Parser({
debug: true,
instruments: configs,
speed: 1,
xmlStr
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# JSON
{
"parts": [
{
"duration": 6500,
"measures": []
}
],
"title": "",
"_debug": true,
"_speed": 1
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11