Skip to content

Commit a6fb1eb

Browse files
authored
Documentation first pass (#6)
* update readme * add todo for benching * fix: remove single-type read error kind * update note macro
1 parent 1797e72 commit a6fb1eb

8 files changed

Lines changed: 29 additions & 87 deletions

File tree

README.md

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
A suite of tools used to read, modify, and manage MIDI-related systems
77

8-
### NOTE: The main branch is in development. Stable versions are on their own branches.
9-
10-
118
## Overview
129

1310
`midix` provides users with human readable MIDI structures without invariant states. That is, the midi 1.0 specification has been strongly typed such that programatic commands built with this crate are not invariant.
@@ -17,12 +14,13 @@ calling [`Reader::read_event`](crate::prelude::Reader::read_event) will yield a
1714

1815
Additionally, `midix` provides the user with [`LiveEvent::from_bytes`](crate::events::LiveEvent), which will parse events from a live MIDI source.
1916

20-
You may also make your own MIDI representation using the provided structs. A significant portion of
21-
this library lives within the `bevy` feature. See details below on usage with the bevy engine.
17+
You may also make your own MIDI representation using the provided structs.
2218

2319
## Goal
2420
`midix` is NOT designed to be as fast as possible. It is designed for a user to navigate the MIDI format to read and write to. Instead of working directly with bytes, use language to define what your MIDI is supposed to do.
2521

22+
TODO: Benches
23+
2624
## Getting Started
2725

2826
MIDI can be interpreted in two main ways: through `LiveEvent`s and regular file `Events`.
@@ -83,37 +81,17 @@ assert_eq!(velocity.byte(), 96);
8381

8482

8583
## Semantic Versioning and Support
86-
`midix` will adhere to semantic versioning. This means that I've opted to use major versions, even if this crate does not consider itself feature complete (you might get a midix `v29.3.1` someday)
84+
`midix` will adhere to semantic versioning. I've opted to use major versions.
8785

8886
The current MSRV is rust `1.87`
8987

90-
## Acknowledgments
91-
92-
This crate was originally forked from [`bevy_midi`](https://github.com/BlackPhlox/bevy_midi). Please check them out if this crate doesn't suit your needs!
93-
94-
## MIDIx feature roadmap
95-
- `no_std`
96-
- Streamer (midir ext)
97-
- Interfaces between `MidiSource` and `Midi` (some representable MIDI type, like a file, events, etc.)
98-
- MIDI writers
99-
- Streamer (async timed stream event via midir)
100-
- MidiFile
101-
10288
## General feature schedule
10389
The SUPPORT.md file denotes the length of time major revisions are supported.
10490

10591
When the major version of the crate is incremented, new features for the previous version(s)
10692
will likely be neglected. If you need a non-breaking feature for an older version before the end
10793
of its maintenence period, please let me know!
10894

109-
## Feature roadmap
110-
- `no_std`
111-
- Streamer (midir ext)
112-
- Interfaces between `MidiSource` and `Midi` (some representable MIDI type, like a file, events, etc.)
113-
- MIDI writers
114-
- Streamer (async timed stream event via midir)
115-
- MidiFile
116-
11795
## Acknowledgments
11896
A lot of the documentation is copied directly from
11997
[this documentation](http://www.music.mcgill.ca/~ich/classes/mumt306/StandardMIDIfileformat.html).
@@ -126,23 +104,9 @@ EMail: david@csw2.co.uk
126104
Web: http://www.csw2.co.uk
127105
```
128106

129-
Inspired by/copied from
130-
131-
### `midix`
107+
## Inspired by/copied from
132108

133109
inspired by [`midly`](https://github.com/kovaxis/midly)
134110
and [`quick-xml`](https://github.com/tafia/quick-xml).
135111

136-
If you are in need of a MIDI writer, I highly
137-
recommend using `midly`, as this `midix` does not yet
138-
support file writing.
139-
140112
Thanks to these mainters and contributors for inspiration!
141-
142-
### `bevy` feature
143-
144-
Forked originally from [`bevy_midi`](https://github.com/BlackPhlox/bevy_midi). Huge thank you for the examples and docs!
145-
146-
### hidden `synth` feature
147-
148-
Forked originally from [rustysynth](https://github.com/sinshu/rustysynth).

src/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::message::{ChannelVoiceMessage, VoiceEvent};
1111

1212
/// Identifies a channel for MIDI.
1313
///
14-
/// To get this channel from a `u8`, use [`Channel::try_from_primitive`].
14+
/// To get this channel from a `u8`, use [`Channel::try_from_byte`].
1515
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
1616
#[cfg_attr(
1717
feature = "bevy",

src/file/builder.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use alloc::vec::Vec;
22

3-
use crate::{
4-
prelude::*,
5-
reader::{ReadError, ReaderErrorKind},
6-
};
3+
use crate::{prelude::*, reader::ReaderErrorKind};
74

85
use super::MidiFile;
96

@@ -109,7 +106,7 @@ impl<'a> MidiFileBuilder<'a> {
109106
self.unknown_chunks.push(data);
110107
Ok(())
111108
}
112-
EOF => Err(ReaderErrorKind::ReadError(ReadError::OutOfBounds)),
109+
EOF => Err(ReaderErrorKind::OutOfBounds),
113110
}
114111
}
115112
pub fn build(self) -> Result<MidiFile<'a>, FileError> {

src/file/timed_event_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::prelude::*;
22

3-
/// An iterator returned from [`ParsedMidiFile::into_events`].
3+
/// An iterator returned from [`MidiFile::into_events`].
44
pub enum OptTimedEventIterator<'a> {
55
/// No tracks in the file
66
None,

src/file_repr/chunk/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ not fall into th
1010
## [`RawHeaderChunk`]
1111
This chunk type contains meta information about the MIDI file, such as
1212
- [`RawFormat`](crate::prelude::RawFormat), which identifies how tracks should be played, and the claimed track count
13-
- [`Timing`](crate::prelude::Timing), which defines how delta-seconds are to be interpreted
13+
- [`Timing`], which defines how delta-seconds are to be interpreted
1414
1515
## [`]
1616

src/message/channel/voice.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
channel::Channel,
44
events::FromLiveEventBytes,
55
message::VoiceEvent,
6-
reader::{MidiSource, ReadError, ReadResult, Reader, ReaderError, ReaderErrorKind, inv_data},
6+
reader::{MidiSource, ReadResult, Reader, ReaderError, ReaderErrorKind, inv_data},
77
};
88

99
/// Represents a MIDI voice message.
@@ -192,13 +192,10 @@ impl FromLiveEventBytes for ChannelVoiceMessage {
192192
velocity: Velocity::new(data.get_byte(1).ok_or(ParseError::MissingData)?)?,
193193
},
194194
0xB => {
195-
// TODO: really need to unify this
196195
let mut temp = Reader::from_byte_slice(data);
197196
let c = Controller::read(&mut temp).map_err(|e| match e.kind {
198197
ReaderErrorKind::ParseError(p) => p,
199-
ReaderErrorKind::ReadError(p) => match p {
200-
ReadError::OutOfBounds => ParseError::MissingData,
201-
},
198+
ReaderErrorKind::OutOfBounds => ParseError::MissingData,
202199
})?;
203200
VoiceEvent::ControlChange(c)
204201
}

src/note.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Note {
106106
self.0.0
107107
}
108108
}
109-
/// Efficiently make a note.
109+
/// Create a note the easy way.
110110
///
111111
///
112112
/// ## Example
@@ -259,7 +259,7 @@ pub enum Key {
259259
B,
260260
}
261261
impl Key {
262-
/// Returns an array beginning with [`Note::C`] to [`Note::B`]
262+
/// Returns an array beginning with [`Key::C`] to [`Key::B`]
263263
pub fn all() -> [Key; 12] {
264264
use Key::*;
265265
[C, CSharp, D, DSharp, E, F, FSharp, G, GSharp, A, ASharp, B]

src/reader/error.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{ChunkError, ParseError};
33
use thiserror::Error;
44

55
#[doc = r#"
6-
A set of errors that can occur while reading something into a midi representation
6+
A set of errors that can occur while reading data into the midi representation
77
"#]
88
#[derive(Debug, Error)]
99
#[error("Reading at Position {position}, {kind}")]
@@ -18,9 +18,9 @@ pub enum ReaderErrorKind {
1818
/// Parsing errors
1919
#[error("Parsing {0}")]
2020
ParseError(#[from] ParseError),
21-
/// Errors unrelated to parsing (out of bounds)
22-
#[error("Reading {0}")]
23-
ReadError(#[from] ReadError),
21+
/// Reading out of bounds.
22+
#[error("Read out of bounds!")]
23+
OutOfBounds,
2424
}
2525

2626
impl ReaderErrorKind {
@@ -29,25 +29,22 @@ impl ReaderErrorKind {
2929
}
3030
}
3131

32-
/// Errors reading from some [`MidiSource`](crate::prelude::MidiSource)
33-
#[derive(Debug, Error)]
34-
pub enum ReadError {
35-
/// Read out of bounds
36-
#[error("Read out of bounds!")]
37-
OutOfBounds,
38-
}
39-
4032
impl ReaderError {
4133
/// Create a reader error from a position and kind
4234
pub const fn new(position: usize, kind: ReaderErrorKind) -> Self {
4335
Self { position, kind }
4436
}
4537
/// True if out of bounds or unexpected end of file
4638
pub const fn is_out_of_bounds(&self) -> bool {
47-
matches!(
48-
self.kind,
49-
ReaderErrorKind::ReadError(ReadError::OutOfBounds)
50-
)
39+
matches!(self.kind, ReaderErrorKind::OutOfBounds)
40+
}
41+
/// Returns the error kind of the reader.
42+
pub fn error_kind(&self) -> &ReaderErrorKind {
43+
&self.kind
44+
}
45+
/// Returns the position where the read error occurred.
46+
pub fn position(&self) -> usize {
47+
self.position
5148
}
5249

5350
/// Create a new invalid data error
@@ -62,31 +59,18 @@ impl ReaderError {
6259
pub const fn oob(position: usize) -> Self {
6360
Self {
6461
position,
65-
kind: ReaderErrorKind::ReadError(ReadError::OutOfBounds),
62+
kind: ReaderErrorKind::OutOfBounds,
6663
}
6764
}
6865
}
6966

70-
/// A result type that is either `T` or an [`io::Error`].
67+
/// The Read Result type (see [`ReaderError`])
7168
///
7269
/// This may change in a future release if `midix`
7370
/// should support `no-std` environments.
7471
pub type ReadResult<T> = Result<T, ReaderError>;
7572

76-
// pub(crate) fn unexp_eof() -> ReaderError {
77-
// io::Error::new(ErrorKind::UnexpectedEof, "Read past the end of the file").into()
78-
// }
79-
8073
pub(crate) fn inv_data<R>(reader: &mut Reader<R>, v: impl Into<ParseError>) -> ReaderError {
8174
reader.set_last_error_offset(reader.buffer_position());
8275
ReaderError::parse_error(reader.buffer_position(), v.into())
8376
}
84-
// #[allow(dead_code)]
85-
// pub(crate) fn inv_input<R>(reader: &mut Reader<R>, v: impl fmt::Display) -> ReaderError {
86-
// reader.set_last_error_offset(reader.buffer_position());
87-
// io::Error::new(
88-
// ErrorKind::InvalidInput,
89-
// format!("Cursor at {}: {}", reader.buffer_position(), v),
90-
// )
91-
// .into()
92-
// }

0 commit comments

Comments
 (0)