Skip to main content

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 [`TickTime::rebase`](crate::TickTime::rebase) could not be performed
22    /// exactly.
23    #[error("inexact TPQ rebase")]
24    InexactRebase,
25}
26
27/// An error raised while pumping events from a source into a sink, recording
28/// which side failed.
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub enum PumpError<S, T> {
31    /// The [`MidiSource`](crate::MidiSource) returned an error.
32    Source(S),
33    /// The [`MidiSink`](crate::MidiSink) returned an error.
34    Sink(T),
35}