pub struct Duration {
pub numerator: Numerator,
pub denominator: Denominator,
pub dots: Dots,
}Expand description
Represents the duration of a musical note.
A duration combines:
- Numerator: The note type (whole, half, quarter, etc.)
- Denominator: The tuplet grouping (2 = normal, 3 = triplet, etc.)
- Dots: Number of dots extending the duration
§Examples
// Quarter note
let quarter = Duration::new(
Numerator::Quarter,
Denominator::from_value(2).unwrap(),
Dots::ZERO
);
assert_eq!(quarter.tick_length(), 240);
// Dotted quarter note
let dotted_quarter = Duration::new(
Numerator::Quarter,
Denominator::from_value(2).unwrap(),
Dots::ONE
);
assert_eq!(dotted_quarter.tick_length(), 360);Fields§
§numerator: NumeratorThe note type (whole, half, quarter, etc.).
denominator: DenominatorThe tuplet denominator (2 = normal, 3 = triplet, etc.).
dots: DotsThe number of dots (0-7).
Implementations§
Source§impl Duration
impl Duration
Sourcepub const TICK_RESOLUTION: i32 = 240i32
pub const TICK_RESOLUTION: i32 = 240i32
Ticks per quarter note (MIDI standard).
Sourcepub const MAX_TICK_LENGTH: i32 = 1_920i32
pub const MAX_TICK_LENGTH: i32 = 1_920i32
Maximum tick length (whole note * 2).
Sourcepub const MIN_DENOMINATOR: u8 = 2u8
pub const MIN_DENOMINATOR: u8 = 2u8
Minimum denominator value.
Sourcepub const MAX_DENOMINATOR: u8 = 255u8
pub const MAX_DENOMINATOR: u8 = 255u8
Maximum denominator value.
Sourcepub const MAX_NUMERATOR: u8 = 7u8
pub const MAX_NUMERATOR: u8 = 7u8
Maximum numerator ordinal.
Sourcepub fn new(
numerator: Numerator,
denominator: Denominator,
dots: Dots,
) -> Duration
pub fn new( numerator: Numerator, denominator: Denominator, dots: Dots, ) -> Duration
Creates a new duration.
§Arguments
numerator- The note type.denominator- The tuplet denominator.dots- The number of dots.
Sourcepub const fn tick_length(self) -> u32
pub const fn tick_length(self) -> u32
Calculates the duration in ticks.
§Returns
The duration in ticks, accounting for note type, tuplets, and dots.
Sourcepub fn with_numerator(self, numerator: Numerator) -> Duration
pub fn with_numerator(self, numerator: Numerator) -> Duration
Creates a new duration with a different numerator.
Sourcepub fn with_denominator(self, denominator: Denominator) -> Duration
pub fn with_denominator(self, denominator: Denominator) -> Duration
Creates a new duration with a different denominator.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Duration
impl<'de> Deserialize<'de> for Duration
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Duration
impl Eq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations§
impl Freeze for Duration
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more