MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / writeTo

Method writeTo

packages/alphatab/src/midi/MidiFile.ts:55–73  ·  view source on GitHub ↗

* Writes the midi track as binary into the given stream. * @returns The stream to write to.

(s: IWriteable)

Source from the content-addressed store, hash-verified

53 * @returns The stream to write to.
54 */
55 public writeTo(s: IWriteable): void {
56 // build track data first
57 const trackData: ByteBuffer = ByteBuffer.empty();
58 let previousTick: number = 0;
59 for (const midiEvent of this.events) {
60 const delta: number = midiEvent.tick - previousTick;
61 MidiFile.writeVariableInt(trackData, delta);
62 midiEvent.writeTo(trackData);
63 previousTick = midiEvent.tick;
64 }
65 // end of track
66 // magic number "MTrk" (0x4D54726B)
67 const b = new Uint8Array([0x4d, 0x54, 0x72, 0x6b]);
68 s.write(b, 0, b.length);
69 // size as integer
70 const data: Uint8Array = trackData.toArray();
71 IOHelper.writeInt32BE(s, data.length);
72 s.write(data, 0, data.length);
73 }
74}
75
76/**

Callers

nothing calls this directly

Calls 6

emptyMethod · 0.80
writeVariableIntMethod · 0.80
toArrayMethod · 0.80
writeInt32BEMethod · 0.80
writeMethod · 0.65
writeToMethod · 0.45

Tested by

no test coverage detected