Skip to main content

Duration

Struct Duration 

Source
pub struct Duration { /* private fields */ }
Expand description

Rhythmic duration measured in quarter lengths.

A quarter note has a quarter length of 1.0; an eighth note is 0.5; a whole note is 4.0.

Implementations§

Source§

impl Duration

Source

pub fn new(quarter_length: FloatType) -> Result<Self>

Creates a duration from a quarter-length value.

Source

pub fn quarter() -> Self

Returns a quarter-note duration.

Source

pub fn half() -> Self

Returns a half-note duration.

Source

pub fn whole() -> Self

Returns a whole-note duration.

Source

pub fn eighth() -> Self

Returns an eighth-note duration.

Source

pub fn from_type(duration_type: DurationType) -> Self

Creates a duration from a note-value type.

Source

pub fn from_type_with_dots(duration_type: DurationType, dots: u32) -> Self

Creates a duration from a note-value type carrying augmentation dots.

Source

pub fn type_and_dots(&self) -> Option<(DurationType, u32)>

Returns the note-value type and dot count that together make exactly this length, such as a half note with one dot for 3.0. None for a length no single dotted note value has, such as a tuplet or a tie.

Source

pub fn dots(&self) -> u32

Returns the augmentation dots on this duration, or 0 when it is not a single dotted note value.

Source

pub fn ordinal(&self) -> Option<usize>

music21’s ordinal for the duration’s type, or None where music21 says complex or the duration is zero: a duration whose quarter length is not a single dotted note value.

Source

pub fn augment_or_diminish(&self, factor: FloatType) -> Result<Duration>

Returns the duration scaled by a positive factor: music21’s augmentOrDiminish, so a quarter by two is a half.

Source

pub fn tuplet(&self) -> Option<Tuplet>

The tuplet this length is written as, if any: the first of quarter_length_to_tuplet.

A length that is already a plain written value is that value rather than a tuplet of some other one, so a quarter answers None: music21 tries the exact match before it tries any ratio, and a plain quarter is a quarter even though it is also two thirds of a dotted quarter in a triplet.

Source

pub fn tuplets(&self) -> Vec<Tuplet>

The tuplets this length is written inside: the ones a caller set, or the one read off the length when nobody has.

This is music21’s tuplets, which is likewise inferred until it is assigned. Setting it to nothing is not the same as never setting it: two thirds of a quarter reads as a quarter triplet on its own, and stays two thirds of a quarter written as no tuplet once told so.

Source

pub fn aggregate_tuplet_multiplier(&self) -> FractionType

What the written values are multiplied by to give the sounding length: music21’s aggregateTupletMultiplier, every tuplet’s ratio multiplied together, so a triplet inside a quintuplet is 8/15.

Source

pub fn quarter_length_no_tuplets(&self) -> FloatType

The total of the written values, before any tuplet shortens them: music21’s quarterLengthNoTuplets.

Source

pub fn set_tuplets(&mut self, tuplets: Vec<Tuplet>)

Says what tuplets this length is written inside, keeping the written values and changing the sounding length to match: music21’s tuplets setter.

Source

pub fn append_tuplet(&mut self, tuplet: Tuplet)

Writes this length inside one more tuplet, shortening it by that tuplet’s ratio: music21’s appendTuplet.

Source

pub fn components(&self) -> Vec<(DurationType, u32)>

The written note values this length is made of, tied together: music21’s components.

This is the first half of quarter_conversion, read over the written length. A length whose tuplets a caller has set is read as the tie those tuplets leave, without looking for a tuplet of its own.

Source

pub fn is_complex(&self) -> bool

Whether the length needs more than one written value, tied: music21’s isComplex.

Source

pub fn dot_groups(&self) -> Vec<u32>

The dots on the written value, as the one dot group the crate keeps: music21’s dotGroups, which can also write one length twice over where a mensural notation asks for it.

Source

pub fn clear(&mut self)

Takes the length away: music21’s clear, which empties the written values so the duration sounds for no time. The tuplets it was told stay.

Source

pub fn add_duration_tuple(&mut self, duration_type: DurationType, dots: u32)

Ties one more written value onto the end: music21’s addDurationTuple, which lengthens the duration by that value inside whatever tuplets it is written in.

Source

pub fn component_index_at_qtr_position( &self, position: FloatType, ) -> Result<usize>

Which written value is sounding at a position within the duration: music21’s componentIndexAtQtrPosition. The positions are counted in the written values, before any tuplet scales them, and the start and the very end answer the first and the last value.

Source

pub fn component_start_time(&self, index: usize) -> Result<FloatType>

Where a written value starts within the duration, counted in the written values: music21’s componentStartTime. An index past the values is an error.

Source

pub fn full_name(&self) -> String

Returns music21’s fullName for a single written note value, such as "Dotted Quarter", "Double Dotted Half", "Imperfect Longa" or "Quarter Triplet (2/3 QL)".

A length that has to be written as a tie names each of its values and joins them, "Quarter tied to 16th (1 1/4 total QL)". A length no note value reaches is "Inexpressible" and a zero one is "Zero Duration (0 total QL)", both as music21 names them.

Source

pub fn duration_type(&self) -> Option<DurationType>

Returns the note-value type whose undotted length this duration is.

Returns None for a length that is not a plain note value, such as a dotted or tuplet duration.

Source

pub fn quarter_length(&self) -> FloatType

Returns the duration in quarter lengths.

Source

pub fn set_quarter_length(&mut self, quarter_length: FloatType) -> Result<()>

Updates the duration in quarter lengths.

Trait Implementations§

Source§

impl Clone for Duration

Source§

fn clone(&self) -> Duration

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Duration

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Duration

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Duration

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Duration> for Rest

Source§

fn from(value: Duration) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Duration

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Duration

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<f64> for Duration

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: FloatType) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<i32> for Duration

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: IntegerType) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.