use crate::prelude::*;
mod chunk;
pub use chunk::*;
#[doc = r#"
An event that can be yielded from or put into a `.mid` file.
This type is yielded by [`Reader::read_event`] and will be consumed by a Writer in the future.
# Overview
Except [`FileEvent::EOF`] Events can be placed into two categories
## Chunk Events
Three events, [`FileEvent::Header`], [`FileEvent::Track`], and [`FileEvent::Unknown`]
will contain meta information about a MIDI chunk.
- A [`FileEvent::Header`] is a header chunk that provides a minimal amount
of information pertaining to the entire MIDI file. Headers have no "bodies" and
therefore there is no `FileEvent::HeaderEvent` type.
- A [`FileEvent::Track`] is the metadata of a track chunk.
It contains the total length of the proceeding events.
- The concepts of multiple tracks, multiple MIDI outputs, patterns, sequences,
and songs may all be implemented using several track chunks given that the [`FormatType`]
of the midi file is not [`FormatType::SingleMultiChannel`].
- An 'unknown' chunk begins with a chunk name that is not `MThd` or `MTrk`.
The [`Reader`] leaves it up to the user on how to handle these chunks.
## Track Events
A [`FileEvent::TrackEvent`] identifies some event yielded in the
body of a MIDI `track` chunk. This is usually sequential stream
of MIDI data which may contain information for up to 16 MIDI channels.
"#]
#[derive(Clone, Debug, PartialEq)]
pub enum FileEvent<'a> {
Header(RawHeaderChunk<'a>),
Track(TrackChunkHeader),
Unknown(UnknownChunk<'a>),
TrackEvent(TrackEvent<'a>),
EOF,
}
impl<'a> From<RawHeaderChunk<'a>> for FileEvent<'a> {
fn from(value: RawHeaderChunk<'a>) -> Self {
Self::Header(value)
}
}
impl From<TrackChunkHeader> for FileEvent<'_> {
fn from(value: TrackChunkHeader) -> Self {
Self::Track(value)
}
}
impl<'a> From<TrackEvent<'a>> for FileEvent<'a> {
fn from(value: TrackEvent<'a>) -> Self {
Self::TrackEvent(value)
}
}