sim_lib_midi_core/lib.rs
1//! Core MIDI data model and in-memory I/O for the SIM music stack.
2//!
3//! This crate defines the protocol-agnostic MIDI types shared across the
4//! constellation: tick-based timing ([`TickTime`]), the bounded integer
5//! domains used by MIDI bytes ([`U7`], [`U14`], [`Channel`]), the event model
6//! ([`MidiEvent`], [`MidiPayload`], [`ChannelMessage`], [`MetaEvent`],
7//! [`SysExEvent`]), and the streaming [`MidiSource`]/[`MidiSink`] traits with
8//! in-memory implementations. It also provides the [`NoteEchoPlayer`]
9//! transform, controller-number constants, piecewise exact [`MidiTempoMap`]
10//! conversion among ticks, quarter beats, and wall time, and the
11//! host-registered [`MidiIoLib`] that exposes the in-memory cards to a running
12//! SIM [`Cx`](sim_kernel::Cx).
13//!
14//! Higher layers (Standard MIDI File, SysEx, live transports) build on this
15//! model rather than redefining it.
16//!
17//! # Examples
18//!
19//! ```
20//! use sim_lib_midi_core::{Channel, ChannelMessage, U7};
21//!
22//! let note = ChannelMessage::NoteOn {
23//! ch: Channel::new(0).unwrap(),
24//! key: U7(60),
25//! vel: U7(100),
26//! };
27//! assert!(matches!(note, ChannelMessage::NoteOn { .. }));
28//! ```
29//!
30//! ```
31//! use sim_lib_midi_core::TickTime;
32//!
33//! // 480 ticks at 480 tpq is exactly one quarter note.
34//! let one_quarter = TickTime::new(480, 480).unwrap();
35//! assert_eq!(one_quarter.as_f64_quarters(), 1.0);
36//! // Rebasing to a coarser resolution is exact here.
37//! assert_eq!(one_quarter.rebase(96).unwrap().ticks, 96);
38//! ```
39
40#![forbid(unsafe_code)]
41#![allow(deprecated)]
42#![deny(missing_docs)]
43
44mod cc;
45mod error;
46mod frame_digest;
47mod io;
48mod model;
49mod player;
50mod runtime;
51mod tempo;
52
53pub mod meta_view;
54pub mod wire;
55
56pub use cc::*;
57pub use error::*;
58pub use frame_digest::{MidiDigestLib, manifest_name as midi_digest_manifest_name};
59pub use io::*;
60pub use model::*;
61pub use player::*;
62pub use runtime::*;
63pub use tempo::*;
64
65/// Cookbook recipes for this lib, embedded at build time.
66pub static RECIPES: sim_cookbook::EmbeddedDir =
67 include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));
68
69#[cfg(test)]
70mod tests;