* Writes the midi file as binary into the given stream. * @returns The stream to write to.
(s: IWriteable)
| 150 | * @returns The stream to write to. |
| 151 | */ |
| 152 | public writeTo(s: IWriteable): void { |
| 153 | // magic number "MThd" (0x4D546864) |
| 154 | const b: Uint8Array = new Uint8Array([0x4d, 0x54, 0x68, 0x64]); |
| 155 | s.write(b, 0, b.length); |
| 156 | // Header Length 6 (0x00000006) |
| 157 | IOHelper.writeInt32BE(s, 6); |
| 158 | // format (single multi channel track) |
| 159 | IOHelper.writeInt16BE(s, this.format as number); |
| 160 | // number of tracks (1) |
| 161 | IOHelper.writeInt16BE(s, this.tracks.length); |
| 162 | // division |
| 163 | IOHelper.writeInt16BE(s, this.division); |
| 164 | |
| 165 | for (const track of this.tracks) { |
| 166 | track.writeTo(s); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | public static writeVariableInt(s: IWriteable, value: number): void { |
| 171 | const array: Uint8Array = new Uint8Array(4); |
no test coverage detected