@flat/instruments 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/data/instruments.json +1710 -0
- package/dist/data/instruments.json +1710 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +43 -0
- package/dist/src/types.d.ts +39 -0
- package/dist/src/types.js +2 -0
- package/package.json +56 -0
- package/schema/instruments.schema.json +94 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Instrument, InstrumentGroup } from './types';
|
|
2
|
+
export type { Instrument, InstrumentGroup, InstrumentType, InstrumentsFile } from './types';
|
|
3
|
+
/** All instrument groups, in catalog display order. */
|
|
4
|
+
export declare const groups: InstrumentGroup[];
|
|
5
|
+
/** Flat list of every instrument, in catalog display order. */
|
|
6
|
+
export declare const instruments: Instrument[];
|
|
7
|
+
/**
|
|
8
|
+
* Look up an instrument by its canonical `group.instrument` ID.
|
|
9
|
+
*
|
|
10
|
+
* @returns the instrument, or `undefined` if the ID is unknown.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getInstrument(id: string): Instrument | undefined;
|
|
13
|
+
/** Whether `id` is a known canonical instrument ID. */
|
|
14
|
+
export declare function isValidInstrumentId(id: string): boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.instruments = exports.groups = void 0;
|
|
7
|
+
exports.getInstrument = getInstrument;
|
|
8
|
+
exports.isValidInstrumentId = isValidInstrumentId;
|
|
9
|
+
const instruments_json_1 = __importDefault(require("../data/instruments.json"));
|
|
10
|
+
function toInstrumentType(value, id) {
|
|
11
|
+
if (value === 'pitched' || value === 'unpitched') {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`Invalid instrument type "${value}" for instrument "${id}"`);
|
|
15
|
+
}
|
|
16
|
+
/** All instrument groups, in catalog display order. */
|
|
17
|
+
exports.groups = instruments_json_1.default.groups.map(group => ({
|
|
18
|
+
id: group.id,
|
|
19
|
+
name: group.name,
|
|
20
|
+
instruments: group.instruments.map(instrument => ({
|
|
21
|
+
id: instrument.id,
|
|
22
|
+
group: instrument.group,
|
|
23
|
+
name: instrument.name,
|
|
24
|
+
shortname: instrument.shortname,
|
|
25
|
+
type: toInstrumentType(instrument.type, instrument.id),
|
|
26
|
+
premium: instrument.premium,
|
|
27
|
+
})),
|
|
28
|
+
}));
|
|
29
|
+
/** Flat list of every instrument, in catalog display order. */
|
|
30
|
+
exports.instruments = exports.groups.flatMap(group => group.instruments);
|
|
31
|
+
const byId = new Map(exports.instruments.map(instrument => [instrument.id, instrument]));
|
|
32
|
+
/**
|
|
33
|
+
* Look up an instrument by its canonical `group.instrument` ID.
|
|
34
|
+
*
|
|
35
|
+
* @returns the instrument, or `undefined` if the ID is unknown.
|
|
36
|
+
*/
|
|
37
|
+
function getInstrument(id) {
|
|
38
|
+
return byId.get(id);
|
|
39
|
+
}
|
|
40
|
+
/** Whether `id` is a known canonical instrument ID. */
|
|
41
|
+
function isValidInstrumentId(id) {
|
|
42
|
+
return byId.has(id);
|
|
43
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an instrument is pitched (melodic) or unpitched (percussion / drum-style kit).
|
|
3
|
+
*/
|
|
4
|
+
export type InstrumentType = 'pitched' | 'unpitched';
|
|
5
|
+
/**
|
|
6
|
+
* A single instrument in Flat's public catalog.
|
|
7
|
+
*/
|
|
8
|
+
export interface Instrument {
|
|
9
|
+
/** Canonical instrument ID in `group.instrument` form, e.g. `"keyboards.piano"`. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Group / family ID this instrument belongs to, e.g. `"keyboards"`. */
|
|
12
|
+
group: string;
|
|
13
|
+
/** English display name, e.g. `"Piano"`. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Short English label used on staves, e.g. `"Pno."`. */
|
|
16
|
+
shortname: string;
|
|
17
|
+
/** `"pitched"` for melodic instruments, `"unpitched"` for percussion / drum-style kits. */
|
|
18
|
+
type: InstrumentType;
|
|
19
|
+
/** `true` when the instrument requires a paid Flat plan. */
|
|
20
|
+
premium: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A group / family of instruments (e.g. Keyboards, Brass), in catalog display order.
|
|
24
|
+
*/
|
|
25
|
+
export interface InstrumentGroup {
|
|
26
|
+
/** Group ID, e.g. `"keyboards"`. */
|
|
27
|
+
id: string;
|
|
28
|
+
/** English display name, e.g. `"Keyboards"`. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Instruments in this group, in catalog display order. */
|
|
31
|
+
instruments: Instrument[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Top-level shape of `data/instruments.json` — the published catalog.
|
|
35
|
+
*/
|
|
36
|
+
export interface InstrumentsFile {
|
|
37
|
+
/** All instrument groups, in catalog display order. */
|
|
38
|
+
groups: InstrumentGroup[];
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flat/instruments",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The public catalog of musical instruments used by the Flat platform and API.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"author": "Tutteo Ltd. <hello@flat.io>",
|
|
7
|
+
"homepage": "https://flat.io/developers/docs/api/instruments",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/FlatIO/instruments.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/FlatIO/instruments/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"flat",
|
|
17
|
+
"flat.io",
|
|
18
|
+
"music",
|
|
19
|
+
"instruments",
|
|
20
|
+
"notation",
|
|
21
|
+
"midi",
|
|
22
|
+
"music-notation"
|
|
23
|
+
],
|
|
24
|
+
"main": "dist/src/index.js",
|
|
25
|
+
"types": "dist/src/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/src/index.d.ts",
|
|
29
|
+
"default": "./dist/src/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./data/instruments.json": "./data/instruments.json",
|
|
32
|
+
"./schema/instruments.schema.json": "./schema/instruments.schema.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"data",
|
|
37
|
+
"schema",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^22.10.0",
|
|
45
|
+
"ajv": "^8.17.1",
|
|
46
|
+
"ts-json-schema-generator": "^2.4.0",
|
|
47
|
+
"typescript": "^5.9.3"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc",
|
|
51
|
+
"build-schema": "ts-json-schema-generator --path src/types.ts --type InstrumentsFile --out schema/instruments.schema.json --no-top-ref",
|
|
52
|
+
"validate": "node scripts/validate.mjs",
|
|
53
|
+
"test": "node --test test/*.test.mjs",
|
|
54
|
+
"typecheck": "tsc --noEmit"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"additionalProperties": false,
|
|
4
|
+
"definitions": {
|
|
5
|
+
"Instrument": {
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"description": "A single instrument in Flat's public catalog.",
|
|
8
|
+
"properties": {
|
|
9
|
+
"group": {
|
|
10
|
+
"description": "Group / family ID this instrument belongs to, e.g. `\"keyboards\"`.",
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
"id": {
|
|
14
|
+
"description": "Canonical instrument ID in `group.instrument` form, e.g. `\"keyboards.piano\"`.",
|
|
15
|
+
"type": "string"
|
|
16
|
+
},
|
|
17
|
+
"name": {
|
|
18
|
+
"description": "English display name, e.g. `\"Piano\"`.",
|
|
19
|
+
"type": "string"
|
|
20
|
+
},
|
|
21
|
+
"premium": {
|
|
22
|
+
"description": "`true` when the instrument requires a paid Flat plan.",
|
|
23
|
+
"type": "boolean"
|
|
24
|
+
},
|
|
25
|
+
"shortname": {
|
|
26
|
+
"description": "Short English label used on staves, e.g. `\"Pno.\"`.",
|
|
27
|
+
"type": "string"
|
|
28
|
+
},
|
|
29
|
+
"type": {
|
|
30
|
+
"$ref": "#/definitions/InstrumentType",
|
|
31
|
+
"description": "`\"pitched\"` for melodic instruments, `\"unpitched\"` for percussion / drum-style kits."
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"required": [
|
|
35
|
+
"id",
|
|
36
|
+
"group",
|
|
37
|
+
"name",
|
|
38
|
+
"shortname",
|
|
39
|
+
"type",
|
|
40
|
+
"premium"
|
|
41
|
+
],
|
|
42
|
+
"type": "object"
|
|
43
|
+
},
|
|
44
|
+
"InstrumentGroup": {
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"description": "A group / family of instruments (e.g. Keyboards, Brass), in catalog display order.",
|
|
47
|
+
"properties": {
|
|
48
|
+
"id": {
|
|
49
|
+
"description": "Group ID, e.g. `\"keyboards\"`.",
|
|
50
|
+
"type": "string"
|
|
51
|
+
},
|
|
52
|
+
"instruments": {
|
|
53
|
+
"description": "Instruments in this group, in catalog display order.",
|
|
54
|
+
"items": {
|
|
55
|
+
"$ref": "#/definitions/Instrument"
|
|
56
|
+
},
|
|
57
|
+
"type": "array"
|
|
58
|
+
},
|
|
59
|
+
"name": {
|
|
60
|
+
"description": "English display name, e.g. `\"Keyboards\"`.",
|
|
61
|
+
"type": "string"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"required": [
|
|
65
|
+
"id",
|
|
66
|
+
"name",
|
|
67
|
+
"instruments"
|
|
68
|
+
],
|
|
69
|
+
"type": "object"
|
|
70
|
+
},
|
|
71
|
+
"InstrumentType": {
|
|
72
|
+
"description": "Whether an instrument is pitched (melodic) or unpitched (percussion / drum-style kit).",
|
|
73
|
+
"enum": [
|
|
74
|
+
"pitched",
|
|
75
|
+
"unpitched"
|
|
76
|
+
],
|
|
77
|
+
"type": "string"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"description": "Top-level shape of `data/instruments.json` — the published catalog.",
|
|
81
|
+
"properties": {
|
|
82
|
+
"groups": {
|
|
83
|
+
"description": "All instrument groups, in catalog display order.",
|
|
84
|
+
"items": {
|
|
85
|
+
"$ref": "#/definitions/InstrumentGroup"
|
|
86
|
+
},
|
|
87
|
+
"type": "array"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"required": [
|
|
91
|
+
"groups"
|
|
92
|
+
],
|
|
93
|
+
"type": "object"
|
|
94
|
+
}
|