writeTrackChunk

writeTrackChunk encodes a track chunk to bytes and puts them into output.

This is guaranteed to use "running status" to encode consecutive track events with the same status byte.

void
writeTrackChunk
(
T
)
(
ref T output
,
ref const TrackChunk chunk
)
if (
isOutputRange!(T, ubyte)
)

Parameters

output T

the output range object

chunk TrackChunk

the track chunk to be encoded

Examples

This test demonstrates track chunk writing

import mididi.def : MetaEventType;

const(ubyte)[] result = [];
auto range = DelegateSink((scope const bytes) {
    result ~= bytes;
});
auto chunk = TrackChunk([
    TrackEvent(
        100, // delta time
        // 0x93 = note on
        MIDIEvent(0x93, [0x4C, 0x20]),
    ),
    TrackEvent(
        300,
        // 0x93 = note on (same status)
        MIDIEvent(0x93, [0x4C, 0x00]),
    ),
    TrackEvent(
        400,
        MetaEvent(MetaEventType.endOfTrack, []),
    ),
]);
range.writeTrackChunk(chunk);
assert(result == [
    'M', 'T', 'r', 'k',
    0, 0, 0, 13,
    0x64,       0x93, 0x4C, 0x20,
    0x82, 0x2C,       0x4C, 0x00, // running status
    0x83, 0x10, 0xFF, 0x2F, 0x00,
]);

Meta