Skip to main content

TimeSignature

Struct TimeSignature 

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

A time signature, such as 4/4 or 6/8.

use music21_rs::TimeSignature;

let six_eight = TimeSignature::from_ratio_string("6/8")?;
assert_eq!(six_eight.beat_count(), 2);
assert_eq!(six_eight.beat_quarter_length(), 1.5);
assert_eq!(six_eight.classification(), "Compound Duple");

Implementations§

Source§

impl TimeSignature

Source

pub fn new( numerator: UnsignedIntegerType, denominator: UnsignedIntegerType, ) -> Result<Self>

Creates a time signature from a numerator and denominator.

Both must be non-zero. The denominator need not be a power of two — music21 accepts irrational meters such as 4/3, and so does this.

Source

pub fn from_ratio_string(ratio: &str) -> Result<Self>

Parses a "numerator/denominator" string such as "6/8".

Source

pub fn common() -> Self

Returns common time, 4/4.

Source

pub fn cut() -> Self

Returns cut time, 2/2.

Source

pub fn numerator(self) -> UnsignedIntegerType

Returns the numerator.

Source

pub fn denominator(self) -> UnsignedIntegerType

Returns the denominator.

Source

pub fn ratio_string(self) -> String

Returns the "numerator/denominator" spelling.

Source

pub fn bar_quarter_length(self) -> FloatType

Returns the length of one bar in quarter lengths.

Source

pub fn bar_duration(self) -> Duration

Returns the length of one bar as a Duration.

Source

pub fn beat_count(self) -> UnsignedIntegerType

Returns how many beats one bar carries.

This is music21’s beatCount, which follows the numerator rather than the denominator — except at 3, where 3/4 is three beats but 3/8 is one.

Source

pub fn beat_count_name(self) -> String

Returns music21’s name for the beat count, such as "Duple".

Counts above eight are spelled as "<n>-uple", as music21 does.

Source

pub fn beat_quarter_length(self) -> FloatType

Returns the length of one beat in quarter lengths.

Every meter this type can express has a uniform beat, so unlike music21’s beatDuration this never fails. music21 only reports a non-uniform beat for a hand-partitioned MeterSequence, which has no counterpart here.

Source

pub fn beat_duration(self) -> Duration

Returns the length of one beat as a Duration.

Source

pub fn beat_division(self) -> BeatDivision

Returns how the beat subdivides.

Source

pub fn beat_division_count(self) -> UnsignedIntegerType

Returns the number of divisions in one beat.

Source

pub fn is_compound(self) -> bool

Returns true when beats divide in three.

Source

pub fn classification(self) -> String

Returns music21’s classification, such as "Compound Duple".

Source

pub fn beat_offsets(self) -> Vec<FloatType>

Returns the quarter-length offset of each beat within one bar.

Source

pub fn beat_at_offset(self, offset: FloatType) -> Result<UnsignedIntegerType>

Returns the one-based beat containing offset quarter lengths into a bar.

Matches music21’s getBeat. Offsets at or beyond the end of the bar are rejected rather than wrapping.

Trait Implementations§

Source§

impl Clone for TimeSignature

Source§

fn clone(&self) -> TimeSignature

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 Copy for TimeSignature

Source§

impl Debug for TimeSignature

Source§

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

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

impl Default for TimeSignature

Source§

fn default() -> Self

Returns 4/4, matching music21’s default TimeSignature().

Source§

impl Display for TimeSignature

Source§

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

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

impl Eq for TimeSignature

Source§

impl Hash for TimeSignature

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TimeSignature

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TimeSignature

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.