Skip to main content

smpte_timecode/
lib.rs

1//! SMPTE timecode arithmetic with exact drop-frame handling, and a MIDI Time Code decoder and
2//! encoder.
3//!
4//! - [`Timecode`] is a frame position within one 24-hour day at a [`FrameRate`]. It parses and
5//!   formats labels, wraps at midnight, and converts to and from exact seconds and samples.
6//! - [`Ratio`] and [`Pull`] keep NTSC rates, pulled sample rates and seconds exact.
7//! - [`MtcDecoder`] turns quarter-frame and full-frame messages into checked positions with their
8//!   direction and lock state. [`MtcEncoder`] produces the messages.
9//!
10//! The crate is `no_std`, does not allocate and has no dependencies. It does not open MIDI ports
11//! or keep time: callers pass complete MIDI messages and the time each arrived.
12//!
13//! ```
14//! use smpte_timecode::{FrameRate, Ratio, Rounding, Timecode};
15//!
16//! let tc = Timecode::parse("00:10:00;00", FrameRate::FPS_29_97_DF)?;
17//! assert_eq!(tc.frames(), 17_982);
18//! assert_eq!(tc.to_samples(Ratio::from_integer(48_000), Rounding::Nearest)?, 28_799_971);
19//! # Ok::<(), smpte_timecode::TimecodeError>(())
20//! ```
21
22#![no_std]
23
24mod mtc;
25mod timecode;
26
27pub use mtc::{Direction, LockState, Motion, MtcDecoder, MtcEncoder, MtcError, MtcEvent};
28pub use timecode::{Fields, FrameRate, Pull, Ratio, Rounding, Timecode, TimecodeError};
29
30/// Compiles and runs the README example as a doctest.
31#[cfg(doctest)]
32#[doc = include_str!("../README.md")]
33struct ReadmeDoctests;