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}
32
33/// An error raised while pumping events from a source into a sink, recording
34/// which side failed.
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub enum PumpError<S, T> {
37 /// The [`MidiSource`](crate::MidiSource) returned an error.
38 Source(S),
39 /// The [`MidiSink`](crate::MidiSink) returned an error.
40 Sink(T),
41}