pub struct Beat {
pub num: i64,
pub den: u32,
}Expand description
An exact musical position or duration as a rational number of beats:
num / den, always normalized (denominator positive, gcd-reduced, zero
canonicalized to 0/1). Tuplets and repeated transforms (stretch, rotate,
concatenate) stay exact — no floating-point drift ever accumulates before
the frame boundary.
Beat::new(2, 4) IS Beat::new(1, 2). A zero den is floored to 1 (the
same degenerate-value clamp the song grid applies), so deserialization can
never produce a division by zero. Serde is the flat struct {"num":..,"den":..};
deserializing normalizes through Beat::new.
Fields§
§num: i64The numerator (beats × den), carries the sign.
den: u32The denominator, always > 0 after normalization.
Implementations§
Source§impl Beat
impl Beat
Sourcepub const fn new(num: i64, den: u32) -> Beat
pub const fn new(num: i64, den: u32) -> Beat
A normalized beat: gcd-reduced, den > 0, zero as 0/1. A den of 0
is floored to 1.
Sourcepub fn checked_add(self, other: Beat) -> Result<Beat, BeatError>
pub fn checked_add(self, other: Beat) -> Result<Beat, BeatError>
Exact sum, erroring when the (unreduced) result doesn’t fit a Beat.
Sourcepub fn checked_sub(self, other: Beat) -> Result<Beat, BeatError>
pub fn checked_sub(self, other: Beat) -> Result<Beat, BeatError>
Exact difference, erroring when the (unreduced) result doesn’t fit a
Beat.
Sourcepub fn mul_rational(self, num: i64, den: u32) -> Result<Beat, BeatError>
pub fn mul_rational(self, num: i64, den: u32) -> Result<Beat, BeatError>
Exact scaling by the rational factor num / den, erroring when the
(unreduced) result doesn’t fit a Beat.
Trait Implementations§
impl Copy for Beat
Source§impl<'de> Deserialize<'de> for Beat
Deserializing routes through Beat::new so the normalization invariant
holds no matter where the value came from.
impl<'de> Deserialize<'de> for Beat
Deserializing routes through Beat::new so the normalization invariant
holds no matter where the value came from.
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for Beat
Source§impl JsonSchema for Beat
impl JsonSchema for Beat
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more