pub struct Monzo { /* private fields */ }Expand description
An interval written as the exponents of the primes making up its ratio.
The entries are positional over PRIMES, so [-4 4 -1⟩ is
2^-4 * 3^4 * 5^-1, the syntonic comma. Multiplying two intervals adds
their monzos, which is the whole reason for writing intervals this way.
use music21_rs::tuningsystem::Monzo;
let comma = Monzo::from_ratio(81, 80)?;
assert_eq!(comma.exponents(), [-4, 4, -1]);
assert_eq!(comma.limit(), Some(5));
assert_eq!(comma.to_string(), "[-4 4 -1⟩");Implementations§
Source§impl Monzo
impl Monzo
Sourcepub fn new(exponents: impl Into<Vec<IntegerType>>) -> Self
pub fn new(exponents: impl Into<Vec<IntegerType>>) -> Self
Builds a monzo from prime exponents, lowest prime first.
Sourcepub fn from_ratio(
numerator: IntegerType,
denominator: IntegerType,
) -> Result<Self>
pub fn from_ratio( numerator: IntegerType, denominator: IntegerType, ) -> Result<Self>
Factors a ratio into prime exponents.
Errors on a ratio that is not positive, or one carrying a prime factor
larger than PRIMES reaches.
Sourcepub fn from_fraction(ratio: FractionType) -> Result<Self>
pub fn from_fraction(ratio: FractionType) -> Result<Self>
Factors a FractionType into prime exponents.
Sourcepub fn exponents(&self) -> &[IntegerType] ⓘ
pub fn exponents(&self) -> &[IntegerType] ⓘ
The prime exponents, lowest prime first, without trailing zeros.
Sourcepub fn exponent_of(&self, prime: IntegerType) -> Result<IntegerType>
pub fn exponent_of(&self, prime: IntegerType) -> Result<IntegerType>
The exponent of prime, which is nought for a prime not written.
Errors only for a number that is not a prime this module carries.
Sourcepub fn limit(&self) -> Option<IntegerType>
pub fn limit(&self) -> Option<IntegerType>
The largest prime the monzo actually uses, or None for the unison.
Sourcepub fn ratio(&self) -> Result<FractionType>
pub fn ratio(&self) -> Result<FractionType>
The ratio the exponents multiply out to.
Errors when the ratio does not fit an IntegerType, which a stack of
any size will reach — [-4 4 -1⟩ is 81/80, but twelve of them are not
a fraction of two i32s.
Sourcepub fn multiply(&self, other: &Self) -> Self
pub fn multiply(&self, other: &Self) -> Self
The interval reached by sounding both, which adds the exponents.
Sourcepub fn pow(&self, count: IntegerType) -> Self
pub fn pow(&self, count: IntegerType) -> Self
The interval stacked count times.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Monzo
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Monzo
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>,
impl Eq for Monzo
Source§impl Ord for Monzo
impl Ord for Monzo
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Monzo
impl PartialOrd for Monzo
impl StructuralPartialEq for Monzo
Auto Trait Implementations§
impl Freeze for Monzo
impl RefUnwindSafe for Monzo
impl Send for Monzo
impl Sync for Monzo
impl Unpin for Monzo
impl UnsafeUnpin for Monzo
impl UnwindSafe for Monzo
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