Skip to main content

sim_lib_midi_smf/
error.rs

1#![forbid(unsafe_code)]
2
3use thiserror::Error;
4
5/// Errors raised while reading or writing a Standard MIDI File.
6#[derive(Debug, Error, Clone, PartialEq, Eq)]
7pub enum SmfError {
8    /// The `MThd`/`MTrk` chunk header was malformed.
9    #[error("invalid header at byte {offset}")]
10    InvalidHeader {
11        /// Byte offset of the bad header.
12        offset: usize,
13    },
14    /// The byte stream ended before the structure was complete.
15    #[error("unexpected end of file at byte {offset}")]
16    UnexpectedEof {
17        /// Byte offset where more input was expected.
18        offset: usize,
19    },
20    /// A variable-length quantity was not terminated within four bytes.
21    #[error("invalid VLQ at byte {offset}")]
22    InvalidVlq {
23        /// Byte offset where the VLQ began.
24        offset: usize,
25    },
26    /// The header requested SMPTE division, which is not supported.
27    #[error("unsupported SMPTE division 0x{raw:04x} at byte {offset}")]
28    UnsupportedSmpteDivision {
29        /// Byte offset of the division field.
30        offset: usize,
31        /// The raw division value.
32        raw: u16,
33    },
34    /// A data byte appeared with no running status in effect.
35    #[error("malformed running status at byte {offset}")]
36    MalformedRunningStatus {
37        /// Byte offset of the offending data byte.
38        offset: usize,
39    },
40    /// A status byte that the reader does not handle was encountered.
41    #[error("unsupported MIDI status 0x{status:02x} at byte {offset}")]
42    UnsupportedStatus {
43        /// Byte offset of the status byte.
44        offset: usize,
45        /// The unsupported status byte.
46        status: u8,
47    },
48    /// A channel message carried an out-of-range data byte.
49    #[error("invalid channel payload at byte {offset}")]
50    InvalidChannelData {
51        /// Byte offset of the bad data.
52        offset: usize,
53    },
54    /// The header format and the track count are inconsistent (for example,
55    /// format 0 with more than one track).
56    #[error("SMF format/track count mismatch")]
57    FormatTrackMismatch,
58    /// An event time could not be represented exactly at the file resolution.
59    #[error("event time cannot be represented exactly at target TPQ")]
60    InexactEventTime,
61    /// Track events were not monotonic in absolute time, yielding a negative
62    /// delta.
63    #[error("track events are not monotonic in absolute time")]
64    NegativeDelta,
65}