Skip to main content

sim_lib_midi_live/
lib.rs

1//! Real-time MIDI buffering for the SIM music stack.
2//!
3//! This crate provides fixed-capacity ring buffers that bridge real-time MIDI
4//! I/O into the [`MidiSource`](sim_lib_midi_core::MidiSource)/
5//! [`MidiSink`](sim_lib_midi_core::MidiSink) traits: [`RingMidiBuffer`] acts as
6//! both source and sink, and [`RingTrackedMidiBuffer`] adds per-track tagging.
7//! When a buffer is full the oldest event is dropped and counted, so a slow
8//! consumer never blocks a real-time producer. The host-registered
9//! [`MidiLiveLib`] publishes these buffers as runtime plugin rows.
10//!
11//! # Examples
12//!
13//! A ring buffer accepts written events and yields them back in order:
14//!
15//! ```
16//! use sim_lib_midi_live::RingMidiBuffer;
17//! use sim_lib_midi_core::{
18//!     MetaEvent, MidiEvent, MidiPayload, MidiSink, MidiSource, TickTime,
19//!     synthetic_origin,
20//! };
21//!
22//! let mut buffer = RingMidiBuffer::new(480, 4).unwrap();
23//! let event = MidiEvent {
24//!     time: TickTime::new(0, 480).unwrap(),
25//!     origin: synthetic_origin(),
26//!     payload: MidiPayload::Meta(MetaEvent::EndOfTrack),
27//! };
28//! buffer.write(&event).unwrap();
29//! assert_eq!(buffer.len(), 1);
30//! assert_eq!(buffer.next().unwrap(), Some(event));
31//! ```
32
33#![forbid(unsafe_code)]
34#![deny(missing_docs)]
35
36mod error;
37mod ring;
38mod runtime;
39mod session;
40
41pub use error::*;
42pub use ring::*;
43pub use runtime::*;
44pub use session::*;
45
46/// Cookbook recipes for this lib, embedded at build time.
47pub static RECIPES: sim_cookbook::EmbeddedDir =
48    include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));
49
50#[cfg(test)]
51mod tests;