Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
Add doc strings to public symbols.
  • Loading branch information
webern committed Oct 8, 2023
1 parent 29d283a commit ba88aff
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/core/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ pub enum OnOff {
Off = 0,
}

/// A parameter found on most MIDI keyboards that have built-in sounds. Local Control can be set on
/// or off, and is normally found in the global parameters for a particular instrument. When enabled
/// the keyboard is electronically connected to the internal sounds of the instrument. This is the
/// “normal” or default mode for most instruments. When turned off the keyboard only transmits MIDI
/// to the MIDI out jack. The built-in sounds can then only be accessed from a MIDI input (or an
/// internal sequencer where applicable). When people use keyboards with external sequencing
/// equipment local control is normally turned off, and the sounds are just driven through the
/// sequencer. This prevents a phenomenon known as MIDI echo, where a sound is triggered directly by
/// the keyboard, and then a very short time later the same note is played again due to the data
/// being passed through the sequencer.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct LocalControlValue {
channel: Channel,
Expand All @@ -173,6 +183,8 @@ impl LocalControlValue {
}
}

/// When Mono mode is selected, a single voice is assigned per MIDI Channel. This means that only
/// one note can be played on a given Channel at a given time.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct MonoModeOnValue {
channel: Channel,
Expand Down Expand Up @@ -230,6 +242,12 @@ pub enum SystemRealtimeMessage {
SystemReset = 0xff,
}

/// MIDI System Messages are classified as being System Common Messages, System Real Time Messages,
/// or System Exclusive Messages. System Common messages are intended for all receivers in the
/// system. System Real Time messages are used for synchronization between clock-based MIDI
/// components. System Exclusive messages include a Manufacturer's Identification (ID) code, and are
/// used to transfer any number of data bytes in a format specified by the referenced manufacturer.
// TODO - add system exclusive messages (sysex)
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[allow(dead_code)]
pub enum SystemMessage {
Expand All @@ -243,7 +261,14 @@ impl Default for SystemMessage {
}
}

/// A MIDI message is made up of an eight-bit status byte which is generally followed by one or two
/// data bytes. There are a number of different types of MIDI messages. At the highest level, MIDI
/// messages are classified as being either Channel Messages or System Messages. Channel messages
/// are those which apply to a specific Channel, and the Channel number is included in the status
/// byte for these messages. System messages are not Channel specific, and no Channel number is
/// indicated in their status bytes.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[allow(missing_docs)]
pub enum Message {
NoteOff(NoteMessage),
NoteOn(NoteMessage),
Expand Down Expand Up @@ -520,6 +545,7 @@ where
/// byte. `Control` values greater than 31 are for the Lsb in these two-byte messages.
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
#[allow(missing_docs)]
pub enum Control {
#[default]
BankSelect = 0,
Expand Down
1 change: 1 addition & 0 deletions src/file/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct TrackEvent {
}

impl TrackEvent {
/// Create a new track event.
pub fn new(delta_time: u32, event: Event) -> Self {
Self { delta_time, event }
}
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*!
A library for reading, writing and creating MIDI files.
!*/

// one per line to simplify commenting certain ones out during development
#![deny(arithmetic_overflow)]
#![deny(clippy::complexity)]
Expand All @@ -6,7 +12,7 @@
// TODO - maybe document all pub(crate) types
// #![deny(missing_crate_level_docs)]
// TODO - document all
// #![deny(missing_docs)]
#![warn(missing_docs)]
#![deny(nonstandard_style)]
#![deny(rust_2018_idioms)]
#![deny(unreachable_patterns)]
Expand Down Expand Up @@ -183,6 +189,7 @@ impl MidiFile {
self.write(&mut scribe)
}

/// The number of tracks, i.e. the length of the vector of tracks.
pub fn tracks_len(&self) -> u32 {
u32::try_from(self.tracks.len()).unwrap_or(u32::MAX)
}
Expand All @@ -201,6 +208,7 @@ impl MidiFile {
self.tracks.get(i)
}

/// Add a track to the file.
pub fn push_track(&mut self, track: Track) -> Result<()> {
ensure!(
self.tracks_len() < u32::MAX,
Expand All @@ -213,6 +221,7 @@ impl MidiFile {
Ok(())
}

/// Insert a track at a certain place in the vector of tracks.
pub fn insert_track(&mut self, index: u32, track: Track) -> Result<()> {
ensure!(
self.tracks_len() < u32::MAX,
Expand All @@ -232,6 +241,7 @@ impl MidiFile {
Ok(())
}

/// Remove a track from the file. Same behavior as `vec.remove(index)`.
pub fn remove_track(&mut self, index: u32) -> Result<Track> {
ensure!(
index < self.tracks_len(),
Expand Down

0 comments on commit ba88aff

Please sign in to comment.