sim_lib_midi_core/error.rs
1use thiserror::Error;
2
3/// Errors produced when constructing or converting core MIDI values.
4#[derive(Debug, Error, Clone, PartialEq, Eq)]
5pub enum MidiError {
6 /// A ticks-per-quarter resolution was zero.
7 #[error("tpq must be non-zero")]
8 ZeroTpq,
9 /// A value exceeded the 7-bit ([`U7`](crate::U7)) range.
10 #[error("value {0} is out of u7 range")]
11 InvalidU7(u16),
12 /// A value exceeded the 14-bit ([`U14`](crate::U14)) range.
13 #[error("value {0} is out of u14 range")]
14 InvalidU14(u16),
15 /// A value exceeded the valid [`Channel`](crate::Channel) range.
16 #[error("value {0} is out of channel range")]
17 InvalidChannel(u8),
18 /// A scaling ratio had a zero numerator or denominator.
19 #[error("invalid ratio {0}/{1}")]
20 InvalidRatio(i64, i64),
21 /// A channel-message decode ran out of data bytes.
22 #[error("channel message data is truncated")]
23 TruncatedChannel,
24 /// A status byte's high nibble is not a channel-voice message.
25 #[error("status byte {0:#04x} is not a channel message")]
26 NotChannelStatus(u8),
27 /// A [`TickTime::rebase`](crate::TickTime::rebase) could not be performed
28 /// exactly.
29 #[error("inexact TPQ rebase")]
30 InexactRebase,
31 /// A tempo meta event carried the forbidden zero microseconds-per-quarter
32 /// value.
33 #[error("MIDI tempo must be non-zero")]
34 ZeroTempo,
35 /// An event or conversion used a negative tick, which is outside an SMF
36 /// tempo timeline.
37 #[error("MIDI tempo-map ticks must be non-negative")]
38 NegativeTempoTick,
39 /// Tempo-map source events were not ordered by exact tick time.
40 #[error("MIDI tempo events must be ordered by tick")]
41 TempoEventsOutOfOrder,
42 /// A tempo map was requested for a non-metrical time division.
43 #[error("MIDI tempo maps require a metrical ticks-per-quarter division")]
44 MetricalTempoRequired,
45 /// An exact beat or wall-time position does not land on an integer MIDI
46 /// tick at the map's resolution.
47 #[error("time does not land on an exact MIDI tick")]
48 InexactTempoTick,
49 /// A tempo conversion exceeded its integer representation.
50 #[error("MIDI tempo conversion overflowed")]
51 TempoOverflow,
52 /// The shared stream-clock chart rejected tempo arithmetic.
53 #[error("MIDI tempo chart failed: {0}")]
54 TempoChart(String),
55}
56
57/// An error raised while pumping events from a source into a sink, recording
58/// which side failed.
59#[derive(Debug, Clone, PartialEq, Eq)]
60pub enum PumpError<S, T> {
61 /// The [`MidiSource`](crate::MidiSource) returned an error.
62 Source(S),
63 /// The [`MidiSink`](crate::MidiSink) returned an error.
64 Sink(T),
65}