-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.d.ts
157 lines (151 loc) · 4.54 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
export interface MidiHeader {
format: 0 | 1 | 2;
numTracks: number;
timeDivision?: number;
framesPerSecond?: number;
ticksPerFrame?: number;
ticksPerBeat?: number;
}
export interface MidiBaseEvent<T> {
deltaTime: number;
type: T;
}
export interface MidiMetaEvent<T> extends MidiBaseEvent<T> {
meta?: true;
}
export interface MidiSmpteOffsetMixins {
frameRate: 24 | 25 | 26 | 29 | 30;
hour: number;
min: number;
sec: number;
frame: number;
subFrame: number;
}
export interface MidiTimeSignatureMixins {
numerator: number;
denominator: number;
metronome: number;
thirtyseconds: number;
}
export interface MidiKeySignatureMixins {
key: number;
scale: number;
}
export interface MidiDataMixins {
data: ArrayLike<number>;
}
export interface MidiUnknownMixins {
data: ArrayLike<number>;
metatypeByte: number;
}
export interface MidiNumberMixins {
number: number;
}
export interface MidiTextMixins {
text: string;
}
export type MidiSequenceNumberEvent = MidiMetaEvent<"sequenceNumber"> &
MidiNumberMixins;
export type MidiTextEvent = MidiMetaEvent<"text"> & MidiTextMixins;
export type MidiCopyrightNoticeEvent = MidiMetaEvent<"copyrightNotice"> &
MidiTextMixins;
export type MidiTrackNameEvent = MidiMetaEvent<"trackName"> & MidiTextMixins;
export type MidiInstrumentNameEvent = MidiMetaEvent<"instrumentName"> &
MidiTextMixins;
export type MidiLyricsEvent = MidiMetaEvent<"lyrics"> & MidiTextMixins;
export type MidiMarkerEvent = MidiMetaEvent<"marker"> & MidiTextMixins;
export type MidiCuePointEvent = MidiMetaEvent<"cuePoint"> & MidiTextMixins;
export type MidiChannelPrefixEvent = MidiMetaEvent<"channelPrefix"> & {
channel: number;
};
export type MidiPortPrefixEvent = MidiMetaEvent<"portPrefix"> & {
port: number;
};
export type MidiEndOfTrackEvent = MidiMetaEvent<"endOfTrack">;
export type MidiSetTempoEvent = MidiMetaEvent<"setTempo"> & {
microsecondsPerBeat: number;
};
export type MidiSmpteOffsetEvent = MidiMetaEvent<"smpteOffset"> &
MidiSmpteOffsetMixins;
export type MidiTimeSignatureEvent = MidiMetaEvent<"timeSignature"> &
MidiTimeSignatureMixins;
export type MidiKeySignatureEvent = MidiMetaEvent<"keySignature"> &
MidiKeySignatureMixins;
export type MidiSequencerSpecificEvent = MidiMetaEvent<"sequencerSpecific"> &
MidiDataMixins;
export type MidiUnknownEvent = MidiMetaEvent<"unknownMeta"> & MidiUnknownMixins;
export type MidiSysExEvent = MidiBaseEvent<"sysEx"> & MidiDataMixins;
export type MidiEndSysExEvent = MidiBaseEvent<"endSysEx"> & MidiDataMixins;
export interface MidiNoteMixins {
noteNumber: number;
velocity: number;
byte9?: true;
}
export interface MidiNoteAftertouchMixins {
noteNumber: number;
amount: number;
}
export interface MidiControllerMixins {
controllerType: number;
value: number;
}
export interface MidiChannelEvent<T> extends MidiBaseEvent<T> {
running?: true;
channel: number;
}
export type MidiNoteOnEvent = MidiChannelEvent<"noteOn"> & MidiNoteMixins;
export type MidiNoteOffEvent = MidiChannelEvent<"noteOff"> & MidiNoteMixins;
export type MidiNoteAftertouchEvent = MidiChannelEvent<"noteAftertouch"> &
MidiNoteAftertouchMixins;
export type MidiControllerEvent = MidiChannelEvent<"controller"> &
MidiControllerMixins;
export type MidiProgramChangeEvent = MidiChannelEvent<"programChange"> & {
programNumber: number;
};
export type MidiChannelAftertouchEvent =
MidiChannelEvent<"channelAftertouch"> & {
amount: number;
};
export type MidiPitchBendEvent = MidiChannelEvent<"pitchBend"> & {
value: number;
};
export type MidiEvent =
| MidiSequenceNumberEvent
| MidiTextEvent
| MidiCopyrightNoticeEvent
| MidiTrackNameEvent
| MidiInstrumentNameEvent
| MidiLyricsEvent
| MidiMarkerEvent
| MidiCuePointEvent
| MidiChannelPrefixEvent
| MidiPortPrefixEvent
| MidiEndOfTrackEvent
| MidiSetTempoEvent
| MidiSmpteOffsetEvent
| MidiTimeSignatureEvent
| MidiKeySignatureEvent
| MidiSequencerSpecificEvent
| MidiUnknownEvent
| MidiSysExEvent
| MidiEndSysExEvent
| MidiControllerEvent
| MidiProgramChangeEvent
| MidiChannelAftertouchEvent
| MidiPitchBendEvent
| MidiNoteAftertouchEvent
| MidiNoteOnEvent
| MidiNoteOffEvent;
export interface MidiData {
header: MidiHeader;
tracks: Array<MidiEvent[]>;
}
export function parseMidi(data: ArrayLike<number>): MidiData;
export interface MidiWriteOption {
running?: boolean; //reuse previous eventTypeByte when possible, to compress file
useByte9ForNoteOff?: boolean; //use 0x09 for noteOff when velocity is zero
}
export function writeMidi(
data: MidiData,
opts?: MidiWriteOption
): Array<number>;