Function midly::write

source ·
pub fn write<'a, T, E, W>(
    header: &Header,
    tracks: T,
    out: &mut W
) -> WriteResult<W>where
    T: IntoIterator<Item = E>,
    T::IntoIter: ExactSizeIterator + Clone + Send,
    E: IntoIterator<Item = &'a TrackEvent<'a>>,
    E::IntoIter: Clone + Send,
    W: Write,
Expand description

Encode and write a generic MIDI file into the given generic writer. The MIDI file is represented by a header and a list of tracks.

Errors

The MIDI writer raises almost no errors by itself, it only bubbles errors from the underlying writer. The only exception to this rule are extreme cases that break the limits of the MIDI spec: if there are more than 65535 tracks, if the data for a single event is 256MB or larger, or if the total size of any track is 4GB or larger.

Implementation notes

Currently this function will attempt to use multiple threads to encode the file if possible and the file is large enough to make it worth it.

Otherwise, each track will be written to an in-memory buffer before writing to disk.

If allocation is disabled, but the writer is seekable, the file will be written once and it will be seeked back in order to write down the chunk sizes.

Otherwise, encoding will happen twice: once to determine the size of the chunks and once again to actually write down the file.