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
impl Duration
Sourcepub fn new(quarter_length: FloatType) -> Result<Self>
pub fn new(quarter_length: FloatType) -> Result<Self>
Creates a duration from a quarter-length value.
Sourcepub fn from_type(duration_type: DurationType) -> Self
pub fn from_type(duration_type: DurationType) -> Self
Creates a duration from a note-value type.
Sourcepub fn from_type_with_dots(duration_type: DurationType, dots: u32) -> Self
pub fn from_type_with_dots(duration_type: DurationType, dots: u32) -> Self
Creates a duration from a note-value type carrying augmentation dots.
Sourcepub fn type_and_dots(&self) -> Option<(DurationType, u32)>
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.
Sourcepub fn dots(&self) -> u32
pub fn dots(&self) -> u32
Returns the augmentation dots on this duration, or 0 when it is not
a single dotted note value.
Sourcepub fn ordinal(&self) -> Option<usize>
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.
Sourcepub fn augment_or_diminish(&self, factor: FloatType) -> Result<Duration>
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.
Sourcepub fn tuplet(&self) -> Option<Tuplet>
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.
Sourcepub fn tuplets(&self) -> Vec<Tuplet>
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.
Sourcepub fn aggregate_tuplet_multiplier(&self) -> FractionType
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.
Sourcepub fn quarter_length_no_tuplets(&self) -> FloatType
pub fn quarter_length_no_tuplets(&self) -> FloatType
The total of the written values, before any tuplet shortens them:
music21’s quarterLengthNoTuplets.
Sourcepub fn set_tuplets(&mut self, tuplets: Vec<Tuplet>)
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.
Sourcepub fn append_tuplet(&mut self, tuplet: Tuplet)
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.
Sourcepub fn components(&self) -> Vec<(DurationType, u32)>
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.
Sourcepub fn is_complex(&self) -> bool
pub fn is_complex(&self) -> bool
Whether the length needs more than one written value, tied: music21’s
isComplex.
Sourcepub fn dot_groups(&self) -> Vec<u32>
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.
Sourcepub fn clear(&mut self)
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.
Sourcepub fn add_duration_tuple(&mut self, duration_type: DurationType, dots: u32)
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.
Sourcepub fn component_index_at_qtr_position(
&self,
position: FloatType,
) -> Result<usize>
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.
Sourcepub fn component_start_time(&self, index: usize) -> Result<FloatType>
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.
Sourcepub fn full_name(&self) -> String
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.
Sourcepub fn duration_type(&self) -> Option<DurationType>
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.
Sourcepub fn quarter_length(&self) -> FloatType
pub fn quarter_length(&self) -> FloatType
Returns the duration in quarter lengths.
Sourcepub fn set_quarter_length(&mut self, quarter_length: FloatType) -> Result<()>
pub fn set_quarter_length(&mut self, quarter_length: FloatType) -> Result<()>
Updates the duration in quarter lengths.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Duration
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Duration
serde only.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>,
Auto Trait Implementations§
impl Freeze for Duration
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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